blob: c264effd00a69f97654e9a53959414321ea01668 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010062 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
63 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
64 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
65 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
66 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010068 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010069#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300212static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc902008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200391 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200398 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200399 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200400 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200401 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500402 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400403};
404
Johannes Berge31b8212010-10-05 19:39:30 +0200405/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000406static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200407 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 [NL80211_KEY_IDX] = { .type = NLA_U8 },
409 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200410 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200411 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
412 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200413 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100414 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
415};
416
417/* policy for the key default flags */
418static const struct nla_policy
419nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
420 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200422};
423
Johannes Bergff1b6e62011-05-04 15:37:28 +0200424/* policy for WoWLAN attributes */
425static const struct nla_policy
426nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
427 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200431 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100435 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300436 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100437};
438
439static const struct nla_policy
440nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
441 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
442 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
443 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
444 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
445 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
448 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
449 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
451 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
452 },
453 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
454 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
455 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200456};
457
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700458/* policy for coalesce rule attributes */
459static const struct nla_policy
460nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
461 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
462 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
463 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
464};
465
Johannes Berge5497d72011-07-05 16:35:40 +0200466/* policy for GTK rekey offload attributes */
467static const struct nla_policy
468nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
469 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
470 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
471 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
472};
473
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474static const struct nla_policy
475nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200476 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300477 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700478 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300479};
480
Johannes Berg97990a02013-04-19 01:02:55 +0200481static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
482 struct netlink_callback *cb,
483 struct cfg80211_registered_device **rdev,
484 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 int err;
487
Johannes Berg67748892010-10-04 21:14:06 +0200488 rtnl_lock();
489
Johannes Berg97990a02013-04-19 01:02:55 +0200490 if (!cb->args[0]) {
491 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
492 nl80211_fam.attrbuf, nl80211_fam.maxattr,
493 nl80211_policy);
494 if (err)
495 goto out_unlock;
496
497 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
498 nl80211_fam.attrbuf);
499 if (IS_ERR(*wdev)) {
500 err = PTR_ERR(*wdev);
501 goto out_unlock;
502 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800503 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200504 /* 0 is the first index - add 1 to parse only once */
505 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200506 cb->args[1] = (*wdev)->identifier;
507 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200508 /* subtract the 1 again here */
509 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200510 struct wireless_dev *tmp;
511
512 if (!wiphy) {
513 err = -ENODEV;
514 goto out_unlock;
515 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800516 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200517 *wdev = NULL;
518
Johannes Berg97990a02013-04-19 01:02:55 +0200519 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
520 if (tmp->identifier == cb->args[1]) {
521 *wdev = tmp;
522 break;
523 }
524 }
Johannes Berg97990a02013-04-19 01:02:55 +0200525
526 if (!*wdev) {
527 err = -ENODEV;
528 goto out_unlock;
529 }
Johannes Berg67748892010-10-04 21:14:06 +0200530 }
531
Johannes Berg67748892010-10-04 21:14:06 +0200532 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200533 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200534 rtnl_unlock();
535 return err;
536}
537
Johannes Berg97990a02013-04-19 01:02:55 +0200538static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200539{
Johannes Berg67748892010-10-04 21:14:06 +0200540 rtnl_unlock();
541}
542
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100543/* IE validation */
544static bool is_valid_ie_attr(const struct nlattr *attr)
545{
546 const u8 *pos;
547 int len;
548
549 if (!attr)
550 return true;
551
552 pos = nla_data(attr);
553 len = nla_len(attr);
554
555 while (len) {
556 u8 elemlen;
557
558 if (len < 2)
559 return false;
560 len -= 2;
561
562 elemlen = pos[1];
563 if (elemlen > len)
564 return false;
565
566 len -= elemlen;
567 pos += 2 + elemlen;
568 }
569
570 return true;
571}
572
Johannes Berg55682962007-09-20 13:09:35 -0400573/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000574static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400575 int flags, u8 cmd)
576{
577 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000578 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400579}
580
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100582 struct ieee80211_channel *chan,
583 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400584{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200585 /* Some channels must be completely excluded from the
586 * list to protect old user-space tools from breaking
587 */
588 if (!large && chan->flags &
589 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
590 return 0;
591
David S. Miller9360ffd2012-03-29 04:41:26 -0400592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
593 chan->center_freq))
594 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400595
David S. Miller9360ffd2012-03-29 04:41:26 -0400596 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
597 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
598 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200599 if (chan->flags & IEEE80211_CHAN_NO_IR) {
600 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
601 goto nla_put_failure;
602 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
603 goto nla_put_failure;
604 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100605 if (chan->flags & IEEE80211_CHAN_RADAR) {
606 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
607 goto nla_put_failure;
608 if (large) {
609 u32 time;
610
611 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
612
613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
614 chan->dfs_state))
615 goto nla_put_failure;
616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
617 time))
618 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100619 if (nla_put_u32(msg,
620 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
621 chan->dfs_cac_ms))
622 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100623 }
624 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400625
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100626 if (large) {
627 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
638 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200639 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
641 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300642 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200644 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200645 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
646 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
647 goto nla_put_failure;
648 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
649 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
650 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100651 }
652
David S. Miller9360ffd2012-03-29 04:41:26 -0400653 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
654 DBM_TO_MBM(chan->max_power)))
655 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400656
657 return 0;
658
659 nla_put_failure:
660 return -ENOBUFS;
661}
662
Johannes Berg55682962007-09-20 13:09:35 -0400663/* netlink command implementations */
664
Johannes Bergb9454e82009-07-08 13:29:08 +0200665struct key_parse {
666 struct key_params p;
667 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200668 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200669 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200671};
672
673static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
674{
675 struct nlattr *tb[NL80211_KEY_MAX + 1];
676 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
677 nl80211_key_policy);
678 if (err)
679 return err;
680
681 k->def = !!tb[NL80211_KEY_DEFAULT];
682 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
683
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100684 if (k->def) {
685 k->def_uni = true;
686 k->def_multi = true;
687 }
688 if (k->defmgmt)
689 k->def_multi = true;
690
Johannes Bergb9454e82009-07-08 13:29:08 +0200691 if (tb[NL80211_KEY_IDX])
692 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
693
694 if (tb[NL80211_KEY_DATA]) {
695 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
696 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
697 }
698
699 if (tb[NL80211_KEY_SEQ]) {
700 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
701 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
702 }
703
704 if (tb[NL80211_KEY_CIPHER])
705 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
706
Johannes Berge31b8212010-10-05 19:39:30 +0200707 if (tb[NL80211_KEY_TYPE]) {
708 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
709 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
710 return -EINVAL;
711 }
712
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100713 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
714 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100715 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
716 tb[NL80211_KEY_DEFAULT_TYPES],
717 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100718 if (err)
719 return err;
720
721 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
722 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 return 0;
726}
727
728static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
729{
730 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
731 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
732 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
733 }
734
735 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
736 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
737 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
738 }
739
740 if (info->attrs[NL80211_ATTR_KEY_IDX])
741 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
742
743 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
744 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
745
746 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
747 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
748
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100749 if (k->def) {
750 k->def_uni = true;
751 k->def_multi = true;
752 }
753 if (k->defmgmt)
754 k->def_multi = true;
755
Johannes Berge31b8212010-10-05 19:39:30 +0200756 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
757 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
758 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
759 return -EINVAL;
760 }
761
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100762 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
763 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
764 int err = nla_parse_nested(
765 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
766 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
767 nl80211_key_default_policy);
768 if (err)
769 return err;
770
771 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
772 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
773 }
774
Johannes Bergb9454e82009-07-08 13:29:08 +0200775 return 0;
776}
777
778static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
779{
780 int err;
781
782 memset(k, 0, sizeof(*k));
783 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200784 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200785
786 if (info->attrs[NL80211_ATTR_KEY])
787 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
788 else
789 err = nl80211_parse_key_old(info, k);
790
791 if (err)
792 return err;
793
794 if (k->def && k->defmgmt)
795 return -EINVAL;
796
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100797 if (k->defmgmt) {
798 if (k->def_uni || !k->def_multi)
799 return -EINVAL;
800 }
801
Johannes Bergb9454e82009-07-08 13:29:08 +0200802 if (k->idx != -1) {
803 if (k->defmgmt) {
804 if (k->idx < 4 || k->idx > 5)
805 return -EINVAL;
806 } else if (k->def) {
807 if (k->idx < 0 || k->idx > 3)
808 return -EINVAL;
809 } else {
810 if (k->idx < 0 || k->idx > 5)
811 return -EINVAL;
812 }
813 }
814
815 return 0;
816}
817
Johannes Bergfffd0932009-07-08 14:22:54 +0200818static struct cfg80211_cached_keys *
819nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530820 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200821{
822 struct key_parse parse;
823 struct nlattr *key;
824 struct cfg80211_cached_keys *result;
825 int rem, err, def = 0;
826
827 result = kzalloc(sizeof(*result), GFP_KERNEL);
828 if (!result)
829 return ERR_PTR(-ENOMEM);
830
831 result->def = -1;
832 result->defmgmt = -1;
833
834 nla_for_each_nested(key, keys, rem) {
835 memset(&parse, 0, sizeof(parse));
836 parse.idx = -1;
837
838 err = nl80211_parse_key_new(key, &parse);
839 if (err)
840 goto error;
841 err = -EINVAL;
842 if (!parse.p.key)
843 goto error;
844 if (parse.idx < 0 || parse.idx > 4)
845 goto error;
846 if (parse.def) {
847 if (def)
848 goto error;
849 def = 1;
850 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100851 if (!parse.def_uni || !parse.def_multi)
852 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200853 } else if (parse.defmgmt)
854 goto error;
855 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200856 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200857 if (err)
858 goto error;
859 result->params[parse.idx].cipher = parse.p.cipher;
860 result->params[parse.idx].key_len = parse.p.key_len;
861 result->params[parse.idx].key = result->data[parse.idx];
862 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530863
864 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
865 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
866 if (no_ht)
867 *no_ht = true;
868 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200869 }
870
871 return result;
872 error:
873 kfree(result);
874 return ERR_PTR(err);
875}
876
877static int nl80211_key_allowed(struct wireless_dev *wdev)
878{
879 ASSERT_WDEV_LOCK(wdev);
880
Johannes Bergfffd0932009-07-08 14:22:54 +0200881 switch (wdev->iftype) {
882 case NL80211_IFTYPE_AP:
883 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200884 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700885 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200886 break;
887 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200889 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200890 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200891 return -ENOLINK;
892 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100893 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100894 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100895 case NL80211_IFTYPE_MONITOR:
896 case NL80211_IFTYPE_P2P_DEVICE:
897 case NL80211_IFTYPE_WDS:
898 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200899 return -EINVAL;
900 }
901
902 return 0;
903}
904
Jouni Malinen664834d2014-01-15 00:01:44 +0200905static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
906 struct nlattr *tb)
907{
908 struct ieee80211_channel *chan;
909
910 if (tb == NULL)
911 return NULL;
912 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
913 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
914 return NULL;
915 return chan;
916}
917
Johannes Berg7527a782011-05-13 10:58:57 +0200918static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
919{
920 struct nlattr *nl_modes = nla_nest_start(msg, attr);
921 int i;
922
923 if (!nl_modes)
924 goto nla_put_failure;
925
926 i = 0;
927 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400928 if ((ifmodes & 1) && nla_put_flag(msg, i))
929 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200930 ifmodes >>= 1;
931 i++;
932 }
933
934 nla_nest_end(msg, nl_modes);
935 return 0;
936
937nla_put_failure:
938 return -ENOBUFS;
939}
940
941static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100942 struct sk_buff *msg,
943 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200944{
945 struct nlattr *nl_combis;
946 int i, j;
947
948 nl_combis = nla_nest_start(msg,
949 NL80211_ATTR_INTERFACE_COMBINATIONS);
950 if (!nl_combis)
951 goto nla_put_failure;
952
953 for (i = 0; i < wiphy->n_iface_combinations; i++) {
954 const struct ieee80211_iface_combination *c;
955 struct nlattr *nl_combi, *nl_limits;
956
957 c = &wiphy->iface_combinations[i];
958
959 nl_combi = nla_nest_start(msg, i + 1);
960 if (!nl_combi)
961 goto nla_put_failure;
962
963 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
964 if (!nl_limits)
965 goto nla_put_failure;
966
967 for (j = 0; j < c->n_limits; j++) {
968 struct nlattr *nl_limit;
969
970 nl_limit = nla_nest_start(msg, j + 1);
971 if (!nl_limit)
972 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
974 c->limits[j].max))
975 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200976 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
977 c->limits[j].types))
978 goto nla_put_failure;
979 nla_nest_end(msg, nl_limit);
980 }
981
982 nla_nest_end(msg, nl_limits);
983
David S. Miller9360ffd2012-03-29 04:41:26 -0400984 if (c->beacon_int_infra_match &&
985 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
986 goto nla_put_failure;
987 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
988 c->num_different_channels) ||
989 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
990 c->max_interfaces))
991 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100992 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200993 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
994 c->radar_detect_widths) ||
995 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
996 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100997 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200998
999 nla_nest_end(msg, nl_combi);
1000 }
1001
1002 nla_nest_end(msg, nl_combis);
1003
1004 return 0;
1005nla_put_failure:
1006 return -ENOBUFS;
1007}
1008
Johannes Berg3713b4e2013-02-14 16:19:38 +01001009#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001010static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1011 struct sk_buff *msg)
1012{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001014 struct nlattr *nl_tcp;
1015
1016 if (!tcp)
1017 return 0;
1018
1019 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1020 if (!nl_tcp)
1021 return -ENOBUFS;
1022
1023 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1024 tcp->data_payload_max))
1025 return -ENOBUFS;
1026
1027 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1028 tcp->data_payload_max))
1029 return -ENOBUFS;
1030
1031 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1032 return -ENOBUFS;
1033
1034 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1035 sizeof(*tcp->tok), tcp->tok))
1036 return -ENOBUFS;
1037
1038 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1039 tcp->data_interval_max))
1040 return -ENOBUFS;
1041
1042 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1043 tcp->wake_payload_max))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_tcp);
1047 return 0;
1048}
1049
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001052 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053{
1054 struct nlattr *nl_wowlan;
1055
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 return 0;
1058
1059 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1060 if (!nl_wowlan)
1061 return -ENOBUFS;
1062
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001066 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001069 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001073 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1079 return -ENOBUFS;
1080
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001082 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001083 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1084 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1085 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1086 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 };
1088
1089 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1090 sizeof(pat), &pat))
1091 return -ENOBUFS;
1092 }
1093
Luciano Coelho75453cc2015-01-09 14:06:37 +02001094 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1095 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1096 rdev->wiphy.wowlan->max_nd_match_sets))
1097 return -ENOBUFS;
1098
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001099 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001100 return -ENOBUFS;
1101
Johannes Berg3713b4e2013-02-14 16:19:38 +01001102 nla_nest_end(msg, nl_wowlan);
1103
1104 return 0;
1105}
1106#endif
1107
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001108static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001109 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001110{
1111 struct nl80211_coalesce_rule_support rule;
1112
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001113 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001114 return 0;
1115
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001116 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1117 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1118 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1119 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1120 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1121 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001122
1123 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1124 return -ENOBUFS;
1125
1126 return 0;
1127}
1128
Johannes Berg3713b4e2013-02-14 16:19:38 +01001129static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1130 struct ieee80211_supported_band *sband)
1131{
1132 struct nlattr *nl_rates, *nl_rate;
1133 struct ieee80211_rate *rate;
1134 int i;
1135
1136 /* add HT info */
1137 if (sband->ht_cap.ht_supported &&
1138 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1139 sizeof(sband->ht_cap.mcs),
1140 &sband->ht_cap.mcs) ||
1141 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1142 sband->ht_cap.cap) ||
1143 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1144 sband->ht_cap.ampdu_factor) ||
1145 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1146 sband->ht_cap.ampdu_density)))
1147 return -ENOBUFS;
1148
1149 /* add VHT info */
1150 if (sband->vht_cap.vht_supported &&
1151 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1152 sizeof(sband->vht_cap.vht_mcs),
1153 &sband->vht_cap.vht_mcs) ||
1154 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1155 sband->vht_cap.cap)))
1156 return -ENOBUFS;
1157
1158 /* add bitrates */
1159 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1160 if (!nl_rates)
1161 return -ENOBUFS;
1162
1163 for (i = 0; i < sband->n_bitrates; i++) {
1164 nl_rate = nla_nest_start(msg, i);
1165 if (!nl_rate)
1166 return -ENOBUFS;
1167
1168 rate = &sband->bitrates[i];
1169 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1170 rate->bitrate))
1171 return -ENOBUFS;
1172 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1173 nla_put_flag(msg,
1174 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1175 return -ENOBUFS;
1176
1177 nla_nest_end(msg, nl_rate);
1178 }
1179
1180 nla_nest_end(msg, nl_rates);
1181
1182 return 0;
1183}
1184
1185static int
1186nl80211_send_mgmt_stypes(struct sk_buff *msg,
1187 const struct ieee80211_txrx_stypes *mgmt_stypes)
1188{
1189 u16 stypes;
1190 struct nlattr *nl_ftypes, *nl_ifs;
1191 enum nl80211_iftype ift;
1192 int i;
1193
1194 if (!mgmt_stypes)
1195 return 0;
1196
1197 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1198 if (!nl_ifs)
1199 return -ENOBUFS;
1200
1201 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1202 nl_ftypes = nla_nest_start(msg, ift);
1203 if (!nl_ftypes)
1204 return -ENOBUFS;
1205 i = 0;
1206 stypes = mgmt_stypes[ift].tx;
1207 while (stypes) {
1208 if ((stypes & 1) &&
1209 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1210 (i << 4) | IEEE80211_FTYPE_MGMT))
1211 return -ENOBUFS;
1212 stypes >>= 1;
1213 i++;
1214 }
1215 nla_nest_end(msg, nl_ftypes);
1216 }
1217
1218 nla_nest_end(msg, nl_ifs);
1219
1220 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1221 if (!nl_ifs)
1222 return -ENOBUFS;
1223
1224 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1225 nl_ftypes = nla_nest_start(msg, ift);
1226 if (!nl_ftypes)
1227 return -ENOBUFS;
1228 i = 0;
1229 stypes = mgmt_stypes[ift].rx;
1230 while (stypes) {
1231 if ((stypes & 1) &&
1232 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1233 (i << 4) | IEEE80211_FTYPE_MGMT))
1234 return -ENOBUFS;
1235 stypes >>= 1;
1236 i++;
1237 }
1238 nla_nest_end(msg, nl_ftypes);
1239 }
1240 nla_nest_end(msg, nl_ifs);
1241
1242 return 0;
1243}
1244
Johannes Berg86e8cf92013-06-19 10:57:22 +02001245struct nl80211_dump_wiphy_state {
1246 s64 filter_wiphy;
1247 long start;
1248 long split_start, band_start, chan_start;
1249 bool split;
1250};
1251
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001252static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001253 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001254 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001255 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001256{
1257 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001258 struct nlattr *nl_bands, *nl_band;
1259 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001260 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001261 enum ieee80211_band band;
1262 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001263 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001264 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001266 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001267
Johannes Berg3bb20552014-05-26 13:52:25 +02001268 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001269 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 return -ENOBUFS;
1271
Johannes Berg86e8cf92013-06-19 10:57:22 +02001272 if (WARN_ON(!state))
1273 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001274
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001278 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001280 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001281
Johannes Berg3bb20552014-05-26 13:52:25 +02001282 if (cmd != NL80211_CMD_NEW_WIPHY)
1283 goto finish;
1284
Johannes Berg86e8cf92013-06-19 10:57:22 +02001285 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 case 0:
1287 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001307 goto nla_put_failure;
1308
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1311 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001312 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1314 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1317 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001318 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1320 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1323 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001326 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 state->split_start++;
1328 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 break;
1330 case 1:
1331 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1333 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001334 goto nla_put_failure;
1335
Johannes Berg3713b4e2013-02-14 16:19:38 +01001336 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001338 goto nla_put_failure;
1339
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1342 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001343
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001347 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001349
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001350 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001354
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 if ((rdev->wiphy.available_antennas_tx ||
1356 rdev->wiphy.available_antennas_rx) &&
1357 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 u32 tx_ant = 0, rx_ant = 0;
1359 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001360 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 if (!res) {
1362 if (nla_put_u32(msg,
1363 NL80211_ATTR_WIPHY_ANTENNA_TX,
1364 tx_ant) ||
1365 nla_put_u32(msg,
1366 NL80211_ATTR_WIPHY_ANTENNA_RX,
1367 rx_ant))
1368 goto nla_put_failure;
1369 }
Johannes Bergee688b002008-01-24 19:38:39 +01001370 }
1371
Johannes Berg86e8cf92013-06-19 10:57:22 +02001372 state->split_start++;
1373 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 break;
1375 case 2:
1376 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001377 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 state->split_start++;
1380 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 break;
1382 case 3:
1383 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1384 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001385 goto nla_put_failure;
1386
Johannes Berg86e8cf92013-06-19 10:57:22 +02001387 for (band = state->band_start;
1388 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 struct ieee80211_supported_band *sband;
1390
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001391 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392
1393 if (!sband)
1394 continue;
1395
1396 nl_band = nla_nest_start(msg, band);
1397 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001398 goto nla_put_failure;
1399
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001401 case 0:
1402 if (nl80211_send_band_rateinfo(msg, sband))
1403 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->chan_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 default:
1408 /* add frequencies */
1409 nl_freqs = nla_nest_start(
1410 msg, NL80211_BAND_ATTR_FREQS);
1411 if (!nl_freqs)
1412 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001413
Johannes Berg86e8cf92013-06-19 10:57:22 +02001414 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 i < sband->n_channels;
1416 i++) {
1417 nl_freq = nla_nest_start(msg, i);
1418 if (!nl_freq)
1419 goto nla_put_failure;
1420
1421 chan = &sband->channels[i];
1422
Johannes Berg86e8cf92013-06-19 10:57:22 +02001423 if (nl80211_msg_put_channel(
1424 msg, chan,
1425 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 goto nla_put_failure;
1427
1428 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 break;
1431 }
1432 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001433 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 nla_nest_end(msg, nl_freqs);
1437 }
1438
1439 nla_nest_end(msg, nl_band);
1440
Johannes Berg86e8cf92013-06-19 10:57:22 +02001441 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001443 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 band--;
1445 break;
1446 }
Johannes Bergee688b002008-01-24 19:38:39 +01001447 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001449
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001451 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001453 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001454
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001456 if (state->band_start == 0 && state->chan_start == 0)
1457 state->split_start++;
1458 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 break;
1460 case 4:
1461 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1462 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001463 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464
1465 i = 0;
1466#define CMD(op, n) \
1467 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 i++; \
1470 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1471 goto nla_put_failure; \
1472 } \
1473 } while (0)
1474
1475 CMD(add_virtual_intf, NEW_INTERFACE);
1476 CMD(change_virtual_intf, SET_INTERFACE);
1477 CMD(add_key, NEW_KEY);
1478 CMD(start_ap, START_AP);
1479 CMD(add_station, NEW_STATION);
1480 CMD(add_mpath, NEW_MPATH);
1481 CMD(update_mesh_config, SET_MESH_CONFIG);
1482 CMD(change_bss, SET_BSS);
1483 CMD(auth, AUTHENTICATE);
1484 CMD(assoc, ASSOCIATE);
1485 CMD(deauth, DEAUTHENTICATE);
1486 CMD(disassoc, DISASSOCIATE);
1487 CMD(join_ibss, JOIN_IBSS);
1488 CMD(join_mesh, JOIN_MESH);
1489 CMD(set_pmksa, SET_PMKSA);
1490 CMD(del_pmksa, DEL_PMKSA);
1491 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001492 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1494 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1495 CMD(mgmt_tx, FRAME);
1496 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 i++;
1499 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1500 goto nla_put_failure;
1501 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1503 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 i++;
1505 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1506 goto nla_put_failure;
1507 }
1508 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001509 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 CMD(tdls_mgmt, TDLS_MGMT);
1511 CMD(tdls_oper, TDLS_OPER);
1512 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 CMD(sched_scan_start, START_SCHED_SCAN);
1515 CMD(probe_client, PROBE_CLIENT);
1516 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 i++;
1519 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1520 goto nla_put_failure;
1521 }
1522 CMD(start_p2p_device, START_P2P_DEVICE);
1523 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001524#ifdef CONFIG_NL80211_TESTMODE
1525 CMD(testmode_cmd, TESTMODE);
1526#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001528 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1529 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001531 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001532 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001533 if (rdev->wiphy.features &
1534 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001535 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001536 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001537 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001538#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001539
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 i++;
1542 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001543 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001544 }
1545
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001546 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547 i++;
1548 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1549 goto nla_put_failure;
1550 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001551
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001553 state->split_start++;
1554 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555 break;
1556 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001557 if (rdev->ops->remain_on_channel &&
1558 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 nla_put_u32(msg,
1560 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001561 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001562 goto nla_put_failure;
1563
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001564 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1566 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001567
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1569 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001570 state->split_start++;
1571 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 break;
1573 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001574#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001577 state->split_start++;
1578 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 break;
1580#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582#endif
1583 case 7:
1584 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001586 goto nla_put_failure;
1587
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001589 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001591
Johannes Berg86e8cf92013-06-19 10:57:22 +02001592 state->split_start++;
1593 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 break;
1595 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 goto nla_put_failure;
1600
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001601 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001602 /*
1603 * We can only add the per-channel limit information if the
1604 * dump is split, otherwise it makes it too big. Therefore
1605 * only advertise it in that case.
1606 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001607 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001608 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1609 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 goto nla_put_failure;
1611
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1615 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 goto nla_put_failure;
1617
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001618 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1619 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001620 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 goto nla_put_failure;
1623
1624 /*
1625 * Any information below this point is only available to
1626 * applications that can deal with it being split. This
1627 * helps ensure that newly added capabilities don't break
1628 * older tools by overrunning their buffers.
1629 *
1630 * We still increment split_start so that in the split
1631 * case we'll continue with more data in the next round,
1632 * but break unconditionally so unsplit data stops here.
1633 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001634 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 break;
1636 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001638 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 rdev->wiphy.extended_capabilities_len,
1640 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001641 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 rdev->wiphy.extended_capabilities_len,
1643 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001644 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001647 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1649 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001650 goto nla_put_failure;
1651
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001652 state->split_start++;
1653 break;
1654 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001656 goto nla_put_failure;
1657
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001658 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001659 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1660 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1661 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001664 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001666 goto nla_put_failure;
1667
Johannes Bergad7e7182013-11-13 13:37:47 +01001668 state->split_start++;
1669 break;
1670 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 const struct nl80211_vendor_cmd_info *info;
1673 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001674
Johannes Berg567ffc32013-12-18 14:43:31 +01001675 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1676 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001677 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001678
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001679 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1680 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001681 if (nla_put(msg, i + 1, sizeof(*info), info))
1682 goto nla_put_failure;
1683 }
1684 nla_nest_end(msg, nested);
1685 }
1686
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001687 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001688 const struct nl80211_vendor_cmd_info *info;
1689 struct nlattr *nested;
1690
1691 nested = nla_nest_start(msg,
1692 NL80211_ATTR_VENDOR_EVENTS);
1693 if (!nested)
1694 goto nla_put_failure;
1695
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1697 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001698 if (nla_put(msg, i + 1, sizeof(*info), info))
1699 goto nla_put_failure;
1700 }
1701 nla_nest_end(msg, nested);
1702 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001703 state->split_start++;
1704 break;
1705 case 12:
1706 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1707 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1708 rdev->wiphy.max_num_csa_counters))
1709 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001710
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001711 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1712 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1713 goto nla_put_failure;
1714
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001715 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1716 sizeof(rdev->wiphy.ext_features),
1717 rdev->wiphy.ext_features))
1718 goto nla_put_failure;
1719
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001721 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001722 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001723 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001724 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001725 genlmsg_end(msg, hdr);
1726 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001727
1728 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001729 genlmsg_cancel(msg, hdr);
1730 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001731}
1732
Johannes Berg86e8cf92013-06-19 10:57:22 +02001733static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1734 struct netlink_callback *cb,
1735 struct nl80211_dump_wiphy_state *state)
1736{
1737 struct nlattr **tb = nl80211_fam.attrbuf;
1738 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1739 tb, nl80211_fam.maxattr, nl80211_policy);
1740 /* ignore parse errors for backward compatibility */
1741 if (ret)
1742 return 0;
1743
1744 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1745 if (tb[NL80211_ATTR_WIPHY])
1746 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1747 if (tb[NL80211_ATTR_WDEV])
1748 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1749 if (tb[NL80211_ATTR_IFINDEX]) {
1750 struct net_device *netdev;
1751 struct cfg80211_registered_device *rdev;
1752 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1753
Ying Xue7f2b8562014-01-15 10:23:45 +08001754 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001755 if (!netdev)
1756 return -ENODEV;
1757 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001758 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 netdev->ieee80211_ptr->wiphy);
1760 state->filter_wiphy = rdev->wiphy_idx;
1761 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762 }
1763
1764 return 0;
1765}
1766
Johannes Berg55682962007-09-20 13:09:35 -04001767static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1768{
Johannes Berg645e77d2013-03-01 14:03:49 +01001769 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001770 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001771 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001772
Johannes Berg5fe231e2013-05-08 21:45:15 +02001773 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001774 if (!state) {
1775 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001776 if (!state) {
1777 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001780 state->filter_wiphy = -1;
1781 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1782 if (ret) {
1783 kfree(state);
1784 rtnl_unlock();
1785 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001786 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001787 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 }
1789
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001790 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1791 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001792 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001793 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001794 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001795 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001796 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001797 continue;
1798 /* attempt to fit multiple wiphy data chunks into the skb */
1799 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001800 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1801 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001802 NETLINK_CB(cb->skb).portid,
1803 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 if (ret < 0) {
1806 /*
1807 * If sending the wiphy data didn't fit (ENOBUFS
1808 * or EMSGSIZE returned), this SKB is still
1809 * empty (so it's not too big because another
1810 * wiphy dataset is already in the skb) and
1811 * we've not tried to adjust the dump allocation
1812 * yet ... then adjust the alloc size to be
1813 * bigger, and return 1 but with the empty skb.
1814 * This results in an empty message being RX'ed
1815 * in userspace, but that is ignored.
1816 *
1817 * We can then retry with the larger buffer.
1818 */
1819 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001820 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001821 cb->min_dump_alloc < 4096) {
1822 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001823 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001824 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001825 return 1;
1826 }
1827 idx--;
1828 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001829 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001830 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001831 break;
Johannes Berg55682962007-09-20 13:09:35 -04001832 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001833 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001834
Johannes Berg86e8cf92013-06-19 10:57:22 +02001835 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001836
1837 return skb->len;
1838}
1839
Johannes Berg86e8cf92013-06-19 10:57:22 +02001840static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1841{
1842 kfree((void *)cb->args[0]);
1843 return 0;
1844}
1845
Johannes Berg55682962007-09-20 13:09:35 -04001846static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1847{
1848 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001850 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001851
Johannes Berg645e77d2013-03-01 14:03:49 +01001852 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001853 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001854 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001855
Johannes Berg3bb20552014-05-26 13:52:25 +02001856 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1857 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001858 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001859 nlmsg_free(msg);
1860 return -ENOBUFS;
1861 }
Johannes Berg55682962007-09-20 13:09:35 -04001862
Johannes Berg134e6372009-07-10 09:51:34 +00001863 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001864}
1865
Jouni Malinen31888482008-10-30 16:59:24 +02001866static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1867 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1868 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1869 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1870 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1871 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1872};
1873
1874static int parse_txq_params(struct nlattr *tb[],
1875 struct ieee80211_txq_params *txq_params)
1876{
Johannes Berga3304b02012-03-28 11:04:24 +02001877 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001878 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1879 !tb[NL80211_TXQ_ATTR_AIFS])
1880 return -EINVAL;
1881
Johannes Berga3304b02012-03-28 11:04:24 +02001882 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001883 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1884 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1885 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1886 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1887
Johannes Berga3304b02012-03-28 11:04:24 +02001888 if (txq_params->ac >= NL80211_NUM_ACS)
1889 return -EINVAL;
1890
Jouni Malinen31888482008-10-30 16:59:24 +02001891 return 0;
1892}
1893
Johannes Bergf444de02010-05-05 15:25:02 +02001894static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1895{
1896 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001897 * You can only set the channel explicitly for WDS interfaces,
1898 * all others have their channel managed via their respective
1899 * "establish a connection" command (connect, join, ...)
1900 *
1901 * For AP/GO and mesh mode, the channel can be set with the
1902 * channel userspace API, but is only stored and passed to the
1903 * low-level driver when the AP starts or the mesh is joined.
1904 * This is for backward compatibility, userspace can also give
1905 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001906 *
1907 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001908 * whatever else is going on, so they have their own special
1909 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001910 */
1911 return !wdev ||
1912 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001913 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001914 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1915 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001916}
1917
Johannes Berg683b6d32012-11-08 21:25:48 +01001918static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1919 struct genl_info *info,
1920 struct cfg80211_chan_def *chandef)
1921{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301922 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001923
1924 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1925 return -EINVAL;
1926
1927 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1928
1929 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001930 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1931 chandef->center_freq1 = control_freq;
1932 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001933
1934 /* Primary channel not allowed */
1935 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1936 return -EINVAL;
1937
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1939 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001940
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001941 chantype = nla_get_u32(
1942 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1943
1944 switch (chantype) {
1945 case NL80211_CHAN_NO_HT:
1946 case NL80211_CHAN_HT20:
1947 case NL80211_CHAN_HT40PLUS:
1948 case NL80211_CHAN_HT40MINUS:
1949 cfg80211_chandef_create(chandef, chandef->chan,
1950 chantype);
1951 break;
1952 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001953 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001954 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001955 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1956 chandef->width =
1957 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1958 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1959 chandef->center_freq1 =
1960 nla_get_u32(
1961 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1962 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1963 chandef->center_freq2 =
1964 nla_get_u32(
1965 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1966 }
1967
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001968 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001969 return -EINVAL;
1970
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001971 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1972 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001973 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001974
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001975 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1976 chandef->width == NL80211_CHAN_WIDTH_10) &&
1977 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1978 return -EINVAL;
1979
Johannes Berg683b6d32012-11-08 21:25:48 +01001980 return 0;
1981}
1982
Johannes Bergf444de02010-05-05 15:25:02 +02001983static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001984 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001985 struct genl_info *info)
1986{
Johannes Berg683b6d32012-11-08 21:25:48 +01001987 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001988 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001989 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001990 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001991
Jouni Malinene16821b2014-04-28 11:22:08 +03001992 if (dev)
1993 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001994 if (!nl80211_can_set_dev_channel(wdev))
1995 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001996 if (wdev)
1997 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001998
Johannes Berg683b6d32012-11-08 21:25:48 +01001999 result = nl80211_parse_chandef(rdev, info, &chandef);
2000 if (result)
2001 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002002
Johannes Berge8c9bd52012-06-06 08:18:22 +02002003 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002004 case NL80211_IFTYPE_AP:
2005 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02002006 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002007 result = -EINVAL;
2008 break;
2009 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002010 if (wdev->beacon_interval) {
2011 if (!dev || !rdev->ops->set_ap_chanwidth ||
2012 !(rdev->wiphy.features &
2013 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2014 result = -EBUSY;
2015 break;
2016 }
2017
2018 /* Only allow dynamic channel width changes */
2019 if (chandef.chan != wdev->preset_chandef.chan) {
2020 result = -EBUSY;
2021 break;
2022 }
2023 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2024 if (result)
2025 break;
2026 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002027 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002028 result = 0;
2029 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002030 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002031 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002032 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002033 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002034 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002035 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002036 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002037 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002038 }
Johannes Bergf444de02010-05-05 15:25:02 +02002039
2040 return result;
2041}
2042
2043static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2044{
Johannes Berg4c476992010-10-04 21:36:35 +02002045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2046 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002047
Jouni Malinene16821b2014-04-28 11:22:08 +03002048 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002049}
2050
Bill Jordane8347eb2010-10-01 13:54:28 -04002051static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2052{
Johannes Berg43b19952010-10-07 13:10:30 +02002053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2054 struct net_device *dev = info->user_ptr[1];
2055 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002056 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002057
2058 if (!info->attrs[NL80211_ATTR_MAC])
2059 return -EINVAL;
2060
Johannes Berg43b19952010-10-07 13:10:30 +02002061 if (netif_running(dev))
2062 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002063
Johannes Berg43b19952010-10-07 13:10:30 +02002064 if (!rdev->ops->set_wds_peer)
2065 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002066
Johannes Berg43b19952010-10-07 13:10:30 +02002067 if (wdev->iftype != NL80211_IFTYPE_WDS)
2068 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002069
2070 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002071 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002072}
2073
2074
Johannes Berg55682962007-09-20 13:09:35 -04002075static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2076{
2077 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002078 struct net_device *netdev = NULL;
2079 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002080 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002081 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002082 u32 changed;
2083 u8 retry_short = 0, retry_long = 0;
2084 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002085 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002086
Johannes Berg5fe231e2013-05-08 21:45:15 +02002087 ASSERT_RTNL();
2088
Johannes Bergf444de02010-05-05 15:25:02 +02002089 /*
2090 * Try to find the wiphy and netdev. Normally this
2091 * function shouldn't need the netdev, but this is
2092 * done for backward compatibility -- previously
2093 * setting the channel was done per wiphy, but now
2094 * it is per netdev. Previous userland like hostapd
2095 * also passed a netdev to set_wiphy, so that it is
2096 * possible to let that go to the right netdev!
2097 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002098
Johannes Bergf444de02010-05-05 15:25:02 +02002099 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2100 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2101
Ying Xue7f2b8562014-01-15 10:23:45 +08002102 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002103 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002104 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002105 else
Johannes Bergf444de02010-05-05 15:25:02 +02002106 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002107 }
2108
Johannes Bergf444de02010-05-05 15:25:02 +02002109 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002110 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2111 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002112 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002113 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002114 wdev = NULL;
2115 netdev = NULL;
2116 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002117 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002118 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002119
2120 /*
2121 * end workaround code, by now the rdev is available
2122 * and locked, and wdev may or may not be NULL.
2123 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002124
2125 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002126 result = cfg80211_dev_rename(
2127 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002128
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002129 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002130 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002131
Jouni Malinen31888482008-10-30 16:59:24 +02002132 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2133 struct ieee80211_txq_params txq_params;
2134 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2135
Ying Xue7f2b8562014-01-15 10:23:45 +08002136 if (!rdev->ops->set_txq_params)
2137 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002138
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 if (!netdev)
2140 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002141
Johannes Berg133a3ff2011-11-03 14:50:13 +01002142 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002143 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2144 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002145
Ying Xue7f2b8562014-01-15 10:23:45 +08002146 if (!netif_running(netdev))
2147 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002148
Jouni Malinen31888482008-10-30 16:59:24 +02002149 nla_for_each_nested(nl_txq_params,
2150 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2151 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002152 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2153 nla_data(nl_txq_params),
2154 nla_len(nl_txq_params),
2155 txq_params_policy);
2156 if (result)
2157 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002158 result = parse_txq_params(tb, &txq_params);
2159 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002160 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002161
Hila Gonene35e4d22012-06-27 17:19:42 +03002162 result = rdev_set_txq_params(rdev, netdev,
2163 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002164 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002165 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002166 }
2167 }
2168
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002169 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002170 result = __nl80211_set_channel(
2171 rdev,
2172 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2173 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002174 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002176 }
2177
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002178 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002179 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002180 enum nl80211_tx_power_setting type;
2181 int idx, mbm = 0;
2182
Johannes Bergc8442112012-10-24 10:17:18 +02002183 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2184 txp_wdev = NULL;
2185
Ying Xue7f2b8562014-01-15 10:23:45 +08002186 if (!rdev->ops->set_tx_power)
2187 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002188
2189 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2190 type = nla_get_u32(info->attrs[idx]);
2191
2192 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002193 (type != NL80211_TX_POWER_AUTOMATIC))
2194 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002195
2196 if (type != NL80211_TX_POWER_AUTOMATIC) {
2197 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2198 mbm = nla_get_u32(info->attrs[idx]);
2199 }
2200
Johannes Bergc8442112012-10-24 10:17:18 +02002201 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002202 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002203 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002204 }
2205
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002206 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2207 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2208 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002209 if ((!rdev->wiphy.available_antennas_tx &&
2210 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002211 !rdev->ops->set_antenna)
2212 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002213
2214 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2215 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2216
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002217 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002218 * available antenna masks, except for the "all" mask */
2219 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002220 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2221 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002222
Bruno Randolf7f531e02010-12-16 11:30:22 +09002223 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2224 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002225
Hila Gonene35e4d22012-06-27 17:19:42 +03002226 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002227 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002229 }
2230
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002231 changed = 0;
2232
2233 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2234 retry_short = nla_get_u8(
2235 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002236 if (retry_short == 0)
2237 return -EINVAL;
2238
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002239 changed |= WIPHY_PARAM_RETRY_SHORT;
2240 }
2241
2242 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2243 retry_long = nla_get_u8(
2244 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002245 if (retry_long == 0)
2246 return -EINVAL;
2247
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002248 changed |= WIPHY_PARAM_RETRY_LONG;
2249 }
2250
2251 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2252 frag_threshold = nla_get_u32(
2253 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002254 if (frag_threshold < 256)
2255 return -EINVAL;
2256
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002257 if (frag_threshold != (u32) -1) {
2258 /*
2259 * Fragments (apart from the last one) are required to
2260 * have even length. Make the fragmentation code
2261 * simpler by stripping LSB should someone try to use
2262 * odd threshold value.
2263 */
2264 frag_threshold &= ~0x1;
2265 }
2266 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2267 }
2268
2269 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2270 rts_threshold = nla_get_u32(
2271 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2272 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2273 }
2274
Lukáš Turek81077e82009-12-21 22:50:47 +01002275 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002276 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2277 return -EINVAL;
2278
Lukáš Turek81077e82009-12-21 22:50:47 +01002279 coverage_class = nla_get_u8(
2280 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2281 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2282 }
2283
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002284 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2285 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2286 return -EOPNOTSUPP;
2287
2288 changed |= WIPHY_PARAM_DYN_ACK;
2289 }
2290
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002291 if (changed) {
2292 u8 old_retry_short, old_retry_long;
2293 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002294 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002295
Ying Xue7f2b8562014-01-15 10:23:45 +08002296 if (!rdev->ops->set_wiphy_params)
2297 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002298
2299 old_retry_short = rdev->wiphy.retry_short;
2300 old_retry_long = rdev->wiphy.retry_long;
2301 old_frag_threshold = rdev->wiphy.frag_threshold;
2302 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002303 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002304
2305 if (changed & WIPHY_PARAM_RETRY_SHORT)
2306 rdev->wiphy.retry_short = retry_short;
2307 if (changed & WIPHY_PARAM_RETRY_LONG)
2308 rdev->wiphy.retry_long = retry_long;
2309 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2310 rdev->wiphy.frag_threshold = frag_threshold;
2311 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2312 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002313 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2314 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002315
Hila Gonene35e4d22012-06-27 17:19:42 +03002316 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002317 if (result) {
2318 rdev->wiphy.retry_short = old_retry_short;
2319 rdev->wiphy.retry_long = old_retry_long;
2320 rdev->wiphy.frag_threshold = old_frag_threshold;
2321 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002322 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002323 }
2324 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002325 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002326}
2327
Johannes Berg71bbc992012-06-15 15:30:18 +02002328static inline u64 wdev_id(struct wireless_dev *wdev)
2329{
2330 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002331 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002332}
Johannes Berg55682962007-09-20 13:09:35 -04002333
Johannes Berg683b6d32012-11-08 21:25:48 +01002334static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002335 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002336{
Johannes Berg601555c2014-11-27 17:26:56 +01002337 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2338 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002339
Johannes Berg683b6d32012-11-08 21:25:48 +01002340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2341 chandef->chan->center_freq))
2342 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002343 switch (chandef->width) {
2344 case NL80211_CHAN_WIDTH_20_NOHT:
2345 case NL80211_CHAN_WIDTH_20:
2346 case NL80211_CHAN_WIDTH_40:
2347 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2348 cfg80211_get_chandef_type(chandef)))
2349 return -ENOBUFS;
2350 break;
2351 default:
2352 break;
2353 }
2354 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2355 return -ENOBUFS;
2356 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2357 return -ENOBUFS;
2358 if (chandef->center_freq2 &&
2359 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002360 return -ENOBUFS;
2361 return 0;
2362}
2363
Eric W. Biederman15e47302012-09-07 20:12:54 +00002364static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002365 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002366 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002367{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002368 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002369 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002370 void *hdr;
2371
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002372 if (removal)
2373 cmd = NL80211_CMD_DEL_INTERFACE;
2374
2375 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002376 if (!hdr)
2377 return -1;
2378
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002379 if (dev &&
2380 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002381 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002382 goto nla_put_failure;
2383
2384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2385 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002386 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002387 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002388 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2389 rdev->devlist_generation ^
2390 (cfg80211_rdev_list_generation << 2)))
2391 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002392
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002393 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002394 int ret;
2395 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002396
Johannes Berg683b6d32012-11-08 21:25:48 +01002397 ret = rdev_get_channel(rdev, wdev, &chandef);
2398 if (ret == 0) {
2399 if (nl80211_send_chandef(msg, &chandef))
2400 goto nla_put_failure;
2401 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002402 }
2403
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002404 if (wdev->ssid_len) {
2405 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2406 goto nla_put_failure;
2407 }
2408
Johannes Berg053c0952015-01-16 22:09:00 +01002409 genlmsg_end(msg, hdr);
2410 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002411
2412 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002413 genlmsg_cancel(msg, hdr);
2414 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002415}
2416
2417static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2418{
2419 int wp_idx = 0;
2420 int if_idx = 0;
2421 int wp_start = cb->args[0];
2422 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002423 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002424 struct wireless_dev *wdev;
2425
Johannes Berg5fe231e2013-05-08 21:45:15 +02002426 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002427 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2428 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002429 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002430 if (wp_idx < wp_start) {
2431 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002432 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002433 }
Johannes Berg55682962007-09-20 13:09:35 -04002434 if_idx = 0;
2435
Johannes Berg89a54e42012-06-15 14:33:17 +02002436 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002437 if (if_idx < if_start) {
2438 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002439 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002440 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002441 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002442 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002443 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002444 goto out;
2445 }
2446 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002447 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002448
2449 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002450 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002451 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002452 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002453
2454 cb->args[0] = wp_idx;
2455 cb->args[1] = if_idx;
2456
2457 return skb->len;
2458}
2459
2460static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2461{
2462 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002464 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002465
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002467 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002468 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002469
Eric W. Biederman15e47302012-09-07 20:12:54 +00002470 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002471 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002472 nlmsg_free(msg);
2473 return -ENOBUFS;
2474 }
Johannes Berg55682962007-09-20 13:09:35 -04002475
Johannes Berg134e6372009-07-10 09:51:34 +00002476 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002477}
2478
Michael Wu66f7ac52008-01-31 19:48:22 +01002479static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2480 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2481 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2482 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2483 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2484 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002485 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002486};
2487
2488static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2489{
2490 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2491 int flag;
2492
2493 *mntrflags = 0;
2494
2495 if (!nla)
2496 return -EINVAL;
2497
2498 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2499 nla, mntr_flags_policy))
2500 return -EINVAL;
2501
2502 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2503 if (flags[flag])
2504 *mntrflags |= (1<<flag);
2505
2506 return 0;
2507}
2508
Johannes Berg9bc383d2009-11-19 11:55:19 +01002509static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002510 struct net_device *netdev, u8 use_4addr,
2511 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002512{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002513 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002514 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002515 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002516 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002517 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002518
2519 switch (iftype) {
2520 case NL80211_IFTYPE_AP_VLAN:
2521 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2522 return 0;
2523 break;
2524 case NL80211_IFTYPE_STATION:
2525 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2526 return 0;
2527 break;
2528 default:
2529 break;
2530 }
2531
2532 return -EOPNOTSUPP;
2533}
2534
Johannes Berg55682962007-09-20 13:09:35 -04002535static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2536{
Johannes Berg4c476992010-10-04 21:36:35 +02002537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002538 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002539 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002540 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002542 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002543 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002544
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002545 memset(&params, 0, sizeof(params));
2546
Johannes Berg04a773a2009-04-19 21:24:32 +02002547 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002548
Johannes Berg723b0382008-09-16 20:22:09 +02002549 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002550 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002551 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002552 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002553 if (ntype > NL80211_IFTYPE_MAX)
2554 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002555 }
2556
Johannes Berg92ffe052008-09-16 20:39:36 +02002557 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002558 struct wireless_dev *wdev = dev->ieee80211_ptr;
2559
Johannes Berg4c476992010-10-04 21:36:35 +02002560 if (ntype != NL80211_IFTYPE_MESH_POINT)
2561 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002562 if (netif_running(dev))
2563 return -EBUSY;
2564
2565 wdev_lock(wdev);
2566 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2567 IEEE80211_MAX_MESH_ID_LEN);
2568 wdev->mesh_id_up_len =
2569 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2570 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2571 wdev->mesh_id_up_len);
2572 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002573 }
2574
Felix Fietkau8b787642009-11-10 18:53:10 +01002575 if (info->attrs[NL80211_ATTR_4ADDR]) {
2576 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2577 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002578 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002579 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002580 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002581 } else {
2582 params.use_4addr = -1;
2583 }
2584
Johannes Berg92ffe052008-09-16 20:39:36 +02002585 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002586 if (ntype != NL80211_IFTYPE_MONITOR)
2587 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002588 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2589 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002590 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002591 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002592
2593 flags = &_flags;
2594 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002595 }
Johannes Berg3b858752009-03-12 09:55:09 +01002596
Luciano Coelho18003292013-08-29 13:26:57 +03002597 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002598 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2599 return -EOPNOTSUPP;
2600
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002601 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002602 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002603 else
2604 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002605
Johannes Berg9bc383d2009-11-19 11:55:19 +01002606 if (!err && params.use_4addr != -1)
2607 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2608
Johannes Berg55682962007-09-20 13:09:35 -04002609 return err;
2610}
2611
2612static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2613{
Johannes Berg4c476992010-10-04 21:36:35 +02002614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002615 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002616 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002617 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002618 int err;
2619 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002620 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002621
Johannes Berg78f22b62014-03-24 17:57:27 +01002622 /* to avoid failing a new interface creation due to pending removal */
2623 cfg80211_destroy_ifaces(rdev);
2624
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002625 memset(&params, 0, sizeof(params));
2626
Johannes Berg55682962007-09-20 13:09:35 -04002627 if (!info->attrs[NL80211_ATTR_IFNAME])
2628 return -EINVAL;
2629
2630 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2631 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2632 if (type > NL80211_IFTYPE_MAX)
2633 return -EINVAL;
2634 }
2635
Johannes Berg79c97e92009-07-07 03:56:12 +02002636 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002637 !(rdev->wiphy.interface_modes & (1 << type)))
2638 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002639
Ben Greeare8f479b2014-10-22 12:23:05 -07002640 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2641 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2642 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002643 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2644 ETH_ALEN);
2645 if (!is_valid_ether_addr(params.macaddr))
2646 return -EADDRNOTAVAIL;
2647 }
2648
Johannes Berg9bc383d2009-11-19 11:55:19 +01002649 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002650 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002651 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002652 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002653 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002654 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002655
Michael Wu66f7ac52008-01-31 19:48:22 +01002656 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2657 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2658 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002659
Luciano Coelho18003292013-08-29 13:26:57 +03002660 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002661 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2662 return -EOPNOTSUPP;
2663
Johannes Berga18c7192015-02-24 10:56:42 +01002664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2665 if (!msg)
2666 return -ENOMEM;
2667
Hila Gonene35e4d22012-06-27 17:19:42 +03002668 wdev = rdev_add_virtual_intf(rdev,
2669 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002670 NET_NAME_USER, type, err ? NULL : &flags,
2671 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002672 if (WARN_ON(!wdev)) {
2673 nlmsg_free(msg);
2674 return -EPROTO;
2675 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002676 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002677 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002678 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002679
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002680 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002681 wdev->owner_nlportid = info->snd_portid;
2682
Johannes Berg98104fde2012-06-16 00:19:54 +02002683 switch (type) {
2684 case NL80211_IFTYPE_MESH_POINT:
2685 if (!info->attrs[NL80211_ATTR_MESH_ID])
2686 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002687 wdev_lock(wdev);
2688 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2689 IEEE80211_MAX_MESH_ID_LEN);
2690 wdev->mesh_id_up_len =
2691 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2692 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2693 wdev->mesh_id_up_len);
2694 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002695 break;
2696 case NL80211_IFTYPE_P2P_DEVICE:
2697 /*
2698 * P2P Device doesn't have a netdev, so doesn't go
2699 * through the netdev notifier and must be added here
2700 */
2701 mutex_init(&wdev->mtx);
2702 INIT_LIST_HEAD(&wdev->event_list);
2703 spin_lock_init(&wdev->event_lock);
2704 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2705 spin_lock_init(&wdev->mgmt_registrations_lock);
2706
Johannes Berg98104fde2012-06-16 00:19:54 +02002707 wdev->identifier = ++rdev->wdev_id;
2708 list_add_rcu(&wdev->list, &rdev->wdev_list);
2709 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002710 break;
2711 default:
2712 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002713 }
2714
Eric W. Biederman15e47302012-09-07 20:12:54 +00002715 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002716 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002717 nlmsg_free(msg);
2718 return -ENOBUFS;
2719 }
2720
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002721 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2722 if (event) {
2723 if (nl80211_send_iface(event, 0, 0, 0,
2724 rdev, wdev, false) < 0) {
2725 nlmsg_free(event);
2726 goto out;
2727 }
2728
2729 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2730 event, 0, NL80211_MCGRP_CONFIG,
2731 GFP_KERNEL);
2732 }
2733
2734out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002735 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002736}
2737
2738static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2739{
Johannes Berg4c476992010-10-04 21:36:35 +02002740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002741 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002742 struct sk_buff *msg;
2743 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002744
Johannes Berg4c476992010-10-04 21:36:35 +02002745 if (!rdev->ops->del_virtual_intf)
2746 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002747
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002748 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2749 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2750 nlmsg_free(msg);
2751 msg = NULL;
2752 }
2753
Johannes Berg84efbb82012-06-16 00:00:26 +02002754 /*
2755 * If we remove a wireless device without a netdev then clear
2756 * user_ptr[1] so that nl80211_post_doit won't dereference it
2757 * to check if it needs to do dev_put(). Otherwise it crashes
2758 * since the wdev has been freed, unlike with a netdev where
2759 * we need the dev_put() for the netdev to really be freed.
2760 */
2761 if (!wdev->netdev)
2762 info->user_ptr[1] = NULL;
2763
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002764 status = rdev_del_virtual_intf(rdev, wdev);
2765 if (status >= 0 && msg)
2766 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2767 msg, 0, NL80211_MCGRP_CONFIG,
2768 GFP_KERNEL);
2769 else
2770 nlmsg_free(msg);
2771
2772 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002773}
2774
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002775static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2776{
2777 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2778 struct net_device *dev = info->user_ptr[1];
2779 u16 noack_map;
2780
2781 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2782 return -EINVAL;
2783
2784 if (!rdev->ops->set_noack_map)
2785 return -EOPNOTSUPP;
2786
2787 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2788
Hila Gonene35e4d22012-06-27 17:19:42 +03002789 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002790}
2791
Johannes Berg41ade002007-12-19 02:03:29 +01002792struct get_key_cookie {
2793 struct sk_buff *msg;
2794 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002795 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002796};
2797
2798static void get_key_callback(void *c, struct key_params *params)
2799{
Johannes Bergb9454e82009-07-08 13:29:08 +02002800 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002801 struct get_key_cookie *cookie = c;
2802
David S. Miller9360ffd2012-03-29 04:41:26 -04002803 if ((params->key &&
2804 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2805 params->key_len, params->key)) ||
2806 (params->seq &&
2807 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2808 params->seq_len, params->seq)) ||
2809 (params->cipher &&
2810 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2811 params->cipher)))
2812 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002813
Johannes Bergb9454e82009-07-08 13:29:08 +02002814 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2815 if (!key)
2816 goto nla_put_failure;
2817
David S. Miller9360ffd2012-03-29 04:41:26 -04002818 if ((params->key &&
2819 nla_put(cookie->msg, NL80211_KEY_DATA,
2820 params->key_len, params->key)) ||
2821 (params->seq &&
2822 nla_put(cookie->msg, NL80211_KEY_SEQ,
2823 params->seq_len, params->seq)) ||
2824 (params->cipher &&
2825 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2826 params->cipher)))
2827 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002828
David S. Miller9360ffd2012-03-29 04:41:26 -04002829 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2830 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002831
2832 nla_nest_end(cookie->msg, key);
2833
Johannes Berg41ade002007-12-19 02:03:29 +01002834 return;
2835 nla_put_failure:
2836 cookie->error = 1;
2837}
2838
2839static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2840{
Johannes Berg4c476992010-10-04 21:36:35 +02002841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002842 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002843 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002844 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002845 const u8 *mac_addr = NULL;
2846 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002847 struct get_key_cookie cookie = {
2848 .error = 0,
2849 };
2850 void *hdr;
2851 struct sk_buff *msg;
2852
2853 if (info->attrs[NL80211_ATTR_KEY_IDX])
2854 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2855
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002856 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002857 return -EINVAL;
2858
2859 if (info->attrs[NL80211_ATTR_MAC])
2860 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2861
Johannes Berge31b8212010-10-05 19:39:30 +02002862 pairwise = !!mac_addr;
2863 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2864 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2865 if (kt >= NUM_NL80211_KEYTYPES)
2866 return -EINVAL;
2867 if (kt != NL80211_KEYTYPE_GROUP &&
2868 kt != NL80211_KEYTYPE_PAIRWISE)
2869 return -EINVAL;
2870 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2871 }
2872
Johannes Berg4c476992010-10-04 21:36:35 +02002873 if (!rdev->ops->get_key)
2874 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002875
Johannes Berg0fa7b392015-01-23 11:10:12 +01002876 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2877 return -ENOENT;
2878
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002880 if (!msg)
2881 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002882
Eric W. Biederman15e47302012-09-07 20:12:54 +00002883 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002884 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002885 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002886 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002887
2888 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002889 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002890
David S. Miller9360ffd2012-03-29 04:41:26 -04002891 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2892 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2893 goto nla_put_failure;
2894 if (mac_addr &&
2895 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2896 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002897
Hila Gonene35e4d22012-06-27 17:19:42 +03002898 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2899 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002900
2901 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002902 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002903
2904 if (cookie.error)
2905 goto nla_put_failure;
2906
2907 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002908 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002909
2910 nla_put_failure:
2911 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002912 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002913 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return err;
2915}
2916
2917static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2918{
Johannes Berg4c476992010-10-04 21:36:35 +02002919 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002920 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002921 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002922 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002923
Johannes Bergb9454e82009-07-08 13:29:08 +02002924 err = nl80211_parse_key(info, &key);
2925 if (err)
2926 return err;
2927
2928 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002929 return -EINVAL;
2930
Johannes Bergb9454e82009-07-08 13:29:08 +02002931 /* only support setting default key */
2932 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002933 return -EINVAL;
2934
Johannes Bergfffd0932009-07-08 14:22:54 +02002935 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002936
2937 if (key.def) {
2938 if (!rdev->ops->set_default_key) {
2939 err = -EOPNOTSUPP;
2940 goto out;
2941 }
2942
2943 err = nl80211_key_allowed(dev->ieee80211_ptr);
2944 if (err)
2945 goto out;
2946
Hila Gonene35e4d22012-06-27 17:19:42 +03002947 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002948 key.def_uni, key.def_multi);
2949
2950 if (err)
2951 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002952
Johannes Berg3d23e342009-09-29 23:27:28 +02002953#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002954 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002955#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002956 } else {
2957 if (key.def_uni || !key.def_multi) {
2958 err = -EINVAL;
2959 goto out;
2960 }
2961
2962 if (!rdev->ops->set_default_mgmt_key) {
2963 err = -EOPNOTSUPP;
2964 goto out;
2965 }
2966
2967 err = nl80211_key_allowed(dev->ieee80211_ptr);
2968 if (err)
2969 goto out;
2970
Hila Gonene35e4d22012-06-27 17:19:42 +03002971 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002972 if (err)
2973 goto out;
2974
2975#ifdef CONFIG_CFG80211_WEXT
2976 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2977#endif
2978 }
2979
2980 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002981 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002982
Johannes Berg41ade002007-12-19 02:03:29 +01002983 return err;
2984}
2985
2986static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2987{
Johannes Berg4c476992010-10-04 21:36:35 +02002988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002989 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002990 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002991 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002992 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002993
Johannes Bergb9454e82009-07-08 13:29:08 +02002994 err = nl80211_parse_key(info, &key);
2995 if (err)
2996 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002997
Johannes Bergb9454e82009-07-08 13:29:08 +02002998 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002999 return -EINVAL;
3000
Johannes Berg41ade002007-12-19 02:03:29 +01003001 if (info->attrs[NL80211_ATTR_MAC])
3002 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3003
Johannes Berge31b8212010-10-05 19:39:30 +02003004 if (key.type == -1) {
3005 if (mac_addr)
3006 key.type = NL80211_KEYTYPE_PAIRWISE;
3007 else
3008 key.type = NL80211_KEYTYPE_GROUP;
3009 }
3010
3011 /* for now */
3012 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3013 key.type != NL80211_KEYTYPE_GROUP)
3014 return -EINVAL;
3015
Johannes Berg4c476992010-10-04 21:36:35 +02003016 if (!rdev->ops->add_key)
3017 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003018
Johannes Berge31b8212010-10-05 19:39:30 +02003019 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3020 key.type == NL80211_KEYTYPE_PAIRWISE,
3021 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003022 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003023
3024 wdev_lock(dev->ieee80211_ptr);
3025 err = nl80211_key_allowed(dev->ieee80211_ptr);
3026 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003027 err = rdev_add_key(rdev, dev, key.idx,
3028 key.type == NL80211_KEYTYPE_PAIRWISE,
3029 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003030 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003031
Johannes Berg41ade002007-12-19 02:03:29 +01003032 return err;
3033}
3034
3035static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3036{
Johannes Berg4c476992010-10-04 21:36:35 +02003037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003038 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003039 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003040 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003041 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003042
Johannes Bergb9454e82009-07-08 13:29:08 +02003043 err = nl80211_parse_key(info, &key);
3044 if (err)
3045 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003046
3047 if (info->attrs[NL80211_ATTR_MAC])
3048 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3049
Johannes Berge31b8212010-10-05 19:39:30 +02003050 if (key.type == -1) {
3051 if (mac_addr)
3052 key.type = NL80211_KEYTYPE_PAIRWISE;
3053 else
3054 key.type = NL80211_KEYTYPE_GROUP;
3055 }
3056
3057 /* for now */
3058 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3059 key.type != NL80211_KEYTYPE_GROUP)
3060 return -EINVAL;
3061
Johannes Berg4c476992010-10-04 21:36:35 +02003062 if (!rdev->ops->del_key)
3063 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003064
Johannes Bergfffd0932009-07-08 14:22:54 +02003065 wdev_lock(dev->ieee80211_ptr);
3066 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003067
Johannes Berg0fa7b392015-01-23 11:10:12 +01003068 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003069 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3070 err = -ENOENT;
3071
Johannes Bergfffd0932009-07-08 14:22:54 +02003072 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003073 err = rdev_del_key(rdev, dev, key.idx,
3074 key.type == NL80211_KEYTYPE_PAIRWISE,
3075 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003076
Johannes Berg3d23e342009-09-29 23:27:28 +02003077#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003078 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003079 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003080 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003081 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003082 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3083 }
3084#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003085 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003086
Johannes Berg41ade002007-12-19 02:03:29 +01003087 return err;
3088}
3089
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303090/* This function returns an error or the number of nested attributes */
3091static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3092{
3093 struct nlattr *attr;
3094 int n_entries = 0, tmp;
3095
3096 nla_for_each_nested(attr, nl_attr, tmp) {
3097 if (nla_len(attr) != ETH_ALEN)
3098 return -EINVAL;
3099
3100 n_entries++;
3101 }
3102
3103 return n_entries;
3104}
3105
3106/*
3107 * This function parses ACL information and allocates memory for ACL data.
3108 * On successful return, the calling function is responsible to free the
3109 * ACL buffer returned by this function.
3110 */
3111static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3112 struct genl_info *info)
3113{
3114 enum nl80211_acl_policy acl_policy;
3115 struct nlattr *attr;
3116 struct cfg80211_acl_data *acl;
3117 int i = 0, n_entries, tmp;
3118
3119 if (!wiphy->max_acl_mac_addrs)
3120 return ERR_PTR(-EOPNOTSUPP);
3121
3122 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3123 return ERR_PTR(-EINVAL);
3124
3125 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3126 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3127 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3128 return ERR_PTR(-EINVAL);
3129
3130 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3131 return ERR_PTR(-EINVAL);
3132
3133 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3134 if (n_entries < 0)
3135 return ERR_PTR(n_entries);
3136
3137 if (n_entries > wiphy->max_acl_mac_addrs)
3138 return ERR_PTR(-ENOTSUPP);
3139
3140 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3141 GFP_KERNEL);
3142 if (!acl)
3143 return ERR_PTR(-ENOMEM);
3144
3145 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3146 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3147 i++;
3148 }
3149
3150 acl->n_acl_entries = n_entries;
3151 acl->acl_policy = acl_policy;
3152
3153 return acl;
3154}
3155
3156static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3157{
3158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3159 struct net_device *dev = info->user_ptr[1];
3160 struct cfg80211_acl_data *acl;
3161 int err;
3162
3163 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3164 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3165 return -EOPNOTSUPP;
3166
3167 if (!dev->ieee80211_ptr->beacon_interval)
3168 return -EINVAL;
3169
3170 acl = parse_acl_data(&rdev->wiphy, info);
3171 if (IS_ERR(acl))
3172 return PTR_ERR(acl);
3173
3174 err = rdev_set_mac_acl(rdev, dev, acl);
3175
3176 kfree(acl);
3177
3178 return err;
3179}
3180
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003181static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003182 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003183{
Johannes Berg88600202012-02-13 15:17:18 +01003184 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003185
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003186 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3187 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3188 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3189 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003190 return -EINVAL;
3191
Johannes Berg88600202012-02-13 15:17:18 +01003192 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003193
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003194 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3195 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3196 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003197 if (!bcn->head_len)
3198 return -EINVAL;
3199 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003200 }
3201
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003202 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3203 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3204 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003205 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003206 }
3207
Johannes Berg4c476992010-10-04 21:36:35 +02003208 if (!haveinfo)
3209 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003210
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003211 if (attrs[NL80211_ATTR_IE]) {
3212 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3213 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003214 }
3215
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003216 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003217 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003218 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003219 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003220 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003221 }
3222
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003223 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003224 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003225 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003226 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003227 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003228 }
3229
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003230 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3231 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3232 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003233 }
3234
Johannes Berg88600202012-02-13 15:17:18 +01003235 return 0;
3236}
3237
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003238static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3239 struct cfg80211_ap_settings *params)
3240{
3241 struct wireless_dev *wdev;
3242 bool ret = false;
3243
Johannes Berg89a54e42012-06-15 14:33:17 +02003244 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003245 if (wdev->iftype != NL80211_IFTYPE_AP &&
3246 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3247 continue;
3248
Johannes Berg683b6d32012-11-08 21:25:48 +01003249 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003250 continue;
3251
Johannes Berg683b6d32012-11-08 21:25:48 +01003252 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003253 ret = true;
3254 break;
3255 }
3256
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003257 return ret;
3258}
3259
Jouni Malinene39e5b52012-09-30 19:29:39 +03003260static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3261 enum nl80211_auth_type auth_type,
3262 enum nl80211_commands cmd)
3263{
3264 if (auth_type > NL80211_AUTHTYPE_MAX)
3265 return false;
3266
3267 switch (cmd) {
3268 case NL80211_CMD_AUTHENTICATE:
3269 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3270 auth_type == NL80211_AUTHTYPE_SAE)
3271 return false;
3272 return true;
3273 case NL80211_CMD_CONNECT:
3274 case NL80211_CMD_START_AP:
3275 /* SAE not supported yet */
3276 if (auth_type == NL80211_AUTHTYPE_SAE)
3277 return false;
3278 return true;
3279 default:
3280 return false;
3281 }
3282}
3283
Johannes Berg88600202012-02-13 15:17:18 +01003284static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3285{
3286 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3287 struct net_device *dev = info->user_ptr[1];
3288 struct wireless_dev *wdev = dev->ieee80211_ptr;
3289 struct cfg80211_ap_settings params;
3290 int err;
3291
3292 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3293 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3294 return -EOPNOTSUPP;
3295
3296 if (!rdev->ops->start_ap)
3297 return -EOPNOTSUPP;
3298
3299 if (wdev->beacon_interval)
3300 return -EALREADY;
3301
3302 memset(&params, 0, sizeof(params));
3303
3304 /* these are required for START_AP */
3305 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3306 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3307 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3308 return -EINVAL;
3309
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003310 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003311 if (err)
3312 return err;
3313
3314 params.beacon_interval =
3315 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3316 params.dtim_period =
3317 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3318
3319 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3320 if (err)
3321 return err;
3322
3323 /*
3324 * In theory, some of these attributes should be required here
3325 * but since they were not used when the command was originally
3326 * added, keep them optional for old user space programs to let
3327 * them continue to work with drivers that do not need the
3328 * additional information -- drivers must check!
3329 */
3330 if (info->attrs[NL80211_ATTR_SSID]) {
3331 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3332 params.ssid_len =
3333 nla_len(info->attrs[NL80211_ATTR_SSID]);
3334 if (params.ssid_len == 0 ||
3335 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3336 return -EINVAL;
3337 }
3338
3339 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3340 params.hidden_ssid = nla_get_u32(
3341 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3342 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3343 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3344 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3345 return -EINVAL;
3346 }
3347
3348 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3349
3350 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3351 params.auth_type = nla_get_u32(
3352 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003353 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3354 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003355 return -EINVAL;
3356 } else
3357 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3358
3359 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3360 NL80211_MAX_NR_CIPHER_SUITES);
3361 if (err)
3362 return err;
3363
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303364 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3365 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3366 return -EOPNOTSUPP;
3367 params.inactivity_timeout = nla_get_u16(
3368 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3369 }
3370
Johannes Berg53cabad2012-11-14 15:17:28 +01003371 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3372 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3373 return -EINVAL;
3374 params.p2p_ctwindow =
3375 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3376 if (params.p2p_ctwindow > 127)
3377 return -EINVAL;
3378 if (params.p2p_ctwindow != 0 &&
3379 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3380 return -EINVAL;
3381 }
3382
3383 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3384 u8 tmp;
3385
3386 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3387 return -EINVAL;
3388 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3389 if (tmp > 1)
3390 return -EINVAL;
3391 params.p2p_opp_ps = tmp;
3392 if (params.p2p_opp_ps != 0 &&
3393 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3394 return -EINVAL;
3395 }
3396
Johannes Bergaa430da2012-05-16 23:50:18 +02003397 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003398 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3399 if (err)
3400 return err;
3401 } else if (wdev->preset_chandef.chan) {
3402 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003403 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003404 return -EINVAL;
3405
Ilan Peer174e0cd2014-02-23 09:13:01 +02003406 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3407 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003408 return -EINVAL;
3409
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303410 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3411 params.acl = parse_acl_data(&rdev->wiphy, info);
3412 if (IS_ERR(params.acl))
3413 return PTR_ERR(params.acl);
3414 }
3415
Eliad Peller18998c32014-09-10 14:07:34 +03003416 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3417 params.smps_mode =
3418 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3419 switch (params.smps_mode) {
3420 case NL80211_SMPS_OFF:
3421 break;
3422 case NL80211_SMPS_STATIC:
3423 if (!(rdev->wiphy.features &
3424 NL80211_FEATURE_STATIC_SMPS))
3425 return -EINVAL;
3426 break;
3427 case NL80211_SMPS_DYNAMIC:
3428 if (!(rdev->wiphy.features &
3429 NL80211_FEATURE_DYNAMIC_SMPS))
3430 return -EINVAL;
3431 break;
3432 default:
3433 return -EINVAL;
3434 }
3435 } else {
3436 params.smps_mode = NL80211_SMPS_OFF;
3437 }
3438
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003439 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003440 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003441 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003442 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003443 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003444 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003445 wdev->ssid_len = params.ssid_len;
3446 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003447 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003448 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303449
3450 kfree(params.acl);
3451
Johannes Berg56d18932011-05-09 18:41:15 +02003452 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003453}
3454
Johannes Berg88600202012-02-13 15:17:18 +01003455static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3456{
3457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3458 struct net_device *dev = info->user_ptr[1];
3459 struct wireless_dev *wdev = dev->ieee80211_ptr;
3460 struct cfg80211_beacon_data params;
3461 int err;
3462
3463 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3464 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3465 return -EOPNOTSUPP;
3466
3467 if (!rdev->ops->change_beacon)
3468 return -EOPNOTSUPP;
3469
3470 if (!wdev->beacon_interval)
3471 return -EINVAL;
3472
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003473 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003474 if (err)
3475 return err;
3476
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003477 wdev_lock(wdev);
3478 err = rdev_change_beacon(rdev, dev, &params);
3479 wdev_unlock(wdev);
3480
3481 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003482}
3483
3484static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003485{
Johannes Berg4c476992010-10-04 21:36:35 +02003486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3487 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003488
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003489 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003490}
3491
Johannes Berg5727ef12007-12-19 02:03:34 +01003492static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3493 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3494 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3495 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003496 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003497 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003498 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003499};
3500
Johannes Bergeccb8e82009-05-11 21:57:56 +03003501static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003502 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003503 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003504{
3505 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003506 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003507 int flag;
3508
Johannes Bergeccb8e82009-05-11 21:57:56 +03003509 /*
3510 * Try parsing the new attribute first so userspace
3511 * can specify both for older kernels.
3512 */
3513 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3514 if (nla) {
3515 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003516
Johannes Bergeccb8e82009-05-11 21:57:56 +03003517 sta_flags = nla_data(nla);
3518 params->sta_flags_mask = sta_flags->mask;
3519 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003520 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003521 if ((params->sta_flags_mask |
3522 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3523 return -EINVAL;
3524 return 0;
3525 }
3526
3527 /* if present, parse the old attribute */
3528
3529 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003530 if (!nla)
3531 return 0;
3532
3533 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3534 nla, sta_flags_policy))
3535 return -EINVAL;
3536
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003537 /*
3538 * Only allow certain flags for interface types so that
3539 * other attributes are silently ignored. Remember that
3540 * this is backward compatibility code with old userspace
3541 * and shouldn't be hit in other cases anyway.
3542 */
3543 switch (iftype) {
3544 case NL80211_IFTYPE_AP:
3545 case NL80211_IFTYPE_AP_VLAN:
3546 case NL80211_IFTYPE_P2P_GO:
3547 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3548 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3549 BIT(NL80211_STA_FLAG_WME) |
3550 BIT(NL80211_STA_FLAG_MFP);
3551 break;
3552 case NL80211_IFTYPE_P2P_CLIENT:
3553 case NL80211_IFTYPE_STATION:
3554 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3555 BIT(NL80211_STA_FLAG_TDLS_PEER);
3556 break;
3557 case NL80211_IFTYPE_MESH_POINT:
3558 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3559 BIT(NL80211_STA_FLAG_MFP) |
3560 BIT(NL80211_STA_FLAG_AUTHORIZED);
3561 default:
3562 return -EINVAL;
3563 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003564
Johannes Berg3383b5a2012-05-10 20:14:43 +02003565 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3566 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003567 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003568
Johannes Berg3383b5a2012-05-10 20:14:43 +02003569 /* no longer support new API additions in old API */
3570 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3571 return -EINVAL;
3572 }
3573 }
3574
Johannes Berg5727ef12007-12-19 02:03:34 +01003575 return 0;
3576}
3577
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003578static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3579 int attr)
3580{
3581 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003582 u32 bitrate;
3583 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003584 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003585
3586 rate = nla_nest_start(msg, attr);
3587 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003588 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003589
3590 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3591 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003592 /* report 16-bit bitrate only if we can */
3593 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003594 if (bitrate > 0 &&
3595 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3596 return false;
3597 if (bitrate_compat > 0 &&
3598 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3599 return false;
3600
Johannes Bergb51f3be2015-01-15 16:14:02 +01003601 switch (info->bw) {
3602 case RATE_INFO_BW_5:
3603 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3604 break;
3605 case RATE_INFO_BW_10:
3606 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3607 break;
3608 default:
3609 WARN_ON(1);
3610 /* fall through */
3611 case RATE_INFO_BW_20:
3612 rate_flg = 0;
3613 break;
3614 case RATE_INFO_BW_40:
3615 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3616 break;
3617 case RATE_INFO_BW_80:
3618 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3619 break;
3620 case RATE_INFO_BW_160:
3621 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3622 break;
3623 }
3624
3625 if (rate_flg && nla_put_flag(msg, rate_flg))
3626 return false;
3627
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003628 if (info->flags & RATE_INFO_FLAGS_MCS) {
3629 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3630 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003631 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3632 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3633 return false;
3634 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3635 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3636 return false;
3637 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3638 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003639 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3640 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3641 return false;
3642 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003643
3644 nla_nest_end(msg, rate);
3645 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003646}
3647
Felix Fietkau119363c2013-04-22 16:29:30 +02003648static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3649 int id)
3650{
3651 void *attr;
3652 int i = 0;
3653
3654 if (!mask)
3655 return true;
3656
3657 attr = nla_nest_start(msg, id);
3658 if (!attr)
3659 return false;
3660
3661 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3662 if (!(mask & BIT(i)))
3663 continue;
3664
3665 if (nla_put_u8(msg, i, signal[i]))
3666 return false;
3667 }
3668
3669 nla_nest_end(msg, attr);
3670
3671 return true;
3672}
3673
Johannes Bergcf5ead82014-11-14 17:14:00 +01003674static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3675 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003676 struct cfg80211_registered_device *rdev,
3677 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003678 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003679{
3680 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003681 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003682
Johannes Bergcf5ead82014-11-14 17:14:00 +01003683 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003684 if (!hdr)
3685 return -1;
3686
David S. Miller9360ffd2012-03-29 04:41:26 -04003687 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3688 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3689 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3690 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003691
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003692 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3693 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003694 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003695
3696#define PUT_SINFO(attr, memb, type) do { \
3697 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3698 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3699 sinfo->memb)) \
3700 goto nla_put_failure; \
3701 } while (0)
3702
3703 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3704 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3705
3706 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3707 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003708 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003709 (u32)sinfo->rx_bytes))
3710 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003711
3712 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3713 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003714 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3715 (u32)sinfo->tx_bytes))
3716 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003717
3718 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3719 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3720 PUT_SINFO(LLID, llid, u16);
3721 PUT_SINFO(PLID, plid, u16);
3722 PUT_SINFO(PLINK_STATE, plink_state, u8);
3723
John W. Linville66266b32012-03-15 13:25:41 -04003724 switch (rdev->wiphy.signal_type) {
3725 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003726 PUT_SINFO(SIGNAL, signal, u8);
3727 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003728 break;
3729 default:
3730 break;
3731 }
Johannes Berg319090b2014-11-17 14:08:11 +01003732 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003733 if (!nl80211_put_signal(msg, sinfo->chains,
3734 sinfo->chain_signal,
3735 NL80211_STA_INFO_CHAIN_SIGNAL))
3736 goto nla_put_failure;
3737 }
Johannes Berg319090b2014-11-17 14:08:11 +01003738 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003739 if (!nl80211_put_signal(msg, sinfo->chains,
3740 sinfo->chain_signal_avg,
3741 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3742 goto nla_put_failure;
3743 }
Johannes Berg319090b2014-11-17 14:08:11 +01003744 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003745 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3746 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003747 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003748 }
Johannes Berg319090b2014-11-17 14:08:11 +01003749 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003750 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3751 NL80211_STA_INFO_RX_BITRATE))
3752 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003753 }
Johannes Berg319090b2014-11-17 14:08:11 +01003754
3755 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3756 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3757 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3758 PUT_SINFO(TX_FAILED, tx_failed, u32);
3759 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3760 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3761 PUT_SINFO(LOCAL_PM, local_pm, u32);
3762 PUT_SINFO(PEER_PM, peer_pm, u32);
3763 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3764
3765 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003766 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3767 if (!bss_param)
3768 goto nla_put_failure;
3769
David S. Miller9360ffd2012-03-29 04:41:26 -04003770 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3771 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3772 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3773 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3774 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3775 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3776 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3777 sinfo->bss_param.dtim_period) ||
3778 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3779 sinfo->bss_param.beacon_interval))
3780 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003781
3782 nla_nest_end(msg, bss_param);
3783 }
Johannes Berg319090b2014-11-17 14:08:11 +01003784 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003785 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3786 sizeof(struct nl80211_sta_flag_update),
3787 &sinfo->sta_flags))
3788 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003789
3790 PUT_SINFO(T_OFFSET, t_offset, u64);
3791 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003792 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3793 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003794
3795#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003796
3797 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3798 struct nlattr *tidsattr;
3799 int tid;
3800
3801 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3802 if (!tidsattr)
3803 goto nla_put_failure;
3804
3805 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3806 struct cfg80211_tid_stats *tidstats;
3807 struct nlattr *tidattr;
3808
3809 tidstats = &sinfo->pertid[tid];
3810
3811 if (!tidstats->filled)
3812 continue;
3813
3814 tidattr = nla_nest_start(msg, tid + 1);
3815 if (!tidattr)
3816 goto nla_put_failure;
3817
3818#define PUT_TIDVAL(attr, memb, type) do { \
3819 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3820 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3821 tidstats->memb)) \
3822 goto nla_put_failure; \
3823 } while (0)
3824
3825 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3826 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3827 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3828 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3829
3830#undef PUT_TIDVAL
3831 nla_nest_end(msg, tidattr);
3832 }
3833
3834 nla_nest_end(msg, tidsattr);
3835 }
3836
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003837 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003838
Johannes Berg319090b2014-11-17 14:08:11 +01003839 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003840 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3841 sinfo->assoc_req_ies))
3842 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003843
Johannes Berg053c0952015-01-16 22:09:00 +01003844 genlmsg_end(msg, hdr);
3845 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003846
3847 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003848 genlmsg_cancel(msg, hdr);
3849 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003850}
3851
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003852static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003853 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003854{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003855 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003856 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003857 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003858 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003859 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003860 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003861
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003862 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003863 if (err)
3864 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003865
Johannes Berg97990a02013-04-19 01:02:55 +02003866 if (!wdev->netdev) {
3867 err = -EINVAL;
3868 goto out_err;
3869 }
3870
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003871 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003872 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003873 goto out_err;
3874 }
3875
Johannes Bergbba95fe2008-07-29 13:22:51 +02003876 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003877 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003878 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003879 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003880 if (err == -ENOENT)
3881 break;
3882 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003883 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003884
Johannes Bergcf5ead82014-11-14 17:14:00 +01003885 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003886 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003887 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003888 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003889 &sinfo) < 0)
3890 goto out;
3891
3892 sta_idx++;
3893 }
3894
3895
3896 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003897 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003898 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003899 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003900 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003901
3902 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003903}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003904
Johannes Berg5727ef12007-12-19 02:03:34 +01003905static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3906{
Johannes Berg4c476992010-10-04 21:36:35 +02003907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3908 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003909 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003910 struct sk_buff *msg;
3911 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003912 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003913
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003914 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003915
3916 if (!info->attrs[NL80211_ATTR_MAC])
3917 return -EINVAL;
3918
3919 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3920
Johannes Berg4c476992010-10-04 21:36:35 +02003921 if (!rdev->ops->get_station)
3922 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003923
Hila Gonene35e4d22012-06-27 17:19:42 +03003924 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003925 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003926 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003927
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003928 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003929 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003930 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003931
Johannes Bergcf5ead82014-11-14 17:14:00 +01003932 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3933 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003934 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003935 nlmsg_free(msg);
3936 return -ENOBUFS;
3937 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003938
Johannes Berg4c476992010-10-04 21:36:35 +02003939 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003940}
3941
Johannes Berg77ee7c82013-02-15 00:48:33 +01003942int cfg80211_check_station_change(struct wiphy *wiphy,
3943 struct station_parameters *params,
3944 enum cfg80211_station_type statype)
3945{
3946 if (params->listen_interval != -1)
3947 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003948 if (params->aid &&
3949 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003950 return -EINVAL;
3951
3952 /* When you run into this, adjust the code below for the new flag */
3953 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3954
3955 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003956 case CFG80211_STA_MESH_PEER_KERNEL:
3957 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003958 /*
3959 * No ignoring the TDLS flag here -- the userspace mesh
3960 * code doesn't have the bug of including TDLS in the
3961 * mask everywhere.
3962 */
3963 if (params->sta_flags_mask &
3964 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3965 BIT(NL80211_STA_FLAG_MFP) |
3966 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3967 return -EINVAL;
3968 break;
3969 case CFG80211_STA_TDLS_PEER_SETUP:
3970 case CFG80211_STA_TDLS_PEER_ACTIVE:
3971 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3972 return -EINVAL;
3973 /* ignore since it can't change */
3974 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3975 break;
3976 default:
3977 /* disallow mesh-specific things */
3978 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3979 return -EINVAL;
3980 if (params->local_pm)
3981 return -EINVAL;
3982 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3983 return -EINVAL;
3984 }
3985
3986 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3987 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3988 /* TDLS can't be set, ... */
3989 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3990 return -EINVAL;
3991 /*
3992 * ... but don't bother the driver with it. This works around
3993 * a hostapd/wpa_supplicant issue -- it always includes the
3994 * TLDS_PEER flag in the mask even for AP mode.
3995 */
3996 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3997 }
3998
3999 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
4000 /* reject other things that can't change */
4001 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4002 return -EINVAL;
4003 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4004 return -EINVAL;
4005 if (params->supported_rates)
4006 return -EINVAL;
4007 if (params->ext_capab || params->ht_capa || params->vht_capa)
4008 return -EINVAL;
4009 }
4010
4011 if (statype != CFG80211_STA_AP_CLIENT) {
4012 if (params->vlan)
4013 return -EINVAL;
4014 }
4015
4016 switch (statype) {
4017 case CFG80211_STA_AP_MLME_CLIENT:
4018 /* Use this only for authorizing/unauthorizing a station */
4019 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4020 return -EOPNOTSUPP;
4021 break;
4022 case CFG80211_STA_AP_CLIENT:
4023 /* accept only the listed bits */
4024 if (params->sta_flags_mask &
4025 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4026 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4027 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4028 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4029 BIT(NL80211_STA_FLAG_WME) |
4030 BIT(NL80211_STA_FLAG_MFP)))
4031 return -EINVAL;
4032
4033 /* but authenticated/associated only if driver handles it */
4034 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4035 params->sta_flags_mask &
4036 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4037 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4038 return -EINVAL;
4039 break;
4040 case CFG80211_STA_IBSS:
4041 case CFG80211_STA_AP_STA:
4042 /* reject any changes other than AUTHORIZED */
4043 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4044 return -EINVAL;
4045 break;
4046 case CFG80211_STA_TDLS_PEER_SETUP:
4047 /* reject any changes other than AUTHORIZED or WME */
4048 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4049 BIT(NL80211_STA_FLAG_WME)))
4050 return -EINVAL;
4051 /* force (at least) rates when authorizing */
4052 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4053 !params->supported_rates)
4054 return -EINVAL;
4055 break;
4056 case CFG80211_STA_TDLS_PEER_ACTIVE:
4057 /* reject any changes */
4058 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004059 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004060 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4061 return -EINVAL;
4062 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004063 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004064 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4065 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004066 return -EINVAL;
4067 break;
4068 }
4069
4070 return 0;
4071}
4072EXPORT_SYMBOL(cfg80211_check_station_change);
4073
Johannes Berg5727ef12007-12-19 02:03:34 +01004074/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004075 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004076 */
Johannes Berg80b99892011-11-18 16:23:01 +01004077static struct net_device *get_vlan(struct genl_info *info,
4078 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004079{
Johannes Berg463d0182009-07-14 00:33:35 +02004080 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004081 struct net_device *v;
4082 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004083
Johannes Berg80b99892011-11-18 16:23:01 +01004084 if (!vlanattr)
4085 return NULL;
4086
4087 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4088 if (!v)
4089 return ERR_PTR(-ENODEV);
4090
4091 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4092 ret = -EINVAL;
4093 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 }
Johannes Berg80b99892011-11-18 16:23:01 +01004095
Johannes Berg77ee7c82013-02-15 00:48:33 +01004096 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4097 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4098 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4099 ret = -EINVAL;
4100 goto error;
4101 }
4102
Johannes Berg80b99892011-11-18 16:23:01 +01004103 if (!netif_running(v)) {
4104 ret = -ENETDOWN;
4105 goto error;
4106 }
4107
4108 return v;
4109 error:
4110 dev_put(v);
4111 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004112}
4113
Johannes Berg94e860f2014-01-20 23:58:15 +01004114static const struct nla_policy
4115nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004116 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4117 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4118};
4119
Johannes Bergff276692013-02-15 00:09:01 +01004120static int nl80211_parse_sta_wme(struct genl_info *info,
4121 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004122{
Jouni Malinendf881292013-02-14 21:10:54 +02004123 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4124 struct nlattr *nla;
4125 int err;
4126
Jouni Malinendf881292013-02-14 21:10:54 +02004127 /* parse WME attributes if present */
4128 if (!info->attrs[NL80211_ATTR_STA_WME])
4129 return 0;
4130
4131 nla = info->attrs[NL80211_ATTR_STA_WME];
4132 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4133 nl80211_sta_wme_policy);
4134 if (err)
4135 return err;
4136
4137 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4138 params->uapsd_queues = nla_get_u8(
4139 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4140 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4141 return -EINVAL;
4142
4143 if (tb[NL80211_STA_WME_MAX_SP])
4144 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4145
4146 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4147 return -EINVAL;
4148
4149 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4150
4151 return 0;
4152}
4153
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304154static int nl80211_parse_sta_channel_info(struct genl_info *info,
4155 struct station_parameters *params)
4156{
4157 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4158 params->supported_channels =
4159 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4160 params->supported_channels_len =
4161 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4162 /*
4163 * Need to include at least one (first channel, number of
4164 * channels) tuple for each subband, and must have proper
4165 * tuples for the rest of the data as well.
4166 */
4167 if (params->supported_channels_len < 2)
4168 return -EINVAL;
4169 if (params->supported_channels_len % 2)
4170 return -EINVAL;
4171 }
4172
4173 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4174 params->supported_oper_classes =
4175 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4176 params->supported_oper_classes_len =
4177 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4178 /*
4179 * The value of the Length field of the Supported Operating
4180 * Classes element is between 2 and 253.
4181 */
4182 if (params->supported_oper_classes_len < 2 ||
4183 params->supported_oper_classes_len > 253)
4184 return -EINVAL;
4185 }
4186 return 0;
4187}
4188
Johannes Bergff276692013-02-15 00:09:01 +01004189static int nl80211_set_station_tdls(struct genl_info *info,
4190 struct station_parameters *params)
4191{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304192 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004193 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004194 if (info->attrs[NL80211_ATTR_PEER_AID])
4195 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004196 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4197 params->ht_capa =
4198 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4199 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4200 params->vht_capa =
4201 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4202
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304203 err = nl80211_parse_sta_channel_info(info, params);
4204 if (err)
4205 return err;
4206
Johannes Bergff276692013-02-15 00:09:01 +01004207 return nl80211_parse_sta_wme(info, params);
4208}
4209
Johannes Berg5727ef12007-12-19 02:03:34 +01004210static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4211{
Johannes Berg4c476992010-10-04 21:36:35 +02004212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004213 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004214 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004215 u8 *mac_addr;
4216 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004217
4218 memset(&params, 0, sizeof(params));
4219
4220 params.listen_interval = -1;
4221
Johannes Berg77ee7c82013-02-15 00:48:33 +01004222 if (!rdev->ops->change_station)
4223 return -EOPNOTSUPP;
4224
Johannes Berg5727ef12007-12-19 02:03:34 +01004225 if (info->attrs[NL80211_ATTR_STA_AID])
4226 return -EINVAL;
4227
4228 if (!info->attrs[NL80211_ATTR_MAC])
4229 return -EINVAL;
4230
4231 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4232
4233 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4234 params.supported_rates =
4235 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4236 params.supported_rates_len =
4237 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4238 }
4239
Jouni Malinen9d62a982013-02-14 21:10:13 +02004240 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4241 params.capability =
4242 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4243 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4244 }
4245
4246 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4247 params.ext_capab =
4248 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4249 params.ext_capab_len =
4250 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4251 }
4252
Jouni Malinendf881292013-02-14 21:10:54 +02004253 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004254 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004255
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004256 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004257 return -EINVAL;
4258
Johannes Bergf8bacc22013-02-14 23:27:01 +01004259 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004261 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4262 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4263 return -EINVAL;
4264 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004265
Johannes Bergf8bacc22013-02-14 23:27:01 +01004266 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004267 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004268 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4269 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4270 return -EINVAL;
4271 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4272 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004273
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004274 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4275 enum nl80211_mesh_power_mode pm = nla_get_u32(
4276 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4277
4278 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4279 pm > NL80211_MESH_POWER_MAX)
4280 return -EINVAL;
4281
4282 params.local_pm = pm;
4283 }
4284
Johannes Berg77ee7c82013-02-15 00:48:33 +01004285 /* Include parameters for TDLS peer (will check later) */
4286 err = nl80211_set_station_tdls(info, &params);
4287 if (err)
4288 return err;
4289
4290 params.vlan = get_vlan(info, rdev);
4291 if (IS_ERR(params.vlan))
4292 return PTR_ERR(params.vlan);
4293
Johannes Berga97f4422009-06-18 17:23:43 +02004294 switch (dev->ieee80211_ptr->iftype) {
4295 case NL80211_IFTYPE_AP:
4296 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004297 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004298 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004299 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004300 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004301 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004302 break;
4303 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004304 err = -EOPNOTSUPP;
4305 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004306 }
4307
Johannes Berg77ee7c82013-02-15 00:48:33 +01004308 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004309 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004310
Johannes Berg77ee7c82013-02-15 00:48:33 +01004311 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004312 if (params.vlan)
4313 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004314
Johannes Berg5727ef12007-12-19 02:03:34 +01004315 return err;
4316}
4317
4318static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4319{
Johannes Berg4c476992010-10-04 21:36:35 +02004320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004321 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004322 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004323 struct station_parameters params;
4324 u8 *mac_addr = NULL;
4325
4326 memset(&params, 0, sizeof(params));
4327
Johannes Berg984c3112013-02-14 23:43:25 +01004328 if (!rdev->ops->add_station)
4329 return -EOPNOTSUPP;
4330
Johannes Berg5727ef12007-12-19 02:03:34 +01004331 if (!info->attrs[NL80211_ATTR_MAC])
4332 return -EINVAL;
4333
Johannes Berg5727ef12007-12-19 02:03:34 +01004334 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4335 return -EINVAL;
4336
4337 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4338 return -EINVAL;
4339
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004340 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4341 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004342 return -EINVAL;
4343
Johannes Berg5727ef12007-12-19 02:03:34 +01004344 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4345 params.supported_rates =
4346 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4347 params.supported_rates_len =
4348 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4349 params.listen_interval =
4350 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004351
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004352 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004353 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004354 else
4355 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004356 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4357 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004358
Jouni Malinen9d62a982013-02-14 21:10:13 +02004359 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4360 params.capability =
4361 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4362 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4363 }
4364
4365 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4366 params.ext_capab =
4367 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4368 params.ext_capab_len =
4369 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4370 }
4371
Jouni Malinen36aedc902008-08-25 11:58:58 +03004372 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4373 params.ht_capa =
4374 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004375
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004376 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4377 params.vht_capa =
4378 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4379
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004380 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4381 params.opmode_notif_used = true;
4382 params.opmode_notif =
4383 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4384 }
4385
Johannes Bergf8bacc22013-02-14 23:27:01 +01004386 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004387 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004388 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4389 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4390 return -EINVAL;
4391 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004392
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304393 err = nl80211_parse_sta_channel_info(info, &params);
4394 if (err)
4395 return err;
4396
Johannes Bergff276692013-02-15 00:09:01 +01004397 err = nl80211_parse_sta_wme(info, &params);
4398 if (err)
4399 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004400
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004401 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004402 return -EINVAL;
4403
Johannes Berg496fcc22015-03-12 08:53:27 +02004404 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4405 * as userspace might just pass through the capabilities from the IEs
4406 * directly, rather than enforcing this restriction and returning an
4407 * error in this case.
4408 */
4409 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4410 params.ht_capa = NULL;
4411 params.vht_capa = NULL;
4412 }
4413
Johannes Berg77ee7c82013-02-15 00:48:33 +01004414 /* When you run into this, adjust the code below for the new flag */
4415 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4416
Johannes Bergbdd90d52011-12-14 12:20:27 +01004417 switch (dev->ieee80211_ptr->iftype) {
4418 case NL80211_IFTYPE_AP:
4419 case NL80211_IFTYPE_AP_VLAN:
4420 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004421 /* ignore WME attributes if iface/sta is not capable */
4422 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4423 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4424 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004425
Johannes Bergbdd90d52011-12-14 12:20:27 +01004426 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004427 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4428 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004429 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004430 /* but don't bother the driver with it */
4431 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004432
Johannes Bergd582cff2012-10-26 17:53:44 +02004433 /* allow authenticated/associated only if driver handles it */
4434 if (!(rdev->wiphy.features &
4435 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4436 params.sta_flags_mask &
4437 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4438 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4439 return -EINVAL;
4440
Johannes Bergbdd90d52011-12-14 12:20:27 +01004441 /* must be last in here for error handling */
4442 params.vlan = get_vlan(info, rdev);
4443 if (IS_ERR(params.vlan))
4444 return PTR_ERR(params.vlan);
4445 break;
4446 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004447 /* ignore uAPSD data */
4448 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4449
Johannes Bergd582cff2012-10-26 17:53:44 +02004450 /* associated is disallowed */
4451 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4452 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004453 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004454 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4455 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004456 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004457 break;
4458 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004459 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004460 /* ignore uAPSD data */
4461 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4462
Johannes Berg77ee7c82013-02-15 00:48:33 +01004463 /* these are disallowed */
4464 if (params.sta_flags_mask &
4465 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4466 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004467 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004468 /* Only TDLS peers can be added */
4469 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4470 return -EINVAL;
4471 /* Can only add if TDLS ... */
4472 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4473 return -EOPNOTSUPP;
4474 /* ... with external setup is supported */
4475 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4476 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004477 /*
4478 * Older wpa_supplicant versions always mark the TDLS peer
4479 * as authorized, but it shouldn't yet be.
4480 */
4481 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004482 break;
4483 default:
4484 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004485 }
4486
Johannes Bergbdd90d52011-12-14 12:20:27 +01004487 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004488
Hila Gonene35e4d22012-06-27 17:19:42 +03004489 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004490
Johannes Berg5727ef12007-12-19 02:03:34 +01004491 if (params.vlan)
4492 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004493 return err;
4494}
4495
4496static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4497{
Johannes Berg4c476992010-10-04 21:36:35 +02004498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4499 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004500 struct station_del_parameters params;
4501
4502 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004503
4504 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004505 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004506
Johannes Berge80cf852009-05-11 14:43:13 +02004507 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004508 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004509 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004510 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4511 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004512
Johannes Berg4c476992010-10-04 21:36:35 +02004513 if (!rdev->ops->del_station)
4514 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004515
Jouni Malinen98856862014-10-20 13:20:45 +03004516 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4517 params.subtype =
4518 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4519 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4520 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4521 return -EINVAL;
4522 } else {
4523 /* Default to Deauthentication frame */
4524 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4525 }
4526
4527 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4528 params.reason_code =
4529 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4530 if (params.reason_code == 0)
4531 return -EINVAL; /* 0 is reserved */
4532 } else {
4533 /* Default to reason code 2 */
4534 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4535 }
4536
Jouni Malinen89c771e2014-10-10 20:52:40 +03004537 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004538}
4539
Eric W. Biederman15e47302012-09-07 20:12:54 +00004540static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004541 int flags, struct net_device *dev,
4542 u8 *dst, u8 *next_hop,
4543 struct mpath_info *pinfo)
4544{
4545 void *hdr;
4546 struct nlattr *pinfoattr;
4547
Henning Rogge1ef4c852014-11-04 16:14:58 +01004548 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004549 if (!hdr)
4550 return -1;
4551
David S. Miller9360ffd2012-03-29 04:41:26 -04004552 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4553 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4554 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4555 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4556 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004557
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004558 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4559 if (!pinfoattr)
4560 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004561 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4562 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4563 pinfo->frame_qlen))
4564 goto nla_put_failure;
4565 if (((pinfo->filled & MPATH_INFO_SN) &&
4566 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4567 ((pinfo->filled & MPATH_INFO_METRIC) &&
4568 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4569 pinfo->metric)) ||
4570 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4571 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4572 pinfo->exptime)) ||
4573 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4574 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4575 pinfo->flags)) ||
4576 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4577 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4578 pinfo->discovery_timeout)) ||
4579 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4580 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4581 pinfo->discovery_retries)))
4582 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004583
4584 nla_nest_end(msg, pinfoattr);
4585
Johannes Berg053c0952015-01-16 22:09:00 +01004586 genlmsg_end(msg, hdr);
4587 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004588
4589 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004590 genlmsg_cancel(msg, hdr);
4591 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004592}
4593
4594static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004595 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004596{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004597 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004598 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004599 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004600 u8 dst[ETH_ALEN];
4601 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004602 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004603 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004604
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004605 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004606 if (err)
4607 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004608
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004609 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004610 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004611 goto out_err;
4612 }
4613
Johannes Berg97990a02013-04-19 01:02:55 +02004614 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004615 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004616 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004617 }
4618
Johannes Bergbba95fe2008-07-29 13:22:51 +02004619 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004620 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004621 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004622 if (err == -ENOENT)
4623 break;
4624 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004625 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004626
Eric W. Biederman15e47302012-09-07 20:12:54 +00004627 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004628 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004629 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004630 &pinfo) < 0)
4631 goto out;
4632
4633 path_idx++;
4634 }
4635
4636
4637 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004638 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004639 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004640 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004641 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004642 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004643}
4644
4645static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4646{
Johannes Berg4c476992010-10-04 21:36:35 +02004647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004648 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004649 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004650 struct mpath_info pinfo;
4651 struct sk_buff *msg;
4652 u8 *dst = NULL;
4653 u8 next_hop[ETH_ALEN];
4654
4655 memset(&pinfo, 0, sizeof(pinfo));
4656
4657 if (!info->attrs[NL80211_ATTR_MAC])
4658 return -EINVAL;
4659
4660 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4661
Johannes Berg4c476992010-10-04 21:36:35 +02004662 if (!rdev->ops->get_mpath)
4663 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004664
Johannes Berg4c476992010-10-04 21:36:35 +02004665 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4666 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004667
Hila Gonene35e4d22012-06-27 17:19:42 +03004668 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004669 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004670 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004671
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004672 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004673 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004674 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004675
Eric W. Biederman15e47302012-09-07 20:12:54 +00004676 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004677 dev, dst, next_hop, &pinfo) < 0) {
4678 nlmsg_free(msg);
4679 return -ENOBUFS;
4680 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004681
Johannes Berg4c476992010-10-04 21:36:35 +02004682 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004683}
4684
4685static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4686{
Johannes Berg4c476992010-10-04 21:36:35 +02004687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4688 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004689 u8 *dst = NULL;
4690 u8 *next_hop = NULL;
4691
4692 if (!info->attrs[NL80211_ATTR_MAC])
4693 return -EINVAL;
4694
4695 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4696 return -EINVAL;
4697
4698 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4699 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4700
Johannes Berg4c476992010-10-04 21:36:35 +02004701 if (!rdev->ops->change_mpath)
4702 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004703
Johannes Berg4c476992010-10-04 21:36:35 +02004704 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4705 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004706
Hila Gonene35e4d22012-06-27 17:19:42 +03004707 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004708}
Johannes Berg4c476992010-10-04 21:36:35 +02004709
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004710static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4711{
Johannes Berg4c476992010-10-04 21:36:35 +02004712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4713 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004714 u8 *dst = NULL;
4715 u8 *next_hop = NULL;
4716
4717 if (!info->attrs[NL80211_ATTR_MAC])
4718 return -EINVAL;
4719
4720 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4721 return -EINVAL;
4722
4723 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4724 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4725
Johannes Berg4c476992010-10-04 21:36:35 +02004726 if (!rdev->ops->add_mpath)
4727 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004728
Johannes Berg4c476992010-10-04 21:36:35 +02004729 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4730 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004731
Hila Gonene35e4d22012-06-27 17:19:42 +03004732 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004733}
4734
4735static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4736{
Johannes Berg4c476992010-10-04 21:36:35 +02004737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4738 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004739 u8 *dst = NULL;
4740
4741 if (info->attrs[NL80211_ATTR_MAC])
4742 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4743
Johannes Berg4c476992010-10-04 21:36:35 +02004744 if (!rdev->ops->del_mpath)
4745 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004746
Hila Gonene35e4d22012-06-27 17:19:42 +03004747 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004748}
4749
Henning Rogge66be7d22014-09-12 08:58:49 +02004750static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4751{
4752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4753 int err;
4754 struct net_device *dev = info->user_ptr[1];
4755 struct mpath_info pinfo;
4756 struct sk_buff *msg;
4757 u8 *dst = NULL;
4758 u8 mpp[ETH_ALEN];
4759
4760 memset(&pinfo, 0, sizeof(pinfo));
4761
4762 if (!info->attrs[NL80211_ATTR_MAC])
4763 return -EINVAL;
4764
4765 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4766
4767 if (!rdev->ops->get_mpp)
4768 return -EOPNOTSUPP;
4769
4770 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4771 return -EOPNOTSUPP;
4772
4773 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4774 if (err)
4775 return err;
4776
4777 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4778 if (!msg)
4779 return -ENOMEM;
4780
4781 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4782 dev, dst, mpp, &pinfo) < 0) {
4783 nlmsg_free(msg);
4784 return -ENOBUFS;
4785 }
4786
4787 return genlmsg_reply(msg, info);
4788}
4789
4790static int nl80211_dump_mpp(struct sk_buff *skb,
4791 struct netlink_callback *cb)
4792{
4793 struct mpath_info pinfo;
4794 struct cfg80211_registered_device *rdev;
4795 struct wireless_dev *wdev;
4796 u8 dst[ETH_ALEN];
4797 u8 mpp[ETH_ALEN];
4798 int path_idx = cb->args[2];
4799 int err;
4800
4801 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4802 if (err)
4803 return err;
4804
4805 if (!rdev->ops->dump_mpp) {
4806 err = -EOPNOTSUPP;
4807 goto out_err;
4808 }
4809
4810 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4811 err = -EOPNOTSUPP;
4812 goto out_err;
4813 }
4814
4815 while (1) {
4816 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4817 mpp, &pinfo);
4818 if (err == -ENOENT)
4819 break;
4820 if (err)
4821 goto out_err;
4822
4823 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4824 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4825 wdev->netdev, dst, mpp,
4826 &pinfo) < 0)
4827 goto out;
4828
4829 path_idx++;
4830 }
4831
4832 out:
4833 cb->args[2] = path_idx;
4834 err = skb->len;
4835 out_err:
4836 nl80211_finish_wdev_dump(rdev);
4837 return err;
4838}
4839
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004840static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4841{
Johannes Berg4c476992010-10-04 21:36:35 +02004842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4843 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004844 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004845 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004846 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004847
4848 memset(&params, 0, sizeof(params));
4849 /* default to not changing parameters */
4850 params.use_cts_prot = -1;
4851 params.use_short_preamble = -1;
4852 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004853 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004854 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004855 params.p2p_ctwindow = -1;
4856 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004857
4858 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4859 params.use_cts_prot =
4860 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4861 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4862 params.use_short_preamble =
4863 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4864 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4865 params.use_short_slot_time =
4866 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004867 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4868 params.basic_rates =
4869 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4870 params.basic_rates_len =
4871 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4872 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004873 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4874 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004875 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4876 params.ht_opmode =
4877 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004878
Johannes Berg53cabad2012-11-14 15:17:28 +01004879 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4880 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4881 return -EINVAL;
4882 params.p2p_ctwindow =
4883 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4884 if (params.p2p_ctwindow < 0)
4885 return -EINVAL;
4886 if (params.p2p_ctwindow != 0 &&
4887 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4888 return -EINVAL;
4889 }
4890
4891 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4892 u8 tmp;
4893
4894 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4895 return -EINVAL;
4896 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4897 if (tmp > 1)
4898 return -EINVAL;
4899 params.p2p_opp_ps = tmp;
4900 if (params.p2p_opp_ps &&
4901 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4902 return -EINVAL;
4903 }
4904
Johannes Berg4c476992010-10-04 21:36:35 +02004905 if (!rdev->ops->change_bss)
4906 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004907
Johannes Berg074ac8d2010-09-16 14:58:22 +02004908 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004909 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4910 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004911
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004912 wdev_lock(wdev);
4913 err = rdev_change_bss(rdev, dev, &params);
4914 wdev_unlock(wdev);
4915
4916 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004917}
4918
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004919static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004920 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4921 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4922 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4923 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4924 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4925 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004926 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004927};
4928
4929static int parse_reg_rule(struct nlattr *tb[],
4930 struct ieee80211_reg_rule *reg_rule)
4931{
4932 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4933 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4934
4935 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4936 return -EINVAL;
4937 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4938 return -EINVAL;
4939 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4940 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004941 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4942 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004943 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4944 return -EINVAL;
4945
4946 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4947
4948 freq_range->start_freq_khz =
4949 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4950 freq_range->end_freq_khz =
4951 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004952 freq_range->max_bandwidth_khz =
4953 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954
4955 power_rule->max_eirp =
4956 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4957
4958 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4959 power_rule->max_antenna_gain =
4960 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4961
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004962 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4963 reg_rule->dfs_cac_ms =
4964 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4965
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004966 return 0;
4967}
4968
4969static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4970{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004971 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004972 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004973 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004974 u32 owner_nlportid;
4975
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004976
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004977 /*
4978 * You should only get this when cfg80211 hasn't yet initialized
4979 * completely when built-in to the kernel right between the time
4980 * window between nl80211_init() and regulatory_init(), if that is
4981 * even possible.
4982 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004983 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004984 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004985
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004986 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4987 user_reg_hint_type =
4988 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4989 else
4990 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4991
4992 switch (user_reg_hint_type) {
4993 case NL80211_USER_REG_HINT_USER:
4994 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004995 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4996 return -EINVAL;
4997
4998 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4999 return regulatory_hint_user(data, user_reg_hint_type);
5000 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005001 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5002 owner_nlportid = info->snd_portid;
5003 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5004 } else {
5005 owner_nlportid = 0;
5006 is_indoor = true;
5007 }
5008
5009 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005010 default:
5011 return -EINVAL;
5012 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005013}
5014
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005015static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005016 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005017{
Johannes Berg4c476992010-10-04 21:36:35 +02005018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005019 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005020 struct wireless_dev *wdev = dev->ieee80211_ptr;
5021 struct mesh_config cur_params;
5022 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005023 void *hdr;
5024 struct nlattr *pinfoattr;
5025 struct sk_buff *msg;
5026
Johannes Berg29cbe682010-12-03 09:20:44 +01005027 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5028 return -EOPNOTSUPP;
5029
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005030 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005031 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005032
Johannes Berg29cbe682010-12-03 09:20:44 +01005033 wdev_lock(wdev);
5034 /* If not connected, get default parameters */
5035 if (!wdev->mesh_id_len)
5036 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5037 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005038 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005039 wdev_unlock(wdev);
5040
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005041 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005042 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005043
5044 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005045 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005046 if (!msg)
5047 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005048 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005049 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005050 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005051 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005052 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005053 if (!pinfoattr)
5054 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005055 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5056 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5057 cur_params.dot11MeshRetryTimeout) ||
5058 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5059 cur_params.dot11MeshConfirmTimeout) ||
5060 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5061 cur_params.dot11MeshHoldingTimeout) ||
5062 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5063 cur_params.dot11MeshMaxPeerLinks) ||
5064 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5065 cur_params.dot11MeshMaxRetries) ||
5066 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5067 cur_params.dot11MeshTTL) ||
5068 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5069 cur_params.element_ttl) ||
5070 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5071 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005072 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5073 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005074 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5075 cur_params.dot11MeshHWMPmaxPREQretries) ||
5076 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5077 cur_params.path_refresh_time) ||
5078 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5079 cur_params.min_discovery_timeout) ||
5080 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5081 cur_params.dot11MeshHWMPactivePathTimeout) ||
5082 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5083 cur_params.dot11MeshHWMPpreqMinInterval) ||
5084 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5085 cur_params.dot11MeshHWMPperrMinInterval) ||
5086 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5087 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5088 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5089 cur_params.dot11MeshHWMPRootMode) ||
5090 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5091 cur_params.dot11MeshHWMPRannInterval) ||
5092 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5093 cur_params.dot11MeshGateAnnouncementProtocol) ||
5094 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5095 cur_params.dot11MeshForwarding) ||
5096 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005097 cur_params.rssi_threshold) ||
5098 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005099 cur_params.ht_opmode) ||
5100 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5101 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5102 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005103 cur_params.dot11MeshHWMProotInterval) ||
5104 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005105 cur_params.dot11MeshHWMPconfirmationInterval) ||
5106 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5107 cur_params.power_mode) ||
5108 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005109 cur_params.dot11MeshAwakeWindowDuration) ||
5110 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5111 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005112 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005113 nla_nest_end(msg, pinfoattr);
5114 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005115 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005116
Johannes Berg3b858752009-03-12 09:55:09 +01005117 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005118 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005119 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005120 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005121 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005122}
5123
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005124static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005125 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5126 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5127 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5128 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5129 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5130 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005131 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005132 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005133 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005134 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5135 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5136 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5137 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5138 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005139 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005140 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005141 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005142 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005143 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005144 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005145 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5146 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005147 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5148 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005149 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005150 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5151 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005152 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005153};
5154
Javier Cardonac80d5452010-12-16 17:37:49 -08005155static const struct nla_policy
5156 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005157 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005158 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5159 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005160 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005161 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005162 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005163 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005164 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005165 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005166};
5167
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005168static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005169 struct mesh_config *cfg,
5170 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005171{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005172 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005173 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005174
Marco Porschea54fba2013-01-07 16:04:48 +01005175#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5176do { \
5177 if (tb[attr]) { \
5178 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5179 return -EINVAL; \
5180 cfg->param = fn(tb[attr]); \
5181 mask |= (1 << (attr - 1)); \
5182 } \
5183} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005184
5185
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005186 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005187 return -EINVAL;
5188 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005189 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005190 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005191 return -EINVAL;
5192
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005193 /* This makes sure that there aren't more than 32 mesh config
5194 * parameters (otherwise our bitfield scheme would not work.) */
5195 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5196
5197 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005198 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005199 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5200 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005201 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005202 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5203 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005204 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005205 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5206 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005207 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005208 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5209 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005210 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005211 mask, NL80211_MESHCONF_MAX_RETRIES,
5212 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005213 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005214 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005215 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005216 mask, NL80211_MESHCONF_ELEMENT_TTL,
5217 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005219 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5220 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005221 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5222 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005223 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5224 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005225 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005226 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5227 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005228 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005229 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5230 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005231 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005232 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5233 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005234 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5235 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005236 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5237 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005239 1, 65535, mask,
5240 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005241 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005243 1, 65535, mask,
5244 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005245 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005247 dot11MeshHWMPnetDiameterTraversalTime,
5248 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005249 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5250 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005251 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5252 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5253 nla_get_u8);
5254 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5255 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005256 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005257 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005258 dot11MeshGateAnnouncementProtocol, 0, 1,
5259 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005260 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005261 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005262 mask, NL80211_MESHCONF_FORWARDING,
5263 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005264 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005265 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005266 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005267 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005268 mask, NL80211_MESHCONF_HT_OPMODE,
5269 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005270 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005271 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005272 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5273 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005274 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005275 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5276 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005277 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005278 dot11MeshHWMPconfirmationInterval,
5279 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005280 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5281 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005282 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5283 NL80211_MESH_POWER_ACTIVE,
5284 NL80211_MESH_POWER_MAX,
5285 mask, NL80211_MESHCONF_POWER_MODE,
5286 nla_get_u32);
5287 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5288 0, 65535, mask,
5289 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005290 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005291 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5292 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005293 if (mask_out)
5294 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005295
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005296 return 0;
5297
5298#undef FILL_IN_MESH_PARAM_IF_SET
5299}
5300
Javier Cardonac80d5452010-12-16 17:37:49 -08005301static int nl80211_parse_mesh_setup(struct genl_info *info,
5302 struct mesh_setup *setup)
5303{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005305 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5306
5307 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5308 return -EINVAL;
5309 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5310 info->attrs[NL80211_ATTR_MESH_SETUP],
5311 nl80211_mesh_setup_params_policy))
5312 return -EINVAL;
5313
Javier Cardonad299a1f2012-03-31 11:31:33 -07005314 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5315 setup->sync_method =
5316 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5317 IEEE80211_SYNC_METHOD_VENDOR :
5318 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5319
Javier Cardonac80d5452010-12-16 17:37:49 -08005320 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5321 setup->path_sel_proto =
5322 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5323 IEEE80211_PATH_PROTOCOL_VENDOR :
5324 IEEE80211_PATH_PROTOCOL_HWMP;
5325
5326 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5327 setup->path_metric =
5328 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5329 IEEE80211_PATH_METRIC_VENDOR :
5330 IEEE80211_PATH_METRIC_AIRTIME;
5331
Javier Cardona581a8b02011-04-07 15:08:27 -07005332
5333 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005334 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005335 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005336 if (!is_valid_ie_attr(ieattr))
5337 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005338 setup->ie = nla_data(ieattr);
5339 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005340 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005341 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5342 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5343 return -EINVAL;
5344 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005345 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5346 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005347 if (setup->is_secure)
5348 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005349
Colleen Twitty6e16d902013-05-08 11:45:59 -07005350 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5351 if (!setup->user_mpm)
5352 return -EINVAL;
5353 setup->auth_id =
5354 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5355 }
5356
Javier Cardonac80d5452010-12-16 17:37:49 -08005357 return 0;
5358}
5359
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005360static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005361 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005362{
5363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5364 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005365 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005366 struct mesh_config cfg;
5367 u32 mask;
5368 int err;
5369
Johannes Berg29cbe682010-12-03 09:20:44 +01005370 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5371 return -EOPNOTSUPP;
5372
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005373 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005374 return -EOPNOTSUPP;
5375
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005376 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005377 if (err)
5378 return err;
5379
Johannes Berg29cbe682010-12-03 09:20:44 +01005380 wdev_lock(wdev);
5381 if (!wdev->mesh_id_len)
5382 err = -ENOLINK;
5383
5384 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005385 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005386
5387 wdev_unlock(wdev);
5388
5389 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005390}
5391
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005392static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5393 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005394{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005395 struct nlattr *nl_reg_rules;
5396 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005397
Johannes Berg458f4f92012-12-06 15:47:38 +01005398 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5399 (regdom->dfs_region &&
5400 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005401 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005402
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005403 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5404 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005405 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005406
Johannes Berg458f4f92012-12-06 15:47:38 +01005407 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005408 struct nlattr *nl_reg_rule;
5409 const struct ieee80211_reg_rule *reg_rule;
5410 const struct ieee80211_freq_range *freq_range;
5411 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005412 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005413
Johannes Berg458f4f92012-12-06 15:47:38 +01005414 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005415 freq_range = &reg_rule->freq_range;
5416 power_rule = &reg_rule->power_rule;
5417
5418 nl_reg_rule = nla_nest_start(msg, i);
5419 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005420 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005421
Janusz Dziedzic97524822014-01-30 09:52:20 +01005422 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5423 if (!max_bandwidth_khz)
5424 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5425 reg_rule);
5426
David S. Miller9360ffd2012-03-29 04:41:26 -04005427 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5428 reg_rule->flags) ||
5429 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5430 freq_range->start_freq_khz) ||
5431 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5432 freq_range->end_freq_khz) ||
5433 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005434 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005435 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5436 power_rule->max_antenna_gain) ||
5437 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005438 power_rule->max_eirp) ||
5439 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5440 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005441 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005442
5443 nla_nest_end(msg, nl_reg_rule);
5444 }
5445
5446 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005447 return 0;
5448
5449nla_put_failure:
5450 return -EMSGSIZE;
5451}
5452
5453static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5454{
5455 const struct ieee80211_regdomain *regdom = NULL;
5456 struct cfg80211_registered_device *rdev;
5457 struct wiphy *wiphy = NULL;
5458 struct sk_buff *msg;
5459 void *hdr;
5460
5461 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5462 if (!msg)
5463 return -ENOBUFS;
5464
5465 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5466 NL80211_CMD_GET_REG);
5467 if (!hdr)
5468 goto put_failure;
5469
5470 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005471 bool self_managed;
5472
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005473 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5474 if (IS_ERR(rdev)) {
5475 nlmsg_free(msg);
5476 return PTR_ERR(rdev);
5477 }
5478
5479 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005480 self_managed = wiphy->regulatory_flags &
5481 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005482 regdom = get_wiphy_regdom(wiphy);
5483
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005484 /* a self-managed-reg device must have a private regdom */
5485 if (WARN_ON(!regdom && self_managed)) {
5486 nlmsg_free(msg);
5487 return -EINVAL;
5488 }
5489
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005490 if (regdom &&
5491 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5492 goto nla_put_failure;
5493 }
5494
5495 if (!wiphy && reg_last_request_cell_base() &&
5496 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5497 NL80211_USER_REG_HINT_CELL_BASE))
5498 goto nla_put_failure;
5499
5500 rcu_read_lock();
5501
5502 if (!regdom)
5503 regdom = rcu_dereference(cfg80211_regdomain);
5504
5505 if (nl80211_put_regdom(regdom, msg))
5506 goto nla_put_failure_rcu;
5507
5508 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005509
5510 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005511 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005512
Johannes Berg458f4f92012-12-06 15:47:38 +01005513nla_put_failure_rcu:
5514 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005515nla_put_failure:
5516 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005517put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005518 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005519 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005520}
5521
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005522static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5523 u32 seq, int flags, struct wiphy *wiphy,
5524 const struct ieee80211_regdomain *regdom)
5525{
5526 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5527 NL80211_CMD_GET_REG);
5528
5529 if (!hdr)
5530 return -1;
5531
5532 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5533
5534 if (nl80211_put_regdom(regdom, msg))
5535 goto nla_put_failure;
5536
5537 if (!wiphy && reg_last_request_cell_base() &&
5538 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5539 NL80211_USER_REG_HINT_CELL_BASE))
5540 goto nla_put_failure;
5541
5542 if (wiphy &&
5543 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5544 goto nla_put_failure;
5545
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005546 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5547 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5548 goto nla_put_failure;
5549
Johannes Berg053c0952015-01-16 22:09:00 +01005550 genlmsg_end(msg, hdr);
5551 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005552
5553nla_put_failure:
5554 genlmsg_cancel(msg, hdr);
5555 return -EMSGSIZE;
5556}
5557
5558static int nl80211_get_reg_dump(struct sk_buff *skb,
5559 struct netlink_callback *cb)
5560{
5561 const struct ieee80211_regdomain *regdom = NULL;
5562 struct cfg80211_registered_device *rdev;
5563 int err, reg_idx, start = cb->args[2];
5564
5565 rtnl_lock();
5566
5567 if (cfg80211_regdomain && start == 0) {
5568 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5569 NLM_F_MULTI, NULL,
5570 rtnl_dereference(cfg80211_regdomain));
5571 if (err < 0)
5572 goto out_err;
5573 }
5574
5575 /* the global regdom is idx 0 */
5576 reg_idx = 1;
5577 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5578 regdom = get_wiphy_regdom(&rdev->wiphy);
5579 if (!regdom)
5580 continue;
5581
5582 if (++reg_idx <= start)
5583 continue;
5584
5585 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5586 NLM_F_MULTI, &rdev->wiphy, regdom);
5587 if (err < 0) {
5588 reg_idx--;
5589 break;
5590 }
5591 }
5592
5593 cb->args[2] = reg_idx;
5594 err = skb->len;
5595out_err:
5596 rtnl_unlock();
5597 return err;
5598}
5599
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005600static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5601{
5602 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5603 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005604 char *alpha2;
5605 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005606 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005607 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005608 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005609
5610 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5611 return -EINVAL;
5612
5613 if (!info->attrs[NL80211_ATTR_REG_RULES])
5614 return -EINVAL;
5615
5616 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5617
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005618 if (info->attrs[NL80211_ATTR_DFS_REGION])
5619 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5620
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005621 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005622 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005623 num_rules++;
5624 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005625 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005626 }
5627
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005628 if (!reg_is_valid_request(alpha2))
5629 return -EINVAL;
5630
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005631 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005632 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005633
5634 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005635 if (!rd)
5636 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005637
5638 rd->n_reg_rules = num_rules;
5639 rd->alpha2[0] = alpha2[0];
5640 rd->alpha2[1] = alpha2[1];
5641
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005642 /*
5643 * Disable DFS master mode if the DFS region was
5644 * not supported or known on this kernel.
5645 */
5646 if (reg_supported_dfs_region(dfs_region))
5647 rd->dfs_region = dfs_region;
5648
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005649 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005650 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005651 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5652 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5653 reg_rule_policy);
5654 if (r)
5655 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005656 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5657 if (r)
5658 goto bad_reg;
5659
5660 rule_idx++;
5661
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005662 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5663 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005664 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005665 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005666 }
5667
Ilan peerc37722b2015-03-30 15:15:49 +03005668 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005669 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005670 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005671
Johannes Bergd2372b32008-10-24 20:32:20 +02005672 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005673 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005674 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005675}
5676
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005677static int validate_scan_freqs(struct nlattr *freqs)
5678{
5679 struct nlattr *attr1, *attr2;
5680 int n_channels = 0, tmp1, tmp2;
5681
5682 nla_for_each_nested(attr1, freqs, tmp1) {
5683 n_channels++;
5684 /*
5685 * Some hardware has a limited channel list for
5686 * scanning, and it is pretty much nonsensical
5687 * to scan for a channel twice, so disallow that
5688 * and don't require drivers to check that the
5689 * channel list they get isn't longer than what
5690 * they can scan, as long as they can scan all
5691 * the channels they registered at once.
5692 */
5693 nla_for_each_nested(attr2, freqs, tmp2)
5694 if (attr1 != attr2 &&
5695 nla_get_u32(attr1) == nla_get_u32(attr2))
5696 return 0;
5697 }
5698
5699 return n_channels;
5700}
5701
Johannes Bergad2b26a2014-06-12 21:39:05 +02005702static int nl80211_parse_random_mac(struct nlattr **attrs,
5703 u8 *mac_addr, u8 *mac_addr_mask)
5704{
5705 int i;
5706
5707 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005708 eth_zero_addr(mac_addr);
5709 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005710 mac_addr[0] = 0x2;
5711 mac_addr_mask[0] = 0x3;
5712
5713 return 0;
5714 }
5715
5716 /* need both or none */
5717 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5718 return -EINVAL;
5719
5720 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5721 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5722
5723 /* don't allow or configure an mcast address */
5724 if (!is_multicast_ether_addr(mac_addr_mask) ||
5725 is_multicast_ether_addr(mac_addr))
5726 return -EINVAL;
5727
5728 /*
5729 * allow users to pass a MAC address that has bits set outside
5730 * of the mask, but don't bother drivers with having to deal
5731 * with such bits
5732 */
5733 for (i = 0; i < ETH_ALEN; i++)
5734 mac_addr[i] &= mac_addr_mask[i];
5735
5736 return 0;
5737}
5738
Johannes Berg2a519312009-02-10 21:25:55 +01005739static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5740{
Johannes Berg4c476992010-10-04 21:36:35 +02005741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005742 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005743 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005744 struct nlattr *attr;
5745 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005746 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005747 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005748
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005749 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5750 return -EINVAL;
5751
Johannes Berg79c97e92009-07-07 03:56:12 +02005752 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005753
Johannes Berg4c476992010-10-04 21:36:35 +02005754 if (!rdev->ops->scan)
5755 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005756
Johannes Bergf9d15d12014-01-22 11:14:19 +02005757 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005758 err = -EBUSY;
5759 goto unlock;
5760 }
Johannes Berg2a519312009-02-10 21:25:55 +01005761
5762 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005763 n_channels = validate_scan_freqs(
5764 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005765 if (!n_channels) {
5766 err = -EINVAL;
5767 goto unlock;
5768 }
Johannes Berg2a519312009-02-10 21:25:55 +01005769 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005770 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005771 }
5772
5773 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5774 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5775 n_ssids++;
5776
Johannes Bergf9f47522013-03-19 15:04:07 +01005777 if (n_ssids > wiphy->max_scan_ssids) {
5778 err = -EINVAL;
5779 goto unlock;
5780 }
Johannes Berg2a519312009-02-10 21:25:55 +01005781
Jouni Malinen70692ad2009-02-16 19:39:13 +02005782 if (info->attrs[NL80211_ATTR_IE])
5783 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5784 else
5785 ie_len = 0;
5786
Johannes Bergf9f47522013-03-19 15:04:07 +01005787 if (ie_len > wiphy->max_scan_ie_len) {
5788 err = -EINVAL;
5789 goto unlock;
5790 }
Johannes Berg18a83652009-03-31 12:12:05 +02005791
Johannes Berg2a519312009-02-10 21:25:55 +01005792 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005793 + sizeof(*request->ssids) * n_ssids
5794 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005795 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005796 if (!request) {
5797 err = -ENOMEM;
5798 goto unlock;
5799 }
Johannes Berg2a519312009-02-10 21:25:55 +01005800
Johannes Berg2a519312009-02-10 21:25:55 +01005801 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005802 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005803 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005804 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005805 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005806 request->ie = (void *)(request->ssids + n_ssids);
5807 else
5808 request->ie = (void *)(request->channels + n_channels);
5809 }
Johannes Berg2a519312009-02-10 21:25:55 +01005810
Johannes Berg584991d2009-11-02 13:32:03 +01005811 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005812 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5813 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005814 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005815 struct ieee80211_channel *chan;
5816
5817 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5818
5819 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005820 err = -EINVAL;
5821 goto out_free;
5822 }
Johannes Berg584991d2009-11-02 13:32:03 +01005823
5824 /* ignore disabled channels */
5825 if (chan->flags & IEEE80211_CHAN_DISABLED)
5826 continue;
5827
5828 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005829 i++;
5830 }
5831 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005832 enum ieee80211_band band;
5833
Johannes Berg2a519312009-02-10 21:25:55 +01005834 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005835 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5836 int j;
5837 if (!wiphy->bands[band])
5838 continue;
5839 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005840 struct ieee80211_channel *chan;
5841
5842 chan = &wiphy->bands[band]->channels[j];
5843
5844 if (chan->flags & IEEE80211_CHAN_DISABLED)
5845 continue;
5846
5847 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005848 i++;
5849 }
5850 }
5851 }
5852
Johannes Berg584991d2009-11-02 13:32:03 +01005853 if (!i) {
5854 err = -EINVAL;
5855 goto out_free;
5856 }
5857
5858 request->n_channels = i;
5859
Johannes Berg2a519312009-02-10 21:25:55 +01005860 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005861 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005862 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005863 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005864 err = -EINVAL;
5865 goto out_free;
5866 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005867 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005868 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005869 i++;
5870 }
5871 }
5872
Jouni Malinen70692ad2009-02-16 19:39:13 +02005873 if (info->attrs[NL80211_ATTR_IE]) {
5874 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005875 memcpy((void *)request->ie,
5876 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005877 request->ie_len);
5878 }
5879
Johannes Berg34850ab2011-07-18 18:08:35 +02005880 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005881 if (wiphy->bands[i])
5882 request->rates[i] =
5883 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005884
5885 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5886 nla_for_each_nested(attr,
5887 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5888 tmp) {
5889 enum ieee80211_band band = nla_type(attr);
5890
Dan Carpenter84404622011-07-29 11:52:18 +03005891 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005892 err = -EINVAL;
5893 goto out_free;
5894 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005895
5896 if (!wiphy->bands[band])
5897 continue;
5898
Johannes Berg34850ab2011-07-18 18:08:35 +02005899 err = ieee80211_get_ratemask(wiphy->bands[band],
5900 nla_data(attr),
5901 nla_len(attr),
5902 &request->rates[band]);
5903 if (err)
5904 goto out_free;
5905 }
5906 }
5907
Sam Leffler46856bb2012-10-11 21:03:32 -07005908 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005909 request->flags = nla_get_u32(
5910 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005911 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5912 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005913 err = -EOPNOTSUPP;
5914 goto out_free;
5915 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005916
5917 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5918 if (!(wiphy->features &
5919 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5920 err = -EOPNOTSUPP;
5921 goto out_free;
5922 }
5923
5924 if (wdev->current_bss) {
5925 err = -EOPNOTSUPP;
5926 goto out_free;
5927 }
5928
5929 err = nl80211_parse_random_mac(info->attrs,
5930 request->mac_addr,
5931 request->mac_addr_mask);
5932 if (err)
5933 goto out_free;
5934 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005935 }
Sam Lefflered4737712012-10-11 21:03:31 -07005936
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305937 request->no_cck =
5938 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5939
Johannes Bergfd014282012-06-18 19:17:03 +02005940 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005941 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005942 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005943
Johannes Berg79c97e92009-07-07 03:56:12 +02005944 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005945 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005946
Johannes Berg463d0182009-07-14 00:33:35 +02005947 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005948 nl80211_send_scan_start(rdev, wdev);
5949 if (wdev->netdev)
5950 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005951 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005952 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005953 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005954 kfree(request);
5955 }
Johannes Berg3b858752009-03-12 09:55:09 +01005956
Johannes Bergf9f47522013-03-19 15:04:07 +01005957 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005958 return err;
5959}
5960
Luciano Coelho256da022014-11-10 16:13:46 +02005961static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005962nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005963 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005964{
5965 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005966 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005967 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005968 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005969 enum ieee80211_band band;
5970 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005971 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005972 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005973
Luciano Coelho256da022014-11-10 16:13:46 +02005974 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5975 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005976
Luciano Coelho256da022014-11-10 16:13:46 +02005977 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5978 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005979
Luciano Coelho256da022014-11-10 16:13:46 +02005980 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005981 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005982 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005983
Luciano Coelho256da022014-11-10 16:13:46 +02005984 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005985 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005986 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005987 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005988 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005989 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005990 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005991 }
5992
Luciano Coelho256da022014-11-10 16:13:46 +02005993 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5994 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005995 tmp)
5996 n_ssids++;
5997
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005998 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005999 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006000
Johannes Bergea73cbc2014-01-24 10:53:53 +01006001 /*
6002 * First, count the number of 'real' matchsets. Due to an issue with
6003 * the old implementation, matchsets containing only the RSSI attribute
6004 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6005 * RSSI for all matchsets, rather than their own matchset for reporting
6006 * all APs with a strong RSSI. This is needed to be compatible with
6007 * older userspace that treated a matchset with only the RSSI as the
6008 * global RSSI for all other matchsets - if there are other matchsets.
6009 */
Luciano Coelho256da022014-11-10 16:13:46 +02006010 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006011 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006012 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006013 tmp) {
6014 struct nlattr *rssi;
6015
6016 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6017 nla_data(attr), nla_len(attr),
6018 nl80211_match_policy);
6019 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006020 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006021 /* add other standalone attributes here */
6022 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6023 n_match_sets++;
6024 continue;
6025 }
6026 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6027 if (rssi)
6028 default_match_rssi = nla_get_s32(rssi);
6029 }
6030 }
6031
6032 /* However, if there's no other matchset, add the RSSI one */
6033 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6034 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006035
6036 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006037 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006038
Luciano Coelho256da022014-11-10 16:13:46 +02006039 if (attrs[NL80211_ATTR_IE])
6040 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006041 else
6042 ie_len = 0;
6043
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006044 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006045 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006046
Luciano Coelho807f8a82011-05-11 17:09:35 +03006047 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006048 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006049 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006050 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006051 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006052 if (!request)
6053 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006054
6055 if (n_ssids)
6056 request->ssids = (void *)&request->channels[n_channels];
6057 request->n_ssids = n_ssids;
6058 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006059 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006060 request->ie = (void *)(request->ssids + n_ssids);
6061 else
6062 request->ie = (void *)(request->channels + n_channels);
6063 }
6064
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006065 if (n_match_sets) {
6066 if (request->ie)
6067 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006068 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006069 request->match_sets =
6070 (void *)(request->ssids + n_ssids);
6071 else
6072 request->match_sets =
6073 (void *)(request->channels + n_channels);
6074 }
6075 request->n_match_sets = n_match_sets;
6076
Luciano Coelho807f8a82011-05-11 17:09:35 +03006077 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006078 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006079 /* user specified, bail out if channel not found */
6080 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006081 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006082 tmp) {
6083 struct ieee80211_channel *chan;
6084
6085 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6086
6087 if (!chan) {
6088 err = -EINVAL;
6089 goto out_free;
6090 }
6091
6092 /* ignore disabled channels */
6093 if (chan->flags & IEEE80211_CHAN_DISABLED)
6094 continue;
6095
6096 request->channels[i] = chan;
6097 i++;
6098 }
6099 } else {
6100 /* all channels */
6101 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6102 int j;
6103 if (!wiphy->bands[band])
6104 continue;
6105 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6106 struct ieee80211_channel *chan;
6107
6108 chan = &wiphy->bands[band]->channels[j];
6109
6110 if (chan->flags & IEEE80211_CHAN_DISABLED)
6111 continue;
6112
6113 request->channels[i] = chan;
6114 i++;
6115 }
6116 }
6117 }
6118
6119 if (!i) {
6120 err = -EINVAL;
6121 goto out_free;
6122 }
6123
6124 request->n_channels = i;
6125
6126 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006127 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006128 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006129 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006130 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006131 err = -EINVAL;
6132 goto out_free;
6133 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006134 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006135 memcpy(request->ssids[i].ssid, nla_data(attr),
6136 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006137 i++;
6138 }
6139 }
6140
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006141 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006142 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006143 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006144 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006145 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006146 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006147
Johannes Bergae811e22014-01-24 10:17:47 +01006148 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6149 nla_data(attr), nla_len(attr),
6150 nl80211_match_policy);
6151 if (err)
6152 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006153 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006154 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006155 if (WARN_ON(i >= n_match_sets)) {
6156 /* this indicates a programming error,
6157 * the loop above should have verified
6158 * things properly
6159 */
6160 err = -EINVAL;
6161 goto out_free;
6162 }
6163
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006164 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6165 err = -EINVAL;
6166 goto out_free;
6167 }
6168 memcpy(request->match_sets[i].ssid.ssid,
6169 nla_data(ssid), nla_len(ssid));
6170 request->match_sets[i].ssid.ssid_len =
6171 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006172 /* special attribute - old implemenation w/a */
6173 request->match_sets[i].rssi_thold =
6174 default_match_rssi;
6175 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6176 if (rssi)
6177 request->match_sets[i].rssi_thold =
6178 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006179 }
6180 i++;
6181 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006182
6183 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006184 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006185 request->match_sets[0].rssi_thold = default_match_rssi;
6186
6187 request->min_rssi_thold = INT_MAX;
6188 for (i = 0; i < n_match_sets; i++)
6189 request->min_rssi_thold =
6190 min(request->match_sets[i].rssi_thold,
6191 request->min_rssi_thold);
6192 } else {
6193 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006194 }
6195
Johannes Berg9900e482014-02-04 21:01:25 +01006196 if (ie_len) {
6197 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006198 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006199 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006200 request->ie_len);
6201 }
6202
Luciano Coelho256da022014-11-10 16:13:46 +02006203 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006204 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006205 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006206 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6207 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006208 err = -EOPNOTSUPP;
6209 goto out_free;
6210 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006211
6212 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6213 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6214
6215 if (!wdev) /* must be net-detect */
6216 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6217
6218 if (!(wiphy->features & flg)) {
6219 err = -EOPNOTSUPP;
6220 goto out_free;
6221 }
6222
6223 if (wdev && wdev->current_bss) {
6224 err = -EOPNOTSUPP;
6225 goto out_free;
6226 }
6227
6228 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6229 request->mac_addr_mask);
6230 if (err)
6231 goto out_free;
6232 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006233 }
Sam Lefflered4737712012-10-11 21:03:31 -07006234
Luciano Coelho9c748932015-01-16 16:04:09 +02006235 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6236 request->delay =
6237 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6238
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006239 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006240 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006241
Luciano Coelho256da022014-11-10 16:13:46 +02006242 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006243
6244out_free:
6245 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006246 return ERR_PTR(err);
6247}
6248
6249static int nl80211_start_sched_scan(struct sk_buff *skb,
6250 struct genl_info *info)
6251{
6252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6253 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006254 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006255 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006256 int err;
6257
6258 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6259 !rdev->ops->sched_scan_start)
6260 return -EOPNOTSUPP;
6261
6262 if (rdev->sched_scan_req)
6263 return -EINPROGRESS;
6264
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006265 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6266 info->attrs);
6267
6268 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006269 if (err)
6270 goto out_err;
6271
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006272 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006273 if (err)
6274 goto out_free;
6275
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006276 sched_scan_req->dev = dev;
6277 sched_scan_req->wiphy = &rdev->wiphy;
6278
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006279 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6280 sched_scan_req->owner_nlportid = info->snd_portid;
6281
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006282 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006283
6284 nl80211_send_sched_scan(rdev, dev,
6285 NL80211_CMD_START_SCHED_SCAN);
6286 return 0;
6287
6288out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006289 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006290out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006291 return err;
6292}
6293
6294static int nl80211_stop_sched_scan(struct sk_buff *skb,
6295 struct genl_info *info)
6296{
6297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6298
6299 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6300 !rdev->ops->sched_scan_stop)
6301 return -EOPNOTSUPP;
6302
Johannes Berg5fe231e2013-05-08 21:45:15 +02006303 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006304}
6305
Simon Wunderlich04f39042013-02-08 18:16:19 +01006306static int nl80211_start_radar_detection(struct sk_buff *skb,
6307 struct genl_info *info)
6308{
6309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6310 struct net_device *dev = info->user_ptr[1];
6311 struct wireless_dev *wdev = dev->ieee80211_ptr;
6312 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006313 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006314 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006315 int err;
6316
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006317 dfs_region = reg_get_dfs_region(wdev->wiphy);
6318 if (dfs_region == NL80211_DFS_UNSET)
6319 return -EINVAL;
6320
Simon Wunderlich04f39042013-02-08 18:16:19 +01006321 err = nl80211_parse_chandef(rdev, info, &chandef);
6322 if (err)
6323 return err;
6324
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006325 if (netif_carrier_ok(dev))
6326 return -EBUSY;
6327
Simon Wunderlich04f39042013-02-08 18:16:19 +01006328 if (wdev->cac_started)
6329 return -EBUSY;
6330
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006331 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006332 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006333 if (err < 0)
6334 return err;
6335
6336 if (err == 0)
6337 return -EINVAL;
6338
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006339 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006340 return -EINVAL;
6341
6342 if (!rdev->ops->start_radar_detection)
6343 return -EOPNOTSUPP;
6344
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006345 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6346 if (WARN_ON(!cac_time_ms))
6347 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6348
6349 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6350 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006351 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006352 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006353 wdev->cac_started = true;
6354 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006355 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006356 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006357 return err;
6358}
6359
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006360static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6361{
6362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6363 struct net_device *dev = info->user_ptr[1];
6364 struct wireless_dev *wdev = dev->ieee80211_ptr;
6365 struct cfg80211_csa_settings params;
6366 /* csa_attrs is defined static to avoid waste of stack size - this
6367 * function is called under RTNL lock, so this should not be a problem.
6368 */
6369 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006370 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006371 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006372 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006373 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006374
6375 if (!rdev->ops->channel_switch ||
6376 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6377 return -EOPNOTSUPP;
6378
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006379 switch (dev->ieee80211_ptr->iftype) {
6380 case NL80211_IFTYPE_AP:
6381 case NL80211_IFTYPE_P2P_GO:
6382 need_new_beacon = true;
6383
6384 /* useless if AP is not running */
6385 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006386 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006387 break;
6388 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006389 if (!wdev->ssid_len)
6390 return -ENOTCONN;
6391 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006392 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006393 if (!wdev->mesh_id_len)
6394 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006395 break;
6396 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006397 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006398 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006399
6400 memset(&params, 0, sizeof(params));
6401
6402 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6403 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6404 return -EINVAL;
6405
6406 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006407 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006408 return -EINVAL;
6409
Luciano Coelho252e07c2014-10-08 09:48:34 +03006410 /* Even though the attribute is u32, the specification says
6411 * u8, so let's make sure we don't overflow.
6412 */
6413 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6414 if (cs_count > 255)
6415 return -EINVAL;
6416
6417 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006418
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006419 if (!need_new_beacon)
6420 goto skip_beacons;
6421
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006422 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6423 if (err)
6424 return err;
6425
6426 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6427 info->attrs[NL80211_ATTR_CSA_IES],
6428 nl80211_policy);
6429 if (err)
6430 return err;
6431
6432 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6433 if (err)
6434 return err;
6435
6436 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6437 return -EINVAL;
6438
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006439 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6440 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006441 return -EINVAL;
6442
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006443 params.n_counter_offsets_beacon = len / sizeof(u16);
6444 if (rdev->wiphy.max_num_csa_counters &&
6445 (params.n_counter_offsets_beacon >
6446 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006447 return -EINVAL;
6448
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006449 params.counter_offsets_beacon =
6450 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6451
6452 /* sanity checks - counters should fit and be the same */
6453 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6454 u16 offset = params.counter_offsets_beacon[i];
6455
6456 if (offset >= params.beacon_csa.tail_len)
6457 return -EINVAL;
6458
6459 if (params.beacon_csa.tail[offset] != params.count)
6460 return -EINVAL;
6461 }
6462
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006463 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006464 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6465 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006466 return -EINVAL;
6467
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006468 params.n_counter_offsets_presp = len / sizeof(u16);
6469 if (rdev->wiphy.max_num_csa_counters &&
6470 (params.n_counter_offsets_beacon >
6471 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006472 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006473
6474 params.counter_offsets_presp =
6475 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6476
6477 /* sanity checks - counters should fit and be the same */
6478 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6479 u16 offset = params.counter_offsets_presp[i];
6480
6481 if (offset >= params.beacon_csa.probe_resp_len)
6482 return -EINVAL;
6483
6484 if (params.beacon_csa.probe_resp[offset] !=
6485 params.count)
6486 return -EINVAL;
6487 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006488 }
6489
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006490skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006491 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6492 if (err)
6493 return err;
6494
Ilan Peer174e0cd2014-02-23 09:13:01 +02006495 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6496 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006497 return -EINVAL;
6498
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006499 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6500 &params.chandef,
6501 wdev->iftype);
6502 if (err < 0)
6503 return err;
6504
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006505 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006506 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006507
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006508 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6509 params.block_tx = true;
6510
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006511 wdev_lock(wdev);
6512 err = rdev_channel_switch(rdev, dev, &params);
6513 wdev_unlock(wdev);
6514
6515 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006516}
6517
Johannes Berg9720bb32011-06-21 09:45:33 +02006518static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6519 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006520 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006521 struct wireless_dev *wdev,
6522 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006523{
Johannes Berg48ab9052009-07-10 18:42:31 +02006524 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006525 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006526 void *hdr;
6527 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006528
6529 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006530
Eric W. Biederman15e47302012-09-07 20:12:54 +00006531 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006532 NL80211_CMD_NEW_SCAN_RESULTS);
6533 if (!hdr)
6534 return -1;
6535
Johannes Berg9720bb32011-06-21 09:45:33 +02006536 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6537
Johannes Berg97990a02013-04-19 01:02:55 +02006538 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6539 goto nla_put_failure;
6540 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006541 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6542 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006543 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6544 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006545
6546 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6547 if (!bss)
6548 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006549 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006550 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006551 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006552
6553 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006554 /* indicate whether we have probe response data or not */
6555 if (rcu_access_pointer(res->proberesp_ies) &&
6556 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6557 goto fail_unlock_rcu;
6558
6559 /* this pointer prefers to be pointed to probe response data
6560 * but is always valid
6561 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006562 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006563 if (ies) {
6564 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6565 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006566 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6567 ies->len, ies->data))
6568 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006569 }
Johannes Berg0e227082014-08-12 20:34:30 +02006570
6571 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006572 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006573 if (ies && ies->from_beacon) {
6574 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006575 goto fail_unlock_rcu;
6576 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6577 ies->len, ies->data))
6578 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006579 }
6580 rcu_read_unlock();
6581
David S. Miller9360ffd2012-03-29 04:41:26 -04006582 if (res->beacon_interval &&
6583 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6584 goto nla_put_failure;
6585 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6586 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006587 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006588 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6589 jiffies_to_msecs(jiffies - intbss->ts)))
6590 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006591
Johannes Berg77965c92009-02-18 18:45:06 +01006592 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006593 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006594 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6595 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006596 break;
6597 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006598 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6599 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006600 break;
6601 default:
6602 break;
6603 }
6604
Johannes Berg48ab9052009-07-10 18:42:31 +02006605 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006606 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006607 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006608 if (intbss == wdev->current_bss &&
6609 nla_put_u32(msg, NL80211_BSS_STATUS,
6610 NL80211_BSS_STATUS_ASSOCIATED))
6611 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006612 break;
6613 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006614 if (intbss == wdev->current_bss &&
6615 nla_put_u32(msg, NL80211_BSS_STATUS,
6616 NL80211_BSS_STATUS_IBSS_JOINED))
6617 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006618 break;
6619 default:
6620 break;
6621 }
6622
Johannes Berg2a519312009-02-10 21:25:55 +01006623 nla_nest_end(msg, bss);
6624
Johannes Berg053c0952015-01-16 22:09:00 +01006625 genlmsg_end(msg, hdr);
6626 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006627
Johannes Berg8cef2c92013-02-05 16:54:31 +01006628 fail_unlock_rcu:
6629 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006630 nla_put_failure:
6631 genlmsg_cancel(msg, hdr);
6632 return -EMSGSIZE;
6633}
6634
Johannes Berg97990a02013-04-19 01:02:55 +02006635static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006636{
Johannes Berg48ab9052009-07-10 18:42:31 +02006637 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006638 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006639 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006640 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006641 int err;
6642
Johannes Berg97990a02013-04-19 01:02:55 +02006643 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006644 if (err)
6645 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006646
Johannes Berg48ab9052009-07-10 18:42:31 +02006647 wdev_lock(wdev);
6648 spin_lock_bh(&rdev->bss_lock);
6649 cfg80211_bss_expire(rdev);
6650
Johannes Berg9720bb32011-06-21 09:45:33 +02006651 cb->seq = rdev->bss_generation;
6652
Johannes Berg48ab9052009-07-10 18:42:31 +02006653 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006654 if (++idx <= start)
6655 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006656 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006657 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006658 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006659 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006660 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006661 }
6662 }
6663
Johannes Berg48ab9052009-07-10 18:42:31 +02006664 spin_unlock_bh(&rdev->bss_lock);
6665 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006666
Johannes Berg97990a02013-04-19 01:02:55 +02006667 cb->args[2] = idx;
6668 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006669
Johannes Berg67748892010-10-04 21:14:06 +02006670 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006671}
6672
Eric W. Biederman15e47302012-09-07 20:12:54 +00006673static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006674 int flags, struct net_device *dev,
6675 bool allow_radio_stats,
6676 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006677{
6678 void *hdr;
6679 struct nlattr *infoattr;
6680
Johannes Berg11f78ac2014-11-14 16:43:50 +01006681 /* skip radio stats if userspace didn't request them */
6682 if (!survey->channel && !allow_radio_stats)
6683 return 0;
6684
Eric W. Biederman15e47302012-09-07 20:12:54 +00006685 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006686 NL80211_CMD_NEW_SURVEY_RESULTS);
6687 if (!hdr)
6688 return -ENOMEM;
6689
David S. Miller9360ffd2012-03-29 04:41:26 -04006690 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6691 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006692
6693 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6694 if (!infoattr)
6695 goto nla_put_failure;
6696
Johannes Berg11f78ac2014-11-14 16:43:50 +01006697 if (survey->channel &&
6698 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006699 survey->channel->center_freq))
6700 goto nla_put_failure;
6701
6702 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6703 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6704 goto nla_put_failure;
6705 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6706 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6707 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006708 if ((survey->filled & SURVEY_INFO_TIME) &&
6709 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6710 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006711 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006712 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6713 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6714 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006715 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006716 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6717 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6718 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006719 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006720 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6721 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6722 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006723 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006724 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6725 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6726 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006727 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006728 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6729 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6730 survey->time_scan))
6731 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006732
6733 nla_nest_end(msg, infoattr);
6734
Johannes Berg053c0952015-01-16 22:09:00 +01006735 genlmsg_end(msg, hdr);
6736 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006737
6738 nla_put_failure:
6739 genlmsg_cancel(msg, hdr);
6740 return -EMSGSIZE;
6741}
6742
Johannes Berg11f78ac2014-11-14 16:43:50 +01006743static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006744{
6745 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006746 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006747 struct wireless_dev *wdev;
6748 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006749 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006750 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006751
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006752 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006753 if (res)
6754 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006755
Johannes Berg11f78ac2014-11-14 16:43:50 +01006756 /* prepare_wdev_dump parsed the attributes */
6757 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6758
Johannes Berg97990a02013-04-19 01:02:55 +02006759 if (!wdev->netdev) {
6760 res = -EINVAL;
6761 goto out_err;
6762 }
6763
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006764 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006765 res = -EOPNOTSUPP;
6766 goto out_err;
6767 }
6768
6769 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006770 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006771 if (res == -ENOENT)
6772 break;
6773 if (res)
6774 goto out_err;
6775
Johannes Berg11f78ac2014-11-14 16:43:50 +01006776 /* don't send disabled channels, but do send non-channel data */
6777 if (survey.channel &&
6778 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006779 survey_idx++;
6780 continue;
6781 }
6782
Holger Schurig61fa7132009-11-11 12:25:40 +01006783 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006784 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006785 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006786 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006787 goto out;
6788 survey_idx++;
6789 }
6790
6791 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006792 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006793 res = skb->len;
6794 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006795 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006796 return res;
6797}
6798
Samuel Ortizb23aa672009-07-01 21:26:54 +02006799static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6800{
6801 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6802 NL80211_WPA_VERSION_2));
6803}
6804
Jouni Malinen636a5d32009-03-19 13:39:22 +02006805static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6806{
Johannes Berg4c476992010-10-04 21:36:35 +02006807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6808 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006809 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006810 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6811 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006812 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006813 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006814 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006815
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006816 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6817 return -EINVAL;
6818
6819 if (!info->attrs[NL80211_ATTR_MAC])
6820 return -EINVAL;
6821
Jouni Malinen17780922009-03-27 20:52:47 +02006822 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6823 return -EINVAL;
6824
Johannes Berg19957bb2009-07-02 17:20:43 +02006825 if (!info->attrs[NL80211_ATTR_SSID])
6826 return -EINVAL;
6827
6828 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6829 return -EINVAL;
6830
Johannes Bergfffd0932009-07-08 14:22:54 +02006831 err = nl80211_parse_key(info, &key);
6832 if (err)
6833 return err;
6834
6835 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006836 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6837 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006838 if (!key.p.key || !key.p.key_len)
6839 return -EINVAL;
6840 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6841 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6842 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6843 key.p.key_len != WLAN_KEY_LEN_WEP104))
6844 return -EINVAL;
6845 if (key.idx > 4)
6846 return -EINVAL;
6847 } else {
6848 key.p.key_len = 0;
6849 key.p.key = NULL;
6850 }
6851
Johannes Bergafea0b72010-08-10 09:46:42 +02006852 if (key.idx >= 0) {
6853 int i;
6854 bool ok = false;
6855 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6856 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6857 ok = true;
6858 break;
6859 }
6860 }
Johannes Berg4c476992010-10-04 21:36:35 +02006861 if (!ok)
6862 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006863 }
6864
Johannes Berg4c476992010-10-04 21:36:35 +02006865 if (!rdev->ops->auth)
6866 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006867
Johannes Berg074ac8d2010-09-16 14:58:22 +02006868 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006869 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6870 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006871
Johannes Berg19957bb2009-07-02 17:20:43 +02006872 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006873 chan = nl80211_get_valid_chan(&rdev->wiphy,
6874 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6875 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006876 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006877
Johannes Berg19957bb2009-07-02 17:20:43 +02006878 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6879 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6880
6881 if (info->attrs[NL80211_ATTR_IE]) {
6882 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6883 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6884 }
6885
6886 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006887 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006888 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006889
Jouni Malinene39e5b52012-09-30 19:29:39 +03006890 if (auth_type == NL80211_AUTHTYPE_SAE &&
6891 !info->attrs[NL80211_ATTR_SAE_DATA])
6892 return -EINVAL;
6893
6894 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6895 if (auth_type != NL80211_AUTHTYPE_SAE)
6896 return -EINVAL;
6897 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6898 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6899 /* need to include at least Auth Transaction and Status Code */
6900 if (sae_data_len < 4)
6901 return -EINVAL;
6902 }
6903
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006904 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6905
Johannes Berg95de8172012-01-20 13:55:25 +01006906 /*
6907 * Since we no longer track auth state, ignore
6908 * requests to only change local state.
6909 */
6910 if (local_state_change)
6911 return 0;
6912
Johannes Berg91bf9b22013-05-15 17:44:01 +02006913 wdev_lock(dev->ieee80211_ptr);
6914 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6915 ssid, ssid_len, ie, ie_len,
6916 key.p.key, key.p.key_len, key.idx,
6917 sae_data, sae_data_len);
6918 wdev_unlock(dev->ieee80211_ptr);
6919 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006920}
6921
Johannes Bergc0692b82010-08-27 14:26:53 +03006922static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6923 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006924 struct cfg80211_crypto_settings *settings,
6925 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006926{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006927 memset(settings, 0, sizeof(*settings));
6928
Samuel Ortizb23aa672009-07-01 21:26:54 +02006929 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6930
Johannes Bergc0692b82010-08-27 14:26:53 +03006931 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6932 u16 proto;
6933 proto = nla_get_u16(
6934 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6935 settings->control_port_ethertype = cpu_to_be16(proto);
6936 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6937 proto != ETH_P_PAE)
6938 return -EINVAL;
6939 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6940 settings->control_port_no_encrypt = true;
6941 } else
6942 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6943
Samuel Ortizb23aa672009-07-01 21:26:54 +02006944 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6945 void *data;
6946 int len, i;
6947
6948 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6949 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6950 settings->n_ciphers_pairwise = len / sizeof(u32);
6951
6952 if (len % sizeof(u32))
6953 return -EINVAL;
6954
Johannes Berg3dc27d22009-07-02 21:36:37 +02006955 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006956 return -EINVAL;
6957
6958 memcpy(settings->ciphers_pairwise, data, len);
6959
6960 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006961 if (!cfg80211_supported_cipher_suite(
6962 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006963 settings->ciphers_pairwise[i]))
6964 return -EINVAL;
6965 }
6966
6967 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6968 settings->cipher_group =
6969 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006970 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6971 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006972 return -EINVAL;
6973 }
6974
6975 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6976 settings->wpa_versions =
6977 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6978 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6979 return -EINVAL;
6980 }
6981
6982 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6983 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006984 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006985
6986 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6987 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6988 settings->n_akm_suites = len / sizeof(u32);
6989
6990 if (len % sizeof(u32))
6991 return -EINVAL;
6992
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006993 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6994 return -EINVAL;
6995
Samuel Ortizb23aa672009-07-01 21:26:54 +02006996 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006997 }
6998
6999 return 0;
7000}
7001
Jouni Malinen636a5d32009-03-19 13:39:22 +02007002static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7003{
Johannes Berg4c476992010-10-04 21:36:35 +02007004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7005 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007006 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007007 struct cfg80211_assoc_request req = {};
7008 const u8 *bssid, *ssid;
7009 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007010
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007011 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7012 return -EINVAL;
7013
7014 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007015 !info->attrs[NL80211_ATTR_SSID] ||
7016 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007017 return -EINVAL;
7018
Johannes Berg4c476992010-10-04 21:36:35 +02007019 if (!rdev->ops->assoc)
7020 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007021
Johannes Berg074ac8d2010-09-16 14:58:22 +02007022 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007023 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7024 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007025
Johannes Berg19957bb2009-07-02 17:20:43 +02007026 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007027
Jouni Malinen664834d2014-01-15 00:01:44 +02007028 chan = nl80211_get_valid_chan(&rdev->wiphy,
7029 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7030 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007031 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007032
Johannes Berg19957bb2009-07-02 17:20:43 +02007033 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7034 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007035
7036 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007037 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7038 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007039 }
7040
Jouni Malinendc6382c2009-05-06 22:09:37 +03007041 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007042 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007043 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007044 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007045 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007046 else if (mfp != NL80211_MFP_NO)
7047 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007048 }
7049
Johannes Berg3e5d7642009-07-07 14:37:26 +02007050 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007051 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007052
Ben Greear7e7c8922011-11-18 11:31:59 -08007053 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007054 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007055
7056 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007057 memcpy(&req.ht_capa_mask,
7058 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7059 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007060
7061 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007062 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007063 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007064 memcpy(&req.ht_capa,
7065 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7066 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007067 }
7068
Johannes Bergee2aca32013-02-21 17:36:01 +01007069 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007070 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007071
7072 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007073 memcpy(&req.vht_capa_mask,
7074 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7075 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007076
7077 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007078 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007079 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007080 memcpy(&req.vht_capa,
7081 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7082 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007083 }
7084
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007085 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7086 if (!(rdev->wiphy.features &
7087 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7088 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7089 return -EINVAL;
7090 req.flags |= ASSOC_REQ_USE_RRM;
7091 }
7092
Johannes Bergf62fab72013-02-21 20:09:09 +01007093 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007094 if (!err) {
7095 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007096 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7097 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007098 wdev_unlock(dev->ieee80211_ptr);
7099 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007100
Jouni Malinen636a5d32009-03-19 13:39:22 +02007101 return err;
7102}
7103
7104static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7105{
Johannes Berg4c476992010-10-04 21:36:35 +02007106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7107 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007108 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007109 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007110 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007111 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007112
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007113 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7114 return -EINVAL;
7115
7116 if (!info->attrs[NL80211_ATTR_MAC])
7117 return -EINVAL;
7118
7119 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7120 return -EINVAL;
7121
Johannes Berg4c476992010-10-04 21:36:35 +02007122 if (!rdev->ops->deauth)
7123 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007124
Johannes Berg074ac8d2010-09-16 14:58:22 +02007125 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007126 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7127 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007128
Johannes Berg19957bb2009-07-02 17:20:43 +02007129 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007130
Johannes Berg19957bb2009-07-02 17:20:43 +02007131 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7132 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007133 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007134 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007135 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007136
7137 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007138 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7139 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007140 }
7141
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007142 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7143
Johannes Berg91bf9b22013-05-15 17:44:01 +02007144 wdev_lock(dev->ieee80211_ptr);
7145 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7146 local_state_change);
7147 wdev_unlock(dev->ieee80211_ptr);
7148 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007149}
7150
7151static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7152{
Johannes Berg4c476992010-10-04 21:36:35 +02007153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7154 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007155 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007156 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007157 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007158 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007159
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007160 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7161 return -EINVAL;
7162
7163 if (!info->attrs[NL80211_ATTR_MAC])
7164 return -EINVAL;
7165
7166 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7167 return -EINVAL;
7168
Johannes Berg4c476992010-10-04 21:36:35 +02007169 if (!rdev->ops->disassoc)
7170 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007171
Johannes Berg074ac8d2010-09-16 14:58:22 +02007172 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007173 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7174 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007175
Johannes Berg19957bb2009-07-02 17:20:43 +02007176 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007177
Johannes Berg19957bb2009-07-02 17:20:43 +02007178 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7179 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007180 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007181 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007182 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007183
7184 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007185 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7186 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007187 }
7188
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007189 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7190
Johannes Berg91bf9b22013-05-15 17:44:01 +02007191 wdev_lock(dev->ieee80211_ptr);
7192 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7193 local_state_change);
7194 wdev_unlock(dev->ieee80211_ptr);
7195 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007196}
7197
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007198static bool
7199nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7200 int mcast_rate[IEEE80211_NUM_BANDS],
7201 int rateval)
7202{
7203 struct wiphy *wiphy = &rdev->wiphy;
7204 bool found = false;
7205 int band, i;
7206
7207 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7208 struct ieee80211_supported_band *sband;
7209
7210 sband = wiphy->bands[band];
7211 if (!sband)
7212 continue;
7213
7214 for (i = 0; i < sband->n_bitrates; i++) {
7215 if (sband->bitrates[i].bitrate == rateval) {
7216 mcast_rate[band] = i + 1;
7217 found = true;
7218 break;
7219 }
7220 }
7221 }
7222
7223 return found;
7224}
7225
Johannes Berg04a773a2009-04-19 21:24:32 +02007226static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7227{
Johannes Berg4c476992010-10-04 21:36:35 +02007228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7229 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007230 struct cfg80211_ibss_params ibss;
7231 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007232 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007233 int err;
7234
Johannes Berg8e30bc52009-04-22 17:45:38 +02007235 memset(&ibss, 0, sizeof(ibss));
7236
Johannes Berg04a773a2009-04-19 21:24:32 +02007237 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7238 return -EINVAL;
7239
Johannes Berg683b6d32012-11-08 21:25:48 +01007240 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007241 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7242 return -EINVAL;
7243
Johannes Berg8e30bc52009-04-22 17:45:38 +02007244 ibss.beacon_interval = 100;
7245
7246 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7247 ibss.beacon_interval =
7248 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7249 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7250 return -EINVAL;
7251 }
7252
Johannes Berg4c476992010-10-04 21:36:35 +02007253 if (!rdev->ops->join_ibss)
7254 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007255
Johannes Berg4c476992010-10-04 21:36:35 +02007256 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7257 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007258
Johannes Berg79c97e92009-07-07 03:56:12 +02007259 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007260
Johannes Berg39193492011-09-16 13:45:25 +02007261 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007262 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007263
7264 if (!is_valid_ether_addr(ibss.bssid))
7265 return -EINVAL;
7266 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007267 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7268 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7269
7270 if (info->attrs[NL80211_ATTR_IE]) {
7271 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7272 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7273 }
7274
Johannes Berg683b6d32012-11-08 21:25:48 +01007275 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7276 if (err)
7277 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007278
Ilan Peer174e0cd2014-02-23 09:13:01 +02007279 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7280 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007281 return -EINVAL;
7282
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007283 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007284 case NL80211_CHAN_WIDTH_5:
7285 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007286 case NL80211_CHAN_WIDTH_20_NOHT:
7287 break;
7288 case NL80211_CHAN_WIDTH_20:
7289 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007290 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7291 return -EINVAL;
7292 break;
7293 case NL80211_CHAN_WIDTH_80:
7294 case NL80211_CHAN_WIDTH_80P80:
7295 case NL80211_CHAN_WIDTH_160:
7296 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7297 return -EINVAL;
7298 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7299 NL80211_EXT_FEATURE_VHT_IBSS))
7300 return -EINVAL;
7301 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007302 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007303 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007304 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007305
Johannes Berg04a773a2009-04-19 21:24:32 +02007306 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007307 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007308
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007309 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7310 u8 *rates =
7311 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7312 int n_rates =
7313 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7314 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007315 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007316
Johannes Berg34850ab2011-07-18 18:08:35 +02007317 err = ieee80211_get_ratemask(sband, rates, n_rates,
7318 &ibss.basic_rates);
7319 if (err)
7320 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007321 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007322
Simon Wunderlich803768f2013-06-28 10:39:58 +02007323 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7324 memcpy(&ibss.ht_capa_mask,
7325 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7326 sizeof(ibss.ht_capa_mask));
7327
7328 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7329 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7330 return -EINVAL;
7331 memcpy(&ibss.ht_capa,
7332 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7333 sizeof(ibss.ht_capa));
7334 }
7335
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007336 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7337 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7338 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7339 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007340
Johannes Berg4c476992010-10-04 21:36:35 +02007341 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307342 bool no_ht = false;
7343
Johannes Berg4c476992010-10-04 21:36:35 +02007344 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307345 info->attrs[NL80211_ATTR_KEYS],
7346 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007347 if (IS_ERR(connkeys))
7348 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307349
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007350 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7351 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307352 kfree(connkeys);
7353 return -EINVAL;
7354 }
Johannes Berg4c476992010-10-04 21:36:35 +02007355 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007356
Antonio Quartulli267335d2012-01-31 20:25:47 +01007357 ibss.control_port =
7358 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7359
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007360 ibss.userspace_handles_dfs =
7361 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7362
Johannes Berg4c476992010-10-04 21:36:35 +02007363 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007364 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007365 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007366 return err;
7367}
7368
7369static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7370{
Johannes Berg4c476992010-10-04 21:36:35 +02007371 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7372 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007373
Johannes Berg4c476992010-10-04 21:36:35 +02007374 if (!rdev->ops->leave_ibss)
7375 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007376
Johannes Berg4c476992010-10-04 21:36:35 +02007377 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7378 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007379
Johannes Berg4c476992010-10-04 21:36:35 +02007380 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007381}
7382
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007383static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7384{
7385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7386 struct net_device *dev = info->user_ptr[1];
7387 int mcast_rate[IEEE80211_NUM_BANDS];
7388 u32 nla_rate;
7389 int err;
7390
7391 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7392 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7393 return -EOPNOTSUPP;
7394
7395 if (!rdev->ops->set_mcast_rate)
7396 return -EOPNOTSUPP;
7397
7398 memset(mcast_rate, 0, sizeof(mcast_rate));
7399
7400 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7401 return -EINVAL;
7402
7403 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7404 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7405 return -EINVAL;
7406
7407 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7408
7409 return err;
7410}
7411
Johannes Bergad7e7182013-11-13 13:37:47 +01007412static struct sk_buff *
7413__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007414 struct wireless_dev *wdev, int approxlen,
7415 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007416 enum nl80211_attrs attr,
7417 const struct nl80211_vendor_cmd_info *info,
7418 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007419{
7420 struct sk_buff *skb;
7421 void *hdr;
7422 struct nlattr *data;
7423
7424 skb = nlmsg_new(approxlen + 100, gfp);
7425 if (!skb)
7426 return NULL;
7427
7428 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7429 if (!hdr) {
7430 kfree_skb(skb);
7431 return NULL;
7432 }
7433
7434 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7435 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007436
7437 if (info) {
7438 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7439 info->vendor_id))
7440 goto nla_put_failure;
7441 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7442 info->subcmd))
7443 goto nla_put_failure;
7444 }
7445
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007446 if (wdev) {
7447 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7448 wdev_id(wdev)))
7449 goto nla_put_failure;
7450 if (wdev->netdev &&
7451 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7452 wdev->netdev->ifindex))
7453 goto nla_put_failure;
7454 }
7455
Johannes Bergad7e7182013-11-13 13:37:47 +01007456 data = nla_nest_start(skb, attr);
7457
7458 ((void **)skb->cb)[0] = rdev;
7459 ((void **)skb->cb)[1] = hdr;
7460 ((void **)skb->cb)[2] = data;
7461
7462 return skb;
7463
7464 nla_put_failure:
7465 kfree_skb(skb);
7466 return NULL;
7467}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007468
Johannes Berge03ad6e2014-01-01 17:22:30 +01007469struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007470 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007471 enum nl80211_commands cmd,
7472 enum nl80211_attrs attr,
7473 int vendor_event_idx,
7474 int approxlen, gfp_t gfp)
7475{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007476 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007477 const struct nl80211_vendor_cmd_info *info;
7478
7479 switch (cmd) {
7480 case NL80211_CMD_TESTMODE:
7481 if (WARN_ON(vendor_event_idx != -1))
7482 return NULL;
7483 info = NULL;
7484 break;
7485 case NL80211_CMD_VENDOR:
7486 if (WARN_ON(vendor_event_idx < 0 ||
7487 vendor_event_idx >= wiphy->n_vendor_events))
7488 return NULL;
7489 info = &wiphy->vendor_events[vendor_event_idx];
7490 break;
7491 default:
7492 WARN_ON(1);
7493 return NULL;
7494 }
7495
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007496 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007497 cmd, attr, info, gfp);
7498}
7499EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7500
7501void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7502{
7503 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7504 void *hdr = ((void **)skb->cb)[1];
7505 struct nlattr *data = ((void **)skb->cb)[2];
7506 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7507
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007508 /* clear CB data for netlink core to own from now on */
7509 memset(skb->cb, 0, sizeof(skb->cb));
7510
Johannes Berge03ad6e2014-01-01 17:22:30 +01007511 nla_nest_end(skb, data);
7512 genlmsg_end(skb, hdr);
7513
7514 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7515 mcgrp = NL80211_MCGRP_VENDOR;
7516
7517 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7518 mcgrp, gfp);
7519}
7520EXPORT_SYMBOL(__cfg80211_send_event_skb);
7521
Johannes Bergaff89a92009-07-01 21:26:51 +02007522#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007523static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7524{
Johannes Berg4c476992010-10-04 21:36:35 +02007525 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007526 struct wireless_dev *wdev =
7527 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007528 int err;
7529
David Spinadelfc73f112013-07-31 18:04:15 +03007530 if (!rdev->ops->testmode_cmd)
7531 return -EOPNOTSUPP;
7532
7533 if (IS_ERR(wdev)) {
7534 err = PTR_ERR(wdev);
7535 if (err != -EINVAL)
7536 return err;
7537 wdev = NULL;
7538 } else if (wdev->wiphy != &rdev->wiphy) {
7539 return -EINVAL;
7540 }
7541
Johannes Bergaff89a92009-07-01 21:26:51 +02007542 if (!info->attrs[NL80211_ATTR_TESTDATA])
7543 return -EINVAL;
7544
Johannes Bergad7e7182013-11-13 13:37:47 +01007545 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007546 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007547 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7548 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007549 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007550
Johannes Bergaff89a92009-07-01 21:26:51 +02007551 return err;
7552}
7553
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007554static int nl80211_testmode_dump(struct sk_buff *skb,
7555 struct netlink_callback *cb)
7556{
Johannes Berg00918d32011-12-13 17:22:05 +01007557 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007558 int err;
7559 long phy_idx;
7560 void *data = NULL;
7561 int data_len = 0;
7562
Johannes Berg5fe231e2013-05-08 21:45:15 +02007563 rtnl_lock();
7564
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007565 if (cb->args[0]) {
7566 /*
7567 * 0 is a valid index, but not valid for args[0],
7568 * so we need to offset by 1.
7569 */
7570 phy_idx = cb->args[0] - 1;
7571 } else {
7572 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7573 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7574 nl80211_policy);
7575 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007576 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007577
Johannes Berg2bd7e352012-06-15 14:23:16 +02007578 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7579 nl80211_fam.attrbuf);
7580 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007581 err = PTR_ERR(rdev);
7582 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007583 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007584 phy_idx = rdev->wiphy_idx;
7585 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007586
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007587 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7588 cb->args[1] =
7589 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7590 }
7591
7592 if (cb->args[1]) {
7593 data = nla_data((void *)cb->args[1]);
7594 data_len = nla_len((void *)cb->args[1]);
7595 }
7596
Johannes Berg00918d32011-12-13 17:22:05 +01007597 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7598 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007599 err = -ENOENT;
7600 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007601 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007602
Johannes Berg00918d32011-12-13 17:22:05 +01007603 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007604 err = -EOPNOTSUPP;
7605 goto out_err;
7606 }
7607
7608 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007609 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007610 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7611 NL80211_CMD_TESTMODE);
7612 struct nlattr *tmdata;
7613
Dan Carpentercb35fba2013-08-14 14:50:01 +03007614 if (!hdr)
7615 break;
7616
David S. Miller9360ffd2012-03-29 04:41:26 -04007617 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007618 genlmsg_cancel(skb, hdr);
7619 break;
7620 }
7621
7622 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7623 if (!tmdata) {
7624 genlmsg_cancel(skb, hdr);
7625 break;
7626 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007627 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007628 nla_nest_end(skb, tmdata);
7629
7630 if (err == -ENOBUFS || err == -ENOENT) {
7631 genlmsg_cancel(skb, hdr);
7632 break;
7633 } else if (err) {
7634 genlmsg_cancel(skb, hdr);
7635 goto out_err;
7636 }
7637
7638 genlmsg_end(skb, hdr);
7639 }
7640
7641 err = skb->len;
7642 /* see above */
7643 cb->args[0] = phy_idx + 1;
7644 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007645 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007646 return err;
7647}
Johannes Bergaff89a92009-07-01 21:26:51 +02007648#endif
7649
Samuel Ortizb23aa672009-07-01 21:26:54 +02007650static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7651{
Johannes Berg4c476992010-10-04 21:36:35 +02007652 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7653 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007654 struct cfg80211_connect_params connect;
7655 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007656 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007657 int err;
7658
7659 memset(&connect, 0, sizeof(connect));
7660
7661 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7662 return -EINVAL;
7663
7664 if (!info->attrs[NL80211_ATTR_SSID] ||
7665 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7666 return -EINVAL;
7667
7668 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7669 connect.auth_type =
7670 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007671 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7672 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007673 return -EINVAL;
7674 } else
7675 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7676
7677 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7678
Johannes Bergc0692b82010-08-27 14:26:53 +03007679 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007680 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007681 if (err)
7682 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007683
Johannes Berg074ac8d2010-09-16 14:58:22 +02007684 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007685 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7686 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007687
Johannes Berg79c97e92009-07-07 03:56:12 +02007688 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007689
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307690 connect.bg_scan_period = -1;
7691 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7692 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7693 connect.bg_scan_period =
7694 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7695 }
7696
Samuel Ortizb23aa672009-07-01 21:26:54 +02007697 if (info->attrs[NL80211_ATTR_MAC])
7698 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007699 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7700 connect.bssid_hint =
7701 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007702 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7703 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7704
7705 if (info->attrs[NL80211_ATTR_IE]) {
7706 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7707 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7708 }
7709
Jouni Malinencee00a92013-01-15 17:15:57 +02007710 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7711 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7712 if (connect.mfp != NL80211_MFP_REQUIRED &&
7713 connect.mfp != NL80211_MFP_NO)
7714 return -EINVAL;
7715 } else {
7716 connect.mfp = NL80211_MFP_NO;
7717 }
7718
Samuel Ortizb23aa672009-07-01 21:26:54 +02007719 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007720 connect.channel = nl80211_get_valid_chan(
7721 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7722 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007723 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007724 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007725 connect.channel_hint = nl80211_get_valid_chan(
7726 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7727 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007728 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007729 }
7730
Johannes Bergfffd0932009-07-08 14:22:54 +02007731 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7732 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307733 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007734 if (IS_ERR(connkeys))
7735 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007736 }
7737
Ben Greear7e7c8922011-11-18 11:31:59 -08007738 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7739 connect.flags |= ASSOC_REQ_DISABLE_HT;
7740
7741 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7742 memcpy(&connect.ht_capa_mask,
7743 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7744 sizeof(connect.ht_capa_mask));
7745
7746 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007747 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007748 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007749 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007750 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007751 memcpy(&connect.ht_capa,
7752 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7753 sizeof(connect.ht_capa));
7754 }
7755
Johannes Bergee2aca32013-02-21 17:36:01 +01007756 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7757 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7758
7759 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7760 memcpy(&connect.vht_capa_mask,
7761 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7762 sizeof(connect.vht_capa_mask));
7763
7764 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7765 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007766 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007767 return -EINVAL;
7768 }
7769 memcpy(&connect.vht_capa,
7770 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7771 sizeof(connect.vht_capa));
7772 }
7773
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007774 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7775 if (!(rdev->wiphy.features &
7776 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7777 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7778 return -EINVAL;
7779 connect.flags |= ASSOC_REQ_USE_RRM;
7780 }
7781
Johannes Berg83739b02013-05-15 17:44:01 +02007782 wdev_lock(dev->ieee80211_ptr);
7783 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7784 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007785 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007786 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007787 return err;
7788}
7789
7790static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7791{
Johannes Berg4c476992010-10-04 21:36:35 +02007792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7793 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007794 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007795 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007796
7797 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7798 reason = WLAN_REASON_DEAUTH_LEAVING;
7799 else
7800 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7801
7802 if (reason == 0)
7803 return -EINVAL;
7804
Johannes Berg074ac8d2010-09-16 14:58:22 +02007805 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007806 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7807 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007808
Johannes Berg83739b02013-05-15 17:44:01 +02007809 wdev_lock(dev->ieee80211_ptr);
7810 ret = cfg80211_disconnect(rdev, dev, reason, true);
7811 wdev_unlock(dev->ieee80211_ptr);
7812 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007813}
7814
Johannes Berg463d0182009-07-14 00:33:35 +02007815static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7816{
Johannes Berg4c476992010-10-04 21:36:35 +02007817 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007818 struct net *net;
7819 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007820
Vadim Kochan4b681c82015-01-12 16:34:05 +02007821 if (info->attrs[NL80211_ATTR_PID]) {
7822 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7823
7824 net = get_net_ns_by_pid(pid);
7825 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7826 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7827
7828 net = get_net_ns_by_fd(fd);
7829 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007830 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007831 }
Johannes Berg463d0182009-07-14 00:33:35 +02007832
Johannes Berg4c476992010-10-04 21:36:35 +02007833 if (IS_ERR(net))
7834 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007835
7836 err = 0;
7837
7838 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007839 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7840 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007841
Johannes Berg463d0182009-07-14 00:33:35 +02007842 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007843 return err;
7844}
7845
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007846static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7847{
Johannes Berg4c476992010-10-04 21:36:35 +02007848 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007849 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7850 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007851 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007852 struct cfg80211_pmksa pmksa;
7853
7854 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7855
7856 if (!info->attrs[NL80211_ATTR_MAC])
7857 return -EINVAL;
7858
7859 if (!info->attrs[NL80211_ATTR_PMKID])
7860 return -EINVAL;
7861
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007862 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7863 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7864
Johannes Berg074ac8d2010-09-16 14:58:22 +02007865 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007866 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7867 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007868
7869 switch (info->genlhdr->cmd) {
7870 case NL80211_CMD_SET_PMKSA:
7871 rdev_ops = rdev->ops->set_pmksa;
7872 break;
7873 case NL80211_CMD_DEL_PMKSA:
7874 rdev_ops = rdev->ops->del_pmksa;
7875 break;
7876 default:
7877 WARN_ON(1);
7878 break;
7879 }
7880
Johannes Berg4c476992010-10-04 21:36:35 +02007881 if (!rdev_ops)
7882 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007883
Johannes Berg4c476992010-10-04 21:36:35 +02007884 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007885}
7886
7887static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7888{
Johannes Berg4c476992010-10-04 21:36:35 +02007889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7890 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007891
Johannes Berg074ac8d2010-09-16 14:58:22 +02007892 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007893 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7894 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007895
Johannes Berg4c476992010-10-04 21:36:35 +02007896 if (!rdev->ops->flush_pmksa)
7897 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007898
Hila Gonene35e4d22012-06-27 17:19:42 +03007899 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007900}
7901
Arik Nemtsov109086c2011-09-28 14:12:50 +03007902static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7903{
7904 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7905 struct net_device *dev = info->user_ptr[1];
7906 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307907 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007908 u16 status_code;
7909 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007910 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007911
7912 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7913 !rdev->ops->tdls_mgmt)
7914 return -EOPNOTSUPP;
7915
7916 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7917 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7918 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7919 !info->attrs[NL80211_ATTR_IE] ||
7920 !info->attrs[NL80211_ATTR_MAC])
7921 return -EINVAL;
7922
7923 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7924 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7925 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7926 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007927 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307928 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7929 peer_capability =
7930 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007931
Hila Gonene35e4d22012-06-27 17:19:42 +03007932 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307933 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007934 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007935 nla_data(info->attrs[NL80211_ATTR_IE]),
7936 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007937}
7938
7939static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7940{
7941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7942 struct net_device *dev = info->user_ptr[1];
7943 enum nl80211_tdls_operation operation;
7944 u8 *peer;
7945
7946 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7947 !rdev->ops->tdls_oper)
7948 return -EOPNOTSUPP;
7949
7950 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7951 !info->attrs[NL80211_ATTR_MAC])
7952 return -EINVAL;
7953
7954 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7955 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7956
Hila Gonene35e4d22012-06-27 17:19:42 +03007957 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007958}
7959
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007960static int nl80211_remain_on_channel(struct sk_buff *skb,
7961 struct genl_info *info)
7962{
Johannes Berg4c476992010-10-04 21:36:35 +02007963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007964 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007965 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007966 struct sk_buff *msg;
7967 void *hdr;
7968 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007969 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007970 int err;
7971
7972 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7973 !info->attrs[NL80211_ATTR_DURATION])
7974 return -EINVAL;
7975
7976 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7977
Johannes Berg7c4ef712011-11-18 15:33:48 +01007978 if (!rdev->ops->remain_on_channel ||
7979 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007980 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007981
Johannes Bergebf348f2012-06-01 12:50:54 +02007982 /*
7983 * We should be on that channel for at least a minimum amount of
7984 * time (10ms) but no longer than the driver supports.
7985 */
7986 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7987 duration > rdev->wiphy.max_remain_on_channel_duration)
7988 return -EINVAL;
7989
Johannes Berg683b6d32012-11-08 21:25:48 +01007990 err = nl80211_parse_chandef(rdev, info, &chandef);
7991 if (err)
7992 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007993
7994 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007995 if (!msg)
7996 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007997
Eric W. Biederman15e47302012-09-07 20:12:54 +00007998 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007999 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008000 if (!hdr) {
8001 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008002 goto free_msg;
8003 }
8004
Johannes Berg683b6d32012-11-08 21:25:48 +01008005 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8006 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008007
8008 if (err)
8009 goto free_msg;
8010
David S. Miller9360ffd2012-03-29 04:41:26 -04008011 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8012 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008013
8014 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008015
8016 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008017
8018 nla_put_failure:
8019 err = -ENOBUFS;
8020 free_msg:
8021 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008022 return err;
8023}
8024
8025static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8026 struct genl_info *info)
8027{
Johannes Berg4c476992010-10-04 21:36:35 +02008028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008029 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008030 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008031
8032 if (!info->attrs[NL80211_ATTR_COOKIE])
8033 return -EINVAL;
8034
Johannes Berg4c476992010-10-04 21:36:35 +02008035 if (!rdev->ops->cancel_remain_on_channel)
8036 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008037
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008038 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8039
Hila Gonene35e4d22012-06-27 17:19:42 +03008040 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008041}
8042
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008043static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8044 u8 *rates, u8 rates_len)
8045{
8046 u8 i;
8047 u32 mask = 0;
8048
8049 for (i = 0; i < rates_len; i++) {
8050 int rate = (rates[i] & 0x7f) * 5;
8051 int ridx;
8052 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8053 struct ieee80211_rate *srate =
8054 &sband->bitrates[ridx];
8055 if (rate == srate->bitrate) {
8056 mask |= 1 << ridx;
8057 break;
8058 }
8059 }
8060 if (ridx == sband->n_bitrates)
8061 return 0; /* rate not found */
8062 }
8063
8064 return mask;
8065}
8066
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008067static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8068 u8 *rates, u8 rates_len,
8069 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8070{
8071 u8 i;
8072
8073 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8074
8075 for (i = 0; i < rates_len; i++) {
8076 int ridx, rbit;
8077
8078 ridx = rates[i] / 8;
8079 rbit = BIT(rates[i] % 8);
8080
8081 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008082 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008083 return false;
8084
8085 /* check availability */
8086 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8087 mcs[ridx] |= rbit;
8088 else
8089 return false;
8090 }
8091
8092 return true;
8093}
8094
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008095static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8096{
8097 u16 mcs_mask = 0;
8098
8099 switch (vht_mcs_map) {
8100 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8101 break;
8102 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8103 mcs_mask = 0x00FF;
8104 break;
8105 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8106 mcs_mask = 0x01FF;
8107 break;
8108 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8109 mcs_mask = 0x03FF;
8110 break;
8111 default:
8112 break;
8113 }
8114
8115 return mcs_mask;
8116}
8117
8118static void vht_build_mcs_mask(u16 vht_mcs_map,
8119 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8120{
8121 u8 nss;
8122
8123 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8124 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8125 vht_mcs_map >>= 2;
8126 }
8127}
8128
8129static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8130 struct nl80211_txrate_vht *txrate,
8131 u16 mcs[NL80211_VHT_NSS_MAX])
8132{
8133 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8134 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8135 u8 i;
8136
8137 if (!sband->vht_cap.vht_supported)
8138 return false;
8139
8140 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8141
8142 /* Build vht_mcs_mask from VHT capabilities */
8143 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8144
8145 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8146 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8147 mcs[i] = txrate->mcs[i];
8148 else
8149 return false;
8150 }
8151
8152 return true;
8153}
8154
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008155static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008156 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8157 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008158 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8159 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008160 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008161 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008162};
8163
8164static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8165 struct genl_info *info)
8166{
8167 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008168 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008169 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008170 int rem, i;
8171 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008172 struct nlattr *tx_rates;
8173 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008174 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008175
Johannes Berg4c476992010-10-04 21:36:35 +02008176 if (!rdev->ops->set_bitrate_mask)
8177 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008178
8179 memset(&mask, 0, sizeof(mask));
8180 /* Default to all rates enabled */
8181 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8182 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008183
8184 if (!sband)
8185 continue;
8186
8187 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008188 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008189 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008190 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008191
8192 if (!sband->vht_cap.vht_supported)
8193 continue;
8194
8195 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8196 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008197 }
8198
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008199 /* if no rates are given set it back to the defaults */
8200 if (!info->attrs[NL80211_ATTR_TX_RATES])
8201 goto out;
8202
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008203 /*
8204 * The nested attribute uses enum nl80211_band as the index. This maps
8205 * directly to the enum ieee80211_band values used in cfg80211.
8206 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008207 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008208 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008209 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008210 int err;
8211
Johannes Berg4c476992010-10-04 21:36:35 +02008212 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8213 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008214 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008215 if (sband == NULL)
8216 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008217 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8218 nla_len(tx_rates), nl80211_txattr_policy);
8219 if (err)
8220 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008221 if (tb[NL80211_TXRATE_LEGACY]) {
8222 mask.control[band].legacy = rateset_to_mask(
8223 sband,
8224 nla_data(tb[NL80211_TXRATE_LEGACY]),
8225 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308226 if ((mask.control[band].legacy == 0) &&
8227 nla_len(tb[NL80211_TXRATE_LEGACY]))
8228 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008229 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008230 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008231 if (!ht_rateset_to_mask(
8232 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008233 nla_data(tb[NL80211_TXRATE_HT]),
8234 nla_len(tb[NL80211_TXRATE_HT]),
8235 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008236 return -EINVAL;
8237 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008238 if (tb[NL80211_TXRATE_VHT]) {
8239 if (!vht_set_mcs_mask(
8240 sband,
8241 nla_data(tb[NL80211_TXRATE_VHT]),
8242 mask.control[band].vht_mcs))
8243 return -EINVAL;
8244 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008245 if (tb[NL80211_TXRATE_GI]) {
8246 mask.control[band].gi =
8247 nla_get_u8(tb[NL80211_TXRATE_GI]);
8248 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8249 return -EINVAL;
8250 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008251
8252 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008253 /* don't allow empty legacy rates if HT or VHT
8254 * are not even supported.
8255 */
8256 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8257 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008258 return -EINVAL;
8259
8260 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008261 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008262 goto out;
8263
8264 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8265 if (mask.control[band].vht_mcs[i])
8266 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008267
8268 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008269 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008270 }
8271 }
8272
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008273out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008274 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008275}
8276
Johannes Berg2e161f72010-08-12 15:38:38 +02008277static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008278{
Johannes Berg4c476992010-10-04 21:36:35 +02008279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008280 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008281 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008282
8283 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8284 return -EINVAL;
8285
Johannes Berg2e161f72010-08-12 15:38:38 +02008286 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8287 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008288
Johannes Berg71bbc992012-06-15 15:30:18 +02008289 switch (wdev->iftype) {
8290 case NL80211_IFTYPE_STATION:
8291 case NL80211_IFTYPE_ADHOC:
8292 case NL80211_IFTYPE_P2P_CLIENT:
8293 case NL80211_IFTYPE_AP:
8294 case NL80211_IFTYPE_AP_VLAN:
8295 case NL80211_IFTYPE_MESH_POINT:
8296 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008297 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008298 break;
8299 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008300 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008301 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008302
8303 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008304 if (!rdev->ops->mgmt_tx)
8305 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008306
Eric W. Biederman15e47302012-09-07 20:12:54 +00008307 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008308 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8309 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008310}
8311
Johannes Berg2e161f72010-08-12 15:38:38 +02008312static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008313{
Johannes Berg4c476992010-10-04 21:36:35 +02008314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008315 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008316 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008317 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008318 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008319 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008320 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008321 struct cfg80211_mgmt_tx_params params = {
8322 .dont_wait_for_ack =
8323 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8324 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008325
Johannes Berg683b6d32012-11-08 21:25:48 +01008326 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008327 return -EINVAL;
8328
Johannes Berg4c476992010-10-04 21:36:35 +02008329 if (!rdev->ops->mgmt_tx)
8330 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008331
Johannes Berg71bbc992012-06-15 15:30:18 +02008332 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008333 case NL80211_IFTYPE_P2P_DEVICE:
8334 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8335 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008336 case NL80211_IFTYPE_STATION:
8337 case NL80211_IFTYPE_ADHOC:
8338 case NL80211_IFTYPE_P2P_CLIENT:
8339 case NL80211_IFTYPE_AP:
8340 case NL80211_IFTYPE_AP_VLAN:
8341 case NL80211_IFTYPE_MESH_POINT:
8342 case NL80211_IFTYPE_P2P_GO:
8343 break;
8344 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008345 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008346 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008347
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008348 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008349 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008350 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008351 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008352
8353 /*
8354 * We should wait on the channel for at least a minimum amount
8355 * of time (10ms) but no longer than the driver supports.
8356 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008357 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8358 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008359 return -EINVAL;
8360
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008361 }
8362
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008363 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008364
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008365 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008366 return -EINVAL;
8367
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008368 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308369
Antonio Quartulliea141b752013-06-11 14:20:03 +02008370 /* get the channel if any has been specified, otherwise pass NULL to
8371 * the driver. The latter will use the current one
8372 */
8373 chandef.chan = NULL;
8374 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8375 err = nl80211_parse_chandef(rdev, info, &chandef);
8376 if (err)
8377 return err;
8378 }
8379
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008380 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008381 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008382
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008383 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8384 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8385
8386 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8387 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8388 int i;
8389
8390 if (len % sizeof(u16))
8391 return -EINVAL;
8392
8393 params.n_csa_offsets = len / sizeof(u16);
8394 params.csa_offsets =
8395 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8396
8397 /* check that all the offsets fit the frame */
8398 for (i = 0; i < params.n_csa_offsets; i++) {
8399 if (params.csa_offsets[i] >= params.len)
8400 return -EINVAL;
8401 }
8402 }
8403
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008404 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008405 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8406 if (!msg)
8407 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008408
Eric W. Biederman15e47302012-09-07 20:12:54 +00008409 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008410 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008411 if (!hdr) {
8412 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008413 goto free_msg;
8414 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008415 }
Johannes Berge247bd902011-11-04 11:18:21 +01008416
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008417 params.chan = chandef.chan;
8418 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008419 if (err)
8420 goto free_msg;
8421
Johannes Berge247bd902011-11-04 11:18:21 +01008422 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008423 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8424 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008425
Johannes Berge247bd902011-11-04 11:18:21 +01008426 genlmsg_end(msg, hdr);
8427 return genlmsg_reply(msg, info);
8428 }
8429
8430 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008431
8432 nla_put_failure:
8433 err = -ENOBUFS;
8434 free_msg:
8435 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008436 return err;
8437}
8438
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008439static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8440{
8441 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008442 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008443 u64 cookie;
8444
8445 if (!info->attrs[NL80211_ATTR_COOKIE])
8446 return -EINVAL;
8447
8448 if (!rdev->ops->mgmt_tx_cancel_wait)
8449 return -EOPNOTSUPP;
8450
Johannes Berg71bbc992012-06-15 15:30:18 +02008451 switch (wdev->iftype) {
8452 case NL80211_IFTYPE_STATION:
8453 case NL80211_IFTYPE_ADHOC:
8454 case NL80211_IFTYPE_P2P_CLIENT:
8455 case NL80211_IFTYPE_AP:
8456 case NL80211_IFTYPE_AP_VLAN:
8457 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008458 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008459 break;
8460 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008461 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008462 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008463
8464 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8465
Hila Gonene35e4d22012-06-27 17:19:42 +03008466 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008467}
8468
Kalle Valoffb9eb32010-02-17 17:58:10 +02008469static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8470{
Johannes Berg4c476992010-10-04 21:36:35 +02008471 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008472 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008473 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008474 u8 ps_state;
8475 bool state;
8476 int err;
8477
Johannes Berg4c476992010-10-04 21:36:35 +02008478 if (!info->attrs[NL80211_ATTR_PS_STATE])
8479 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008480
8481 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8482
Johannes Berg4c476992010-10-04 21:36:35 +02008483 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8484 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008485
8486 wdev = dev->ieee80211_ptr;
8487
Johannes Berg4c476992010-10-04 21:36:35 +02008488 if (!rdev->ops->set_power_mgmt)
8489 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008490
8491 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8492
8493 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008494 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008495
Hila Gonene35e4d22012-06-27 17:19:42 +03008496 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008497 if (!err)
8498 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008499 return err;
8500}
8501
8502static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8503{
Johannes Berg4c476992010-10-04 21:36:35 +02008504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008505 enum nl80211_ps_state ps_state;
8506 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008507 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008508 struct sk_buff *msg;
8509 void *hdr;
8510 int err;
8511
Kalle Valoffb9eb32010-02-17 17:58:10 +02008512 wdev = dev->ieee80211_ptr;
8513
Johannes Berg4c476992010-10-04 21:36:35 +02008514 if (!rdev->ops->set_power_mgmt)
8515 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008516
8517 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008518 if (!msg)
8519 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008520
Eric W. Biederman15e47302012-09-07 20:12:54 +00008521 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008522 NL80211_CMD_GET_POWER_SAVE);
8523 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008524 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008525 goto free_msg;
8526 }
8527
8528 if (wdev->ps)
8529 ps_state = NL80211_PS_ENABLED;
8530 else
8531 ps_state = NL80211_PS_DISABLED;
8532
David S. Miller9360ffd2012-03-29 04:41:26 -04008533 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8534 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008535
8536 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008537 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008538
Johannes Berg4c476992010-10-04 21:36:35 +02008539 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008540 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008541 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008542 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008543 return err;
8544}
8545
Johannes Berg94e860f2014-01-20 23:58:15 +01008546static const struct nla_policy
8547nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008548 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8549 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8550 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008551 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8552 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8553 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008554};
8555
Thomas Pedersen84f10702012-07-12 16:17:33 -07008556static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008557 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008558{
8559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008560 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008561 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008562
Johannes Bergd9d8b012012-11-26 12:51:52 +01008563 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008564 return -EINVAL;
8565
Thomas Pedersen84f10702012-07-12 16:17:33 -07008566 if (!rdev->ops->set_cqm_txe_config)
8567 return -EOPNOTSUPP;
8568
8569 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8570 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8571 return -EOPNOTSUPP;
8572
Hila Gonene35e4d22012-06-27 17:19:42 +03008573 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008574}
8575
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008576static int nl80211_set_cqm_rssi(struct genl_info *info,
8577 s32 threshold, u32 hysteresis)
8578{
Johannes Berg4c476992010-10-04 21:36:35 +02008579 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008580 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008581 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008582
8583 if (threshold > 0)
8584 return -EINVAL;
8585
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008586 /* disabling - hysteresis should also be zero then */
8587 if (threshold == 0)
8588 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008589
Johannes Berg4c476992010-10-04 21:36:35 +02008590 if (!rdev->ops->set_cqm_rssi_config)
8591 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008592
Johannes Berg074ac8d2010-09-16 14:58:22 +02008593 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008594 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8595 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008596
Hila Gonene35e4d22012-06-27 17:19:42 +03008597 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008598}
8599
8600static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8601{
8602 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8603 struct nlattr *cqm;
8604 int err;
8605
8606 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008607 if (!cqm)
8608 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008609
8610 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8611 nl80211_attr_cqm_policy);
8612 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008613 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008614
8615 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8616 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008617 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8618 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008619
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008620 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8621 }
8622
8623 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8624 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8625 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8626 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8627 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8628 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8629
8630 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8631 }
8632
8633 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008634}
8635
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008636static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8637{
8638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8639 struct net_device *dev = info->user_ptr[1];
8640 struct ocb_setup setup = {};
8641 int err;
8642
8643 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8644 if (err)
8645 return err;
8646
8647 return cfg80211_join_ocb(rdev, dev, &setup);
8648}
8649
8650static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8651{
8652 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8653 struct net_device *dev = info->user_ptr[1];
8654
8655 return cfg80211_leave_ocb(rdev, dev);
8656}
8657
Johannes Berg29cbe682010-12-03 09:20:44 +01008658static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8659{
8660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8661 struct net_device *dev = info->user_ptr[1];
8662 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008663 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008664 int err;
8665
8666 /* start with default */
8667 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008668 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008669
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008670 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008671 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008672 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008673 if (err)
8674 return err;
8675 }
8676
8677 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8678 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8679 return -EINVAL;
8680
Javier Cardonac80d5452010-12-16 17:37:49 -08008681 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8682 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8683
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008684 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8685 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8686 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8687 return -EINVAL;
8688
Marco Porsch9bdbf042013-01-07 16:04:51 +01008689 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8690 setup.beacon_interval =
8691 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8692 if (setup.beacon_interval < 10 ||
8693 setup.beacon_interval > 10000)
8694 return -EINVAL;
8695 }
8696
8697 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8698 setup.dtim_period =
8699 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8700 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8701 return -EINVAL;
8702 }
8703
Javier Cardonac80d5452010-12-16 17:37:49 -08008704 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8705 /* parse additional setup parameters if given */
8706 err = nl80211_parse_mesh_setup(info, &setup);
8707 if (err)
8708 return err;
8709 }
8710
Thomas Pedersend37bb182013-03-04 13:06:13 -08008711 if (setup.user_mpm)
8712 cfg.auto_open_plinks = false;
8713
Johannes Bergcc1d2802012-05-16 23:50:20 +02008714 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008715 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8716 if (err)
8717 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008718 } else {
8719 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008720 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008721 }
8722
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008723 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8724 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8725 int n_rates =
8726 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8727 struct ieee80211_supported_band *sband;
8728
8729 if (!setup.chandef.chan)
8730 return -EINVAL;
8731
8732 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8733
8734 err = ieee80211_get_ratemask(sband, rates, n_rates,
8735 &setup.basic_rates);
8736 if (err)
8737 return err;
8738 }
8739
Javier Cardonac80d5452010-12-16 17:37:49 -08008740 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008741}
8742
8743static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8744{
8745 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8746 struct net_device *dev = info->user_ptr[1];
8747
8748 return cfg80211_leave_mesh(rdev, dev);
8749}
8750
Johannes Bergdfb89c52012-06-27 09:23:48 +02008751#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008752static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8753 struct cfg80211_registered_device *rdev)
8754{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008755 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008756 struct nlattr *nl_pats, *nl_pat;
8757 int i, pat_len;
8758
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008759 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008760 return 0;
8761
8762 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8763 if (!nl_pats)
8764 return -ENOBUFS;
8765
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008766 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008767 nl_pat = nla_nest_start(msg, i + 1);
8768 if (!nl_pat)
8769 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008770 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008771 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008772 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008773 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8774 wowlan->patterns[i].pattern) ||
8775 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008776 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008777 return -ENOBUFS;
8778 nla_nest_end(msg, nl_pat);
8779 }
8780 nla_nest_end(msg, nl_pats);
8781
8782 return 0;
8783}
8784
Johannes Berg2a0e0472013-01-23 22:57:40 +01008785static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8786 struct cfg80211_wowlan_tcp *tcp)
8787{
8788 struct nlattr *nl_tcp;
8789
8790 if (!tcp)
8791 return 0;
8792
8793 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8794 if (!nl_tcp)
8795 return -ENOBUFS;
8796
Jiri Benc930345e2015-03-29 16:59:25 +02008797 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8798 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01008799 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8800 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8801 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8802 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8803 tcp->payload_len, tcp->payload) ||
8804 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8805 tcp->data_interval) ||
8806 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8807 tcp->wake_len, tcp->wake_data) ||
8808 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8809 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8810 return -ENOBUFS;
8811
8812 if (tcp->payload_seq.len &&
8813 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8814 sizeof(tcp->payload_seq), &tcp->payload_seq))
8815 return -ENOBUFS;
8816
8817 if (tcp->payload_tok.len &&
8818 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8819 sizeof(tcp->payload_tok) + tcp->tokens_size,
8820 &tcp->payload_tok))
8821 return -ENOBUFS;
8822
Johannes Berge248ad32013-05-16 10:24:28 +02008823 nla_nest_end(msg, nl_tcp);
8824
Johannes Berg2a0e0472013-01-23 22:57:40 +01008825 return 0;
8826}
8827
Luciano Coelho75453cc2015-01-09 14:06:37 +02008828static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8829 struct cfg80211_sched_scan_request *req)
8830{
8831 struct nlattr *nd, *freqs, *matches, *match;
8832 int i;
8833
8834 if (!req)
8835 return 0;
8836
8837 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8838 if (!nd)
8839 return -ENOBUFS;
8840
8841 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
8842 return -ENOBUFS;
8843
Luciano Coelho21fea562015-03-17 16:36:01 +02008844 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
8845 return -ENOBUFS;
8846
Luciano Coelho75453cc2015-01-09 14:06:37 +02008847 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8848 if (!freqs)
8849 return -ENOBUFS;
8850
8851 for (i = 0; i < req->n_channels; i++)
8852 nla_put_u32(msg, i, req->channels[i]->center_freq);
8853
8854 nla_nest_end(msg, freqs);
8855
8856 if (req->n_match_sets) {
8857 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
8858 for (i = 0; i < req->n_match_sets; i++) {
8859 match = nla_nest_start(msg, i);
8860 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
8861 req->match_sets[i].ssid.ssid_len,
8862 req->match_sets[i].ssid.ssid);
8863 nla_nest_end(msg, match);
8864 }
8865 nla_nest_end(msg, matches);
8866 }
8867
8868 nla_nest_end(msg, nd);
8869
8870 return 0;
8871}
8872
Johannes Bergff1b6e62011-05-04 15:37:28 +02008873static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8874{
8875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8876 struct sk_buff *msg;
8877 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008878 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008879
Johannes Berg964dc9e2013-06-03 17:25:34 +02008880 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008881 return -EOPNOTSUPP;
8882
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008883 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008884 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008885 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8886 rdev->wiphy.wowlan_config->tcp->payload_len +
8887 rdev->wiphy.wowlan_config->tcp->wake_len +
8888 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008889 }
8890
8891 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008892 if (!msg)
8893 return -ENOMEM;
8894
Eric W. Biederman15e47302012-09-07 20:12:54 +00008895 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008896 NL80211_CMD_GET_WOWLAN);
8897 if (!hdr)
8898 goto nla_put_failure;
8899
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008900 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008901 struct nlattr *nl_wowlan;
8902
8903 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8904 if (!nl_wowlan)
8905 goto nla_put_failure;
8906
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008907 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008908 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008909 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008910 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008911 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008912 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008913 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008914 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008915 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008916 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008917 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008918 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008919 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008920 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8921 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008922
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008923 if (nl80211_send_wowlan_patterns(msg, rdev))
8924 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008925
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008926 if (nl80211_send_wowlan_tcp(msg,
8927 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008928 goto nla_put_failure;
8929
Luciano Coelho75453cc2015-01-09 14:06:37 +02008930 if (nl80211_send_wowlan_nd(
8931 msg,
8932 rdev->wiphy.wowlan_config->nd_config))
8933 goto nla_put_failure;
8934
Johannes Bergff1b6e62011-05-04 15:37:28 +02008935 nla_nest_end(msg, nl_wowlan);
8936 }
8937
8938 genlmsg_end(msg, hdr);
8939 return genlmsg_reply(msg, info);
8940
8941nla_put_failure:
8942 nlmsg_free(msg);
8943 return -ENOBUFS;
8944}
8945
Johannes Berg2a0e0472013-01-23 22:57:40 +01008946static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8947 struct nlattr *attr,
8948 struct cfg80211_wowlan *trig)
8949{
8950 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8951 struct cfg80211_wowlan_tcp *cfg;
8952 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8953 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8954 u32 size;
8955 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8956 int err, port;
8957
Johannes Berg964dc9e2013-06-03 17:25:34 +02008958 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008959 return -EINVAL;
8960
8961 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8962 nla_data(attr), nla_len(attr),
8963 nl80211_wowlan_tcp_policy);
8964 if (err)
8965 return err;
8966
8967 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8968 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8969 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8970 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8971 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8972 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8973 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8974 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8975 return -EINVAL;
8976
8977 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008978 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008979 return -EINVAL;
8980
8981 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008982 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008983 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008984 return -EINVAL;
8985
8986 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008987 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008988 return -EINVAL;
8989
8990 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8991 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8992 return -EINVAL;
8993
8994 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8995 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8996
8997 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8998 tokens_size = tokln - sizeof(*tok);
8999
9000 if (!tok->len || tokens_size % tok->len)
9001 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009002 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009003 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009004 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009005 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009006 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009007 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009008 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009009 return -EINVAL;
9010 if (tok->offset + tok->len > data_size)
9011 return -EINVAL;
9012 }
9013
9014 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9015 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009016 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009017 return -EINVAL;
9018 if (seq->len == 0 || seq->len > 4)
9019 return -EINVAL;
9020 if (seq->len + seq->offset > data_size)
9021 return -EINVAL;
9022 }
9023
9024 size = sizeof(*cfg);
9025 size += data_size;
9026 size += wake_size + wake_mask_size;
9027 size += tokens_size;
9028
9029 cfg = kzalloc(size, GFP_KERNEL);
9030 if (!cfg)
9031 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009032 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9033 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009034 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9035 ETH_ALEN);
9036 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9037 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9038 else
9039 port = 0;
9040#ifdef CONFIG_INET
9041 /* allocate a socket and port for it and use it */
9042 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9043 IPPROTO_TCP, &cfg->sock, 1);
9044 if (err) {
9045 kfree(cfg);
9046 return err;
9047 }
9048 if (inet_csk_get_port(cfg->sock->sk, port)) {
9049 sock_release(cfg->sock);
9050 kfree(cfg);
9051 return -EADDRINUSE;
9052 }
9053 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9054#else
9055 if (!port) {
9056 kfree(cfg);
9057 return -EINVAL;
9058 }
9059 cfg->src_port = port;
9060#endif
9061
9062 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9063 cfg->payload_len = data_size;
9064 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9065 memcpy((void *)cfg->payload,
9066 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9067 data_size);
9068 if (seq)
9069 cfg->payload_seq = *seq;
9070 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9071 cfg->wake_len = wake_size;
9072 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9073 memcpy((void *)cfg->wake_data,
9074 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9075 wake_size);
9076 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9077 data_size + wake_size;
9078 memcpy((void *)cfg->wake_mask,
9079 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9080 wake_mask_size);
9081 if (tok) {
9082 cfg->tokens_size = tokens_size;
9083 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9084 }
9085
9086 trig->tcp = cfg;
9087
9088 return 0;
9089}
9090
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009091static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9092 const struct wiphy_wowlan_support *wowlan,
9093 struct nlattr *attr,
9094 struct cfg80211_wowlan *trig)
9095{
9096 struct nlattr **tb;
9097 int err;
9098
9099 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9100 if (!tb)
9101 return -ENOMEM;
9102
9103 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9104 err = -EOPNOTSUPP;
9105 goto out;
9106 }
9107
9108 err = nla_parse(tb, NL80211_ATTR_MAX,
9109 nla_data(attr), nla_len(attr),
9110 nl80211_policy);
9111 if (err)
9112 goto out;
9113
Johannes Bergad2b26a2014-06-12 21:39:05 +02009114 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009115 err = PTR_ERR_OR_ZERO(trig->nd_config);
9116 if (err)
9117 trig->nd_config = NULL;
9118
9119out:
9120 kfree(tb);
9121 return err;
9122}
9123
Johannes Bergff1b6e62011-05-04 15:37:28 +02009124static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9125{
9126 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9127 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009128 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009129 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009130 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009131 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009132 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009133 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009134
Johannes Berg964dc9e2013-06-03 17:25:34 +02009135 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009136 return -EOPNOTSUPP;
9137
Johannes Bergae33bd82012-07-12 16:25:02 +02009138 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9139 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009140 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009141 goto set_wakeup;
9142 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009143
9144 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9145 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9146 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9147 nl80211_wowlan_policy);
9148 if (err)
9149 return err;
9150
9151 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9152 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9153 return -EINVAL;
9154 new_triggers.any = true;
9155 }
9156
9157 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9158 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9159 return -EINVAL;
9160 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009161 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009162 }
9163
9164 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9165 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9166 return -EINVAL;
9167 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009168 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009169 }
9170
Johannes Berg77dbbb12011-07-13 10:48:55 +02009171 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9172 return -EINVAL;
9173
9174 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9175 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9176 return -EINVAL;
9177 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009178 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009179 }
9180
9181 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9182 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9183 return -EINVAL;
9184 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009185 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009186 }
9187
9188 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9189 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9190 return -EINVAL;
9191 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009192 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009193 }
9194
9195 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9196 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9197 return -EINVAL;
9198 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009199 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009200 }
9201
Johannes Bergff1b6e62011-05-04 15:37:28 +02009202 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9203 struct nlattr *pat;
9204 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009205 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009206 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009207
Johannes Berg98fc4382015-03-01 09:10:13 +02009208 regular = true;
9209
Johannes Bergff1b6e62011-05-04 15:37:28 +02009210 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9211 rem)
9212 n_patterns++;
9213 if (n_patterns > wowlan->n_patterns)
9214 return -EINVAL;
9215
9216 new_triggers.patterns = kcalloc(n_patterns,
9217 sizeof(new_triggers.patterns[0]),
9218 GFP_KERNEL);
9219 if (!new_triggers.patterns)
9220 return -ENOMEM;
9221
9222 new_triggers.n_patterns = n_patterns;
9223 i = 0;
9224
9225 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9226 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009227 u8 *mask_pat;
9228
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009229 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9230 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009231 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009232 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9233 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009234 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009235 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009236 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009237 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009238 goto error;
9239 if (pat_len > wowlan->pattern_max_len ||
9240 pat_len < wowlan->pattern_min_len)
9241 goto error;
9242
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009243 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009244 pkt_offset = 0;
9245 else
9246 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009247 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009248 if (pkt_offset > wowlan->max_pkt_offset)
9249 goto error;
9250 new_triggers.patterns[i].pkt_offset = pkt_offset;
9251
Johannes Berg922bd802014-05-19 17:59:50 +02009252 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9253 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009254 err = -ENOMEM;
9255 goto error;
9256 }
Johannes Berg922bd802014-05-19 17:59:50 +02009257 new_triggers.patterns[i].mask = mask_pat;
9258 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009259 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009260 mask_pat += mask_len;
9261 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009262 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009263 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009264 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009265 pat_len);
9266 i++;
9267 }
9268 }
9269
Johannes Berg2a0e0472013-01-23 22:57:40 +01009270 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009271 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009272 err = nl80211_parse_wowlan_tcp(
9273 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9274 &new_triggers);
9275 if (err)
9276 goto error;
9277 }
9278
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009279 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009280 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009281 err = nl80211_parse_wowlan_nd(
9282 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9283 &new_triggers);
9284 if (err)
9285 goto error;
9286 }
9287
Johannes Berg98fc4382015-03-01 09:10:13 +02009288 /* The 'any' trigger means the device continues operating more or less
9289 * as in its normal operation mode and wakes up the host on most of the
9290 * normal interrupts (like packet RX, ...)
9291 * It therefore makes little sense to combine with the more constrained
9292 * wakeup trigger modes.
9293 */
9294 if (new_triggers.any && regular) {
9295 err = -EINVAL;
9296 goto error;
9297 }
9298
Johannes Bergae33bd82012-07-12 16:25:02 +02009299 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9300 if (!ntrig) {
9301 err = -ENOMEM;
9302 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009303 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009304 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009305 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009306
Johannes Bergae33bd82012-07-12 16:25:02 +02009307 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009308 if (rdev->ops->set_wakeup &&
9309 prev_enabled != !!rdev->wiphy.wowlan_config)
9310 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009311
Johannes Bergff1b6e62011-05-04 15:37:28 +02009312 return 0;
9313 error:
9314 for (i = 0; i < new_triggers.n_patterns; i++)
9315 kfree(new_triggers.patterns[i].mask);
9316 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009317 if (new_triggers.tcp && new_triggers.tcp->sock)
9318 sock_release(new_triggers.tcp->sock);
9319 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009320 return err;
9321}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009322#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009323
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009324static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9325 struct cfg80211_registered_device *rdev)
9326{
9327 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9328 int i, j, pat_len;
9329 struct cfg80211_coalesce_rules *rule;
9330
9331 if (!rdev->coalesce->n_rules)
9332 return 0;
9333
9334 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9335 if (!nl_rules)
9336 return -ENOBUFS;
9337
9338 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9339 nl_rule = nla_nest_start(msg, i + 1);
9340 if (!nl_rule)
9341 return -ENOBUFS;
9342
9343 rule = &rdev->coalesce->rules[i];
9344 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9345 rule->delay))
9346 return -ENOBUFS;
9347
9348 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9349 rule->condition))
9350 return -ENOBUFS;
9351
9352 nl_pats = nla_nest_start(msg,
9353 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9354 if (!nl_pats)
9355 return -ENOBUFS;
9356
9357 for (j = 0; j < rule->n_patterns; j++) {
9358 nl_pat = nla_nest_start(msg, j + 1);
9359 if (!nl_pat)
9360 return -ENOBUFS;
9361 pat_len = rule->patterns[j].pattern_len;
9362 if (nla_put(msg, NL80211_PKTPAT_MASK,
9363 DIV_ROUND_UP(pat_len, 8),
9364 rule->patterns[j].mask) ||
9365 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9366 rule->patterns[j].pattern) ||
9367 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9368 rule->patterns[j].pkt_offset))
9369 return -ENOBUFS;
9370 nla_nest_end(msg, nl_pat);
9371 }
9372 nla_nest_end(msg, nl_pats);
9373 nla_nest_end(msg, nl_rule);
9374 }
9375 nla_nest_end(msg, nl_rules);
9376
9377 return 0;
9378}
9379
9380static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9381{
9382 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9383 struct sk_buff *msg;
9384 void *hdr;
9385
9386 if (!rdev->wiphy.coalesce)
9387 return -EOPNOTSUPP;
9388
9389 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9390 if (!msg)
9391 return -ENOMEM;
9392
9393 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9394 NL80211_CMD_GET_COALESCE);
9395 if (!hdr)
9396 goto nla_put_failure;
9397
9398 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9399 goto nla_put_failure;
9400
9401 genlmsg_end(msg, hdr);
9402 return genlmsg_reply(msg, info);
9403
9404nla_put_failure:
9405 nlmsg_free(msg);
9406 return -ENOBUFS;
9407}
9408
9409void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9410{
9411 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9412 int i, j;
9413 struct cfg80211_coalesce_rules *rule;
9414
9415 if (!coalesce)
9416 return;
9417
9418 for (i = 0; i < coalesce->n_rules; i++) {
9419 rule = &coalesce->rules[i];
9420 for (j = 0; j < rule->n_patterns; j++)
9421 kfree(rule->patterns[j].mask);
9422 kfree(rule->patterns);
9423 }
9424 kfree(coalesce->rules);
9425 kfree(coalesce);
9426 rdev->coalesce = NULL;
9427}
9428
9429static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9430 struct nlattr *rule,
9431 struct cfg80211_coalesce_rules *new_rule)
9432{
9433 int err, i;
9434 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9435 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9436 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9437 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9438
9439 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9440 nla_len(rule), nl80211_coalesce_policy);
9441 if (err)
9442 return err;
9443
9444 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9445 new_rule->delay =
9446 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9447 if (new_rule->delay > coalesce->max_delay)
9448 return -EINVAL;
9449
9450 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9451 new_rule->condition =
9452 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9453 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9454 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9455 return -EINVAL;
9456
9457 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9458 return -EINVAL;
9459
9460 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9461 rem)
9462 n_patterns++;
9463 if (n_patterns > coalesce->n_patterns)
9464 return -EINVAL;
9465
9466 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9467 GFP_KERNEL);
9468 if (!new_rule->patterns)
9469 return -ENOMEM;
9470
9471 new_rule->n_patterns = n_patterns;
9472 i = 0;
9473
9474 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9475 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009476 u8 *mask_pat;
9477
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009478 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9479 nla_len(pat), NULL);
9480 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9481 !pat_tb[NL80211_PKTPAT_PATTERN])
9482 return -EINVAL;
9483 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9484 mask_len = DIV_ROUND_UP(pat_len, 8);
9485 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9486 return -EINVAL;
9487 if (pat_len > coalesce->pattern_max_len ||
9488 pat_len < coalesce->pattern_min_len)
9489 return -EINVAL;
9490
9491 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9492 pkt_offset = 0;
9493 else
9494 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9495 if (pkt_offset > coalesce->max_pkt_offset)
9496 return -EINVAL;
9497 new_rule->patterns[i].pkt_offset = pkt_offset;
9498
Johannes Berg922bd802014-05-19 17:59:50 +02009499 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9500 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009501 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009502
9503 new_rule->patterns[i].mask = mask_pat;
9504 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9505 mask_len);
9506
9507 mask_pat += mask_len;
9508 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009509 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009510 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9511 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009512 i++;
9513 }
9514
9515 return 0;
9516}
9517
9518static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9519{
9520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9521 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9522 struct cfg80211_coalesce new_coalesce = {};
9523 struct cfg80211_coalesce *n_coalesce;
9524 int err, rem_rule, n_rules = 0, i, j;
9525 struct nlattr *rule;
9526 struct cfg80211_coalesce_rules *tmp_rule;
9527
9528 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9529 return -EOPNOTSUPP;
9530
9531 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9532 cfg80211_rdev_free_coalesce(rdev);
9533 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9534 return 0;
9535 }
9536
9537 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9538 rem_rule)
9539 n_rules++;
9540 if (n_rules > coalesce->n_rules)
9541 return -EINVAL;
9542
9543 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9544 GFP_KERNEL);
9545 if (!new_coalesce.rules)
9546 return -ENOMEM;
9547
9548 new_coalesce.n_rules = n_rules;
9549 i = 0;
9550
9551 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9552 rem_rule) {
9553 err = nl80211_parse_coalesce_rule(rdev, rule,
9554 &new_coalesce.rules[i]);
9555 if (err)
9556 goto error;
9557
9558 i++;
9559 }
9560
9561 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9562 if (err)
9563 goto error;
9564
9565 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9566 if (!n_coalesce) {
9567 err = -ENOMEM;
9568 goto error;
9569 }
9570 cfg80211_rdev_free_coalesce(rdev);
9571 rdev->coalesce = n_coalesce;
9572
9573 return 0;
9574error:
9575 for (i = 0; i < new_coalesce.n_rules; i++) {
9576 tmp_rule = &new_coalesce.rules[i];
9577 for (j = 0; j < tmp_rule->n_patterns; j++)
9578 kfree(tmp_rule->patterns[j].mask);
9579 kfree(tmp_rule->patterns);
9580 }
9581 kfree(new_coalesce.rules);
9582
9583 return err;
9584}
9585
Johannes Berge5497d72011-07-05 16:35:40 +02009586static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9587{
9588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9589 struct net_device *dev = info->user_ptr[1];
9590 struct wireless_dev *wdev = dev->ieee80211_ptr;
9591 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9592 struct cfg80211_gtk_rekey_data rekey_data;
9593 int err;
9594
9595 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9596 return -EINVAL;
9597
9598 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9599 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9600 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9601 nl80211_rekey_policy);
9602 if (err)
9603 return err;
9604
9605 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9606 return -ERANGE;
9607 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9608 return -ERANGE;
9609 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9610 return -ERANGE;
9611
Johannes Berg78f686c2014-09-10 22:28:06 +03009612 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9613 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9614 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009615
9616 wdev_lock(wdev);
9617 if (!wdev->current_bss) {
9618 err = -ENOTCONN;
9619 goto out;
9620 }
9621
9622 if (!rdev->ops->set_rekey_data) {
9623 err = -EOPNOTSUPP;
9624 goto out;
9625 }
9626
Hila Gonene35e4d22012-06-27 17:19:42 +03009627 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009628 out:
9629 wdev_unlock(wdev);
9630 return err;
9631}
9632
Johannes Berg28946da2011-11-04 11:18:12 +01009633static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9634 struct genl_info *info)
9635{
9636 struct net_device *dev = info->user_ptr[1];
9637 struct wireless_dev *wdev = dev->ieee80211_ptr;
9638
9639 if (wdev->iftype != NL80211_IFTYPE_AP &&
9640 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9641 return -EINVAL;
9642
Eric W. Biederman15e47302012-09-07 20:12:54 +00009643 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009644 return -EBUSY;
9645
Eric W. Biederman15e47302012-09-07 20:12:54 +00009646 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009647 return 0;
9648}
9649
Johannes Berg7f6cf312011-11-04 11:18:15 +01009650static int nl80211_probe_client(struct sk_buff *skb,
9651 struct genl_info *info)
9652{
9653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9654 struct net_device *dev = info->user_ptr[1];
9655 struct wireless_dev *wdev = dev->ieee80211_ptr;
9656 struct sk_buff *msg;
9657 void *hdr;
9658 const u8 *addr;
9659 u64 cookie;
9660 int err;
9661
9662 if (wdev->iftype != NL80211_IFTYPE_AP &&
9663 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9664 return -EOPNOTSUPP;
9665
9666 if (!info->attrs[NL80211_ATTR_MAC])
9667 return -EINVAL;
9668
9669 if (!rdev->ops->probe_client)
9670 return -EOPNOTSUPP;
9671
9672 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9673 if (!msg)
9674 return -ENOMEM;
9675
Eric W. Biederman15e47302012-09-07 20:12:54 +00009676 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009677 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009678 if (!hdr) {
9679 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009680 goto free_msg;
9681 }
9682
9683 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9684
Hila Gonene35e4d22012-06-27 17:19:42 +03009685 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009686 if (err)
9687 goto free_msg;
9688
David S. Miller9360ffd2012-03-29 04:41:26 -04009689 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9690 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009691
9692 genlmsg_end(msg, hdr);
9693
9694 return genlmsg_reply(msg, info);
9695
9696 nla_put_failure:
9697 err = -ENOBUFS;
9698 free_msg:
9699 nlmsg_free(msg);
9700 return err;
9701}
9702
Johannes Berg5e7602302011-11-04 11:18:17 +01009703static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9704{
9705 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009706 struct cfg80211_beacon_registration *reg, *nreg;
9707 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009708
9709 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9710 return -EOPNOTSUPP;
9711
Ben Greear37c73b52012-10-26 14:49:25 -07009712 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9713 if (!nreg)
9714 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01009715
Ben Greear37c73b52012-10-26 14:49:25 -07009716 /* First, check if already registered. */
9717 spin_lock_bh(&rdev->beacon_registrations_lock);
9718 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9719 if (reg->nlportid == info->snd_portid) {
9720 rv = -EALREADY;
9721 goto out_err;
9722 }
9723 }
9724 /* Add it to the list */
9725 nreg->nlportid = info->snd_portid;
9726 list_add(&nreg->list, &rdev->beacon_registrations);
9727
9728 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01009729
9730 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009731out_err:
9732 spin_unlock_bh(&rdev->beacon_registrations_lock);
9733 kfree(nreg);
9734 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009735}
9736
Johannes Berg98104fde2012-06-16 00:19:54 +02009737static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9738{
9739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9740 struct wireless_dev *wdev = info->user_ptr[1];
9741 int err;
9742
9743 if (!rdev->ops->start_p2p_device)
9744 return -EOPNOTSUPP;
9745
9746 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9747 return -EOPNOTSUPP;
9748
9749 if (wdev->p2p_started)
9750 return 0;
9751
Luciano Coelhob6a55012014-02-27 11:07:21 +02009752 if (rfkill_blocked(rdev->rfkill))
9753 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009754
Johannes Bergeeb126e2012-10-23 15:16:50 +02009755 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009756 if (err)
9757 return err;
9758
9759 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009760 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009761
9762 return 0;
9763}
9764
9765static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9766{
9767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9768 struct wireless_dev *wdev = info->user_ptr[1];
9769
9770 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9771 return -EOPNOTSUPP;
9772
9773 if (!rdev->ops->stop_p2p_device)
9774 return -EOPNOTSUPP;
9775
Johannes Bergf9f47522013-03-19 15:04:07 +01009776 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009777
9778 return 0;
9779}
9780
Johannes Berg3713b4e2013-02-14 16:19:38 +01009781static int nl80211_get_protocol_features(struct sk_buff *skb,
9782 struct genl_info *info)
9783{
9784 void *hdr;
9785 struct sk_buff *msg;
9786
9787 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9788 if (!msg)
9789 return -ENOMEM;
9790
9791 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9792 NL80211_CMD_GET_PROTOCOL_FEATURES);
9793 if (!hdr)
9794 goto nla_put_failure;
9795
9796 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9797 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9798 goto nla_put_failure;
9799
9800 genlmsg_end(msg, hdr);
9801 return genlmsg_reply(msg, info);
9802
9803 nla_put_failure:
9804 kfree_skb(msg);
9805 return -ENOBUFS;
9806}
9807
Jouni Malinen355199e2013-02-27 17:14:27 +02009808static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9809{
9810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9811 struct cfg80211_update_ft_ies_params ft_params;
9812 struct net_device *dev = info->user_ptr[1];
9813
9814 if (!rdev->ops->update_ft_ies)
9815 return -EOPNOTSUPP;
9816
9817 if (!info->attrs[NL80211_ATTR_MDID] ||
9818 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9819 return -EINVAL;
9820
9821 memset(&ft_params, 0, sizeof(ft_params));
9822 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9823 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9824 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9825
9826 return rdev_update_ft_ies(rdev, dev, &ft_params);
9827}
9828
Arend van Spriel5de17982013-04-18 15:49:00 +02009829static int nl80211_crit_protocol_start(struct sk_buff *skb,
9830 struct genl_info *info)
9831{
9832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9833 struct wireless_dev *wdev = info->user_ptr[1];
9834 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9835 u16 duration;
9836 int ret;
9837
9838 if (!rdev->ops->crit_proto_start)
9839 return -EOPNOTSUPP;
9840
9841 if (WARN_ON(!rdev->ops->crit_proto_stop))
9842 return -EINVAL;
9843
9844 if (rdev->crit_proto_nlportid)
9845 return -EBUSY;
9846
9847 /* determine protocol if provided */
9848 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9849 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9850
9851 if (proto >= NUM_NL80211_CRIT_PROTO)
9852 return -EINVAL;
9853
9854 /* timeout must be provided */
9855 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9856 return -EINVAL;
9857
9858 duration =
9859 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9860
9861 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9862 return -ERANGE;
9863
9864 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9865 if (!ret)
9866 rdev->crit_proto_nlportid = info->snd_portid;
9867
9868 return ret;
9869}
9870
9871static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9872 struct genl_info *info)
9873{
9874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9875 struct wireless_dev *wdev = info->user_ptr[1];
9876
9877 if (!rdev->ops->crit_proto_stop)
9878 return -EOPNOTSUPP;
9879
9880 if (rdev->crit_proto_nlportid) {
9881 rdev->crit_proto_nlportid = 0;
9882 rdev_crit_proto_stop(rdev, wdev);
9883 }
9884 return 0;
9885}
9886
Johannes Bergad7e7182013-11-13 13:37:47 +01009887static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9888{
9889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9890 struct wireless_dev *wdev =
9891 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9892 int i, err;
9893 u32 vid, subcmd;
9894
9895 if (!rdev->wiphy.vendor_commands)
9896 return -EOPNOTSUPP;
9897
9898 if (IS_ERR(wdev)) {
9899 err = PTR_ERR(wdev);
9900 if (err != -EINVAL)
9901 return err;
9902 wdev = NULL;
9903 } else if (wdev->wiphy != &rdev->wiphy) {
9904 return -EINVAL;
9905 }
9906
9907 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9908 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9909 return -EINVAL;
9910
9911 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9912 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9913 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9914 const struct wiphy_vendor_command *vcmd;
9915 void *data = NULL;
9916 int len = 0;
9917
9918 vcmd = &rdev->wiphy.vendor_commands[i];
9919
9920 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9921 continue;
9922
9923 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9924 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9925 if (!wdev)
9926 return -EINVAL;
9927 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9928 !wdev->netdev)
9929 return -EINVAL;
9930
9931 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9932 if (wdev->netdev &&
9933 !netif_running(wdev->netdev))
9934 return -ENETDOWN;
9935 if (!wdev->netdev && !wdev->p2p_started)
9936 return -ENETDOWN;
9937 }
9938 } else {
9939 wdev = NULL;
9940 }
9941
9942 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9943 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9944 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9945 }
9946
9947 rdev->cur_cmd_info = info;
9948 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9949 data, len);
9950 rdev->cur_cmd_info = NULL;
9951 return err;
9952 }
9953
9954 return -EOPNOTSUPP;
9955}
9956
9957struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9958 enum nl80211_commands cmd,
9959 enum nl80211_attrs attr,
9960 int approxlen)
9961{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009962 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009963
9964 if (WARN_ON(!rdev->cur_cmd_info))
9965 return NULL;
9966
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009967 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +01009968 rdev->cur_cmd_info->snd_portid,
9969 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009970 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009971}
9972EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9973
9974int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9975{
9976 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9977 void *hdr = ((void **)skb->cb)[1];
9978 struct nlattr *data = ((void **)skb->cb)[2];
9979
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009980 /* clear CB data for netlink core to own from now on */
9981 memset(skb->cb, 0, sizeof(skb->cb));
9982
Johannes Bergad7e7182013-11-13 13:37:47 +01009983 if (WARN_ON(!rdev->cur_cmd_info)) {
9984 kfree_skb(skb);
9985 return -EINVAL;
9986 }
9987
9988 nla_nest_end(skb, data);
9989 genlmsg_end(skb, hdr);
9990 return genlmsg_reply(skb, rdev->cur_cmd_info);
9991}
9992EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9993
9994
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009995static int nl80211_set_qos_map(struct sk_buff *skb,
9996 struct genl_info *info)
9997{
9998 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9999 struct cfg80211_qos_map *qos_map = NULL;
10000 struct net_device *dev = info->user_ptr[1];
10001 u8 *pos, len, num_des, des_len, des;
10002 int ret;
10003
10004 if (!rdev->ops->set_qos_map)
10005 return -EOPNOTSUPP;
10006
10007 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10008 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10009 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10010
10011 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10012 len > IEEE80211_QOS_MAP_LEN_MAX)
10013 return -EINVAL;
10014
10015 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10016 if (!qos_map)
10017 return -ENOMEM;
10018
10019 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10020 if (num_des) {
10021 des_len = num_des *
10022 sizeof(struct cfg80211_dscp_exception);
10023 memcpy(qos_map->dscp_exception, pos, des_len);
10024 qos_map->num_des = num_des;
10025 for (des = 0; des < num_des; des++) {
10026 if (qos_map->dscp_exception[des].up > 7) {
10027 kfree(qos_map);
10028 return -EINVAL;
10029 }
10030 }
10031 pos += des_len;
10032 }
10033 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10034 }
10035
10036 wdev_lock(dev->ieee80211_ptr);
10037 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10038 if (!ret)
10039 ret = rdev_set_qos_map(rdev, dev, qos_map);
10040 wdev_unlock(dev->ieee80211_ptr);
10041
10042 kfree(qos_map);
10043 return ret;
10044}
10045
Johannes Berg960d01a2014-09-09 22:55:35 +030010046static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10047{
10048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10049 struct net_device *dev = info->user_ptr[1];
10050 struct wireless_dev *wdev = dev->ieee80211_ptr;
10051 const u8 *peer;
10052 u8 tsid, up;
10053 u16 admitted_time = 0;
10054 int err;
10055
Johannes Berg723e73a2014-10-22 09:25:06 +020010056 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010057 return -EOPNOTSUPP;
10058
10059 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10060 !info->attrs[NL80211_ATTR_USER_PRIO])
10061 return -EINVAL;
10062
10063 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10064 if (tsid >= IEEE80211_NUM_TIDS)
10065 return -EINVAL;
10066
10067 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10068 if (up >= IEEE80211_NUM_UPS)
10069 return -EINVAL;
10070
10071 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010072 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010073 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010074 * need more attributes for that (e.g. BA session requirement);
10075 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010076 */
10077 return -EINVAL;
10078 }
10079
10080 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10081
10082 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10083 admitted_time =
10084 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10085 if (!admitted_time)
10086 return -EINVAL;
10087 }
10088
10089 wdev_lock(wdev);
10090 switch (wdev->iftype) {
10091 case NL80211_IFTYPE_STATION:
10092 case NL80211_IFTYPE_P2P_CLIENT:
10093 if (wdev->current_bss)
10094 break;
10095 err = -ENOTCONN;
10096 goto out;
10097 default:
10098 err = -EOPNOTSUPP;
10099 goto out;
10100 }
10101
10102 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10103
10104 out:
10105 wdev_unlock(wdev);
10106 return err;
10107}
10108
10109static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10110{
10111 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10112 struct net_device *dev = info->user_ptr[1];
10113 struct wireless_dev *wdev = dev->ieee80211_ptr;
10114 const u8 *peer;
10115 u8 tsid;
10116 int err;
10117
10118 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10119 return -EINVAL;
10120
10121 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10122 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10123
10124 wdev_lock(wdev);
10125 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10126 wdev_unlock(wdev);
10127
10128 return err;
10129}
10130
Arik Nemtsov1057d352014-11-19 12:54:26 +020010131static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10132 struct genl_info *info)
10133{
10134 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10135 struct net_device *dev = info->user_ptr[1];
10136 struct wireless_dev *wdev = dev->ieee80211_ptr;
10137 struct cfg80211_chan_def chandef = {};
10138 const u8 *addr;
10139 u8 oper_class;
10140 int err;
10141
10142 if (!rdev->ops->tdls_channel_switch ||
10143 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10144 return -EOPNOTSUPP;
10145
10146 switch (dev->ieee80211_ptr->iftype) {
10147 case NL80211_IFTYPE_STATION:
10148 case NL80211_IFTYPE_P2P_CLIENT:
10149 break;
10150 default:
10151 return -EOPNOTSUPP;
10152 }
10153
10154 if (!info->attrs[NL80211_ATTR_MAC] ||
10155 !info->attrs[NL80211_ATTR_OPER_CLASS])
10156 return -EINVAL;
10157
10158 err = nl80211_parse_chandef(rdev, info, &chandef);
10159 if (err)
10160 return err;
10161
10162 /*
10163 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10164 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10165 * specification is not defined for them.
10166 */
10167 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10168 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10169 chandef.width != NL80211_CHAN_WIDTH_20)
10170 return -EINVAL;
10171
10172 /* we will be active on the TDLS link */
10173 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
10174 return -EINVAL;
10175
10176 /* don't allow switching to DFS channels */
10177 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10178 return -EINVAL;
10179
10180 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10181 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10182
10183 wdev_lock(wdev);
10184 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10185 wdev_unlock(wdev);
10186
10187 return err;
10188}
10189
10190static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10191 struct genl_info *info)
10192{
10193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10194 struct net_device *dev = info->user_ptr[1];
10195 struct wireless_dev *wdev = dev->ieee80211_ptr;
10196 const u8 *addr;
10197
10198 if (!rdev->ops->tdls_channel_switch ||
10199 !rdev->ops->tdls_cancel_channel_switch ||
10200 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10201 return -EOPNOTSUPP;
10202
10203 switch (dev->ieee80211_ptr->iftype) {
10204 case NL80211_IFTYPE_STATION:
10205 case NL80211_IFTYPE_P2P_CLIENT:
10206 break;
10207 default:
10208 return -EOPNOTSUPP;
10209 }
10210
10211 if (!info->attrs[NL80211_ATTR_MAC])
10212 return -EINVAL;
10213
10214 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10215
10216 wdev_lock(wdev);
10217 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10218 wdev_unlock(wdev);
10219
10220 return 0;
10221}
10222
Johannes Berg4c476992010-10-04 21:36:35 +020010223#define NL80211_FLAG_NEED_WIPHY 0x01
10224#define NL80211_FLAG_NEED_NETDEV 0x02
10225#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010226#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10227#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10228 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010229#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010230/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010231#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10232 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010233#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010234
Johannes Bergf84f7712013-11-14 17:14:45 +010010235static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010236 struct genl_info *info)
10237{
10238 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010239 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010240 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010241 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10242
10243 if (rtnl)
10244 rtnl_lock();
10245
10246 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010247 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010248 if (IS_ERR(rdev)) {
10249 if (rtnl)
10250 rtnl_unlock();
10251 return PTR_ERR(rdev);
10252 }
10253 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010254 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10255 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010256 ASSERT_RTNL();
10257
Johannes Berg89a54e42012-06-15 14:33:17 +020010258 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10259 info->attrs);
10260 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010261 if (rtnl)
10262 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010263 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010264 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010265
Johannes Berg89a54e42012-06-15 14:33:17 +020010266 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010267 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010268
Johannes Berg1bf614e2012-06-15 15:23:36 +020010269 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10270 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010271 if (rtnl)
10272 rtnl_unlock();
10273 return -EINVAL;
10274 }
10275
10276 info->user_ptr[1] = dev;
10277 } else {
10278 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010279 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010280
Johannes Berg1bf614e2012-06-15 15:23:36 +020010281 if (dev) {
10282 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10283 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010284 if (rtnl)
10285 rtnl_unlock();
10286 return -ENETDOWN;
10287 }
10288
10289 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010290 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10291 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010292 if (rtnl)
10293 rtnl_unlock();
10294 return -ENETDOWN;
10295 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010296 }
10297
Johannes Berg4c476992010-10-04 21:36:35 +020010298 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010299 }
10300
10301 return 0;
10302}
10303
Johannes Bergf84f7712013-11-14 17:14:45 +010010304static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010305 struct genl_info *info)
10306{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010307 if (info->user_ptr[1]) {
10308 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10309 struct wireless_dev *wdev = info->user_ptr[1];
10310
10311 if (wdev->netdev)
10312 dev_put(wdev->netdev);
10313 } else {
10314 dev_put(info->user_ptr[1]);
10315 }
10316 }
Johannes Berg5393b912014-09-10 15:00:16 +030010317
Johannes Berg4c476992010-10-04 21:36:35 +020010318 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10319 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010320
10321 /* If needed, clear the netlink message payload from the SKB
10322 * as it might contain key data that shouldn't stick around on
10323 * the heap after the SKB is freed. The netlink message header
10324 * is still needed for further processing, so leave it intact.
10325 */
10326 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10327 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10328
10329 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10330 }
Johannes Berg4c476992010-10-04 21:36:35 +020010331}
10332
Johannes Berg4534de82013-11-14 17:14:46 +010010333static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010334 {
10335 .cmd = NL80211_CMD_GET_WIPHY,
10336 .doit = nl80211_get_wiphy,
10337 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010338 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010339 .policy = nl80211_policy,
10340 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010341 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10342 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010343 },
10344 {
10345 .cmd = NL80211_CMD_SET_WIPHY,
10346 .doit = nl80211_set_wiphy,
10347 .policy = nl80211_policy,
10348 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010349 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010350 },
10351 {
10352 .cmd = NL80211_CMD_GET_INTERFACE,
10353 .doit = nl80211_get_interface,
10354 .dumpit = nl80211_dump_interface,
10355 .policy = nl80211_policy,
10356 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010357 .internal_flags = NL80211_FLAG_NEED_WDEV |
10358 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010359 },
10360 {
10361 .cmd = NL80211_CMD_SET_INTERFACE,
10362 .doit = nl80211_set_interface,
10363 .policy = nl80211_policy,
10364 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010365 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10366 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010367 },
10368 {
10369 .cmd = NL80211_CMD_NEW_INTERFACE,
10370 .doit = nl80211_new_interface,
10371 .policy = nl80211_policy,
10372 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010373 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10374 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010375 },
10376 {
10377 .cmd = NL80211_CMD_DEL_INTERFACE,
10378 .doit = nl80211_del_interface,
10379 .policy = nl80211_policy,
10380 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010381 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010382 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010383 },
Johannes Berg41ade002007-12-19 02:03:29 +010010384 {
10385 .cmd = NL80211_CMD_GET_KEY,
10386 .doit = nl80211_get_key,
10387 .policy = nl80211_policy,
10388 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010389 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010390 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010391 },
10392 {
10393 .cmd = NL80211_CMD_SET_KEY,
10394 .doit = nl80211_set_key,
10395 .policy = nl80211_policy,
10396 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010398 NL80211_FLAG_NEED_RTNL |
10399 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010400 },
10401 {
10402 .cmd = NL80211_CMD_NEW_KEY,
10403 .doit = nl80211_new_key,
10404 .policy = nl80211_policy,
10405 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010407 NL80211_FLAG_NEED_RTNL |
10408 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010409 },
10410 {
10411 .cmd = NL80211_CMD_DEL_KEY,
10412 .doit = nl80211_del_key,
10413 .policy = nl80211_policy,
10414 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010415 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010416 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010417 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010418 {
10419 .cmd = NL80211_CMD_SET_BEACON,
10420 .policy = nl80211_policy,
10421 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010422 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010423 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010424 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010425 },
10426 {
Johannes Berg88600202012-02-13 15:17:18 +010010427 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010428 .policy = nl80211_policy,
10429 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010430 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010431 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010432 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010433 },
10434 {
Johannes Berg88600202012-02-13 15:17:18 +010010435 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010436 .policy = nl80211_policy,
10437 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010438 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010440 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010441 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010442 {
10443 .cmd = NL80211_CMD_GET_STATION,
10444 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010445 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010446 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010447 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10448 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010449 },
10450 {
10451 .cmd = NL80211_CMD_SET_STATION,
10452 .doit = nl80211_set_station,
10453 .policy = nl80211_policy,
10454 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010456 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010457 },
10458 {
10459 .cmd = NL80211_CMD_NEW_STATION,
10460 .doit = nl80211_new_station,
10461 .policy = nl80211_policy,
10462 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010464 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010465 },
10466 {
10467 .cmd = NL80211_CMD_DEL_STATION,
10468 .doit = nl80211_del_station,
10469 .policy = nl80211_policy,
10470 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010472 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010473 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010474 {
10475 .cmd = NL80211_CMD_GET_MPATH,
10476 .doit = nl80211_get_mpath,
10477 .dumpit = nl80211_dump_mpath,
10478 .policy = nl80211_policy,
10479 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010480 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010481 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010482 },
10483 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010484 .cmd = NL80211_CMD_GET_MPP,
10485 .doit = nl80211_get_mpp,
10486 .dumpit = nl80211_dump_mpp,
10487 .policy = nl80211_policy,
10488 .flags = GENL_ADMIN_PERM,
10489 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10490 NL80211_FLAG_NEED_RTNL,
10491 },
10492 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010493 .cmd = NL80211_CMD_SET_MPATH,
10494 .doit = nl80211_set_mpath,
10495 .policy = nl80211_policy,
10496 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010498 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010499 },
10500 {
10501 .cmd = NL80211_CMD_NEW_MPATH,
10502 .doit = nl80211_new_mpath,
10503 .policy = nl80211_policy,
10504 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010505 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010506 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010507 },
10508 {
10509 .cmd = NL80211_CMD_DEL_MPATH,
10510 .doit = nl80211_del_mpath,
10511 .policy = nl80211_policy,
10512 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010513 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010514 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010515 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010516 {
10517 .cmd = NL80211_CMD_SET_BSS,
10518 .doit = nl80211_set_bss,
10519 .policy = nl80211_policy,
10520 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010522 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010523 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010524 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010525 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010526 .doit = nl80211_get_reg_do,
10527 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010528 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010529 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010530 /* can be retrieved by unprivileged users */
10531 },
10532 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010533 .cmd = NL80211_CMD_SET_REG,
10534 .doit = nl80211_set_reg,
10535 .policy = nl80211_policy,
10536 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010537 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010538 },
10539 {
10540 .cmd = NL80211_CMD_REQ_SET_REG,
10541 .doit = nl80211_req_set_reg,
10542 .policy = nl80211_policy,
10543 .flags = GENL_ADMIN_PERM,
10544 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010545 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010546 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10547 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010548 .policy = nl80211_policy,
10549 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010550 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010551 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010552 },
10553 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010554 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10555 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010556 .policy = nl80211_policy,
10557 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010558 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010559 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010560 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010561 {
Johannes Berg2a519312009-02-10 21:25:55 +010010562 .cmd = NL80211_CMD_TRIGGER_SCAN,
10563 .doit = nl80211_trigger_scan,
10564 .policy = nl80211_policy,
10565 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010566 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010567 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010568 },
10569 {
10570 .cmd = NL80211_CMD_GET_SCAN,
10571 .policy = nl80211_policy,
10572 .dumpit = nl80211_dump_scan,
10573 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010574 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010575 .cmd = NL80211_CMD_START_SCHED_SCAN,
10576 .doit = nl80211_start_sched_scan,
10577 .policy = nl80211_policy,
10578 .flags = GENL_ADMIN_PERM,
10579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10580 NL80211_FLAG_NEED_RTNL,
10581 },
10582 {
10583 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10584 .doit = nl80211_stop_sched_scan,
10585 .policy = nl80211_policy,
10586 .flags = GENL_ADMIN_PERM,
10587 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10588 NL80211_FLAG_NEED_RTNL,
10589 },
10590 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010591 .cmd = NL80211_CMD_AUTHENTICATE,
10592 .doit = nl80211_authenticate,
10593 .policy = nl80211_policy,
10594 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010595 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010596 NL80211_FLAG_NEED_RTNL |
10597 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010598 },
10599 {
10600 .cmd = NL80211_CMD_ASSOCIATE,
10601 .doit = nl80211_associate,
10602 .policy = nl80211_policy,
10603 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010604 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010605 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010606 },
10607 {
10608 .cmd = NL80211_CMD_DEAUTHENTICATE,
10609 .doit = nl80211_deauthenticate,
10610 .policy = nl80211_policy,
10611 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010612 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010613 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010614 },
10615 {
10616 .cmd = NL80211_CMD_DISASSOCIATE,
10617 .doit = nl80211_disassociate,
10618 .policy = nl80211_policy,
10619 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010620 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010621 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010622 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010623 {
10624 .cmd = NL80211_CMD_JOIN_IBSS,
10625 .doit = nl80211_join_ibss,
10626 .policy = nl80211_policy,
10627 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010628 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010629 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010630 },
10631 {
10632 .cmd = NL80211_CMD_LEAVE_IBSS,
10633 .doit = nl80211_leave_ibss,
10634 .policy = nl80211_policy,
10635 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010636 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010637 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010638 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010639#ifdef CONFIG_NL80211_TESTMODE
10640 {
10641 .cmd = NL80211_CMD_TESTMODE,
10642 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010643 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010644 .policy = nl80211_policy,
10645 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010646 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10647 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010648 },
10649#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010650 {
10651 .cmd = NL80211_CMD_CONNECT,
10652 .doit = nl80211_connect,
10653 .policy = nl80211_policy,
10654 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010656 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010657 },
10658 {
10659 .cmd = NL80211_CMD_DISCONNECT,
10660 .doit = nl80211_disconnect,
10661 .policy = nl80211_policy,
10662 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010664 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010665 },
Johannes Berg463d0182009-07-14 00:33:35 +020010666 {
10667 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10668 .doit = nl80211_wiphy_netns,
10669 .policy = nl80211_policy,
10670 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010671 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10672 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010673 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010674 {
10675 .cmd = NL80211_CMD_GET_SURVEY,
10676 .policy = nl80211_policy,
10677 .dumpit = nl80211_dump_survey,
10678 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010679 {
10680 .cmd = NL80211_CMD_SET_PMKSA,
10681 .doit = nl80211_setdel_pmksa,
10682 .policy = nl80211_policy,
10683 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010685 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010686 },
10687 {
10688 .cmd = NL80211_CMD_DEL_PMKSA,
10689 .doit = nl80211_setdel_pmksa,
10690 .policy = nl80211_policy,
10691 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010692 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010693 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010694 },
10695 {
10696 .cmd = NL80211_CMD_FLUSH_PMKSA,
10697 .doit = nl80211_flush_pmksa,
10698 .policy = nl80211_policy,
10699 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010700 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010701 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010702 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010703 {
10704 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10705 .doit = nl80211_remain_on_channel,
10706 .policy = nl80211_policy,
10707 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010708 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010709 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010710 },
10711 {
10712 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10713 .doit = nl80211_cancel_remain_on_channel,
10714 .policy = nl80211_policy,
10715 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010716 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010717 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010718 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010719 {
10720 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10721 .doit = nl80211_set_tx_bitrate_mask,
10722 .policy = nl80211_policy,
10723 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010724 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10725 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010726 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010727 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010728 .cmd = NL80211_CMD_REGISTER_FRAME,
10729 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010730 .policy = nl80211_policy,
10731 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010732 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010733 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010734 },
10735 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010736 .cmd = NL80211_CMD_FRAME,
10737 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010738 .policy = nl80211_policy,
10739 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010740 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010741 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010742 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010743 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010744 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10745 .doit = nl80211_tx_mgmt_cancel_wait,
10746 .policy = nl80211_policy,
10747 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010748 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010749 NL80211_FLAG_NEED_RTNL,
10750 },
10751 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010752 .cmd = NL80211_CMD_SET_POWER_SAVE,
10753 .doit = nl80211_set_power_save,
10754 .policy = nl80211_policy,
10755 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010756 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10757 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010758 },
10759 {
10760 .cmd = NL80211_CMD_GET_POWER_SAVE,
10761 .doit = nl80211_get_power_save,
10762 .policy = nl80211_policy,
10763 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010764 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10765 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010766 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010767 {
10768 .cmd = NL80211_CMD_SET_CQM,
10769 .doit = nl80211_set_cqm,
10770 .policy = nl80211_policy,
10771 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010772 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10773 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010774 },
Johannes Bergf444de02010-05-05 15:25:02 +020010775 {
10776 .cmd = NL80211_CMD_SET_CHANNEL,
10777 .doit = nl80211_set_channel,
10778 .policy = nl80211_policy,
10779 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010780 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10781 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010782 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010783 {
10784 .cmd = NL80211_CMD_SET_WDS_PEER,
10785 .doit = nl80211_set_wds_peer,
10786 .policy = nl80211_policy,
10787 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010788 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10789 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010790 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010791 {
10792 .cmd = NL80211_CMD_JOIN_MESH,
10793 .doit = nl80211_join_mesh,
10794 .policy = nl80211_policy,
10795 .flags = GENL_ADMIN_PERM,
10796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10797 NL80211_FLAG_NEED_RTNL,
10798 },
10799 {
10800 .cmd = NL80211_CMD_LEAVE_MESH,
10801 .doit = nl80211_leave_mesh,
10802 .policy = nl80211_policy,
10803 .flags = GENL_ADMIN_PERM,
10804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10805 NL80211_FLAG_NEED_RTNL,
10806 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010807 {
10808 .cmd = NL80211_CMD_JOIN_OCB,
10809 .doit = nl80211_join_ocb,
10810 .policy = nl80211_policy,
10811 .flags = GENL_ADMIN_PERM,
10812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10813 NL80211_FLAG_NEED_RTNL,
10814 },
10815 {
10816 .cmd = NL80211_CMD_LEAVE_OCB,
10817 .doit = nl80211_leave_ocb,
10818 .policy = nl80211_policy,
10819 .flags = GENL_ADMIN_PERM,
10820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10821 NL80211_FLAG_NEED_RTNL,
10822 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010823#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010824 {
10825 .cmd = NL80211_CMD_GET_WOWLAN,
10826 .doit = nl80211_get_wowlan,
10827 .policy = nl80211_policy,
10828 /* can be retrieved by unprivileged users */
10829 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10830 NL80211_FLAG_NEED_RTNL,
10831 },
10832 {
10833 .cmd = NL80211_CMD_SET_WOWLAN,
10834 .doit = nl80211_set_wowlan,
10835 .policy = nl80211_policy,
10836 .flags = GENL_ADMIN_PERM,
10837 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10838 NL80211_FLAG_NEED_RTNL,
10839 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010840#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010841 {
10842 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10843 .doit = nl80211_set_rekey_data,
10844 .policy = nl80211_policy,
10845 .flags = GENL_ADMIN_PERM,
10846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010847 NL80211_FLAG_NEED_RTNL |
10848 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010849 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010850 {
10851 .cmd = NL80211_CMD_TDLS_MGMT,
10852 .doit = nl80211_tdls_mgmt,
10853 .policy = nl80211_policy,
10854 .flags = GENL_ADMIN_PERM,
10855 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10856 NL80211_FLAG_NEED_RTNL,
10857 },
10858 {
10859 .cmd = NL80211_CMD_TDLS_OPER,
10860 .doit = nl80211_tdls_oper,
10861 .policy = nl80211_policy,
10862 .flags = GENL_ADMIN_PERM,
10863 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10864 NL80211_FLAG_NEED_RTNL,
10865 },
Johannes Berg28946da2011-11-04 11:18:12 +010010866 {
10867 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10868 .doit = nl80211_register_unexpected_frame,
10869 .policy = nl80211_policy,
10870 .flags = GENL_ADMIN_PERM,
10871 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10872 NL80211_FLAG_NEED_RTNL,
10873 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010874 {
10875 .cmd = NL80211_CMD_PROBE_CLIENT,
10876 .doit = nl80211_probe_client,
10877 .policy = nl80211_policy,
10878 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010879 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010880 NL80211_FLAG_NEED_RTNL,
10881 },
Johannes Berg5e7602302011-11-04 11:18:17 +010010882 {
10883 .cmd = NL80211_CMD_REGISTER_BEACONS,
10884 .doit = nl80211_register_beacons,
10885 .policy = nl80211_policy,
10886 .flags = GENL_ADMIN_PERM,
10887 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10888 NL80211_FLAG_NEED_RTNL,
10889 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010890 {
10891 .cmd = NL80211_CMD_SET_NOACK_MAP,
10892 .doit = nl80211_set_noack_map,
10893 .policy = nl80211_policy,
10894 .flags = GENL_ADMIN_PERM,
10895 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10896 NL80211_FLAG_NEED_RTNL,
10897 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010898 {
10899 .cmd = NL80211_CMD_START_P2P_DEVICE,
10900 .doit = nl80211_start_p2p_device,
10901 .policy = nl80211_policy,
10902 .flags = GENL_ADMIN_PERM,
10903 .internal_flags = NL80211_FLAG_NEED_WDEV |
10904 NL80211_FLAG_NEED_RTNL,
10905 },
10906 {
10907 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10908 .doit = nl80211_stop_p2p_device,
10909 .policy = nl80211_policy,
10910 .flags = GENL_ADMIN_PERM,
10911 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10912 NL80211_FLAG_NEED_RTNL,
10913 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010914 {
10915 .cmd = NL80211_CMD_SET_MCAST_RATE,
10916 .doit = nl80211_set_mcast_rate,
10917 .policy = nl80211_policy,
10918 .flags = GENL_ADMIN_PERM,
10919 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10920 NL80211_FLAG_NEED_RTNL,
10921 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010922 {
10923 .cmd = NL80211_CMD_SET_MAC_ACL,
10924 .doit = nl80211_set_mac_acl,
10925 .policy = nl80211_policy,
10926 .flags = GENL_ADMIN_PERM,
10927 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10928 NL80211_FLAG_NEED_RTNL,
10929 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010930 {
10931 .cmd = NL80211_CMD_RADAR_DETECT,
10932 .doit = nl80211_start_radar_detection,
10933 .policy = nl80211_policy,
10934 .flags = GENL_ADMIN_PERM,
10935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10936 NL80211_FLAG_NEED_RTNL,
10937 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010938 {
10939 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10940 .doit = nl80211_get_protocol_features,
10941 .policy = nl80211_policy,
10942 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010943 {
10944 .cmd = NL80211_CMD_UPDATE_FT_IES,
10945 .doit = nl80211_update_ft_ies,
10946 .policy = nl80211_policy,
10947 .flags = GENL_ADMIN_PERM,
10948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10949 NL80211_FLAG_NEED_RTNL,
10950 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010951 {
10952 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10953 .doit = nl80211_crit_protocol_start,
10954 .policy = nl80211_policy,
10955 .flags = GENL_ADMIN_PERM,
10956 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10957 NL80211_FLAG_NEED_RTNL,
10958 },
10959 {
10960 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10961 .doit = nl80211_crit_protocol_stop,
10962 .policy = nl80211_policy,
10963 .flags = GENL_ADMIN_PERM,
10964 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10965 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010966 },
10967 {
10968 .cmd = NL80211_CMD_GET_COALESCE,
10969 .doit = nl80211_get_coalesce,
10970 .policy = nl80211_policy,
10971 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10972 NL80211_FLAG_NEED_RTNL,
10973 },
10974 {
10975 .cmd = NL80211_CMD_SET_COALESCE,
10976 .doit = nl80211_set_coalesce,
10977 .policy = nl80211_policy,
10978 .flags = GENL_ADMIN_PERM,
10979 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10980 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010981 },
10982 {
10983 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10984 .doit = nl80211_channel_switch,
10985 .policy = nl80211_policy,
10986 .flags = GENL_ADMIN_PERM,
10987 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10988 NL80211_FLAG_NEED_RTNL,
10989 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010990 {
10991 .cmd = NL80211_CMD_VENDOR,
10992 .doit = nl80211_vendor_cmd,
10993 .policy = nl80211_policy,
10994 .flags = GENL_ADMIN_PERM,
10995 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10996 NL80211_FLAG_NEED_RTNL,
10997 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010998 {
10999 .cmd = NL80211_CMD_SET_QOS_MAP,
11000 .doit = nl80211_set_qos_map,
11001 .policy = nl80211_policy,
11002 .flags = GENL_ADMIN_PERM,
11003 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11004 NL80211_FLAG_NEED_RTNL,
11005 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011006 {
11007 .cmd = NL80211_CMD_ADD_TX_TS,
11008 .doit = nl80211_add_tx_ts,
11009 .policy = nl80211_policy,
11010 .flags = GENL_ADMIN_PERM,
11011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11012 NL80211_FLAG_NEED_RTNL,
11013 },
11014 {
11015 .cmd = NL80211_CMD_DEL_TX_TS,
11016 .doit = nl80211_del_tx_ts,
11017 .policy = nl80211_policy,
11018 .flags = GENL_ADMIN_PERM,
11019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11020 NL80211_FLAG_NEED_RTNL,
11021 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011022 {
11023 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11024 .doit = nl80211_tdls_channel_switch,
11025 .policy = nl80211_policy,
11026 .flags = GENL_ADMIN_PERM,
11027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11028 NL80211_FLAG_NEED_RTNL,
11029 },
11030 {
11031 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11032 .doit = nl80211_tdls_cancel_channel_switch,
11033 .policy = nl80211_policy,
11034 .flags = GENL_ADMIN_PERM,
11035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11036 NL80211_FLAG_NEED_RTNL,
11037 },
Johannes Berg55682962007-09-20 13:09:35 -040011038};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011039
Johannes Berg55682962007-09-20 13:09:35 -040011040/* notification functions */
11041
Johannes Berg3bb20552014-05-26 13:52:25 +020011042void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11043 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011044{
11045 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011046 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011047
Johannes Berg3bb20552014-05-26 13:52:25 +020011048 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11049 cmd != NL80211_CMD_DEL_WIPHY);
11050
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011051 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011052 if (!msg)
11053 return;
11054
Johannes Berg3bb20552014-05-26 13:52:25 +020011055 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011056 nlmsg_free(msg);
11057 return;
11058 }
11059
Johannes Berg68eb5502013-11-19 15:19:38 +010011060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011061 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011062}
11063
Johannes Berg362a4152009-05-24 16:43:15 +020011064static int nl80211_add_scan_req(struct sk_buff *msg,
11065 struct cfg80211_registered_device *rdev)
11066{
11067 struct cfg80211_scan_request *req = rdev->scan_req;
11068 struct nlattr *nest;
11069 int i;
11070
11071 if (WARN_ON(!req))
11072 return 0;
11073
11074 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11075 if (!nest)
11076 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011077 for (i = 0; i < req->n_ssids; i++) {
11078 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11079 goto nla_put_failure;
11080 }
Johannes Berg362a4152009-05-24 16:43:15 +020011081 nla_nest_end(msg, nest);
11082
11083 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11084 if (!nest)
11085 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011086 for (i = 0; i < req->n_channels; i++) {
11087 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11088 goto nla_put_failure;
11089 }
Johannes Berg362a4152009-05-24 16:43:15 +020011090 nla_nest_end(msg, nest);
11091
David S. Miller9360ffd2012-03-29 04:41:26 -040011092 if (req->ie &&
11093 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11094 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011095
Johannes Bergae917c92013-10-25 11:05:22 +020011096 if (req->flags &&
11097 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11098 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011099
Johannes Berg362a4152009-05-24 16:43:15 +020011100 return 0;
11101 nla_put_failure:
11102 return -ENOBUFS;
11103}
11104
Johannes Berga538e2d2009-06-16 19:56:42 +020011105static int nl80211_send_scan_msg(struct sk_buff *msg,
11106 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011107 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011108 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011109 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011110{
11111 void *hdr;
11112
Eric W. Biederman15e47302012-09-07 20:12:54 +000011113 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011114 if (!hdr)
11115 return -1;
11116
David S. Miller9360ffd2012-03-29 04:41:26 -040011117 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011118 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11119 wdev->netdev->ifindex)) ||
11120 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011121 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011122
Johannes Berg362a4152009-05-24 16:43:15 +020011123 /* ignore errors and send incomplete event anyway */
11124 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011125
Johannes Berg053c0952015-01-16 22:09:00 +010011126 genlmsg_end(msg, hdr);
11127 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011128
11129 nla_put_failure:
11130 genlmsg_cancel(msg, hdr);
11131 return -EMSGSIZE;
11132}
11133
Luciano Coelho807f8a82011-05-11 17:09:35 +030011134static int
11135nl80211_send_sched_scan_msg(struct sk_buff *msg,
11136 struct cfg80211_registered_device *rdev,
11137 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011138 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011139{
11140 void *hdr;
11141
Eric W. Biederman15e47302012-09-07 20:12:54 +000011142 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011143 if (!hdr)
11144 return -1;
11145
David S. Miller9360ffd2012-03-29 04:41:26 -040011146 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11147 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11148 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011149
Johannes Berg053c0952015-01-16 22:09:00 +010011150 genlmsg_end(msg, hdr);
11151 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011152
11153 nla_put_failure:
11154 genlmsg_cancel(msg, hdr);
11155 return -EMSGSIZE;
11156}
11157
Johannes Berga538e2d2009-06-16 19:56:42 +020011158void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011159 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011160{
11161 struct sk_buff *msg;
11162
Thomas Graf58050fc2012-06-28 03:57:45 +000011163 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011164 if (!msg)
11165 return;
11166
Johannes Bergfd014282012-06-18 19:17:03 +020011167 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011168 NL80211_CMD_TRIGGER_SCAN) < 0) {
11169 nlmsg_free(msg);
11170 return;
11171 }
11172
Johannes Berg68eb5502013-11-19 15:19:38 +010011173 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011174 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011175}
11176
Johannes Bergf9d15d12014-01-22 11:14:19 +020011177struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11178 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011179{
11180 struct sk_buff *msg;
11181
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011182 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011183 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011184 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011185
Johannes Bergfd014282012-06-18 19:17:03 +020011186 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011187 aborted ? NL80211_CMD_SCAN_ABORTED :
11188 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011189 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011190 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011191 }
11192
Johannes Bergf9d15d12014-01-22 11:14:19 +020011193 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011194}
11195
Johannes Bergf9d15d12014-01-22 11:14:19 +020011196void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11197 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011198{
Johannes Berg2a519312009-02-10 21:25:55 +010011199 if (!msg)
11200 return;
11201
Johannes Berg68eb5502013-11-19 15:19:38 +010011202 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011203 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011204}
11205
Luciano Coelho807f8a82011-05-11 17:09:35 +030011206void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11207 struct net_device *netdev)
11208{
11209 struct sk_buff *msg;
11210
11211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11212 if (!msg)
11213 return;
11214
11215 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11216 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11217 nlmsg_free(msg);
11218 return;
11219 }
11220
Johannes Berg68eb5502013-11-19 15:19:38 +010011221 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011222 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011223}
11224
11225void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11226 struct net_device *netdev, u32 cmd)
11227{
11228 struct sk_buff *msg;
11229
Thomas Graf58050fc2012-06-28 03:57:45 +000011230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011231 if (!msg)
11232 return;
11233
11234 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11235 nlmsg_free(msg);
11236 return;
11237 }
11238
Johannes Berg68eb5502013-11-19 15:19:38 +010011239 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011240 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011241}
11242
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011243static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11244 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011245{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011246 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011247 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11248 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011249
David S. Miller9360ffd2012-03-29 04:41:26 -040011250 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11251 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11252 NL80211_REGDOM_TYPE_WORLD))
11253 goto nla_put_failure;
11254 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11255 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11256 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11257 goto nla_put_failure;
11258 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11259 request->intersect) {
11260 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11261 NL80211_REGDOM_TYPE_INTERSECTION))
11262 goto nla_put_failure;
11263 } else {
11264 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11265 NL80211_REGDOM_TYPE_COUNTRY) ||
11266 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11267 request->alpha2))
11268 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011269 }
11270
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011271 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11272 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11273
11274 if (wiphy &&
11275 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11276 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011277
11278 if (wiphy &&
11279 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11280 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11281 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011282 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011283
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011284 return true;
11285
11286nla_put_failure:
11287 return false;
11288}
11289
11290/*
11291 * This can happen on global regulatory changes or device specific settings
11292 * based on custom regulatory domains.
11293 */
11294void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11295 struct regulatory_request *request)
11296{
11297 struct sk_buff *msg;
11298 void *hdr;
11299
11300 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11301 if (!msg)
11302 return;
11303
11304 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11305 if (!hdr) {
11306 nlmsg_free(msg);
11307 return;
11308 }
11309
11310 if (nl80211_reg_change_event_fill(msg, request) == false)
11311 goto nla_put_failure;
11312
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011313 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011314
Johannes Bergbc43b282009-07-25 10:54:13 +020011315 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011316 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011317 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011318 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011319
11320 return;
11321
11322nla_put_failure:
11323 genlmsg_cancel(msg, hdr);
11324 nlmsg_free(msg);
11325}
11326
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011327static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11328 struct net_device *netdev,
11329 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011330 enum nl80211_commands cmd, gfp_t gfp,
11331 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011332{
11333 struct sk_buff *msg;
11334 void *hdr;
11335
Johannes Berge6d6e342009-07-01 21:26:47 +020011336 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011337 if (!msg)
11338 return;
11339
11340 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11341 if (!hdr) {
11342 nlmsg_free(msg);
11343 return;
11344 }
11345
David S. Miller9360ffd2012-03-29 04:41:26 -040011346 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11347 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11348 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11349 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011350
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011351 if (uapsd_queues >= 0) {
11352 struct nlattr *nla_wmm =
11353 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11354 if (!nla_wmm)
11355 goto nla_put_failure;
11356
11357 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11358 uapsd_queues))
11359 goto nla_put_failure;
11360
11361 nla_nest_end(msg, nla_wmm);
11362 }
11363
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011364 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011365
Johannes Berg68eb5502013-11-19 15:19:38 +010011366 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011367 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011368 return;
11369
11370 nla_put_failure:
11371 genlmsg_cancel(msg, hdr);
11372 nlmsg_free(msg);
11373}
11374
11375void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011376 struct net_device *netdev, const u8 *buf,
11377 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011378{
11379 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011380 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011381}
11382
11383void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11384 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011385 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011386{
Johannes Berge6d6e342009-07-01 21:26:47 +020011387 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011388 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011389}
11390
Jouni Malinen53b46b82009-03-27 20:53:56 +020011391void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011392 struct net_device *netdev, const u8 *buf,
11393 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011394{
11395 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011396 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011397}
11398
Jouni Malinen53b46b82009-03-27 20:53:56 +020011399void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11400 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011401 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011402{
11403 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011404 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011405}
11406
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011407void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11408 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011409{
Johannes Berg947add32013-02-22 22:05:20 +010011410 struct wireless_dev *wdev = dev->ieee80211_ptr;
11411 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011412 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011413 const struct ieee80211_mgmt *mgmt = (void *)buf;
11414 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011415
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011416 if (WARN_ON(len < 2))
11417 return;
11418
11419 if (ieee80211_is_deauth(mgmt->frame_control))
11420 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11421 else
11422 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11423
11424 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011425 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011426}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011427EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011428
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011429static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11430 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011431 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011432{
11433 struct sk_buff *msg;
11434 void *hdr;
11435
Johannes Berge6d6e342009-07-01 21:26:47 +020011436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011437 if (!msg)
11438 return;
11439
11440 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11441 if (!hdr) {
11442 nlmsg_free(msg);
11443 return;
11444 }
11445
David S. Miller9360ffd2012-03-29 04:41:26 -040011446 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11447 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11448 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11449 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11450 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011451
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011452 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011453
Johannes Berg68eb5502013-11-19 15:19:38 +010011454 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011455 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011456 return;
11457
11458 nla_put_failure:
11459 genlmsg_cancel(msg, hdr);
11460 nlmsg_free(msg);
11461}
11462
11463void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011464 struct net_device *netdev, const u8 *addr,
11465 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011466{
11467 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011468 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011469}
11470
11471void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011472 struct net_device *netdev, const u8 *addr,
11473 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011474{
Johannes Berge6d6e342009-07-01 21:26:47 +020011475 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11476 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011477}
11478
Samuel Ortizb23aa672009-07-01 21:26:54 +020011479void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11480 struct net_device *netdev, const u8 *bssid,
11481 const u8 *req_ie, size_t req_ie_len,
11482 const u8 *resp_ie, size_t resp_ie_len,
11483 u16 status, gfp_t gfp)
11484{
11485 struct sk_buff *msg;
11486 void *hdr;
11487
Thomas Graf58050fc2012-06-28 03:57:45 +000011488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011489 if (!msg)
11490 return;
11491
11492 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11493 if (!hdr) {
11494 nlmsg_free(msg);
11495 return;
11496 }
11497
David S. Miller9360ffd2012-03-29 04:41:26 -040011498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11499 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11500 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11501 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11502 (req_ie &&
11503 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11504 (resp_ie &&
11505 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11506 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011507
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011508 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011509
Johannes Berg68eb5502013-11-19 15:19:38 +010011510 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011511 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011512 return;
11513
11514 nla_put_failure:
11515 genlmsg_cancel(msg, hdr);
11516 nlmsg_free(msg);
11517
11518}
11519
11520void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11521 struct net_device *netdev, const u8 *bssid,
11522 const u8 *req_ie, size_t req_ie_len,
11523 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11524{
11525 struct sk_buff *msg;
11526 void *hdr;
11527
Thomas Graf58050fc2012-06-28 03:57:45 +000011528 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011529 if (!msg)
11530 return;
11531
11532 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11533 if (!hdr) {
11534 nlmsg_free(msg);
11535 return;
11536 }
11537
David S. Miller9360ffd2012-03-29 04:41:26 -040011538 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11539 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11540 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11541 (req_ie &&
11542 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11543 (resp_ie &&
11544 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11545 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011546
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011547 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011548
Johannes Berg68eb5502013-11-19 15:19:38 +010011549 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011550 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011551 return;
11552
11553 nla_put_failure:
11554 genlmsg_cancel(msg, hdr);
11555 nlmsg_free(msg);
11556
11557}
11558
11559void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11560 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011561 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011562{
11563 struct sk_buff *msg;
11564 void *hdr;
11565
Thomas Graf58050fc2012-06-28 03:57:45 +000011566 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011567 if (!msg)
11568 return;
11569
11570 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11571 if (!hdr) {
11572 nlmsg_free(msg);
11573 return;
11574 }
11575
David S. Miller9360ffd2012-03-29 04:41:26 -040011576 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11577 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11578 (from_ap && reason &&
11579 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11580 (from_ap &&
11581 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11582 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11583 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011584
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011585 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011586
Johannes Berg68eb5502013-11-19 15:19:38 +010011587 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011588 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011589 return;
11590
11591 nla_put_failure:
11592 genlmsg_cancel(msg, hdr);
11593 nlmsg_free(msg);
11594
11595}
11596
Johannes Berg04a773a2009-04-19 21:24:32 +020011597void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11598 struct net_device *netdev, const u8 *bssid,
11599 gfp_t gfp)
11600{
11601 struct sk_buff *msg;
11602 void *hdr;
11603
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011605 if (!msg)
11606 return;
11607
11608 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11609 if (!hdr) {
11610 nlmsg_free(msg);
11611 return;
11612 }
11613
David S. Miller9360ffd2012-03-29 04:41:26 -040011614 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11615 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11616 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11617 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011618
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011619 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011620
Johannes Berg68eb5502013-11-19 15:19:38 +010011621 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011622 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011623 return;
11624
11625 nla_put_failure:
11626 genlmsg_cancel(msg, hdr);
11627 nlmsg_free(msg);
11628}
11629
Johannes Berg947add32013-02-22 22:05:20 +010011630void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11631 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011632{
Johannes Berg947add32013-02-22 22:05:20 +010011633 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011634 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011635 struct sk_buff *msg;
11636 void *hdr;
11637
Johannes Berg947add32013-02-22 22:05:20 +010011638 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11639 return;
11640
11641 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11642
Javier Cardonac93b5e72011-04-07 15:08:34 -070011643 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11644 if (!msg)
11645 return;
11646
11647 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11648 if (!hdr) {
11649 nlmsg_free(msg);
11650 return;
11651 }
11652
David S. Miller9360ffd2012-03-29 04:41:26 -040011653 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011654 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11655 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011656 (ie_len && ie &&
11657 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11658 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011659
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011660 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011661
Johannes Berg68eb5502013-11-19 15:19:38 +010011662 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011663 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011664 return;
11665
11666 nla_put_failure:
11667 genlmsg_cancel(msg, hdr);
11668 nlmsg_free(msg);
11669}
Johannes Berg947add32013-02-22 22:05:20 +010011670EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011671
Jouni Malinena3b8b052009-03-27 21:59:49 +020011672void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11673 struct net_device *netdev, const u8 *addr,
11674 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011675 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011676{
11677 struct sk_buff *msg;
11678 void *hdr;
11679
Johannes Berge6d6e342009-07-01 21:26:47 +020011680 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011681 if (!msg)
11682 return;
11683
11684 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11685 if (!hdr) {
11686 nlmsg_free(msg);
11687 return;
11688 }
11689
David S. Miller9360ffd2012-03-29 04:41:26 -040011690 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11692 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11693 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11694 (key_id != -1 &&
11695 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11696 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11697 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011698
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011699 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011700
Johannes Berg68eb5502013-11-19 15:19:38 +010011701 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011702 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011703 return;
11704
11705 nla_put_failure:
11706 genlmsg_cancel(msg, hdr);
11707 nlmsg_free(msg);
11708}
11709
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011710void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11711 struct ieee80211_channel *channel_before,
11712 struct ieee80211_channel *channel_after)
11713{
11714 struct sk_buff *msg;
11715 void *hdr;
11716 struct nlattr *nl_freq;
11717
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011718 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011719 if (!msg)
11720 return;
11721
11722 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11723 if (!hdr) {
11724 nlmsg_free(msg);
11725 return;
11726 }
11727
11728 /*
11729 * Since we are applying the beacon hint to a wiphy we know its
11730 * wiphy_idx is valid
11731 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11733 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011734
11735 /* Before */
11736 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11737 if (!nl_freq)
11738 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011739 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011740 goto nla_put_failure;
11741 nla_nest_end(msg, nl_freq);
11742
11743 /* After */
11744 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11745 if (!nl_freq)
11746 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011747 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011748 goto nla_put_failure;
11749 nla_nest_end(msg, nl_freq);
11750
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011751 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011752
Johannes Berg463d0182009-07-14 00:33:35 +020011753 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011754 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011755 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011756 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011757
11758 return;
11759
11760nla_put_failure:
11761 genlmsg_cancel(msg, hdr);
11762 nlmsg_free(msg);
11763}
11764
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011765static void nl80211_send_remain_on_chan_event(
11766 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011767 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011768 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011769 unsigned int duration, gfp_t gfp)
11770{
11771 struct sk_buff *msg;
11772 void *hdr;
11773
11774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11775 if (!msg)
11776 return;
11777
11778 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11779 if (!hdr) {
11780 nlmsg_free(msg);
11781 return;
11782 }
11783
David S. Miller9360ffd2012-03-29 04:41:26 -040011784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011785 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11786 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011787 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011788 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011789 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11790 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011791 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11792 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011793
David S. Miller9360ffd2012-03-29 04:41:26 -040011794 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11795 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11796 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011797
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011798 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011799
Johannes Berg68eb5502013-11-19 15:19:38 +010011800 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011801 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011802 return;
11803
11804 nla_put_failure:
11805 genlmsg_cancel(msg, hdr);
11806 nlmsg_free(msg);
11807}
11808
Johannes Berg947add32013-02-22 22:05:20 +010011809void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11810 struct ieee80211_channel *chan,
11811 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011812{
Johannes Berg947add32013-02-22 22:05:20 +010011813 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011814 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011815
11816 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011817 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011818 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011819 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011820}
Johannes Berg947add32013-02-22 22:05:20 +010011821EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011822
Johannes Berg947add32013-02-22 22:05:20 +010011823void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11824 struct ieee80211_channel *chan,
11825 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011826{
Johannes Berg947add32013-02-22 22:05:20 +010011827 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011828 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011829
11830 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011831 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011832 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011833}
Johannes Berg947add32013-02-22 22:05:20 +010011834EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011835
Johannes Berg947add32013-02-22 22:05:20 +010011836void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11837 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011838{
Johannes Berg947add32013-02-22 22:05:20 +010011839 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011840 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011841 struct sk_buff *msg;
11842
Johannes Berg947add32013-02-22 22:05:20 +010011843 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11844
Thomas Graf58050fc2012-06-28 03:57:45 +000011845 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011846 if (!msg)
11847 return;
11848
Johannes Bergcf5ead82014-11-14 17:14:00 +010011849 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040011850 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011851 nlmsg_free(msg);
11852 return;
11853 }
11854
Johannes Berg68eb5502013-11-19 15:19:38 +010011855 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011856 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011857}
Johannes Berg947add32013-02-22 22:05:20 +010011858EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011859
Johannes Bergcf5ead82014-11-14 17:14:00 +010011860void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
11861 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011862{
Johannes Berg947add32013-02-22 22:05:20 +010011863 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011864 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011865 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010011866 struct station_info empty_sinfo = {};
11867
11868 if (!sinfo)
11869 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020011870
Johannes Berg947add32013-02-22 22:05:20 +010011871 trace_cfg80211_del_sta(dev, mac_addr);
11872
Thomas Graf58050fc2012-06-28 03:57:45 +000011873 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011874 if (!msg)
11875 return;
11876
Johannes Bergcf5ead82014-11-14 17:14:00 +010011877 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010011878 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020011879 nlmsg_free(msg);
11880 return;
11881 }
11882
Johannes Berg68eb5502013-11-19 15:19:38 +010011883 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011884 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011885}
Johannes Bergcf5ead82014-11-14 17:14:00 +010011886EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020011887
Johannes Berg947add32013-02-22 22:05:20 +010011888void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11889 enum nl80211_connect_failed_reason reason,
11890 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011891{
Johannes Berg947add32013-02-22 22:05:20 +010011892 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011893 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011894 struct sk_buff *msg;
11895 void *hdr;
11896
11897 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11898 if (!msg)
11899 return;
11900
11901 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11902 if (!hdr) {
11903 nlmsg_free(msg);
11904 return;
11905 }
11906
11907 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11908 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11909 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11910 goto nla_put_failure;
11911
11912 genlmsg_end(msg, hdr);
11913
Johannes Berg68eb5502013-11-19 15:19:38 +010011914 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011915 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011916 return;
11917
11918 nla_put_failure:
11919 genlmsg_cancel(msg, hdr);
11920 nlmsg_free(msg);
11921}
Johannes Berg947add32013-02-22 22:05:20 +010011922EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011923
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011924static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11925 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011926{
11927 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011928 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011929 struct sk_buff *msg;
11930 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011931 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011932
Eric W. Biederman15e47302012-09-07 20:12:54 +000011933 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011934 return false;
11935
11936 msg = nlmsg_new(100, gfp);
11937 if (!msg)
11938 return true;
11939
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011940 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011941 if (!hdr) {
11942 nlmsg_free(msg);
11943 return true;
11944 }
11945
David S. Miller9360ffd2012-03-29 04:41:26 -040011946 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11947 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11948 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11949 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011950
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011951 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011952 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011953 return true;
11954
11955 nla_put_failure:
11956 genlmsg_cancel(msg, hdr);
11957 nlmsg_free(msg);
11958 return true;
11959}
11960
Johannes Berg947add32013-02-22 22:05:20 +010011961bool cfg80211_rx_spurious_frame(struct net_device *dev,
11962 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011963{
Johannes Berg947add32013-02-22 22:05:20 +010011964 struct wireless_dev *wdev = dev->ieee80211_ptr;
11965 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011966
Johannes Berg947add32013-02-22 22:05:20 +010011967 trace_cfg80211_rx_spurious_frame(dev, addr);
11968
11969 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11970 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11971 trace_cfg80211_return_bool(false);
11972 return false;
11973 }
11974 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11975 addr, gfp);
11976 trace_cfg80211_return_bool(ret);
11977 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011978}
Johannes Berg947add32013-02-22 22:05:20 +010011979EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11980
11981bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11982 const u8 *addr, gfp_t gfp)
11983{
11984 struct wireless_dev *wdev = dev->ieee80211_ptr;
11985 bool ret;
11986
11987 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11988
11989 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11990 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11991 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11992 trace_cfg80211_return_bool(false);
11993 return false;
11994 }
11995 ret = __nl80211_unexpected_frame(dev,
11996 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11997 addr, gfp);
11998 trace_cfg80211_return_bool(ret);
11999 return ret;
12000}
12001EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012002
Johannes Berg2e161f72010-08-12 15:38:38 +020012003int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012004 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012005 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012006 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012007{
Johannes Berg71bbc992012-06-15 15:30:18 +020012008 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012009 struct sk_buff *msg;
12010 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012011
12012 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12013 if (!msg)
12014 return -ENOMEM;
12015
Johannes Berg2e161f72010-08-12 15:38:38 +020012016 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012017 if (!hdr) {
12018 nlmsg_free(msg);
12019 return -ENOMEM;
12020 }
12021
David S. Miller9360ffd2012-03-29 04:41:26 -040012022 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012023 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12024 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012025 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012026 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12027 (sig_dbm &&
12028 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012029 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12030 (flags &&
12031 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012032 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012033
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012034 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012035
Eric W. Biederman15e47302012-09-07 20:12:54 +000012036 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012037
12038 nla_put_failure:
12039 genlmsg_cancel(msg, hdr);
12040 nlmsg_free(msg);
12041 return -ENOBUFS;
12042}
12043
Johannes Berg947add32013-02-22 22:05:20 +010012044void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12045 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012046{
Johannes Berg947add32013-02-22 22:05:20 +010012047 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012048 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012049 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012050 struct sk_buff *msg;
12051 void *hdr;
12052
Johannes Berg947add32013-02-22 22:05:20 +010012053 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12054
Jouni Malinen026331c2010-02-15 12:53:10 +020012055 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12056 if (!msg)
12057 return;
12058
Johannes Berg2e161f72010-08-12 15:38:38 +020012059 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012060 if (!hdr) {
12061 nlmsg_free(msg);
12062 return;
12063 }
12064
David S. Miller9360ffd2012-03-29 04:41:26 -040012065 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012066 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12067 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012068 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012069 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12070 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12071 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12072 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012073
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012074 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012075
Johannes Berg68eb5502013-11-19 15:19:38 +010012076 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012077 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012078 return;
12079
12080 nla_put_failure:
12081 genlmsg_cancel(msg, hdr);
12082 nlmsg_free(msg);
12083}
Johannes Berg947add32013-02-22 22:05:20 +010012084EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012085
Johannes Berg5b97f492014-11-26 12:37:43 +010012086static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12087 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012088{
Johannes Berg947add32013-02-22 22:05:20 +010012089 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012090 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12091 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12092 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012093
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012094 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012095 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012096
Johannes Berg5b97f492014-11-26 12:37:43 +010012097 cb = (void **)msg->cb;
12098
12099 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12100 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012101 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012102 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012103 }
12104
David S. Miller9360ffd2012-03-29 04:41:26 -040012105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012106 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012107 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012108
Johannes Berg5b97f492014-11-26 12:37:43 +010012109 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012110 goto nla_put_failure;
12111
Johannes Berg5b97f492014-11-26 12:37:43 +010012112 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12113 if (!cb[1])
12114 goto nla_put_failure;
12115
12116 cb[2] = rdev;
12117
12118 return msg;
12119 nla_put_failure:
12120 nlmsg_free(msg);
12121 return NULL;
12122}
12123
12124static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12125{
12126 void **cb = (void **)msg->cb;
12127 struct cfg80211_registered_device *rdev = cb[2];
12128
12129 nla_nest_end(msg, cb[1]);
12130 genlmsg_end(msg, cb[0]);
12131
12132 memset(msg->cb, 0, sizeof(msg->cb));
12133
12134 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12135 NL80211_MCGRP_MLME, gfp);
12136}
12137
12138void cfg80211_cqm_rssi_notify(struct net_device *dev,
12139 enum nl80211_cqm_rssi_threshold_event rssi_event,
12140 gfp_t gfp)
12141{
12142 struct sk_buff *msg;
12143
12144 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12145
Johannes Berg98f03342014-11-26 12:42:02 +010012146 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12147 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12148 return;
12149
Johannes Berg5b97f492014-11-26 12:37:43 +010012150 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12151 if (!msg)
12152 return;
12153
David S. Miller9360ffd2012-03-29 04:41:26 -040012154 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12155 rssi_event))
12156 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012157
Johannes Berg5b97f492014-11-26 12:37:43 +010012158 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012159
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012160 return;
12161
12162 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012163 nlmsg_free(msg);
12164}
Johannes Berg947add32013-02-22 22:05:20 +010012165EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012166
Johannes Berg5b97f492014-11-26 12:37:43 +010012167void cfg80211_cqm_txe_notify(struct net_device *dev,
12168 const u8 *peer, u32 num_packets,
12169 u32 rate, u32 intvl, gfp_t gfp)
12170{
12171 struct sk_buff *msg;
12172
12173 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12174 if (!msg)
12175 return;
12176
12177 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12178 goto nla_put_failure;
12179
12180 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12181 goto nla_put_failure;
12182
12183 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12184 goto nla_put_failure;
12185
12186 cfg80211_send_cqm(msg, gfp);
12187 return;
12188
12189 nla_put_failure:
12190 nlmsg_free(msg);
12191}
12192EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12193
12194void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12195 const u8 *peer, u32 num_packets, gfp_t gfp)
12196{
12197 struct sk_buff *msg;
12198
12199 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12200
12201 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12202 if (!msg)
12203 return;
12204
12205 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12206 goto nla_put_failure;
12207
12208 cfg80211_send_cqm(msg, gfp);
12209 return;
12210
12211 nla_put_failure:
12212 nlmsg_free(msg);
12213}
12214EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12215
Johannes Berg98f03342014-11-26 12:42:02 +010012216void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12217{
12218 struct sk_buff *msg;
12219
12220 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12221 if (!msg)
12222 return;
12223
12224 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12225 goto nla_put_failure;
12226
12227 cfg80211_send_cqm(msg, gfp);
12228 return;
12229
12230 nla_put_failure:
12231 nlmsg_free(msg);
12232}
12233EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12234
Johannes Berg947add32013-02-22 22:05:20 +010012235static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12236 struct net_device *netdev, const u8 *bssid,
12237 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012238{
12239 struct sk_buff *msg;
12240 struct nlattr *rekey_attr;
12241 void *hdr;
12242
Thomas Graf58050fc2012-06-28 03:57:45 +000012243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012244 if (!msg)
12245 return;
12246
12247 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12248 if (!hdr) {
12249 nlmsg_free(msg);
12250 return;
12251 }
12252
David S. Miller9360ffd2012-03-29 04:41:26 -040012253 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12254 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12255 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12256 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012257
12258 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12259 if (!rekey_attr)
12260 goto nla_put_failure;
12261
David S. Miller9360ffd2012-03-29 04:41:26 -040012262 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12263 NL80211_REPLAY_CTR_LEN, replay_ctr))
12264 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012265
12266 nla_nest_end(msg, rekey_attr);
12267
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012268 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012269
Johannes Berg68eb5502013-11-19 15:19:38 +010012270 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012271 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012272 return;
12273
12274 nla_put_failure:
12275 genlmsg_cancel(msg, hdr);
12276 nlmsg_free(msg);
12277}
12278
Johannes Berg947add32013-02-22 22:05:20 +010012279void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12280 const u8 *replay_ctr, gfp_t gfp)
12281{
12282 struct wireless_dev *wdev = dev->ieee80211_ptr;
12283 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012284 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012285
12286 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12287 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12288}
12289EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12290
12291static void
12292nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12293 struct net_device *netdev, int index,
12294 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012295{
12296 struct sk_buff *msg;
12297 struct nlattr *attr;
12298 void *hdr;
12299
Thomas Graf58050fc2012-06-28 03:57:45 +000012300 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012301 if (!msg)
12302 return;
12303
12304 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12305 if (!hdr) {
12306 nlmsg_free(msg);
12307 return;
12308 }
12309
David S. Miller9360ffd2012-03-29 04:41:26 -040012310 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12311 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12312 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012313
12314 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12315 if (!attr)
12316 goto nla_put_failure;
12317
David S. Miller9360ffd2012-03-29 04:41:26 -040012318 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12319 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12320 (preauth &&
12321 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12322 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012323
12324 nla_nest_end(msg, attr);
12325
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012326 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012327
Johannes Berg68eb5502013-11-19 15:19:38 +010012328 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012329 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012330 return;
12331
12332 nla_put_failure:
12333 genlmsg_cancel(msg, hdr);
12334 nlmsg_free(msg);
12335}
12336
Johannes Berg947add32013-02-22 22:05:20 +010012337void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12338 const u8 *bssid, bool preauth, gfp_t gfp)
12339{
12340 struct wireless_dev *wdev = dev->ieee80211_ptr;
12341 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012342 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012343
12344 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12345 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12346}
12347EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12348
12349static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12350 struct net_device *netdev,
12351 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012352 gfp_t gfp,
12353 enum nl80211_commands notif,
12354 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012355{
12356 struct sk_buff *msg;
12357 void *hdr;
12358
Thomas Graf58050fc2012-06-28 03:57:45 +000012359 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012360 if (!msg)
12361 return;
12362
Luciano Coelhof8d75522014-11-07 14:31:35 +020012363 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012364 if (!hdr) {
12365 nlmsg_free(msg);
12366 return;
12367 }
12368
Johannes Berg683b6d32012-11-08 21:25:48 +010012369 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12370 goto nla_put_failure;
12371
12372 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012373 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012374
Luciano Coelhof8d75522014-11-07 14:31:35 +020012375 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12376 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12377 goto nla_put_failure;
12378
Thomas Pedersen53145262012-04-06 13:35:47 -070012379 genlmsg_end(msg, hdr);
12380
Johannes Berg68eb5502013-11-19 15:19:38 +010012381 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012382 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012383 return;
12384
12385 nla_put_failure:
12386 genlmsg_cancel(msg, hdr);
12387 nlmsg_free(msg);
12388}
12389
Johannes Berg947add32013-02-22 22:05:20 +010012390void cfg80211_ch_switch_notify(struct net_device *dev,
12391 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012392{
Johannes Berg947add32013-02-22 22:05:20 +010012393 struct wireless_dev *wdev = dev->ieee80211_ptr;
12394 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012395 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012396
Simon Wunderliche487eae2013-11-21 18:19:51 +010012397 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012398
Simon Wunderliche487eae2013-11-21 18:19:51 +010012399 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012400
Michal Kazior9e0e2962014-01-29 14:22:27 +010012401 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012402 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012403 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12404 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012405}
12406EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12407
Luciano Coelhof8d75522014-11-07 14:31:35 +020012408void cfg80211_ch_switch_started_notify(struct net_device *dev,
12409 struct cfg80211_chan_def *chandef,
12410 u8 count)
12411{
12412 struct wireless_dev *wdev = dev->ieee80211_ptr;
12413 struct wiphy *wiphy = wdev->wiphy;
12414 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12415
12416 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12417
12418 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12419 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12420}
12421EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12422
Thomas Pedersen84f10702012-07-12 16:17:33 -070012423void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012424nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012425 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012426 enum nl80211_radar_event event,
12427 struct net_device *netdev, gfp_t gfp)
12428{
12429 struct sk_buff *msg;
12430 void *hdr;
12431
12432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12433 if (!msg)
12434 return;
12435
12436 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12437 if (!hdr) {
12438 nlmsg_free(msg);
12439 return;
12440 }
12441
12442 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12443 goto nla_put_failure;
12444
12445 /* NOP and radar events don't need a netdev parameter */
12446 if (netdev) {
12447 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12448
12449 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12450 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12451 goto nla_put_failure;
12452 }
12453
12454 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12455 goto nla_put_failure;
12456
12457 if (nl80211_send_chandef(msg, chandef))
12458 goto nla_put_failure;
12459
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012460 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012461
Johannes Berg68eb5502013-11-19 15:19:38 +010012462 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012463 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012464 return;
12465
12466 nla_put_failure:
12467 genlmsg_cancel(msg, hdr);
12468 nlmsg_free(msg);
12469}
12470
Johannes Berg7f6cf312011-11-04 11:18:15 +010012471void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12472 u64 cookie, bool acked, gfp_t gfp)
12473{
12474 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012475 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012476 struct sk_buff *msg;
12477 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012478
Beni Lev4ee3e062012-08-27 12:49:39 +030012479 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12480
Thomas Graf58050fc2012-06-28 03:57:45 +000012481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012482
Johannes Berg7f6cf312011-11-04 11:18:15 +010012483 if (!msg)
12484 return;
12485
12486 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12487 if (!hdr) {
12488 nlmsg_free(msg);
12489 return;
12490 }
12491
David S. Miller9360ffd2012-03-29 04:41:26 -040012492 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12493 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12494 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12495 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12496 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12497 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012498
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012499 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012500
Johannes Berg68eb5502013-11-19 15:19:38 +010012501 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012502 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012503 return;
12504
12505 nla_put_failure:
12506 genlmsg_cancel(msg, hdr);
12507 nlmsg_free(msg);
12508}
12509EXPORT_SYMBOL(cfg80211_probe_status);
12510
Johannes Berg5e7602302011-11-04 11:18:17 +010012511void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12512 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012513 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010012514{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012515 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010012516 struct sk_buff *msg;
12517 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012518 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010012519
Beni Lev4ee3e062012-08-27 12:49:39 +030012520 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12521
Ben Greear37c73b52012-10-26 14:49:25 -070012522 spin_lock_bh(&rdev->beacon_registrations_lock);
12523 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12524 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12525 if (!msg) {
12526 spin_unlock_bh(&rdev->beacon_registrations_lock);
12527 return;
12528 }
Johannes Berg5e7602302011-11-04 11:18:17 +010012529
Ben Greear37c73b52012-10-26 14:49:25 -070012530 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12531 if (!hdr)
12532 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010012533
Ben Greear37c73b52012-10-26 14:49:25 -070012534 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12535 (freq &&
12536 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12537 (sig_dbm &&
12538 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12539 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12540 goto nla_put_failure;
12541
12542 genlmsg_end(msg, hdr);
12543
12544 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010012545 }
Ben Greear37c73b52012-10-26 14:49:25 -070012546 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010012547 return;
12548
12549 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012550 spin_unlock_bh(&rdev->beacon_registrations_lock);
12551 if (hdr)
12552 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010012553 nlmsg_free(msg);
12554}
12555EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12556
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012557#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012558static int cfg80211_net_detect_results(struct sk_buff *msg,
12559 struct cfg80211_wowlan_wakeup *wakeup)
12560{
12561 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12562 struct nlattr *nl_results, *nl_match, *nl_freqs;
12563 int i, j;
12564
12565 nl_results = nla_nest_start(
12566 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12567 if (!nl_results)
12568 return -EMSGSIZE;
12569
12570 for (i = 0; i < nd->n_matches; i++) {
12571 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12572
12573 nl_match = nla_nest_start(msg, i);
12574 if (!nl_match)
12575 break;
12576
12577 /* The SSID attribute is optional in nl80211, but for
12578 * simplicity reasons it's always present in the
12579 * cfg80211 structure. If a driver can't pass the
12580 * SSID, that needs to be changed. A zero length SSID
12581 * is still a valid SSID (wildcard), so it cannot be
12582 * used for this purpose.
12583 */
12584 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12585 match->ssid.ssid)) {
12586 nla_nest_cancel(msg, nl_match);
12587 goto out;
12588 }
12589
12590 if (match->n_channels) {
12591 nl_freqs = nla_nest_start(
12592 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12593 if (!nl_freqs) {
12594 nla_nest_cancel(msg, nl_match);
12595 goto out;
12596 }
12597
12598 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020012599 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012600 nla_nest_cancel(msg, nl_freqs);
12601 nla_nest_cancel(msg, nl_match);
12602 goto out;
12603 }
12604 }
12605
12606 nla_nest_end(msg, nl_freqs);
12607 }
12608
12609 nla_nest_end(msg, nl_match);
12610 }
12611
12612out:
12613 nla_nest_end(msg, nl_results);
12614 return 0;
12615}
12616
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012617void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12618 struct cfg80211_wowlan_wakeup *wakeup,
12619 gfp_t gfp)
12620{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012621 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012622 struct sk_buff *msg;
12623 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012624 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012625
12626 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12627
12628 if (wakeup)
12629 size += wakeup->packet_present_len;
12630
12631 msg = nlmsg_new(size, gfp);
12632 if (!msg)
12633 return;
12634
12635 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12636 if (!hdr)
12637 goto free_msg;
12638
12639 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12640 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12641 goto free_msg;
12642
12643 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12644 wdev->netdev->ifindex))
12645 goto free_msg;
12646
12647 if (wakeup) {
12648 struct nlattr *reasons;
12649
12650 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012651 if (!reasons)
12652 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012653
12654 if (wakeup->disconnect &&
12655 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12656 goto free_msg;
12657 if (wakeup->magic_pkt &&
12658 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12659 goto free_msg;
12660 if (wakeup->gtk_rekey_failure &&
12661 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12662 goto free_msg;
12663 if (wakeup->eap_identity_req &&
12664 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12665 goto free_msg;
12666 if (wakeup->four_way_handshake &&
12667 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12668 goto free_msg;
12669 if (wakeup->rfkill_release &&
12670 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12671 goto free_msg;
12672
12673 if (wakeup->pattern_idx >= 0 &&
12674 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12675 wakeup->pattern_idx))
12676 goto free_msg;
12677
Johannes Bergae917c92013-10-25 11:05:22 +020012678 if (wakeup->tcp_match &&
12679 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12680 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012681
Johannes Bergae917c92013-10-25 11:05:22 +020012682 if (wakeup->tcp_connlost &&
12683 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12684 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012685
Johannes Bergae917c92013-10-25 11:05:22 +020012686 if (wakeup->tcp_nomoretokens &&
12687 nla_put_flag(msg,
12688 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12689 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012690
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012691 if (wakeup->packet) {
12692 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12693 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12694
12695 if (!wakeup->packet_80211) {
12696 pkt_attr =
12697 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12698 len_attr =
12699 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12700 }
12701
12702 if (wakeup->packet_len &&
12703 nla_put_u32(msg, len_attr, wakeup->packet_len))
12704 goto free_msg;
12705
12706 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12707 wakeup->packet))
12708 goto free_msg;
12709 }
12710
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012711 if (wakeup->net_detect &&
12712 cfg80211_net_detect_results(msg, wakeup))
12713 goto free_msg;
12714
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012715 nla_nest_end(msg, reasons);
12716 }
12717
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012718 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012719
Johannes Berg68eb5502013-11-19 15:19:38 +010012720 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012721 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012722 return;
12723
12724 free_msg:
12725 nlmsg_free(msg);
12726}
12727EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12728#endif
12729
Jouni Malinen3475b092012-11-16 22:49:57 +020012730void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12731 enum nl80211_tdls_operation oper,
12732 u16 reason_code, gfp_t gfp)
12733{
12734 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012735 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012736 struct sk_buff *msg;
12737 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012738
12739 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12740 reason_code);
12741
12742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12743 if (!msg)
12744 return;
12745
12746 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12747 if (!hdr) {
12748 nlmsg_free(msg);
12749 return;
12750 }
12751
12752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12753 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12754 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12755 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12756 (reason_code > 0 &&
12757 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12758 goto nla_put_failure;
12759
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012760 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012761
Johannes Berg68eb5502013-11-19 15:19:38 +010012762 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012763 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012764 return;
12765
12766 nla_put_failure:
12767 genlmsg_cancel(msg, hdr);
12768 nlmsg_free(msg);
12769}
12770EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12771
Jouni Malinen026331c2010-02-15 12:53:10 +020012772static int nl80211_netlink_notify(struct notifier_block * nb,
12773 unsigned long state,
12774 void *_notify)
12775{
12776 struct netlink_notify *notify = _notify;
12777 struct cfg80211_registered_device *rdev;
12778 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012779 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012780
12781 if (state != NETLINK_URELEASE)
12782 return NOTIFY_DONE;
12783
12784 rcu_read_lock();
12785
Johannes Berg5e7602302011-11-04 11:18:17 +010012786 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012787 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012788 bool schedule_scan_stop = false;
12789 struct cfg80211_sched_scan_request *sched_scan_req =
12790 rcu_dereference(rdev->sched_scan_req);
12791
12792 if (sched_scan_req && notify->portid &&
12793 sched_scan_req->owner_nlportid == notify->portid)
12794 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012795
12796 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012797 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012798
Johannes Berg78f22b62014-03-24 17:57:27 +010012799 if (wdev->owner_nlportid == notify->portid)
12800 schedule_destroy_work = true;
12801 }
12802
Ben Greear37c73b52012-10-26 14:49:25 -070012803 spin_lock_bh(&rdev->beacon_registrations_lock);
12804 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12805 list) {
12806 if (reg->nlportid == notify->portid) {
12807 list_del(&reg->list);
12808 kfree(reg);
12809 break;
12810 }
12811 }
12812 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012813
12814 if (schedule_destroy_work) {
12815 struct cfg80211_iface_destroy *destroy;
12816
12817 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12818 if (destroy) {
12819 destroy->nlportid = notify->portid;
12820 spin_lock(&rdev->destroy_list_lock);
12821 list_add(&destroy->list, &rdev->destroy_list);
12822 spin_unlock(&rdev->destroy_list_lock);
12823 schedule_work(&rdev->destroy_work);
12824 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012825 } else if (schedule_scan_stop) {
12826 sched_scan_req->owner_nlportid = 0;
12827
12828 if (rdev->ops->sched_scan_stop &&
12829 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12830 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012831 }
Johannes Berg5e7602302011-11-04 11:18:17 +010012832 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012833
12834 rcu_read_unlock();
12835
Ilan peer05050752015-03-04 00:32:06 -050012836 /*
12837 * It is possible that the user space process that is controlling the
12838 * indoor setting disappeared, so notify the regulatory core.
12839 */
12840 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012841 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012842}
12843
12844static struct notifier_block nl80211_netlink_notifier = {
12845 .notifier_call = nl80211_netlink_notify,
12846};
12847
Jouni Malinen355199e2013-02-27 17:14:27 +020012848void cfg80211_ft_event(struct net_device *netdev,
12849 struct cfg80211_ft_event_params *ft_event)
12850{
12851 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012852 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012853 struct sk_buff *msg;
12854 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012855
12856 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12857
12858 if (!ft_event->target_ap)
12859 return;
12860
12861 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12862 if (!msg)
12863 return;
12864
12865 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012866 if (!hdr)
12867 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012868
Johannes Bergae917c92013-10-25 11:05:22 +020012869 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12870 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12871 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12872 goto out;
12873
12874 if (ft_event->ies &&
12875 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12876 goto out;
12877 if (ft_event->ric_ies &&
12878 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12879 ft_event->ric_ies))
12880 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012881
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012882 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012883
Johannes Berg68eb5502013-11-19 15:19:38 +010012884 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012885 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012886 return;
12887 out:
12888 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012889}
12890EXPORT_SYMBOL(cfg80211_ft_event);
12891
Arend van Spriel5de17982013-04-18 15:49:00 +020012892void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12893{
12894 struct cfg80211_registered_device *rdev;
12895 struct sk_buff *msg;
12896 void *hdr;
12897 u32 nlportid;
12898
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012899 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012900 if (!rdev->crit_proto_nlportid)
12901 return;
12902
12903 nlportid = rdev->crit_proto_nlportid;
12904 rdev->crit_proto_nlportid = 0;
12905
12906 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12907 if (!msg)
12908 return;
12909
12910 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12911 if (!hdr)
12912 goto nla_put_failure;
12913
12914 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12915 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12916 goto nla_put_failure;
12917
12918 genlmsg_end(msg, hdr);
12919
12920 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12921 return;
12922
12923 nla_put_failure:
12924 if (hdr)
12925 genlmsg_cancel(msg, hdr);
12926 nlmsg_free(msg);
12927
12928}
12929EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12930
Johannes Berg348baf02014-01-24 14:06:29 +010012931void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12932{
12933 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012934 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012935 struct sk_buff *msg;
12936 void *hdr;
12937
12938 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12939 if (!msg)
12940 return;
12941
12942 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12943 if (!hdr)
12944 goto out;
12945
12946 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12947 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12948 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12949 goto out;
12950
12951 genlmsg_end(msg, hdr);
12952
12953 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12954 NL80211_MCGRP_MLME, GFP_KERNEL);
12955 return;
12956 out:
12957 nlmsg_free(msg);
12958}
12959
Johannes Berg55682962007-09-20 13:09:35 -040012960/* initialisation/exit functions */
12961
12962int nl80211_init(void)
12963{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012964 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012965
Johannes Berg2a94fe42013-11-19 15:19:39 +010012966 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12967 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012968 if (err)
12969 return err;
12970
Jouni Malinen026331c2010-02-15 12:53:10 +020012971 err = netlink_register_notifier(&nl80211_netlink_notifier);
12972 if (err)
12973 goto err_out;
12974
Johannes Berg55682962007-09-20 13:09:35 -040012975 return 0;
12976 err_out:
12977 genl_unregister_family(&nl80211_fam);
12978 return err;
12979}
12980
12981void nl80211_exit(void)
12982{
Jouni Malinen026331c2010-02-15 12:53:10 +020012983 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012984 genl_unregister_family(&nl80211_fam);
12985}