blob: c81491b1f7375e323b897eceeecd7f40c71b50c7 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
62 [NL80211_MCGRP_CONFIG] = { .name = "config", },
63 [NL80211_MCGRP_SCAN] = { .name = "scan", },
64 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
65 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010066 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
68 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
69#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300212static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni 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 },
Johannes Berg55682962007-09-20 13:09:35 -0400399};
400
Johannes Berge31b8212010-10-05 19:39:30 +0200401/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000402static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200403 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200404 [NL80211_KEY_IDX] = { .type = NLA_U8 },
405 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200406 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200407 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
408 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200409 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100410 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
411};
412
413/* policy for the key default flags */
414static const struct nla_policy
415nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
416 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
417 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200418};
419
Johannes Bergff1b6e62011-05-04 15:37:28 +0200420/* policy for WoWLAN attributes */
421static const struct nla_policy
422nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
423 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
424 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
426 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200427 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100431 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300432 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100433};
434
435static const struct nla_policy
436nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
437 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
438 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
439 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
440 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
441 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
442 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
443 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
444 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
445 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
447 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
448 },
449 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
450 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
451 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200452};
453
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700454/* policy for coalesce rule attributes */
455static const struct nla_policy
456nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
457 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
458 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
459 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
460};
461
Johannes Berge5497d72011-07-05 16:35:40 +0200462/* policy for GTK rekey offload attributes */
463static const struct nla_policy
464nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
465 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
466 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
467 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
468};
469
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300470static const struct nla_policy
471nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200472 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300473 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700474 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300475};
476
Johannes Berg97990a02013-04-19 01:02:55 +0200477static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
478 struct netlink_callback *cb,
479 struct cfg80211_registered_device **rdev,
480 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100481{
Johannes Berg67748892010-10-04 21:14:06 +0200482 int err;
483
Johannes Berg67748892010-10-04 21:14:06 +0200484 rtnl_lock();
485
Johannes Berg97990a02013-04-19 01:02:55 +0200486 if (!cb->args[0]) {
487 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
488 nl80211_fam.attrbuf, nl80211_fam.maxattr,
489 nl80211_policy);
490 if (err)
491 goto out_unlock;
492
493 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
494 nl80211_fam.attrbuf);
495 if (IS_ERR(*wdev)) {
496 err = PTR_ERR(*wdev);
497 goto out_unlock;
498 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800499 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200500 /* 0 is the first index - add 1 to parse only once */
501 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200502 cb->args[1] = (*wdev)->identifier;
503 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200504 /* subtract the 1 again here */
505 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200506 struct wireless_dev *tmp;
507
508 if (!wiphy) {
509 err = -ENODEV;
510 goto out_unlock;
511 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800512 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200513 *wdev = NULL;
514
Johannes Berg97990a02013-04-19 01:02:55 +0200515 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
516 if (tmp->identifier == cb->args[1]) {
517 *wdev = tmp;
518 break;
519 }
520 }
Johannes Berg97990a02013-04-19 01:02:55 +0200521
522 if (!*wdev) {
523 err = -ENODEV;
524 goto out_unlock;
525 }
Johannes Berg67748892010-10-04 21:14:06 +0200526 }
527
Johannes Berg67748892010-10-04 21:14:06 +0200528 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200529 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200530 rtnl_unlock();
531 return err;
532}
533
Johannes Berg97990a02013-04-19 01:02:55 +0200534static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200535{
Johannes Berg67748892010-10-04 21:14:06 +0200536 rtnl_unlock();
537}
538
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100539/* IE validation */
540static bool is_valid_ie_attr(const struct nlattr *attr)
541{
542 const u8 *pos;
543 int len;
544
545 if (!attr)
546 return true;
547
548 pos = nla_data(attr);
549 len = nla_len(attr);
550
551 while (len) {
552 u8 elemlen;
553
554 if (len < 2)
555 return false;
556 len -= 2;
557
558 elemlen = pos[1];
559 if (elemlen > len)
560 return false;
561
562 len -= elemlen;
563 pos += 2 + elemlen;
564 }
565
566 return true;
567}
568
Johannes Berg55682962007-09-20 13:09:35 -0400569/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000570static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400571 int flags, u8 cmd)
572{
573 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000574 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400575}
576
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400577static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100578 struct ieee80211_channel *chan,
579 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400580{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200581 /* Some channels must be completely excluded from the
582 * list to protect old user-space tools from breaking
583 */
584 if (!large && chan->flags &
585 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
586 return 0;
587
David S. Miller9360ffd2012-03-29 04:41:26 -0400588 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
589 chan->center_freq))
590 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400591
David S. Miller9360ffd2012-03-29 04:41:26 -0400592 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
593 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
594 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200595 if (chan->flags & IEEE80211_CHAN_NO_IR) {
596 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
597 goto nla_put_failure;
598 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
599 goto nla_put_failure;
600 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100601 if (chan->flags & IEEE80211_CHAN_RADAR) {
602 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
603 goto nla_put_failure;
604 if (large) {
605 u32 time;
606
607 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
608
609 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
610 chan->dfs_state))
611 goto nla_put_failure;
612 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
613 time))
614 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100615 if (nla_put_u32(msg,
616 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
617 chan->dfs_cac_ms))
618 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100619 }
620 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400621
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100622 if (large) {
623 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
624 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
625 goto nla_put_failure;
626 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
627 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
628 goto nla_put_failure;
629 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
630 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
631 goto nla_put_failure;
632 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
633 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
634 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200635 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
636 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
637 goto nla_put_failure;
638 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
639 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
640 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200641 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
642 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
643 goto nla_put_failure;
644 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
645 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
646 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100647 }
648
David S. Miller9360ffd2012-03-29 04:41:26 -0400649 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
650 DBM_TO_MBM(chan->max_power)))
651 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400652
653 return 0;
654
655 nla_put_failure:
656 return -ENOBUFS;
657}
658
Johannes Berg55682962007-09-20 13:09:35 -0400659/* netlink command implementations */
660
Johannes Bergb9454e82009-07-08 13:29:08 +0200661struct key_parse {
662 struct key_params p;
663 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200664 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200665 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100666 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200667};
668
669static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
670{
671 struct nlattr *tb[NL80211_KEY_MAX + 1];
672 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
673 nl80211_key_policy);
674 if (err)
675 return err;
676
677 k->def = !!tb[NL80211_KEY_DEFAULT];
678 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
679
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100680 if (k->def) {
681 k->def_uni = true;
682 k->def_multi = true;
683 }
684 if (k->defmgmt)
685 k->def_multi = true;
686
Johannes Bergb9454e82009-07-08 13:29:08 +0200687 if (tb[NL80211_KEY_IDX])
688 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
689
690 if (tb[NL80211_KEY_DATA]) {
691 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
692 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
693 }
694
695 if (tb[NL80211_KEY_SEQ]) {
696 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
697 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
698 }
699
700 if (tb[NL80211_KEY_CIPHER])
701 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
702
Johannes Berge31b8212010-10-05 19:39:30 +0200703 if (tb[NL80211_KEY_TYPE]) {
704 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
705 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
706 return -EINVAL;
707 }
708
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100709 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
710 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100711 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
712 tb[NL80211_KEY_DEFAULT_TYPES],
713 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100714 if (err)
715 return err;
716
717 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
718 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
719 }
720
Johannes Bergb9454e82009-07-08 13:29:08 +0200721 return 0;
722}
723
724static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
725{
726 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
727 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
728 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
729 }
730
731 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
732 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
733 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
734 }
735
736 if (info->attrs[NL80211_ATTR_KEY_IDX])
737 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
738
739 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
740 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
741
742 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
743 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
744
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100745 if (k->def) {
746 k->def_uni = true;
747 k->def_multi = true;
748 }
749 if (k->defmgmt)
750 k->def_multi = true;
751
Johannes Berge31b8212010-10-05 19:39:30 +0200752 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
753 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
754 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
755 return -EINVAL;
756 }
757
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100758 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
759 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
760 int err = nla_parse_nested(
761 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
762 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
763 nl80211_key_default_policy);
764 if (err)
765 return err;
766
767 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
768 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
769 }
770
Johannes Bergb9454e82009-07-08 13:29:08 +0200771 return 0;
772}
773
774static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
775{
776 int err;
777
778 memset(k, 0, sizeof(*k));
779 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200780 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200781
782 if (info->attrs[NL80211_ATTR_KEY])
783 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
784 else
785 err = nl80211_parse_key_old(info, k);
786
787 if (err)
788 return err;
789
790 if (k->def && k->defmgmt)
791 return -EINVAL;
792
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100793 if (k->defmgmt) {
794 if (k->def_uni || !k->def_multi)
795 return -EINVAL;
796 }
797
Johannes Bergb9454e82009-07-08 13:29:08 +0200798 if (k->idx != -1) {
799 if (k->defmgmt) {
800 if (k->idx < 4 || k->idx > 5)
801 return -EINVAL;
802 } else if (k->def) {
803 if (k->idx < 0 || k->idx > 3)
804 return -EINVAL;
805 } else {
806 if (k->idx < 0 || k->idx > 5)
807 return -EINVAL;
808 }
809 }
810
811 return 0;
812}
813
Johannes Bergfffd0932009-07-08 14:22:54 +0200814static struct cfg80211_cached_keys *
815nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530816 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200817{
818 struct key_parse parse;
819 struct nlattr *key;
820 struct cfg80211_cached_keys *result;
821 int rem, err, def = 0;
822
823 result = kzalloc(sizeof(*result), GFP_KERNEL);
824 if (!result)
825 return ERR_PTR(-ENOMEM);
826
827 result->def = -1;
828 result->defmgmt = -1;
829
830 nla_for_each_nested(key, keys, rem) {
831 memset(&parse, 0, sizeof(parse));
832 parse.idx = -1;
833
834 err = nl80211_parse_key_new(key, &parse);
835 if (err)
836 goto error;
837 err = -EINVAL;
838 if (!parse.p.key)
839 goto error;
840 if (parse.idx < 0 || parse.idx > 4)
841 goto error;
842 if (parse.def) {
843 if (def)
844 goto error;
845 def = 1;
846 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100847 if (!parse.def_uni || !parse.def_multi)
848 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200849 } else if (parse.defmgmt)
850 goto error;
851 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200852 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200853 if (err)
854 goto error;
855 result->params[parse.idx].cipher = parse.p.cipher;
856 result->params[parse.idx].key_len = parse.p.key_len;
857 result->params[parse.idx].key = result->data[parse.idx];
858 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530859
860 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
861 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
862 if (no_ht)
863 *no_ht = true;
864 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200865 }
866
867 return result;
868 error:
869 kfree(result);
870 return ERR_PTR(err);
871}
872
873static int nl80211_key_allowed(struct wireless_dev *wdev)
874{
875 ASSERT_WDEV_LOCK(wdev);
876
Johannes Bergfffd0932009-07-08 14:22:54 +0200877 switch (wdev->iftype) {
878 case NL80211_IFTYPE_AP:
879 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200880 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700881 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 break;
883 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200884 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200885 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200886 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200887 return -ENOLINK;
888 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100889 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100890 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100891 case NL80211_IFTYPE_MONITOR:
892 case NL80211_IFTYPE_P2P_DEVICE:
893 case NL80211_IFTYPE_WDS:
894 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200895 return -EINVAL;
896 }
897
898 return 0;
899}
900
Jouni Malinen664834d2014-01-15 00:01:44 +0200901static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
902 struct nlattr *tb)
903{
904 struct ieee80211_channel *chan;
905
906 if (tb == NULL)
907 return NULL;
908 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
909 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
910 return NULL;
911 return chan;
912}
913
Johannes Berg7527a782011-05-13 10:58:57 +0200914static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
915{
916 struct nlattr *nl_modes = nla_nest_start(msg, attr);
917 int i;
918
919 if (!nl_modes)
920 goto nla_put_failure;
921
922 i = 0;
923 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400924 if ((ifmodes & 1) && nla_put_flag(msg, i))
925 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200926 ifmodes >>= 1;
927 i++;
928 }
929
930 nla_nest_end(msg, nl_modes);
931 return 0;
932
933nla_put_failure:
934 return -ENOBUFS;
935}
936
937static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100938 struct sk_buff *msg,
939 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200940{
941 struct nlattr *nl_combis;
942 int i, j;
943
944 nl_combis = nla_nest_start(msg,
945 NL80211_ATTR_INTERFACE_COMBINATIONS);
946 if (!nl_combis)
947 goto nla_put_failure;
948
949 for (i = 0; i < wiphy->n_iface_combinations; i++) {
950 const struct ieee80211_iface_combination *c;
951 struct nlattr *nl_combi, *nl_limits;
952
953 c = &wiphy->iface_combinations[i];
954
955 nl_combi = nla_nest_start(msg, i + 1);
956 if (!nl_combi)
957 goto nla_put_failure;
958
959 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
960 if (!nl_limits)
961 goto nla_put_failure;
962
963 for (j = 0; j < c->n_limits; j++) {
964 struct nlattr *nl_limit;
965
966 nl_limit = nla_nest_start(msg, j + 1);
967 if (!nl_limit)
968 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400969 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
970 c->limits[j].max))
971 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200972 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
973 c->limits[j].types))
974 goto nla_put_failure;
975 nla_nest_end(msg, nl_limit);
976 }
977
978 nla_nest_end(msg, nl_limits);
979
David S. Miller9360ffd2012-03-29 04:41:26 -0400980 if (c->beacon_int_infra_match &&
981 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
982 goto nla_put_failure;
983 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
984 c->num_different_channels) ||
985 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
986 c->max_interfaces))
987 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100988 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200989 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
990 c->radar_detect_widths) ||
991 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
992 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100993 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200994
995 nla_nest_end(msg, nl_combi);
996 }
997
998 nla_nest_end(msg, nl_combis);
999
1000 return 0;
1001nla_put_failure:
1002 return -ENOBUFS;
1003}
1004
Johannes Berg3713b4e2013-02-14 16:19:38 +01001005#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001006static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1007 struct sk_buff *msg)
1008{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001010 struct nlattr *nl_tcp;
1011
1012 if (!tcp)
1013 return 0;
1014
1015 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1016 if (!nl_tcp)
1017 return -ENOBUFS;
1018
1019 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1020 tcp->data_payload_max))
1021 return -ENOBUFS;
1022
1023 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1024 tcp->data_payload_max))
1025 return -ENOBUFS;
1026
1027 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1028 return -ENOBUFS;
1029
1030 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1031 sizeof(*tcp->tok), tcp->tok))
1032 return -ENOBUFS;
1033
1034 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1035 tcp->data_interval_max))
1036 return -ENOBUFS;
1037
1038 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1039 tcp->wake_payload_max))
1040 return -ENOBUFS;
1041
1042 nla_nest_end(msg, nl_tcp);
1043 return 0;
1044}
1045
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001047 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001048 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001049{
1050 struct nlattr *nl_wowlan;
1051
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053 return 0;
1054
1055 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1056 if (!nl_wowlan)
1057 return -ENOBUFS;
1058
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001061 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001062 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001066 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001069 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001073 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1075 return -ENOBUFS;
1076
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001078 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001079 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1080 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1081 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1082 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001083 };
1084
1085 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1086 sizeof(pat), &pat))
1087 return -ENOBUFS;
1088 }
1089
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001091 return -ENOBUFS;
1092
Luciano Coelho8cd4d452014-09-17 11:55:28 +03001093 /* TODO: send wowlan net detect */
1094
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_nest_end(msg, nl_wowlan);
1096
1097 return 0;
1098}
1099#endif
1100
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001101static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001103{
1104 struct nl80211_coalesce_rule_support rule;
1105
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001106 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001107 return 0;
1108
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001109 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1110 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1111 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1112 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1113 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1114 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001115
1116 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1117 return -ENOBUFS;
1118
1119 return 0;
1120}
1121
Johannes Berg3713b4e2013-02-14 16:19:38 +01001122static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1123 struct ieee80211_supported_band *sband)
1124{
1125 struct nlattr *nl_rates, *nl_rate;
1126 struct ieee80211_rate *rate;
1127 int i;
1128
1129 /* add HT info */
1130 if (sband->ht_cap.ht_supported &&
1131 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1132 sizeof(sband->ht_cap.mcs),
1133 &sband->ht_cap.mcs) ||
1134 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1135 sband->ht_cap.cap) ||
1136 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1137 sband->ht_cap.ampdu_factor) ||
1138 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1139 sband->ht_cap.ampdu_density)))
1140 return -ENOBUFS;
1141
1142 /* add VHT info */
1143 if (sband->vht_cap.vht_supported &&
1144 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1145 sizeof(sband->vht_cap.vht_mcs),
1146 &sband->vht_cap.vht_mcs) ||
1147 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1148 sband->vht_cap.cap)))
1149 return -ENOBUFS;
1150
1151 /* add bitrates */
1152 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1153 if (!nl_rates)
1154 return -ENOBUFS;
1155
1156 for (i = 0; i < sband->n_bitrates; i++) {
1157 nl_rate = nla_nest_start(msg, i);
1158 if (!nl_rate)
1159 return -ENOBUFS;
1160
1161 rate = &sband->bitrates[i];
1162 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1163 rate->bitrate))
1164 return -ENOBUFS;
1165 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1166 nla_put_flag(msg,
1167 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1168 return -ENOBUFS;
1169
1170 nla_nest_end(msg, nl_rate);
1171 }
1172
1173 nla_nest_end(msg, nl_rates);
1174
1175 return 0;
1176}
1177
1178static int
1179nl80211_send_mgmt_stypes(struct sk_buff *msg,
1180 const struct ieee80211_txrx_stypes *mgmt_stypes)
1181{
1182 u16 stypes;
1183 struct nlattr *nl_ftypes, *nl_ifs;
1184 enum nl80211_iftype ift;
1185 int i;
1186
1187 if (!mgmt_stypes)
1188 return 0;
1189
1190 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1191 if (!nl_ifs)
1192 return -ENOBUFS;
1193
1194 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1195 nl_ftypes = nla_nest_start(msg, ift);
1196 if (!nl_ftypes)
1197 return -ENOBUFS;
1198 i = 0;
1199 stypes = mgmt_stypes[ift].tx;
1200 while (stypes) {
1201 if ((stypes & 1) &&
1202 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1203 (i << 4) | IEEE80211_FTYPE_MGMT))
1204 return -ENOBUFS;
1205 stypes >>= 1;
1206 i++;
1207 }
1208 nla_nest_end(msg, nl_ftypes);
1209 }
1210
1211 nla_nest_end(msg, nl_ifs);
1212
1213 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1214 if (!nl_ifs)
1215 return -ENOBUFS;
1216
1217 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1218 nl_ftypes = nla_nest_start(msg, ift);
1219 if (!nl_ftypes)
1220 return -ENOBUFS;
1221 i = 0;
1222 stypes = mgmt_stypes[ift].rx;
1223 while (stypes) {
1224 if ((stypes & 1) &&
1225 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1226 (i << 4) | IEEE80211_FTYPE_MGMT))
1227 return -ENOBUFS;
1228 stypes >>= 1;
1229 i++;
1230 }
1231 nla_nest_end(msg, nl_ftypes);
1232 }
1233 nla_nest_end(msg, nl_ifs);
1234
1235 return 0;
1236}
1237
Johannes Berg86e8cf92013-06-19 10:57:22 +02001238struct nl80211_dump_wiphy_state {
1239 s64 filter_wiphy;
1240 long start;
1241 long split_start, band_start, chan_start;
1242 bool split;
1243};
1244
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001245static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001246 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001247 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001248 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001249{
1250 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001251 struct nlattr *nl_bands, *nl_band;
1252 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001253 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001254 enum ieee80211_band band;
1255 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001256 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001257 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001258 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001259 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001260
Johannes Berg3bb20552014-05-26 13:52:25 +02001261 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001262 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 return -ENOBUFS;
1264
Johannes Berg86e8cf92013-06-19 10:57:22 +02001265 if (WARN_ON(!state))
1266 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001267
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001268 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001269 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001270 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001271 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001273 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001274
Johannes Berg3bb20552014-05-26 13:52:25 +02001275 if (cmd != NL80211_CMD_NEW_WIPHY)
1276 goto finish;
1277
Johannes Berg86e8cf92013-06-19 10:57:22 +02001278 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 case 0:
1280 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001285 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001287 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001289 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001291 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001297 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001300 goto nla_put_failure;
1301
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1304 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001305 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1307 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001308 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1310 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1313 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001315 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1316 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001319 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001320 state->split_start++;
1321 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 break;
1323 case 1:
1324 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1326 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001327 goto nla_put_failure;
1328
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001330 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001331 goto nla_put_failure;
1332
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001333 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1335 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001336
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001338 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001342
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001347
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001348 if ((rdev->wiphy.available_antennas_tx ||
1349 rdev->wiphy.available_antennas_rx) &&
1350 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 u32 tx_ant = 0, rx_ant = 0;
1352 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001353 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 if (!res) {
1355 if (nla_put_u32(msg,
1356 NL80211_ATTR_WIPHY_ANTENNA_TX,
1357 tx_ant) ||
1358 nla_put_u32(msg,
1359 NL80211_ATTR_WIPHY_ANTENNA_RX,
1360 rx_ant))
1361 goto nla_put_failure;
1362 }
Johannes Bergee688b002008-01-24 19:38:39 +01001363 }
1364
Johannes Berg86e8cf92013-06-19 10:57:22 +02001365 state->split_start++;
1366 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 break;
1368 case 2:
1369 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001370 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001372 state->split_start++;
1373 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 break;
1375 case 3:
1376 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1377 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001378 goto nla_put_failure;
1379
Johannes Berg86e8cf92013-06-19 10:57:22 +02001380 for (band = state->band_start;
1381 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 struct ieee80211_supported_band *sband;
1383
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001384 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385
1386 if (!sband)
1387 continue;
1388
1389 nl_band = nla_nest_start(msg, band);
1390 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001391 goto nla_put_failure;
1392
Johannes Berg86e8cf92013-06-19 10:57:22 +02001393 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 case 0:
1395 if (nl80211_send_band_rateinfo(msg, sband))
1396 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001397 state->chan_start++;
1398 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 break;
1400 default:
1401 /* add frequencies */
1402 nl_freqs = nla_nest_start(
1403 msg, NL80211_BAND_ATTR_FREQS);
1404 if (!nl_freqs)
1405 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001406
Johannes Berg86e8cf92013-06-19 10:57:22 +02001407 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001408 i < sband->n_channels;
1409 i++) {
1410 nl_freq = nla_nest_start(msg, i);
1411 if (!nl_freq)
1412 goto nla_put_failure;
1413
1414 chan = &sband->channels[i];
1415
Johannes Berg86e8cf92013-06-19 10:57:22 +02001416 if (nl80211_msg_put_channel(
1417 msg, chan,
1418 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 goto nla_put_failure;
1420
1421 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423 break;
1424 }
1425 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001426 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001428 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 nla_nest_end(msg, nl_freqs);
1430 }
1431
1432 nla_nest_end(msg, nl_band);
1433
Johannes Berg86e8cf92013-06-19 10:57:22 +02001434 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 band--;
1438 break;
1439 }
Johannes Bergee688b002008-01-24 19:38:39 +01001440 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001441 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001442
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001444 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001449 if (state->band_start == 0 && state->chan_start == 0)
1450 state->split_start++;
1451 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 break;
1453 case 4:
1454 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1455 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001456 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457
1458 i = 0;
1459#define CMD(op, n) \
1460 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001461 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 i++; \
1463 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1464 goto nla_put_failure; \
1465 } \
1466 } while (0)
1467
1468 CMD(add_virtual_intf, NEW_INTERFACE);
1469 CMD(change_virtual_intf, SET_INTERFACE);
1470 CMD(add_key, NEW_KEY);
1471 CMD(start_ap, START_AP);
1472 CMD(add_station, NEW_STATION);
1473 CMD(add_mpath, NEW_MPATH);
1474 CMD(update_mesh_config, SET_MESH_CONFIG);
1475 CMD(change_bss, SET_BSS);
1476 CMD(auth, AUTHENTICATE);
1477 CMD(assoc, ASSOCIATE);
1478 CMD(deauth, DEAUTHENTICATE);
1479 CMD(disassoc, DISASSOCIATE);
1480 CMD(join_ibss, JOIN_IBSS);
1481 CMD(join_mesh, JOIN_MESH);
1482 CMD(set_pmksa, SET_PMKSA);
1483 CMD(del_pmksa, DEL_PMKSA);
1484 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001485 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001486 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1487 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1488 CMD(mgmt_tx, FRAME);
1489 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001490 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 i++;
1492 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1493 goto nla_put_failure;
1494 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001495 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1496 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 i++;
1498 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1499 goto nla_put_failure;
1500 }
1501 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 CMD(tdls_mgmt, TDLS_MGMT);
1504 CMD(tdls_oper, TDLS_OPER);
1505 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 CMD(sched_scan_start, START_SCHED_SCAN);
1508 CMD(probe_client, PROBE_CLIENT);
1509 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 i++;
1512 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1513 goto nla_put_failure;
1514 }
1515 CMD(start_p2p_device, START_P2P_DEVICE);
1516 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001517#ifdef CONFIG_NL80211_TESTMODE
1518 CMD(testmode_cmd, TESTMODE);
1519#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001520 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001521 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1522 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001524 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001525 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001526 if (rdev->wiphy.features &
1527 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001528 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001529 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001530 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001531#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001532
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001533 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001534 i++;
1535 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001536 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001537 }
1538
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001539 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 i++;
1541 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1542 goto nla_put_failure;
1543 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001544
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001546 state->split_start++;
1547 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 break;
1549 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001550 if (rdev->ops->remain_on_channel &&
1551 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 nla_put_u32(msg,
1553 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001554 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001555 goto nla_put_failure;
1556
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001557 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001558 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1559 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001560
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1562 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split_start++;
1564 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 break;
1566 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001567#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001568 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001570 state->split_start++;
1571 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 break;
1573#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001574 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575#endif
1576 case 7:
1577 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001579 goto nla_put_failure;
1580
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001581 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001582 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001584
Johannes Berg86e8cf92013-06-19 10:57:22 +02001585 state->split_start++;
1586 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 break;
1588 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001591 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 goto nla_put_failure;
1593
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001594 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001595 /*
1596 * We can only add the per-channel limit information if the
1597 * dump is split, otherwise it makes it too big. Therefore
1598 * only advertise it in that case.
1599 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001600 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001601 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1602 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 goto nla_put_failure;
1604
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001605 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001606 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1608 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 goto nla_put_failure;
1610
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001611 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1612 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 goto nla_put_failure;
1616
1617 /*
1618 * Any information below this point is only available to
1619 * applications that can deal with it being split. This
1620 * helps ensure that newly added capabilities don't break
1621 * older tools by overrunning their buffers.
1622 *
1623 * We still increment split_start so that in the split
1624 * case we'll continue with more data in the next round,
1625 * but break unconditionally so unsplit data stops here.
1626 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001627 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001628 break;
1629 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001631 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 rdev->wiphy.extended_capabilities_len,
1633 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001634 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001635 rdev->wiphy.extended_capabilities_len,
1636 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001637 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001640 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001641 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1642 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001643 goto nla_put_failure;
1644
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001645 state->split_start++;
1646 break;
1647 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001649 goto nla_put_failure;
1650
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001651 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001652 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1653 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1654 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001655
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001656 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001657 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001658 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001659 goto nla_put_failure;
1660
Johannes Bergad7e7182013-11-13 13:37:47 +01001661 state->split_start++;
1662 break;
1663 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001665 const struct nl80211_vendor_cmd_info *info;
1666 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001667
Johannes Berg567ffc32013-12-18 14:43:31 +01001668 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1669 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001670 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001671
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001672 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1673 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001674 if (nla_put(msg, i + 1, sizeof(*info), info))
1675 goto nla_put_failure;
1676 }
1677 nla_nest_end(msg, nested);
1678 }
1679
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001681 const struct nl80211_vendor_cmd_info *info;
1682 struct nlattr *nested;
1683
1684 nested = nla_nest_start(msg,
1685 NL80211_ATTR_VENDOR_EVENTS);
1686 if (!nested)
1687 goto nla_put_failure;
1688
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001689 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1690 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001691 if (nla_put(msg, i + 1, sizeof(*info), info))
1692 goto nla_put_failure;
1693 }
1694 nla_nest_end(msg, nested);
1695 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001696 state->split_start++;
1697 break;
1698 case 12:
1699 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1700 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1701 rdev->wiphy.max_num_csa_counters))
1702 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001703
Johannes Berg3713b4e2013-02-14 16:19:38 +01001704 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001705 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001706 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001707 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001708 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001709 return genlmsg_end(msg, hdr);
1710
1711 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001712 genlmsg_cancel(msg, hdr);
1713 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001714}
1715
Johannes Berg86e8cf92013-06-19 10:57:22 +02001716static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1717 struct netlink_callback *cb,
1718 struct nl80211_dump_wiphy_state *state)
1719{
1720 struct nlattr **tb = nl80211_fam.attrbuf;
1721 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1722 tb, nl80211_fam.maxattr, nl80211_policy);
1723 /* ignore parse errors for backward compatibility */
1724 if (ret)
1725 return 0;
1726
1727 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1728 if (tb[NL80211_ATTR_WIPHY])
1729 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1730 if (tb[NL80211_ATTR_WDEV])
1731 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1732 if (tb[NL80211_ATTR_IFINDEX]) {
1733 struct net_device *netdev;
1734 struct cfg80211_registered_device *rdev;
1735 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1736
Ying Xue7f2b8562014-01-15 10:23:45 +08001737 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 if (!netdev)
1739 return -ENODEV;
1740 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001741 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001742 netdev->ieee80211_ptr->wiphy);
1743 state->filter_wiphy = rdev->wiphy_idx;
1744 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001745 }
1746
1747 return 0;
1748}
1749
Johannes Berg55682962007-09-20 13:09:35 -04001750static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1751{
Johannes Berg645e77d2013-03-01 14:03:49 +01001752 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001753 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001754 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001755
Johannes Berg5fe231e2013-05-08 21:45:15 +02001756 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 if (!state) {
1758 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001759 if (!state) {
1760 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001761 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001762 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001763 state->filter_wiphy = -1;
1764 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1765 if (ret) {
1766 kfree(state);
1767 rtnl_unlock();
1768 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001770 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001771 }
1772
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001773 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1774 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001775 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001776 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001777 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001779 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001780 continue;
1781 /* attempt to fit multiple wiphy data chunks into the skb */
1782 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001783 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1784 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001785 NETLINK_CB(cb->skb).portid,
1786 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001787 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 if (ret < 0) {
1789 /*
1790 * If sending the wiphy data didn't fit (ENOBUFS
1791 * or EMSGSIZE returned), this SKB is still
1792 * empty (so it's not too big because another
1793 * wiphy dataset is already in the skb) and
1794 * we've not tried to adjust the dump allocation
1795 * yet ... then adjust the alloc size to be
1796 * bigger, and return 1 but with the empty skb.
1797 * This results in an empty message being RX'ed
1798 * in userspace, but that is ignored.
1799 *
1800 * We can then retry with the larger buffer.
1801 */
1802 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001803 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001804 cb->min_dump_alloc < 4096) {
1805 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001806 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001807 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001808 return 1;
1809 }
1810 idx--;
1811 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001812 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 break;
Johannes Berg55682962007-09-20 13:09:35 -04001815 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001816 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001817
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001819
1820 return skb->len;
1821}
1822
Johannes Berg86e8cf92013-06-19 10:57:22 +02001823static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1824{
1825 kfree((void *)cb->args[0]);
1826 return 0;
1827}
1828
Johannes Berg55682962007-09-20 13:09:35 -04001829static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1830{
1831 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001833 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001834
Johannes Berg645e77d2013-03-01 14:03:49 +01001835 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001836 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001837 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001838
Johannes Berg3bb20552014-05-26 13:52:25 +02001839 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1840 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001841 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001842 nlmsg_free(msg);
1843 return -ENOBUFS;
1844 }
Johannes Berg55682962007-09-20 13:09:35 -04001845
Johannes Berg134e6372009-07-10 09:51:34 +00001846 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001847}
1848
Jouni Malinen31888482008-10-30 16:59:24 +02001849static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1850 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1851 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1852 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1853 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1854 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1855};
1856
1857static int parse_txq_params(struct nlattr *tb[],
1858 struct ieee80211_txq_params *txq_params)
1859{
Johannes Berga3304b02012-03-28 11:04:24 +02001860 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001861 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1862 !tb[NL80211_TXQ_ATTR_AIFS])
1863 return -EINVAL;
1864
Johannes Berga3304b02012-03-28 11:04:24 +02001865 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001866 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1867 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1868 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1869 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1870
Johannes Berga3304b02012-03-28 11:04:24 +02001871 if (txq_params->ac >= NL80211_NUM_ACS)
1872 return -EINVAL;
1873
Jouni Malinen31888482008-10-30 16:59:24 +02001874 return 0;
1875}
1876
Johannes Bergf444de02010-05-05 15:25:02 +02001877static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1878{
1879 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001880 * You can only set the channel explicitly for WDS interfaces,
1881 * all others have their channel managed via their respective
1882 * "establish a connection" command (connect, join, ...)
1883 *
1884 * For AP/GO and mesh mode, the channel can be set with the
1885 * channel userspace API, but is only stored and passed to the
1886 * low-level driver when the AP starts or the mesh is joined.
1887 * This is for backward compatibility, userspace can also give
1888 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001889 *
1890 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001891 * whatever else is going on, so they have their own special
1892 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001893 */
1894 return !wdev ||
1895 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001896 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001897 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1898 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001899}
1900
Johannes Berg683b6d32012-11-08 21:25:48 +01001901static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1902 struct genl_info *info,
1903 struct cfg80211_chan_def *chandef)
1904{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301905 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001906
1907 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1908 return -EINVAL;
1909
1910 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1911
1912 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001913 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1914 chandef->center_freq1 = control_freq;
1915 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001916
1917 /* Primary channel not allowed */
1918 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1919 return -EINVAL;
1920
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001921 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1922 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001923
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001924 chantype = nla_get_u32(
1925 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1926
1927 switch (chantype) {
1928 case NL80211_CHAN_NO_HT:
1929 case NL80211_CHAN_HT20:
1930 case NL80211_CHAN_HT40PLUS:
1931 case NL80211_CHAN_HT40MINUS:
1932 cfg80211_chandef_create(chandef, chandef->chan,
1933 chantype);
1934 break;
1935 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001936 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001937 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1939 chandef->width =
1940 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1941 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1942 chandef->center_freq1 =
1943 nla_get_u32(
1944 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1945 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1946 chandef->center_freq2 =
1947 nla_get_u32(
1948 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1949 }
1950
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001951 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001952 return -EINVAL;
1953
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001954 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1955 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001956 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001957
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001958 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1959 chandef->width == NL80211_CHAN_WIDTH_10) &&
1960 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1961 return -EINVAL;
1962
Johannes Berg683b6d32012-11-08 21:25:48 +01001963 return 0;
1964}
1965
Johannes Bergf444de02010-05-05 15:25:02 +02001966static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001967 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001968 struct genl_info *info)
1969{
Johannes Berg683b6d32012-11-08 21:25:48 +01001970 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001971 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001972 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001973 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001974
Jouni Malinene16821b2014-04-28 11:22:08 +03001975 if (dev)
1976 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001977 if (!nl80211_can_set_dev_channel(wdev))
1978 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001979 if (wdev)
1980 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001981
Johannes Berg683b6d32012-11-08 21:25:48 +01001982 result = nl80211_parse_chandef(rdev, info, &chandef);
1983 if (result)
1984 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001985
Johannes Berge8c9bd52012-06-06 08:18:22 +02001986 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001987 case NL80211_IFTYPE_AP:
1988 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001989 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001990 result = -EINVAL;
1991 break;
1992 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001993 if (wdev->beacon_interval) {
1994 if (!dev || !rdev->ops->set_ap_chanwidth ||
1995 !(rdev->wiphy.features &
1996 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1997 result = -EBUSY;
1998 break;
1999 }
2000
2001 /* Only allow dynamic channel width changes */
2002 if (chandef.chan != wdev->preset_chandef.chan) {
2003 result = -EBUSY;
2004 break;
2005 }
2006 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2007 if (result)
2008 break;
2009 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002010 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002011 result = 0;
2012 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002013 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002014 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002015 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002016 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002017 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002018 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002019 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002020 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002021 }
Johannes Bergf444de02010-05-05 15:25:02 +02002022
2023 return result;
2024}
2025
2026static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2027{
Johannes Berg4c476992010-10-04 21:36:35 +02002028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2029 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002030
Jouni Malinene16821b2014-04-28 11:22:08 +03002031 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002032}
2033
Bill Jordane8347eb2010-10-01 13:54:28 -04002034static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2035{
Johannes Berg43b19952010-10-07 13:10:30 +02002036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2037 struct net_device *dev = info->user_ptr[1];
2038 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002039 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002040
2041 if (!info->attrs[NL80211_ATTR_MAC])
2042 return -EINVAL;
2043
Johannes Berg43b19952010-10-07 13:10:30 +02002044 if (netif_running(dev))
2045 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002046
Johannes Berg43b19952010-10-07 13:10:30 +02002047 if (!rdev->ops->set_wds_peer)
2048 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002049
Johannes Berg43b19952010-10-07 13:10:30 +02002050 if (wdev->iftype != NL80211_IFTYPE_WDS)
2051 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002052
2053 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002054 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002055}
2056
2057
Johannes Berg55682962007-09-20 13:09:35 -04002058static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2059{
2060 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002061 struct net_device *netdev = NULL;
2062 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002063 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002064 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002065 u32 changed;
2066 u8 retry_short = 0, retry_long = 0;
2067 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002068 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002069
Johannes Berg5fe231e2013-05-08 21:45:15 +02002070 ASSERT_RTNL();
2071
Johannes Bergf444de02010-05-05 15:25:02 +02002072 /*
2073 * Try to find the wiphy and netdev. Normally this
2074 * function shouldn't need the netdev, but this is
2075 * done for backward compatibility -- previously
2076 * setting the channel was done per wiphy, but now
2077 * it is per netdev. Previous userland like hostapd
2078 * also passed a netdev to set_wiphy, so that it is
2079 * possible to let that go to the right netdev!
2080 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002081
Johannes Bergf444de02010-05-05 15:25:02 +02002082 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2083 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2084
Ying Xue7f2b8562014-01-15 10:23:45 +08002085 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002086 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002087 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002088 else
Johannes Bergf444de02010-05-05 15:25:02 +02002089 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002090 }
2091
Johannes Bergf444de02010-05-05 15:25:02 +02002092 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002093 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2094 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002095 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002096 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002097 wdev = NULL;
2098 netdev = NULL;
2099 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002100 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002101 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002102
2103 /*
2104 * end workaround code, by now the rdev is available
2105 * and locked, and wdev may or may not be NULL.
2106 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002107
2108 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002109 result = cfg80211_dev_rename(
2110 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002111
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002112 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002113 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002114
Jouni Malinen31888482008-10-30 16:59:24 +02002115 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2116 struct ieee80211_txq_params txq_params;
2117 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2118
Ying Xue7f2b8562014-01-15 10:23:45 +08002119 if (!rdev->ops->set_txq_params)
2120 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002121
Ying Xue7f2b8562014-01-15 10:23:45 +08002122 if (!netdev)
2123 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002124
Johannes Berg133a3ff2011-11-03 14:50:13 +01002125 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002126 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2127 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002128
Ying Xue7f2b8562014-01-15 10:23:45 +08002129 if (!netif_running(netdev))
2130 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002131
Jouni Malinen31888482008-10-30 16:59:24 +02002132 nla_for_each_nested(nl_txq_params,
2133 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2134 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002135 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2136 nla_data(nl_txq_params),
2137 nla_len(nl_txq_params),
2138 txq_params_policy);
2139 if (result)
2140 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002141 result = parse_txq_params(tb, &txq_params);
2142 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002143 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002144
Hila Gonene35e4d22012-06-27 17:19:42 +03002145 result = rdev_set_txq_params(rdev, netdev,
2146 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002147 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002148 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002149 }
2150 }
2151
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002152 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002153 result = __nl80211_set_channel(
2154 rdev,
2155 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2156 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002157 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002158 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002159 }
2160
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002161 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002162 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002163 enum nl80211_tx_power_setting type;
2164 int idx, mbm = 0;
2165
Johannes Bergc8442112012-10-24 10:17:18 +02002166 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2167 txp_wdev = NULL;
2168
Ying Xue7f2b8562014-01-15 10:23:45 +08002169 if (!rdev->ops->set_tx_power)
2170 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002171
2172 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2173 type = nla_get_u32(info->attrs[idx]);
2174
2175 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002176 (type != NL80211_TX_POWER_AUTOMATIC))
2177 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002178
2179 if (type != NL80211_TX_POWER_AUTOMATIC) {
2180 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2181 mbm = nla_get_u32(info->attrs[idx]);
2182 }
2183
Johannes Bergc8442112012-10-24 10:17:18 +02002184 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002185 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002186 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002187 }
2188
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002189 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2190 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2191 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002192 if ((!rdev->wiphy.available_antennas_tx &&
2193 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 !rdev->ops->set_antenna)
2195 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002196
2197 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2198 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2199
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002200 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002201 * available antenna masks, except for the "all" mask */
2202 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002203 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2204 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002205
Bruno Randolf7f531e02010-12-16 11:30:22 +09002206 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2207 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002208
Hila Gonene35e4d22012-06-27 17:19:42 +03002209 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002210 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002211 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002212 }
2213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002214 changed = 0;
2215
2216 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2217 retry_short = nla_get_u8(
2218 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002219 if (retry_short == 0)
2220 return -EINVAL;
2221
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002222 changed |= WIPHY_PARAM_RETRY_SHORT;
2223 }
2224
2225 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2226 retry_long = nla_get_u8(
2227 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 if (retry_long == 0)
2229 return -EINVAL;
2230
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002231 changed |= WIPHY_PARAM_RETRY_LONG;
2232 }
2233
2234 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2235 frag_threshold = nla_get_u32(
2236 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002237 if (frag_threshold < 256)
2238 return -EINVAL;
2239
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002240 if (frag_threshold != (u32) -1) {
2241 /*
2242 * Fragments (apart from the last one) are required to
2243 * have even length. Make the fragmentation code
2244 * simpler by stripping LSB should someone try to use
2245 * odd threshold value.
2246 */
2247 frag_threshold &= ~0x1;
2248 }
2249 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2250 }
2251
2252 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2253 rts_threshold = nla_get_u32(
2254 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2255 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2256 }
2257
Lukáš Turek81077e82009-12-21 22:50:47 +01002258 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002259 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2260 return -EINVAL;
2261
Lukáš Turek81077e82009-12-21 22:50:47 +01002262 coverage_class = nla_get_u8(
2263 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2264 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2265 }
2266
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002267 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2268 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2269 return -EOPNOTSUPP;
2270
2271 changed |= WIPHY_PARAM_DYN_ACK;
2272 }
2273
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002274 if (changed) {
2275 u8 old_retry_short, old_retry_long;
2276 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002277 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002278
Ying Xue7f2b8562014-01-15 10:23:45 +08002279 if (!rdev->ops->set_wiphy_params)
2280 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002281
2282 old_retry_short = rdev->wiphy.retry_short;
2283 old_retry_long = rdev->wiphy.retry_long;
2284 old_frag_threshold = rdev->wiphy.frag_threshold;
2285 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002286 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002287
2288 if (changed & WIPHY_PARAM_RETRY_SHORT)
2289 rdev->wiphy.retry_short = retry_short;
2290 if (changed & WIPHY_PARAM_RETRY_LONG)
2291 rdev->wiphy.retry_long = retry_long;
2292 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2293 rdev->wiphy.frag_threshold = frag_threshold;
2294 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2295 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002296 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2297 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002298
Hila Gonene35e4d22012-06-27 17:19:42 +03002299 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002300 if (result) {
2301 rdev->wiphy.retry_short = old_retry_short;
2302 rdev->wiphy.retry_long = old_retry_long;
2303 rdev->wiphy.frag_threshold = old_frag_threshold;
2304 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002305 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002306 }
2307 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002308 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002309}
2310
Johannes Berg71bbc992012-06-15 15:30:18 +02002311static inline u64 wdev_id(struct wireless_dev *wdev)
2312{
2313 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002314 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002315}
Johannes Berg55682962007-09-20 13:09:35 -04002316
Johannes Berg683b6d32012-11-08 21:25:48 +01002317static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002318 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002319{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002320 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002321
Johannes Berg683b6d32012-11-08 21:25:48 +01002322 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2323 chandef->chan->center_freq))
2324 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002325 switch (chandef->width) {
2326 case NL80211_CHAN_WIDTH_20_NOHT:
2327 case NL80211_CHAN_WIDTH_20:
2328 case NL80211_CHAN_WIDTH_40:
2329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2330 cfg80211_get_chandef_type(chandef)))
2331 return -ENOBUFS;
2332 break;
2333 default:
2334 break;
2335 }
2336 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2337 return -ENOBUFS;
2338 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2339 return -ENOBUFS;
2340 if (chandef->center_freq2 &&
2341 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002342 return -ENOBUFS;
2343 return 0;
2344}
2345
Eric W. Biederman15e47302012-09-07 20:12:54 +00002346static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002347 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002348 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002349{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002350 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002351 void *hdr;
2352
Eric W. Biederman15e47302012-09-07 20:12:54 +00002353 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002354 if (!hdr)
2355 return -1;
2356
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002357 if (dev &&
2358 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002359 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002360 goto nla_put_failure;
2361
2362 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2363 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002364 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002366 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2367 rdev->devlist_generation ^
2368 (cfg80211_rdev_list_generation << 2)))
2369 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002370
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002371 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002372 int ret;
2373 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002374
Johannes Berg683b6d32012-11-08 21:25:48 +01002375 ret = rdev_get_channel(rdev, wdev, &chandef);
2376 if (ret == 0) {
2377 if (nl80211_send_chandef(msg, &chandef))
2378 goto nla_put_failure;
2379 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002380 }
2381
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002382 if (wdev->ssid_len) {
2383 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2384 goto nla_put_failure;
2385 }
2386
Johannes Berg55682962007-09-20 13:09:35 -04002387 return genlmsg_end(msg, hdr);
2388
2389 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002390 genlmsg_cancel(msg, hdr);
2391 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002392}
2393
2394static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2395{
2396 int wp_idx = 0;
2397 int if_idx = 0;
2398 int wp_start = cb->args[0];
2399 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002400 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002401 struct wireless_dev *wdev;
2402
Johannes Berg5fe231e2013-05-08 21:45:15 +02002403 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002404 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2405 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002406 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002407 if (wp_idx < wp_start) {
2408 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002409 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002410 }
Johannes Berg55682962007-09-20 13:09:35 -04002411 if_idx = 0;
2412
Johannes Berg89a54e42012-06-15 14:33:17 +02002413 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002414 if (if_idx < if_start) {
2415 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002416 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002417 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002418 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002419 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002420 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002421 goto out;
2422 }
2423 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002424 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002425
2426 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002427 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002428 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002429 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002430
2431 cb->args[0] = wp_idx;
2432 cb->args[1] = if_idx;
2433
2434 return skb->len;
2435}
2436
2437static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2438{
2439 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002441 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002442
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002443 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002444 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002445 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002446
Eric W. Biederman15e47302012-09-07 20:12:54 +00002447 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002448 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002449 nlmsg_free(msg);
2450 return -ENOBUFS;
2451 }
Johannes Berg55682962007-09-20 13:09:35 -04002452
Johannes Berg134e6372009-07-10 09:51:34 +00002453 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002454}
2455
Michael Wu66f7ac52008-01-31 19:48:22 +01002456static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2457 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2458 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2459 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2460 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2461 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002462 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002463};
2464
2465static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2466{
2467 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2468 int flag;
2469
2470 *mntrflags = 0;
2471
2472 if (!nla)
2473 return -EINVAL;
2474
2475 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2476 nla, mntr_flags_policy))
2477 return -EINVAL;
2478
2479 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2480 if (flags[flag])
2481 *mntrflags |= (1<<flag);
2482
2483 return 0;
2484}
2485
Johannes Berg9bc383d2009-11-19 11:55:19 +01002486static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002487 struct net_device *netdev, u8 use_4addr,
2488 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002489{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002490 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002491 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002492 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002493 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002494 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002495
2496 switch (iftype) {
2497 case NL80211_IFTYPE_AP_VLAN:
2498 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2499 return 0;
2500 break;
2501 case NL80211_IFTYPE_STATION:
2502 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2503 return 0;
2504 break;
2505 default:
2506 break;
2507 }
2508
2509 return -EOPNOTSUPP;
2510}
2511
Johannes Berg55682962007-09-20 13:09:35 -04002512static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2513{
Johannes Berg4c476992010-10-04 21:36:35 +02002514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002515 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002516 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002517 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002518 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002519 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002520 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002521
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002522 memset(&params, 0, sizeof(params));
2523
Johannes Berg04a773a2009-04-19 21:24:32 +02002524 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002525
Johannes Berg723b0382008-09-16 20:22:09 +02002526 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002527 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002528 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002529 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002530 if (ntype > NL80211_IFTYPE_MAX)
2531 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002532 }
2533
Johannes Berg92ffe052008-09-16 20:39:36 +02002534 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002535 struct wireless_dev *wdev = dev->ieee80211_ptr;
2536
Johannes Berg4c476992010-10-04 21:36:35 +02002537 if (ntype != NL80211_IFTYPE_MESH_POINT)
2538 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002539 if (netif_running(dev))
2540 return -EBUSY;
2541
2542 wdev_lock(wdev);
2543 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2544 IEEE80211_MAX_MESH_ID_LEN);
2545 wdev->mesh_id_up_len =
2546 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2547 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2548 wdev->mesh_id_up_len);
2549 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002550 }
2551
Felix Fietkau8b787642009-11-10 18:53:10 +01002552 if (info->attrs[NL80211_ATTR_4ADDR]) {
2553 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2554 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002555 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002556 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002557 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002558 } else {
2559 params.use_4addr = -1;
2560 }
2561
Johannes Berg92ffe052008-09-16 20:39:36 +02002562 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002563 if (ntype != NL80211_IFTYPE_MONITOR)
2564 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002565 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2566 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002567 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002568 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002569
2570 flags = &_flags;
2571 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002572 }
Johannes Berg3b858752009-03-12 09:55:09 +01002573
Luciano Coelho18003292013-08-29 13:26:57 +03002574 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002575 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2576 return -EOPNOTSUPP;
2577
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002578 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002579 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002580 else
2581 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002582
Johannes Berg9bc383d2009-11-19 11:55:19 +01002583 if (!err && params.use_4addr != -1)
2584 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2585
Johannes Berg55682962007-09-20 13:09:35 -04002586 return err;
2587}
2588
2589static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2590{
Johannes Berg4c476992010-10-04 21:36:35 +02002591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002592 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002593 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002594 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002595 int err;
2596 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002597 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002598
Johannes Berg78f22b62014-03-24 17:57:27 +01002599 /* to avoid failing a new interface creation due to pending removal */
2600 cfg80211_destroy_ifaces(rdev);
2601
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002602 memset(&params, 0, sizeof(params));
2603
Johannes Berg55682962007-09-20 13:09:35 -04002604 if (!info->attrs[NL80211_ATTR_IFNAME])
2605 return -EINVAL;
2606
2607 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2608 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2609 if (type > NL80211_IFTYPE_MAX)
2610 return -EINVAL;
2611 }
2612
Johannes Berg79c97e92009-07-07 03:56:12 +02002613 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002614 !(rdev->wiphy.interface_modes & (1 << type)))
2615 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002616
Ben Greeare8f479b2014-10-22 12:23:05 -07002617 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2618 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2619 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002620 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2621 ETH_ALEN);
2622 if (!is_valid_ether_addr(params.macaddr))
2623 return -EADDRNOTAVAIL;
2624 }
2625
Johannes Berg9bc383d2009-11-19 11:55:19 +01002626 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002627 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002628 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002629 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002630 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002631 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002632
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002633 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2634 if (!msg)
2635 return -ENOMEM;
2636
Michael Wu66f7ac52008-01-31 19:48:22 +01002637 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2638 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2639 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002640
Luciano Coelho18003292013-08-29 13:26:57 +03002641 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002642 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2643 return -EOPNOTSUPP;
2644
Hila Gonene35e4d22012-06-27 17:19:42 +03002645 wdev = rdev_add_virtual_intf(rdev,
2646 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2647 type, err ? NULL : &flags, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002648 if (WARN_ON(!wdev)) {
2649 nlmsg_free(msg);
2650 return -EPROTO;
2651 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002652 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002653 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002654 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002655
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002656 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002657 wdev->owner_nlportid = info->snd_portid;
2658
Johannes Berg98104fde2012-06-16 00:19:54 +02002659 switch (type) {
2660 case NL80211_IFTYPE_MESH_POINT:
2661 if (!info->attrs[NL80211_ATTR_MESH_ID])
2662 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002663 wdev_lock(wdev);
2664 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2665 IEEE80211_MAX_MESH_ID_LEN);
2666 wdev->mesh_id_up_len =
2667 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2668 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2669 wdev->mesh_id_up_len);
2670 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002671 break;
2672 case NL80211_IFTYPE_P2P_DEVICE:
2673 /*
2674 * P2P Device doesn't have a netdev, so doesn't go
2675 * through the netdev notifier and must be added here
2676 */
2677 mutex_init(&wdev->mtx);
2678 INIT_LIST_HEAD(&wdev->event_list);
2679 spin_lock_init(&wdev->event_lock);
2680 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2681 spin_lock_init(&wdev->mgmt_registrations_lock);
2682
Johannes Berg98104fde2012-06-16 00:19:54 +02002683 wdev->identifier = ++rdev->wdev_id;
2684 list_add_rcu(&wdev->list, &rdev->wdev_list);
2685 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002686 break;
2687 default:
2688 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002689 }
2690
Eric W. Biederman15e47302012-09-07 20:12:54 +00002691 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002692 rdev, wdev) < 0) {
2693 nlmsg_free(msg);
2694 return -ENOBUFS;
2695 }
2696
2697 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002698}
2699
2700static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2701{
Johannes Berg4c476992010-10-04 21:36:35 +02002702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002703 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002704
Johannes Berg4c476992010-10-04 21:36:35 +02002705 if (!rdev->ops->del_virtual_intf)
2706 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002707
Johannes Berg84efbb82012-06-16 00:00:26 +02002708 /*
2709 * If we remove a wireless device without a netdev then clear
2710 * user_ptr[1] so that nl80211_post_doit won't dereference it
2711 * to check if it needs to do dev_put(). Otherwise it crashes
2712 * since the wdev has been freed, unlike with a netdev where
2713 * we need the dev_put() for the netdev to really be freed.
2714 */
2715 if (!wdev->netdev)
2716 info->user_ptr[1] = NULL;
2717
Hila Gonene35e4d22012-06-27 17:19:42 +03002718 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002719}
2720
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002721static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2722{
2723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2724 struct net_device *dev = info->user_ptr[1];
2725 u16 noack_map;
2726
2727 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2728 return -EINVAL;
2729
2730 if (!rdev->ops->set_noack_map)
2731 return -EOPNOTSUPP;
2732
2733 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2734
Hila Gonene35e4d22012-06-27 17:19:42 +03002735 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002736}
2737
Johannes Berg41ade002007-12-19 02:03:29 +01002738struct get_key_cookie {
2739 struct sk_buff *msg;
2740 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002741 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002742};
2743
2744static void get_key_callback(void *c, struct key_params *params)
2745{
Johannes Bergb9454e82009-07-08 13:29:08 +02002746 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002747 struct get_key_cookie *cookie = c;
2748
David S. Miller9360ffd2012-03-29 04:41:26 -04002749 if ((params->key &&
2750 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2751 params->key_len, params->key)) ||
2752 (params->seq &&
2753 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2754 params->seq_len, params->seq)) ||
2755 (params->cipher &&
2756 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2757 params->cipher)))
2758 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002759
Johannes Bergb9454e82009-07-08 13:29:08 +02002760 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2761 if (!key)
2762 goto nla_put_failure;
2763
David S. Miller9360ffd2012-03-29 04:41:26 -04002764 if ((params->key &&
2765 nla_put(cookie->msg, NL80211_KEY_DATA,
2766 params->key_len, params->key)) ||
2767 (params->seq &&
2768 nla_put(cookie->msg, NL80211_KEY_SEQ,
2769 params->seq_len, params->seq)) ||
2770 (params->cipher &&
2771 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2772 params->cipher)))
2773 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002774
David S. Miller9360ffd2012-03-29 04:41:26 -04002775 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2776 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002777
2778 nla_nest_end(cookie->msg, key);
2779
Johannes Berg41ade002007-12-19 02:03:29 +01002780 return;
2781 nla_put_failure:
2782 cookie->error = 1;
2783}
2784
2785static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2786{
Johannes Berg4c476992010-10-04 21:36:35 +02002787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002788 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002789 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002790 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002791 const u8 *mac_addr = NULL;
2792 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002793 struct get_key_cookie cookie = {
2794 .error = 0,
2795 };
2796 void *hdr;
2797 struct sk_buff *msg;
2798
2799 if (info->attrs[NL80211_ATTR_KEY_IDX])
2800 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2801
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002802 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002803 return -EINVAL;
2804
2805 if (info->attrs[NL80211_ATTR_MAC])
2806 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2807
Johannes Berge31b8212010-10-05 19:39:30 +02002808 pairwise = !!mac_addr;
2809 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2810 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2811 if (kt >= NUM_NL80211_KEYTYPES)
2812 return -EINVAL;
2813 if (kt != NL80211_KEYTYPE_GROUP &&
2814 kt != NL80211_KEYTYPE_PAIRWISE)
2815 return -EINVAL;
2816 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2817 }
2818
Johannes Berg4c476992010-10-04 21:36:35 +02002819 if (!rdev->ops->get_key)
2820 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002821
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002822 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002823 if (!msg)
2824 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002825
Eric W. Biederman15e47302012-09-07 20:12:54 +00002826 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002827 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002828 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002829 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002830
2831 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002832 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002833
David S. Miller9360ffd2012-03-29 04:41:26 -04002834 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2835 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2836 goto nla_put_failure;
2837 if (mac_addr &&
2838 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2839 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002840
Johannes Berge31b8212010-10-05 19:39:30 +02002841 if (pairwise && mac_addr &&
2842 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2843 return -ENOENT;
2844
Hila Gonene35e4d22012-06-27 17:19:42 +03002845 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2846 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002847
2848 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002849 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002850
2851 if (cookie.error)
2852 goto nla_put_failure;
2853
2854 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002855 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002856
2857 nla_put_failure:
2858 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002859 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002860 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002861 return err;
2862}
2863
2864static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2865{
Johannes Berg4c476992010-10-04 21:36:35 +02002866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002867 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002868 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002869 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002870
Johannes Bergb9454e82009-07-08 13:29:08 +02002871 err = nl80211_parse_key(info, &key);
2872 if (err)
2873 return err;
2874
2875 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002876 return -EINVAL;
2877
Johannes Bergb9454e82009-07-08 13:29:08 +02002878 /* only support setting default key */
2879 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002880 return -EINVAL;
2881
Johannes Bergfffd0932009-07-08 14:22:54 +02002882 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002883
2884 if (key.def) {
2885 if (!rdev->ops->set_default_key) {
2886 err = -EOPNOTSUPP;
2887 goto out;
2888 }
2889
2890 err = nl80211_key_allowed(dev->ieee80211_ptr);
2891 if (err)
2892 goto out;
2893
Hila Gonene35e4d22012-06-27 17:19:42 +03002894 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002895 key.def_uni, key.def_multi);
2896
2897 if (err)
2898 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002899
Johannes Berg3d23e342009-09-29 23:27:28 +02002900#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002901 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002902#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002903 } else {
2904 if (key.def_uni || !key.def_multi) {
2905 err = -EINVAL;
2906 goto out;
2907 }
2908
2909 if (!rdev->ops->set_default_mgmt_key) {
2910 err = -EOPNOTSUPP;
2911 goto out;
2912 }
2913
2914 err = nl80211_key_allowed(dev->ieee80211_ptr);
2915 if (err)
2916 goto out;
2917
Hila Gonene35e4d22012-06-27 17:19:42 +03002918 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002919 if (err)
2920 goto out;
2921
2922#ifdef CONFIG_CFG80211_WEXT
2923 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2924#endif
2925 }
2926
2927 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002928 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002929
Johannes Berg41ade002007-12-19 02:03:29 +01002930 return err;
2931}
2932
2933static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2934{
Johannes Berg4c476992010-10-04 21:36:35 +02002935 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002936 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002937 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002938 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002939 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002940
Johannes Bergb9454e82009-07-08 13:29:08 +02002941 err = nl80211_parse_key(info, &key);
2942 if (err)
2943 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002944
Johannes Bergb9454e82009-07-08 13:29:08 +02002945 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002946 return -EINVAL;
2947
Johannes Berg41ade002007-12-19 02:03:29 +01002948 if (info->attrs[NL80211_ATTR_MAC])
2949 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2950
Johannes Berge31b8212010-10-05 19:39:30 +02002951 if (key.type == -1) {
2952 if (mac_addr)
2953 key.type = NL80211_KEYTYPE_PAIRWISE;
2954 else
2955 key.type = NL80211_KEYTYPE_GROUP;
2956 }
2957
2958 /* for now */
2959 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2960 key.type != NL80211_KEYTYPE_GROUP)
2961 return -EINVAL;
2962
Johannes Berg4c476992010-10-04 21:36:35 +02002963 if (!rdev->ops->add_key)
2964 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002965
Johannes Berge31b8212010-10-05 19:39:30 +02002966 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2967 key.type == NL80211_KEYTYPE_PAIRWISE,
2968 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002969 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002970
2971 wdev_lock(dev->ieee80211_ptr);
2972 err = nl80211_key_allowed(dev->ieee80211_ptr);
2973 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002974 err = rdev_add_key(rdev, dev, key.idx,
2975 key.type == NL80211_KEYTYPE_PAIRWISE,
2976 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002977 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002978
Johannes Berg41ade002007-12-19 02:03:29 +01002979 return err;
2980}
2981
2982static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2983{
Johannes Berg4c476992010-10-04 21:36:35 +02002984 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002985 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002986 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002987 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002988 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002989
Johannes Bergb9454e82009-07-08 13:29:08 +02002990 err = nl80211_parse_key(info, &key);
2991 if (err)
2992 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002993
2994 if (info->attrs[NL80211_ATTR_MAC])
2995 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2996
Johannes Berge31b8212010-10-05 19:39:30 +02002997 if (key.type == -1) {
2998 if (mac_addr)
2999 key.type = NL80211_KEYTYPE_PAIRWISE;
3000 else
3001 key.type = NL80211_KEYTYPE_GROUP;
3002 }
3003
3004 /* for now */
3005 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3006 key.type != NL80211_KEYTYPE_GROUP)
3007 return -EINVAL;
3008
Johannes Berg4c476992010-10-04 21:36:35 +02003009 if (!rdev->ops->del_key)
3010 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003011
Johannes Bergfffd0932009-07-08 14:22:54 +02003012 wdev_lock(dev->ieee80211_ptr);
3013 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003014
3015 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3016 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3017 err = -ENOENT;
3018
Johannes Bergfffd0932009-07-08 14:22:54 +02003019 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003020 err = rdev_del_key(rdev, dev, key.idx,
3021 key.type == NL80211_KEYTYPE_PAIRWISE,
3022 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003023
Johannes Berg3d23e342009-09-29 23:27:28 +02003024#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003025 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003026 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003027 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003028 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003029 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3030 }
3031#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003032 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003033
Johannes Berg41ade002007-12-19 02:03:29 +01003034 return err;
3035}
3036
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303037/* This function returns an error or the number of nested attributes */
3038static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3039{
3040 struct nlattr *attr;
3041 int n_entries = 0, tmp;
3042
3043 nla_for_each_nested(attr, nl_attr, tmp) {
3044 if (nla_len(attr) != ETH_ALEN)
3045 return -EINVAL;
3046
3047 n_entries++;
3048 }
3049
3050 return n_entries;
3051}
3052
3053/*
3054 * This function parses ACL information and allocates memory for ACL data.
3055 * On successful return, the calling function is responsible to free the
3056 * ACL buffer returned by this function.
3057 */
3058static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3059 struct genl_info *info)
3060{
3061 enum nl80211_acl_policy acl_policy;
3062 struct nlattr *attr;
3063 struct cfg80211_acl_data *acl;
3064 int i = 0, n_entries, tmp;
3065
3066 if (!wiphy->max_acl_mac_addrs)
3067 return ERR_PTR(-EOPNOTSUPP);
3068
3069 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3070 return ERR_PTR(-EINVAL);
3071
3072 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3073 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3074 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3075 return ERR_PTR(-EINVAL);
3076
3077 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3078 return ERR_PTR(-EINVAL);
3079
3080 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3081 if (n_entries < 0)
3082 return ERR_PTR(n_entries);
3083
3084 if (n_entries > wiphy->max_acl_mac_addrs)
3085 return ERR_PTR(-ENOTSUPP);
3086
3087 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3088 GFP_KERNEL);
3089 if (!acl)
3090 return ERR_PTR(-ENOMEM);
3091
3092 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3093 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3094 i++;
3095 }
3096
3097 acl->n_acl_entries = n_entries;
3098 acl->acl_policy = acl_policy;
3099
3100 return acl;
3101}
3102
3103static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3104{
3105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3106 struct net_device *dev = info->user_ptr[1];
3107 struct cfg80211_acl_data *acl;
3108 int err;
3109
3110 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3111 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3112 return -EOPNOTSUPP;
3113
3114 if (!dev->ieee80211_ptr->beacon_interval)
3115 return -EINVAL;
3116
3117 acl = parse_acl_data(&rdev->wiphy, info);
3118 if (IS_ERR(acl))
3119 return PTR_ERR(acl);
3120
3121 err = rdev_set_mac_acl(rdev, dev, acl);
3122
3123 kfree(acl);
3124
3125 return err;
3126}
3127
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003128static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003129 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003130{
Johannes Berg88600202012-02-13 15:17:18 +01003131 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003132
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003133 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3134 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3135 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3136 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003137 return -EINVAL;
3138
Johannes Berg88600202012-02-13 15:17:18 +01003139 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003140
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003141 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3142 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3143 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003144 if (!bcn->head_len)
3145 return -EINVAL;
3146 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003147 }
3148
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003149 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3150 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3151 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003152 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003153 }
3154
Johannes Berg4c476992010-10-04 21:36:35 +02003155 if (!haveinfo)
3156 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003157
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003158 if (attrs[NL80211_ATTR_IE]) {
3159 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3160 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003161 }
3162
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003163 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003164 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003165 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003166 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003167 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003168 }
3169
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003170 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003171 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003172 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003173 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003174 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003175 }
3176
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003177 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3178 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3179 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003180 }
3181
Johannes Berg88600202012-02-13 15:17:18 +01003182 return 0;
3183}
3184
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003185static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3186 struct cfg80211_ap_settings *params)
3187{
3188 struct wireless_dev *wdev;
3189 bool ret = false;
3190
Johannes Berg89a54e42012-06-15 14:33:17 +02003191 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003192 if (wdev->iftype != NL80211_IFTYPE_AP &&
3193 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3194 continue;
3195
Johannes Berg683b6d32012-11-08 21:25:48 +01003196 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003197 continue;
3198
Johannes Berg683b6d32012-11-08 21:25:48 +01003199 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003200 ret = true;
3201 break;
3202 }
3203
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003204 return ret;
3205}
3206
Jouni Malinene39e5b52012-09-30 19:29:39 +03003207static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3208 enum nl80211_auth_type auth_type,
3209 enum nl80211_commands cmd)
3210{
3211 if (auth_type > NL80211_AUTHTYPE_MAX)
3212 return false;
3213
3214 switch (cmd) {
3215 case NL80211_CMD_AUTHENTICATE:
3216 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3217 auth_type == NL80211_AUTHTYPE_SAE)
3218 return false;
3219 return true;
3220 case NL80211_CMD_CONNECT:
3221 case NL80211_CMD_START_AP:
3222 /* SAE not supported yet */
3223 if (auth_type == NL80211_AUTHTYPE_SAE)
3224 return false;
3225 return true;
3226 default:
3227 return false;
3228 }
3229}
3230
Johannes Berg88600202012-02-13 15:17:18 +01003231static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3232{
3233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3234 struct net_device *dev = info->user_ptr[1];
3235 struct wireless_dev *wdev = dev->ieee80211_ptr;
3236 struct cfg80211_ap_settings params;
3237 int err;
3238
3239 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3240 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3241 return -EOPNOTSUPP;
3242
3243 if (!rdev->ops->start_ap)
3244 return -EOPNOTSUPP;
3245
3246 if (wdev->beacon_interval)
3247 return -EALREADY;
3248
3249 memset(&params, 0, sizeof(params));
3250
3251 /* these are required for START_AP */
3252 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3253 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3254 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3255 return -EINVAL;
3256
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003257 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003258 if (err)
3259 return err;
3260
3261 params.beacon_interval =
3262 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3263 params.dtim_period =
3264 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3265
3266 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3267 if (err)
3268 return err;
3269
3270 /*
3271 * In theory, some of these attributes should be required here
3272 * but since they were not used when the command was originally
3273 * added, keep them optional for old user space programs to let
3274 * them continue to work with drivers that do not need the
3275 * additional information -- drivers must check!
3276 */
3277 if (info->attrs[NL80211_ATTR_SSID]) {
3278 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3279 params.ssid_len =
3280 nla_len(info->attrs[NL80211_ATTR_SSID]);
3281 if (params.ssid_len == 0 ||
3282 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3283 return -EINVAL;
3284 }
3285
3286 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3287 params.hidden_ssid = nla_get_u32(
3288 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3289 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3290 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3291 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3292 return -EINVAL;
3293 }
3294
3295 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3296
3297 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3298 params.auth_type = nla_get_u32(
3299 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003300 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3301 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003302 return -EINVAL;
3303 } else
3304 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3305
3306 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3307 NL80211_MAX_NR_CIPHER_SUITES);
3308 if (err)
3309 return err;
3310
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303311 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3312 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3313 return -EOPNOTSUPP;
3314 params.inactivity_timeout = nla_get_u16(
3315 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3316 }
3317
Johannes Berg53cabad2012-11-14 15:17:28 +01003318 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3319 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3320 return -EINVAL;
3321 params.p2p_ctwindow =
3322 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3323 if (params.p2p_ctwindow > 127)
3324 return -EINVAL;
3325 if (params.p2p_ctwindow != 0 &&
3326 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3327 return -EINVAL;
3328 }
3329
3330 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3331 u8 tmp;
3332
3333 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3334 return -EINVAL;
3335 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3336 if (tmp > 1)
3337 return -EINVAL;
3338 params.p2p_opp_ps = tmp;
3339 if (params.p2p_opp_ps != 0 &&
3340 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3341 return -EINVAL;
3342 }
3343
Johannes Bergaa430da2012-05-16 23:50:18 +02003344 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003345 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3346 if (err)
3347 return err;
3348 } else if (wdev->preset_chandef.chan) {
3349 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003350 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003351 return -EINVAL;
3352
Ilan Peer174e0cd2014-02-23 09:13:01 +02003353 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3354 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003355 return -EINVAL;
3356
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303357 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3358 params.acl = parse_acl_data(&rdev->wiphy, info);
3359 if (IS_ERR(params.acl))
3360 return PTR_ERR(params.acl);
3361 }
3362
Eliad Peller18998c32014-09-10 14:07:34 +03003363 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3364 params.smps_mode =
3365 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3366 switch (params.smps_mode) {
3367 case NL80211_SMPS_OFF:
3368 break;
3369 case NL80211_SMPS_STATIC:
3370 if (!(rdev->wiphy.features &
3371 NL80211_FEATURE_STATIC_SMPS))
3372 return -EINVAL;
3373 break;
3374 case NL80211_SMPS_DYNAMIC:
3375 if (!(rdev->wiphy.features &
3376 NL80211_FEATURE_DYNAMIC_SMPS))
3377 return -EINVAL;
3378 break;
3379 default:
3380 return -EINVAL;
3381 }
3382 } else {
3383 params.smps_mode = NL80211_SMPS_OFF;
3384 }
3385
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003386 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003387 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003388 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003389 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003390 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003391 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003392 wdev->ssid_len = params.ssid_len;
3393 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003394 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003395 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303396
3397 kfree(params.acl);
3398
Johannes Berg56d18932011-05-09 18:41:15 +02003399 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003400}
3401
Johannes Berg88600202012-02-13 15:17:18 +01003402static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3403{
3404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3405 struct net_device *dev = info->user_ptr[1];
3406 struct wireless_dev *wdev = dev->ieee80211_ptr;
3407 struct cfg80211_beacon_data params;
3408 int err;
3409
3410 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3411 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3412 return -EOPNOTSUPP;
3413
3414 if (!rdev->ops->change_beacon)
3415 return -EOPNOTSUPP;
3416
3417 if (!wdev->beacon_interval)
3418 return -EINVAL;
3419
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003420 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003421 if (err)
3422 return err;
3423
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003424 wdev_lock(wdev);
3425 err = rdev_change_beacon(rdev, dev, &params);
3426 wdev_unlock(wdev);
3427
3428 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003429}
3430
3431static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003432{
Johannes Berg4c476992010-10-04 21:36:35 +02003433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3434 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003435
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003436 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003437}
3438
Johannes Berg5727ef12007-12-19 02:03:34 +01003439static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3440 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3441 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3442 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003443 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003444 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003445 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003446};
3447
Johannes Bergeccb8e82009-05-11 21:57:56 +03003448static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003449 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003450 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003451{
3452 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003453 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003454 int flag;
3455
Johannes Bergeccb8e82009-05-11 21:57:56 +03003456 /*
3457 * Try parsing the new attribute first so userspace
3458 * can specify both for older kernels.
3459 */
3460 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3461 if (nla) {
3462 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003463
Johannes Bergeccb8e82009-05-11 21:57:56 +03003464 sta_flags = nla_data(nla);
3465 params->sta_flags_mask = sta_flags->mask;
3466 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003467 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003468 if ((params->sta_flags_mask |
3469 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3470 return -EINVAL;
3471 return 0;
3472 }
3473
3474 /* if present, parse the old attribute */
3475
3476 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003477 if (!nla)
3478 return 0;
3479
3480 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3481 nla, sta_flags_policy))
3482 return -EINVAL;
3483
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003484 /*
3485 * Only allow certain flags for interface types so that
3486 * other attributes are silently ignored. Remember that
3487 * this is backward compatibility code with old userspace
3488 * and shouldn't be hit in other cases anyway.
3489 */
3490 switch (iftype) {
3491 case NL80211_IFTYPE_AP:
3492 case NL80211_IFTYPE_AP_VLAN:
3493 case NL80211_IFTYPE_P2P_GO:
3494 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3495 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3496 BIT(NL80211_STA_FLAG_WME) |
3497 BIT(NL80211_STA_FLAG_MFP);
3498 break;
3499 case NL80211_IFTYPE_P2P_CLIENT:
3500 case NL80211_IFTYPE_STATION:
3501 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3502 BIT(NL80211_STA_FLAG_TDLS_PEER);
3503 break;
3504 case NL80211_IFTYPE_MESH_POINT:
3505 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3506 BIT(NL80211_STA_FLAG_MFP) |
3507 BIT(NL80211_STA_FLAG_AUTHORIZED);
3508 default:
3509 return -EINVAL;
3510 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003511
Johannes Berg3383b5a2012-05-10 20:14:43 +02003512 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3513 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003514 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003515
Johannes Berg3383b5a2012-05-10 20:14:43 +02003516 /* no longer support new API additions in old API */
3517 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3518 return -EINVAL;
3519 }
3520 }
3521
Johannes Berg5727ef12007-12-19 02:03:34 +01003522 return 0;
3523}
3524
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003525static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3526 int attr)
3527{
3528 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003529 u32 bitrate;
3530 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003531
3532 rate = nla_nest_start(msg, attr);
3533 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003534 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003535
3536 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3537 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003538 /* report 16-bit bitrate only if we can */
3539 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003540 if (bitrate > 0 &&
3541 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3542 return false;
3543 if (bitrate_compat > 0 &&
3544 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3545 return false;
3546
3547 if (info->flags & RATE_INFO_FLAGS_MCS) {
3548 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3549 return false;
3550 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3551 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3552 return false;
3553 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3554 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3555 return false;
3556 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3557 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3558 return false;
3559 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3560 return false;
3561 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3562 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3563 return false;
3564 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3565 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3566 return false;
3567 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3568 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3569 return false;
3570 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3571 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3572 return false;
3573 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3574 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3575 return false;
3576 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003577
3578 nla_nest_end(msg, rate);
3579 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003580}
3581
Felix Fietkau119363c2013-04-22 16:29:30 +02003582static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3583 int id)
3584{
3585 void *attr;
3586 int i = 0;
3587
3588 if (!mask)
3589 return true;
3590
3591 attr = nla_nest_start(msg, id);
3592 if (!attr)
3593 return false;
3594
3595 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3596 if (!(mask & BIT(i)))
3597 continue;
3598
3599 if (nla_put_u8(msg, i, signal[i]))
3600 return false;
3601 }
3602
3603 nla_nest_end(msg, attr);
3604
3605 return true;
3606}
3607
Eric W. Biederman15e47302012-09-07 20:12:54 +00003608static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003609 int flags,
3610 struct cfg80211_registered_device *rdev,
3611 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003612 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003613{
3614 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003615 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003616
Eric W. Biederman15e47302012-09-07 20:12:54 +00003617 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003618 if (!hdr)
3619 return -1;
3620
David S. Miller9360ffd2012-03-29 04:41:26 -04003621 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3622 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3623 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3624 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003625
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003626 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3627 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003628 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003629 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3630 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3631 sinfo->connected_time))
3632 goto nla_put_failure;
3633 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3634 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3635 sinfo->inactive_time))
3636 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003637 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3638 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003639 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003640 (u32)sinfo->rx_bytes))
3641 goto nla_put_failure;
3642 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003643 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003644 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3645 (u32)sinfo->tx_bytes))
3646 goto nla_put_failure;
3647 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3648 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003649 sinfo->rx_bytes))
3650 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003651 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3652 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003653 sinfo->tx_bytes))
3654 goto nla_put_failure;
3655 if ((sinfo->filled & STATION_INFO_LLID) &&
3656 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3657 goto nla_put_failure;
3658 if ((sinfo->filled & STATION_INFO_PLID) &&
3659 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3660 goto nla_put_failure;
3661 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3662 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3663 sinfo->plink_state))
3664 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003665 switch (rdev->wiphy.signal_type) {
3666 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003667 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3668 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3669 sinfo->signal))
3670 goto nla_put_failure;
3671 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3672 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3673 sinfo->signal_avg))
3674 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003675 break;
3676 default:
3677 break;
3678 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003679 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3680 if (!nl80211_put_signal(msg, sinfo->chains,
3681 sinfo->chain_signal,
3682 NL80211_STA_INFO_CHAIN_SIGNAL))
3683 goto nla_put_failure;
3684 }
3685 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3686 if (!nl80211_put_signal(msg, sinfo->chains,
3687 sinfo->chain_signal_avg,
3688 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3689 goto nla_put_failure;
3690 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003691 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003692 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3693 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003694 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003695 }
3696 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3697 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3698 NL80211_STA_INFO_RX_BITRATE))
3699 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003700 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003701 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3702 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3703 sinfo->rx_packets))
3704 goto nla_put_failure;
3705 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3706 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3707 sinfo->tx_packets))
3708 goto nla_put_failure;
3709 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3710 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3711 sinfo->tx_retries))
3712 goto nla_put_failure;
3713 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3714 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3715 sinfo->tx_failed))
3716 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003717 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3718 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3719 sinfo->expected_throughput))
3720 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003721 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3722 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3723 sinfo->beacon_loss_count))
3724 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003725 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3726 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3727 sinfo->local_pm))
3728 goto nla_put_failure;
3729 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3730 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3731 sinfo->peer_pm))
3732 goto nla_put_failure;
3733 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3734 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3735 sinfo->nonpeer_pm))
3736 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003737 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3738 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3739 if (!bss_param)
3740 goto nla_put_failure;
3741
David S. Miller9360ffd2012-03-29 04:41:26 -04003742 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3743 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3744 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3745 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3746 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3747 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3748 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3749 sinfo->bss_param.dtim_period) ||
3750 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3751 sinfo->bss_param.beacon_interval))
3752 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003753
3754 nla_nest_end(msg, bss_param);
3755 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003756 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3757 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3758 sizeof(struct nl80211_sta_flag_update),
3759 &sinfo->sta_flags))
3760 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003761 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3762 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3763 sinfo->t_offset))
3764 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003765 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003766
David S. Miller9360ffd2012-03-29 04:41:26 -04003767 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3768 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3769 sinfo->assoc_req_ies))
3770 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003771
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003772 return genlmsg_end(msg, hdr);
3773
3774 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003775 genlmsg_cancel(msg, hdr);
3776 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003777}
3778
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003779static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003780 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003781{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003782 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003783 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003784 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003785 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003786 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003787 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003788
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003789 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003790 if (err)
3791 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003792
Johannes Berg97990a02013-04-19 01:02:55 +02003793 if (!wdev->netdev) {
3794 err = -EINVAL;
3795 goto out_err;
3796 }
3797
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003798 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003799 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003800 goto out_err;
3801 }
3802
Johannes Bergbba95fe2008-07-29 13:22:51 +02003803 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003804 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003805 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003806 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003807 if (err == -ENOENT)
3808 break;
3809 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003810 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003811
3812 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003813 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003814 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003815 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003816 &sinfo) < 0)
3817 goto out;
3818
3819 sta_idx++;
3820 }
3821
3822
3823 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003824 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003825 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003826 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003827 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003828
3829 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003830}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003831
Johannes Berg5727ef12007-12-19 02:03:34 +01003832static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3833{
Johannes Berg4c476992010-10-04 21:36:35 +02003834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3835 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003836 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003837 struct sk_buff *msg;
3838 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003839 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003840
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003841 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003842
3843 if (!info->attrs[NL80211_ATTR_MAC])
3844 return -EINVAL;
3845
3846 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3847
Johannes Berg4c476992010-10-04 21:36:35 +02003848 if (!rdev->ops->get_station)
3849 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003850
Hila Gonene35e4d22012-06-27 17:19:42 +03003851 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003852 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003853 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003854
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003855 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003856 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003857 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003858
Eric W. Biederman15e47302012-09-07 20:12:54 +00003859 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003860 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003861 nlmsg_free(msg);
3862 return -ENOBUFS;
3863 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003864
Johannes Berg4c476992010-10-04 21:36:35 +02003865 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003866}
3867
Johannes Berg77ee7c82013-02-15 00:48:33 +01003868int cfg80211_check_station_change(struct wiphy *wiphy,
3869 struct station_parameters *params,
3870 enum cfg80211_station_type statype)
3871{
3872 if (params->listen_interval != -1)
3873 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003874 if (params->aid &&
3875 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003876 return -EINVAL;
3877
3878 /* When you run into this, adjust the code below for the new flag */
3879 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3880
3881 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003882 case CFG80211_STA_MESH_PEER_KERNEL:
3883 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003884 /*
3885 * No ignoring the TDLS flag here -- the userspace mesh
3886 * code doesn't have the bug of including TDLS in the
3887 * mask everywhere.
3888 */
3889 if (params->sta_flags_mask &
3890 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3891 BIT(NL80211_STA_FLAG_MFP) |
3892 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3893 return -EINVAL;
3894 break;
3895 case CFG80211_STA_TDLS_PEER_SETUP:
3896 case CFG80211_STA_TDLS_PEER_ACTIVE:
3897 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3898 return -EINVAL;
3899 /* ignore since it can't change */
3900 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3901 break;
3902 default:
3903 /* disallow mesh-specific things */
3904 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3905 return -EINVAL;
3906 if (params->local_pm)
3907 return -EINVAL;
3908 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3909 return -EINVAL;
3910 }
3911
3912 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3913 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3914 /* TDLS can't be set, ... */
3915 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3916 return -EINVAL;
3917 /*
3918 * ... but don't bother the driver with it. This works around
3919 * a hostapd/wpa_supplicant issue -- it always includes the
3920 * TLDS_PEER flag in the mask even for AP mode.
3921 */
3922 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3923 }
3924
3925 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3926 /* reject other things that can't change */
3927 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3928 return -EINVAL;
3929 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3930 return -EINVAL;
3931 if (params->supported_rates)
3932 return -EINVAL;
3933 if (params->ext_capab || params->ht_capa || params->vht_capa)
3934 return -EINVAL;
3935 }
3936
3937 if (statype != CFG80211_STA_AP_CLIENT) {
3938 if (params->vlan)
3939 return -EINVAL;
3940 }
3941
3942 switch (statype) {
3943 case CFG80211_STA_AP_MLME_CLIENT:
3944 /* Use this only for authorizing/unauthorizing a station */
3945 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3946 return -EOPNOTSUPP;
3947 break;
3948 case CFG80211_STA_AP_CLIENT:
3949 /* accept only the listed bits */
3950 if (params->sta_flags_mask &
3951 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3952 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3953 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3954 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3955 BIT(NL80211_STA_FLAG_WME) |
3956 BIT(NL80211_STA_FLAG_MFP)))
3957 return -EINVAL;
3958
3959 /* but authenticated/associated only if driver handles it */
3960 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3961 params->sta_flags_mask &
3962 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3963 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3964 return -EINVAL;
3965 break;
3966 case CFG80211_STA_IBSS:
3967 case CFG80211_STA_AP_STA:
3968 /* reject any changes other than AUTHORIZED */
3969 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3970 return -EINVAL;
3971 break;
3972 case CFG80211_STA_TDLS_PEER_SETUP:
3973 /* reject any changes other than AUTHORIZED or WME */
3974 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3975 BIT(NL80211_STA_FLAG_WME)))
3976 return -EINVAL;
3977 /* force (at least) rates when authorizing */
3978 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3979 !params->supported_rates)
3980 return -EINVAL;
3981 break;
3982 case CFG80211_STA_TDLS_PEER_ACTIVE:
3983 /* reject any changes */
3984 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003985 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003986 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3987 return -EINVAL;
3988 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003989 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003990 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3991 return -EINVAL;
3992 break;
3993 }
3994
3995 return 0;
3996}
3997EXPORT_SYMBOL(cfg80211_check_station_change);
3998
Johannes Berg5727ef12007-12-19 02:03:34 +01003999/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004000 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004001 */
Johannes Berg80b99892011-11-18 16:23:01 +01004002static struct net_device *get_vlan(struct genl_info *info,
4003 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004004{
Johannes Berg463d0182009-07-14 00:33:35 +02004005 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004006 struct net_device *v;
4007 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004008
Johannes Berg80b99892011-11-18 16:23:01 +01004009 if (!vlanattr)
4010 return NULL;
4011
4012 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4013 if (!v)
4014 return ERR_PTR(-ENODEV);
4015
4016 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4017 ret = -EINVAL;
4018 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004019 }
Johannes Berg80b99892011-11-18 16:23:01 +01004020
Johannes Berg77ee7c82013-02-15 00:48:33 +01004021 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4022 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4023 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4024 ret = -EINVAL;
4025 goto error;
4026 }
4027
Johannes Berg80b99892011-11-18 16:23:01 +01004028 if (!netif_running(v)) {
4029 ret = -ENETDOWN;
4030 goto error;
4031 }
4032
4033 return v;
4034 error:
4035 dev_put(v);
4036 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004037}
4038
Johannes Berg94e860f2014-01-20 23:58:15 +01004039static const struct nla_policy
4040nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004041 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4042 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4043};
4044
Johannes Bergff276692013-02-15 00:09:01 +01004045static int nl80211_parse_sta_wme(struct genl_info *info,
4046 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004047{
Jouni Malinendf881292013-02-14 21:10:54 +02004048 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4049 struct nlattr *nla;
4050 int err;
4051
Jouni Malinendf881292013-02-14 21:10:54 +02004052 /* parse WME attributes if present */
4053 if (!info->attrs[NL80211_ATTR_STA_WME])
4054 return 0;
4055
4056 nla = info->attrs[NL80211_ATTR_STA_WME];
4057 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4058 nl80211_sta_wme_policy);
4059 if (err)
4060 return err;
4061
4062 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4063 params->uapsd_queues = nla_get_u8(
4064 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4065 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4066 return -EINVAL;
4067
4068 if (tb[NL80211_STA_WME_MAX_SP])
4069 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4070
4071 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4072 return -EINVAL;
4073
4074 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4075
4076 return 0;
4077}
4078
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304079static int nl80211_parse_sta_channel_info(struct genl_info *info,
4080 struct station_parameters *params)
4081{
4082 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4083 params->supported_channels =
4084 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4085 params->supported_channels_len =
4086 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4087 /*
4088 * Need to include at least one (first channel, number of
4089 * channels) tuple for each subband, and must have proper
4090 * tuples for the rest of the data as well.
4091 */
4092 if (params->supported_channels_len < 2)
4093 return -EINVAL;
4094 if (params->supported_channels_len % 2)
4095 return -EINVAL;
4096 }
4097
4098 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4099 params->supported_oper_classes =
4100 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4101 params->supported_oper_classes_len =
4102 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4103 /*
4104 * The value of the Length field of the Supported Operating
4105 * Classes element is between 2 and 253.
4106 */
4107 if (params->supported_oper_classes_len < 2 ||
4108 params->supported_oper_classes_len > 253)
4109 return -EINVAL;
4110 }
4111 return 0;
4112}
4113
Johannes Bergff276692013-02-15 00:09:01 +01004114static int nl80211_set_station_tdls(struct genl_info *info,
4115 struct station_parameters *params)
4116{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304117 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004118 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004119 if (info->attrs[NL80211_ATTR_PEER_AID])
4120 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004121 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4122 params->ht_capa =
4123 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4124 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4125 params->vht_capa =
4126 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4127
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304128 err = nl80211_parse_sta_channel_info(info, params);
4129 if (err)
4130 return err;
4131
Johannes Bergff276692013-02-15 00:09:01 +01004132 return nl80211_parse_sta_wme(info, params);
4133}
4134
Johannes Berg5727ef12007-12-19 02:03:34 +01004135static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4136{
Johannes Berg4c476992010-10-04 21:36:35 +02004137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004138 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004139 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004140 u8 *mac_addr;
4141 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004142
4143 memset(&params, 0, sizeof(params));
4144
4145 params.listen_interval = -1;
4146
Johannes Berg77ee7c82013-02-15 00:48:33 +01004147 if (!rdev->ops->change_station)
4148 return -EOPNOTSUPP;
4149
Johannes Berg5727ef12007-12-19 02:03:34 +01004150 if (info->attrs[NL80211_ATTR_STA_AID])
4151 return -EINVAL;
4152
4153 if (!info->attrs[NL80211_ATTR_MAC])
4154 return -EINVAL;
4155
4156 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4157
4158 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4159 params.supported_rates =
4160 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4161 params.supported_rates_len =
4162 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4163 }
4164
Jouni Malinen9d62a982013-02-14 21:10:13 +02004165 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4166 params.capability =
4167 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4168 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4169 }
4170
4171 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4172 params.ext_capab =
4173 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4174 params.ext_capab_len =
4175 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4176 }
4177
Jouni Malinendf881292013-02-14 21:10:54 +02004178 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004179 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004180
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004181 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004182 return -EINVAL;
4183
Johannes Bergf8bacc22013-02-14 23:27:01 +01004184 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004185 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004186 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4187 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4188 return -EINVAL;
4189 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004190
Johannes Bergf8bacc22013-02-14 23:27:01 +01004191 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004192 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004193 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4194 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4195 return -EINVAL;
4196 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4197 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004198
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004199 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4200 enum nl80211_mesh_power_mode pm = nla_get_u32(
4201 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4202
4203 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4204 pm > NL80211_MESH_POWER_MAX)
4205 return -EINVAL;
4206
4207 params.local_pm = pm;
4208 }
4209
Johannes Berg77ee7c82013-02-15 00:48:33 +01004210 /* Include parameters for TDLS peer (will check later) */
4211 err = nl80211_set_station_tdls(info, &params);
4212 if (err)
4213 return err;
4214
4215 params.vlan = get_vlan(info, rdev);
4216 if (IS_ERR(params.vlan))
4217 return PTR_ERR(params.vlan);
4218
Johannes Berga97f4422009-06-18 17:23:43 +02004219 switch (dev->ieee80211_ptr->iftype) {
4220 case NL80211_IFTYPE_AP:
4221 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004222 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004223 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004224 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004225 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004226 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004227 break;
4228 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004229 err = -EOPNOTSUPP;
4230 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004231 }
4232
Johannes Berg77ee7c82013-02-15 00:48:33 +01004233 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004234 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004235
Johannes Berg77ee7c82013-02-15 00:48:33 +01004236 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004237 if (params.vlan)
4238 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004239
Johannes Berg5727ef12007-12-19 02:03:34 +01004240 return err;
4241}
4242
4243static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4244{
Johannes Berg4c476992010-10-04 21:36:35 +02004245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004246 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004247 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004248 struct station_parameters params;
4249 u8 *mac_addr = NULL;
4250
4251 memset(&params, 0, sizeof(params));
4252
Johannes Berg984c3112013-02-14 23:43:25 +01004253 if (!rdev->ops->add_station)
4254 return -EOPNOTSUPP;
4255
Johannes Berg5727ef12007-12-19 02:03:34 +01004256 if (!info->attrs[NL80211_ATTR_MAC])
4257 return -EINVAL;
4258
Johannes Berg5727ef12007-12-19 02:03:34 +01004259 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4260 return -EINVAL;
4261
4262 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4263 return -EINVAL;
4264
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004265 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4266 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004267 return -EINVAL;
4268
Johannes Berg5727ef12007-12-19 02:03:34 +01004269 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4270 params.supported_rates =
4271 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4272 params.supported_rates_len =
4273 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4274 params.listen_interval =
4275 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004276
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004277 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004278 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004279 else
4280 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004281 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4282 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004283
Jouni Malinen9d62a982013-02-14 21:10:13 +02004284 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4285 params.capability =
4286 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4287 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4288 }
4289
4290 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4291 params.ext_capab =
4292 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4293 params.ext_capab_len =
4294 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4295 }
4296
Jouni Malinen36aedc902008-08-25 11:58:58 +03004297 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4298 params.ht_capa =
4299 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004300
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004301 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4302 params.vht_capa =
4303 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4304
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004305 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4306 params.opmode_notif_used = true;
4307 params.opmode_notif =
4308 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4309 }
4310
Johannes Bergf8bacc22013-02-14 23:27:01 +01004311 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004312 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004313 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4314 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4315 return -EINVAL;
4316 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004317
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304318 err = nl80211_parse_sta_channel_info(info, &params);
4319 if (err)
4320 return err;
4321
Johannes Bergff276692013-02-15 00:09:01 +01004322 err = nl80211_parse_sta_wme(info, &params);
4323 if (err)
4324 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004325
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004326 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004327 return -EINVAL;
4328
Johannes Berg77ee7c82013-02-15 00:48:33 +01004329 /* When you run into this, adjust the code below for the new flag */
4330 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4331
Johannes Bergbdd90d52011-12-14 12:20:27 +01004332 switch (dev->ieee80211_ptr->iftype) {
4333 case NL80211_IFTYPE_AP:
4334 case NL80211_IFTYPE_AP_VLAN:
4335 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004336 /* ignore WME attributes if iface/sta is not capable */
4337 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4338 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4339 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004340
Johannes Bergbdd90d52011-12-14 12:20:27 +01004341 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004342 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4343 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004344 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004345 /* but don't bother the driver with it */
4346 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004347
Johannes Bergd582cff2012-10-26 17:53:44 +02004348 /* allow authenticated/associated only if driver handles it */
4349 if (!(rdev->wiphy.features &
4350 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4351 params.sta_flags_mask &
4352 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4353 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4354 return -EINVAL;
4355
Johannes Bergbdd90d52011-12-14 12:20:27 +01004356 /* must be last in here for error handling */
4357 params.vlan = get_vlan(info, rdev);
4358 if (IS_ERR(params.vlan))
4359 return PTR_ERR(params.vlan);
4360 break;
4361 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004362 /* ignore uAPSD data */
4363 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4364
Johannes Bergd582cff2012-10-26 17:53:44 +02004365 /* associated is disallowed */
4366 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4367 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004368 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004369 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4370 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004371 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004372 break;
4373 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004374 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004375 /* ignore uAPSD data */
4376 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4377
Johannes Berg77ee7c82013-02-15 00:48:33 +01004378 /* these are disallowed */
4379 if (params.sta_flags_mask &
4380 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4381 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004382 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004383 /* Only TDLS peers can be added */
4384 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4385 return -EINVAL;
4386 /* Can only add if TDLS ... */
4387 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4388 return -EOPNOTSUPP;
4389 /* ... with external setup is supported */
4390 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4391 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004392 /*
4393 * Older wpa_supplicant versions always mark the TDLS peer
4394 * as authorized, but it shouldn't yet be.
4395 */
4396 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004397 break;
4398 default:
4399 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004400 }
4401
Johannes Bergbdd90d52011-12-14 12:20:27 +01004402 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004403
Hila Gonene35e4d22012-06-27 17:19:42 +03004404 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004405
Johannes Berg5727ef12007-12-19 02:03:34 +01004406 if (params.vlan)
4407 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004408 return err;
4409}
4410
4411static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4412{
Johannes Berg4c476992010-10-04 21:36:35 +02004413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4414 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004415 struct station_del_parameters params;
4416
4417 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004418
4419 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004420 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004421
Johannes Berge80cf852009-05-11 14:43:13 +02004422 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004423 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004424 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004425 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4426 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004427
Johannes Berg4c476992010-10-04 21:36:35 +02004428 if (!rdev->ops->del_station)
4429 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004430
Jouni Malinen98856862014-10-20 13:20:45 +03004431 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4432 params.subtype =
4433 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4434 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4435 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4436 return -EINVAL;
4437 } else {
4438 /* Default to Deauthentication frame */
4439 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4440 }
4441
4442 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4443 params.reason_code =
4444 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4445 if (params.reason_code == 0)
4446 return -EINVAL; /* 0 is reserved */
4447 } else {
4448 /* Default to reason code 2 */
4449 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4450 }
4451
Jouni Malinen89c771e2014-10-10 20:52:40 +03004452 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004453}
4454
Eric W. Biederman15e47302012-09-07 20:12:54 +00004455static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004456 int flags, struct net_device *dev,
4457 u8 *dst, u8 *next_hop,
4458 struct mpath_info *pinfo)
4459{
4460 void *hdr;
4461 struct nlattr *pinfoattr;
4462
Henning Rogge1ef4c852014-11-04 16:14:58 +01004463 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004464 if (!hdr)
4465 return -1;
4466
David S. Miller9360ffd2012-03-29 04:41:26 -04004467 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4468 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4469 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4470 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4471 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004472
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004473 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4474 if (!pinfoattr)
4475 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004476 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4477 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4478 pinfo->frame_qlen))
4479 goto nla_put_failure;
4480 if (((pinfo->filled & MPATH_INFO_SN) &&
4481 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4482 ((pinfo->filled & MPATH_INFO_METRIC) &&
4483 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4484 pinfo->metric)) ||
4485 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4486 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4487 pinfo->exptime)) ||
4488 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4489 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4490 pinfo->flags)) ||
4491 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4492 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4493 pinfo->discovery_timeout)) ||
4494 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4495 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4496 pinfo->discovery_retries)))
4497 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004498
4499 nla_nest_end(msg, pinfoattr);
4500
4501 return genlmsg_end(msg, hdr);
4502
4503 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004504 genlmsg_cancel(msg, hdr);
4505 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506}
4507
4508static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004509 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004510{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004511 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004512 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004513 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004514 u8 dst[ETH_ALEN];
4515 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004516 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004518
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004519 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004520 if (err)
4521 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004522
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004523 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004524 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004525 goto out_err;
4526 }
4527
Johannes Berg97990a02013-04-19 01:02:55 +02004528 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004529 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004530 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004531 }
4532
Johannes Bergbba95fe2008-07-29 13:22:51 +02004533 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004534 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004535 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004536 if (err == -ENOENT)
4537 break;
4538 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004539 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004540
Eric W. Biederman15e47302012-09-07 20:12:54 +00004541 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004542 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004543 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004544 &pinfo) < 0)
4545 goto out;
4546
4547 path_idx++;
4548 }
4549
4550
4551 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004552 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004553 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004554 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004555 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004556 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004557}
4558
4559static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4560{
Johannes Berg4c476992010-10-04 21:36:35 +02004561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004562 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004563 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004564 struct mpath_info pinfo;
4565 struct sk_buff *msg;
4566 u8 *dst = NULL;
4567 u8 next_hop[ETH_ALEN];
4568
4569 memset(&pinfo, 0, sizeof(pinfo));
4570
4571 if (!info->attrs[NL80211_ATTR_MAC])
4572 return -EINVAL;
4573
4574 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4575
Johannes Berg4c476992010-10-04 21:36:35 +02004576 if (!rdev->ops->get_mpath)
4577 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004578
Johannes Berg4c476992010-10-04 21:36:35 +02004579 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4580 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004581
Hila Gonene35e4d22012-06-27 17:19:42 +03004582 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004583 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004584 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004585
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004586 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004587 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004588 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004589
Eric W. Biederman15e47302012-09-07 20:12:54 +00004590 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004591 dev, dst, next_hop, &pinfo) < 0) {
4592 nlmsg_free(msg);
4593 return -ENOBUFS;
4594 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004595
Johannes Berg4c476992010-10-04 21:36:35 +02004596 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004597}
4598
4599static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4600{
Johannes Berg4c476992010-10-04 21:36:35 +02004601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4602 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004603 u8 *dst = NULL;
4604 u8 *next_hop = NULL;
4605
4606 if (!info->attrs[NL80211_ATTR_MAC])
4607 return -EINVAL;
4608
4609 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4610 return -EINVAL;
4611
4612 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4613 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4614
Johannes Berg4c476992010-10-04 21:36:35 +02004615 if (!rdev->ops->change_mpath)
4616 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004617
Johannes Berg4c476992010-10-04 21:36:35 +02004618 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4619 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004620
Hila Gonene35e4d22012-06-27 17:19:42 +03004621 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004622}
Johannes Berg4c476992010-10-04 21:36:35 +02004623
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004624static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4625{
Johannes Berg4c476992010-10-04 21:36:35 +02004626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4627 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004628 u8 *dst = NULL;
4629 u8 *next_hop = NULL;
4630
4631 if (!info->attrs[NL80211_ATTR_MAC])
4632 return -EINVAL;
4633
4634 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4635 return -EINVAL;
4636
4637 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4638 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4639
Johannes Berg4c476992010-10-04 21:36:35 +02004640 if (!rdev->ops->add_mpath)
4641 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004642
Johannes Berg4c476992010-10-04 21:36:35 +02004643 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4644 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004645
Hila Gonene35e4d22012-06-27 17:19:42 +03004646 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004647}
4648
4649static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4650{
Johannes Berg4c476992010-10-04 21:36:35 +02004651 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4652 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004653 u8 *dst = NULL;
4654
4655 if (info->attrs[NL80211_ATTR_MAC])
4656 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4657
Johannes Berg4c476992010-10-04 21:36:35 +02004658 if (!rdev->ops->del_mpath)
4659 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004660
Hila Gonene35e4d22012-06-27 17:19:42 +03004661 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004662}
4663
Henning Rogge66be7d22014-09-12 08:58:49 +02004664static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4665{
4666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4667 int err;
4668 struct net_device *dev = info->user_ptr[1];
4669 struct mpath_info pinfo;
4670 struct sk_buff *msg;
4671 u8 *dst = NULL;
4672 u8 mpp[ETH_ALEN];
4673
4674 memset(&pinfo, 0, sizeof(pinfo));
4675
4676 if (!info->attrs[NL80211_ATTR_MAC])
4677 return -EINVAL;
4678
4679 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4680
4681 if (!rdev->ops->get_mpp)
4682 return -EOPNOTSUPP;
4683
4684 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4685 return -EOPNOTSUPP;
4686
4687 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4688 if (err)
4689 return err;
4690
4691 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4692 if (!msg)
4693 return -ENOMEM;
4694
4695 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4696 dev, dst, mpp, &pinfo) < 0) {
4697 nlmsg_free(msg);
4698 return -ENOBUFS;
4699 }
4700
4701 return genlmsg_reply(msg, info);
4702}
4703
4704static int nl80211_dump_mpp(struct sk_buff *skb,
4705 struct netlink_callback *cb)
4706{
4707 struct mpath_info pinfo;
4708 struct cfg80211_registered_device *rdev;
4709 struct wireless_dev *wdev;
4710 u8 dst[ETH_ALEN];
4711 u8 mpp[ETH_ALEN];
4712 int path_idx = cb->args[2];
4713 int err;
4714
4715 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4716 if (err)
4717 return err;
4718
4719 if (!rdev->ops->dump_mpp) {
4720 err = -EOPNOTSUPP;
4721 goto out_err;
4722 }
4723
4724 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4725 err = -EOPNOTSUPP;
4726 goto out_err;
4727 }
4728
4729 while (1) {
4730 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4731 mpp, &pinfo);
4732 if (err == -ENOENT)
4733 break;
4734 if (err)
4735 goto out_err;
4736
4737 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4738 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4739 wdev->netdev, dst, mpp,
4740 &pinfo) < 0)
4741 goto out;
4742
4743 path_idx++;
4744 }
4745
4746 out:
4747 cb->args[2] = path_idx;
4748 err = skb->len;
4749 out_err:
4750 nl80211_finish_wdev_dump(rdev);
4751 return err;
4752}
4753
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004754static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4755{
Johannes Berg4c476992010-10-04 21:36:35 +02004756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4757 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004758 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004759 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004760 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004761
4762 memset(&params, 0, sizeof(params));
4763 /* default to not changing parameters */
4764 params.use_cts_prot = -1;
4765 params.use_short_preamble = -1;
4766 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004767 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004768 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004769 params.p2p_ctwindow = -1;
4770 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004771
4772 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4773 params.use_cts_prot =
4774 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4775 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4776 params.use_short_preamble =
4777 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4778 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4779 params.use_short_slot_time =
4780 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004781 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4782 params.basic_rates =
4783 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4784 params.basic_rates_len =
4785 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4786 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004787 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4788 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004789 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4790 params.ht_opmode =
4791 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004792
Johannes Berg53cabad2012-11-14 15:17:28 +01004793 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4794 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4795 return -EINVAL;
4796 params.p2p_ctwindow =
4797 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4798 if (params.p2p_ctwindow < 0)
4799 return -EINVAL;
4800 if (params.p2p_ctwindow != 0 &&
4801 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4802 return -EINVAL;
4803 }
4804
4805 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4806 u8 tmp;
4807
4808 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4809 return -EINVAL;
4810 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4811 if (tmp > 1)
4812 return -EINVAL;
4813 params.p2p_opp_ps = tmp;
4814 if (params.p2p_opp_ps &&
4815 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4816 return -EINVAL;
4817 }
4818
Johannes Berg4c476992010-10-04 21:36:35 +02004819 if (!rdev->ops->change_bss)
4820 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004821
Johannes Berg074ac8d2010-09-16 14:58:22 +02004822 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004823 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4824 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004825
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004826 wdev_lock(wdev);
4827 err = rdev_change_bss(rdev, dev, &params);
4828 wdev_unlock(wdev);
4829
4830 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004831}
4832
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004833static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004834 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4835 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4836 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4837 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4838 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4839 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004840 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004841};
4842
4843static int parse_reg_rule(struct nlattr *tb[],
4844 struct ieee80211_reg_rule *reg_rule)
4845{
4846 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4847 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4848
4849 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4850 return -EINVAL;
4851 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4852 return -EINVAL;
4853 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4854 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004855 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4856 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004857 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4858 return -EINVAL;
4859
4860 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4861
4862 freq_range->start_freq_khz =
4863 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4864 freq_range->end_freq_khz =
4865 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004866 freq_range->max_bandwidth_khz =
4867 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004868
4869 power_rule->max_eirp =
4870 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4871
4872 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4873 power_rule->max_antenna_gain =
4874 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4875
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004876 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4877 reg_rule->dfs_cac_ms =
4878 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4879
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004880 return 0;
4881}
4882
4883static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4884{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004885 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004886 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004887
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004888 /*
4889 * You should only get this when cfg80211 hasn't yet initialized
4890 * completely when built-in to the kernel right between the time
4891 * window between nl80211_init() and regulatory_init(), if that is
4892 * even possible.
4893 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004894 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004895 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004896
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004897 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4898 user_reg_hint_type =
4899 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4900 else
4901 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4902
4903 switch (user_reg_hint_type) {
4904 case NL80211_USER_REG_HINT_USER:
4905 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004906 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4907 return -EINVAL;
4908
4909 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4910 return regulatory_hint_user(data, user_reg_hint_type);
4911 case NL80211_USER_REG_HINT_INDOOR:
4912 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004913 default:
4914 return -EINVAL;
4915 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004916}
4917
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004918static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004919 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004920{
Johannes Berg4c476992010-10-04 21:36:35 +02004921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004922 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004923 struct wireless_dev *wdev = dev->ieee80211_ptr;
4924 struct mesh_config cur_params;
4925 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004926 void *hdr;
4927 struct nlattr *pinfoattr;
4928 struct sk_buff *msg;
4929
Johannes Berg29cbe682010-12-03 09:20:44 +01004930 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4931 return -EOPNOTSUPP;
4932
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004933 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004934 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004935
Johannes Berg29cbe682010-12-03 09:20:44 +01004936 wdev_lock(wdev);
4937 /* If not connected, get default parameters */
4938 if (!wdev->mesh_id_len)
4939 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4940 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004941 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004942 wdev_unlock(wdev);
4943
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004944 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004945 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004946
4947 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004948 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004949 if (!msg)
4950 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004951 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004952 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004953 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004954 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004955 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004956 if (!pinfoattr)
4957 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004958 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4959 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4960 cur_params.dot11MeshRetryTimeout) ||
4961 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4962 cur_params.dot11MeshConfirmTimeout) ||
4963 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4964 cur_params.dot11MeshHoldingTimeout) ||
4965 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4966 cur_params.dot11MeshMaxPeerLinks) ||
4967 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4968 cur_params.dot11MeshMaxRetries) ||
4969 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4970 cur_params.dot11MeshTTL) ||
4971 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4972 cur_params.element_ttl) ||
4973 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4974 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004975 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4976 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004977 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4978 cur_params.dot11MeshHWMPmaxPREQretries) ||
4979 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4980 cur_params.path_refresh_time) ||
4981 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4982 cur_params.min_discovery_timeout) ||
4983 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4984 cur_params.dot11MeshHWMPactivePathTimeout) ||
4985 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4986 cur_params.dot11MeshHWMPpreqMinInterval) ||
4987 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4988 cur_params.dot11MeshHWMPperrMinInterval) ||
4989 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4990 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4991 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4992 cur_params.dot11MeshHWMPRootMode) ||
4993 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4994 cur_params.dot11MeshHWMPRannInterval) ||
4995 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4996 cur_params.dot11MeshGateAnnouncementProtocol) ||
4997 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4998 cur_params.dot11MeshForwarding) ||
4999 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005000 cur_params.rssi_threshold) ||
5001 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005002 cur_params.ht_opmode) ||
5003 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5004 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5005 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005006 cur_params.dot11MeshHWMProotInterval) ||
5007 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005008 cur_params.dot11MeshHWMPconfirmationInterval) ||
5009 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5010 cur_params.power_mode) ||
5011 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005012 cur_params.dot11MeshAwakeWindowDuration) ||
5013 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5014 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005015 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005016 nla_nest_end(msg, pinfoattr);
5017 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005018 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005019
Johannes Berg3b858752009-03-12 09:55:09 +01005020 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005021 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005022 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005023 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005024 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005025}
5026
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005027static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005028 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5029 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5030 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5031 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5032 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5033 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005034 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005035 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005036 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005037 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5038 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5039 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5040 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5041 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005042 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005043 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005044 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005045 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005046 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005047 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005048 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5049 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005050 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5051 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005052 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005053 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5054 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005055 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005056};
5057
Javier Cardonac80d5452010-12-16 17:37:49 -08005058static const struct nla_policy
5059 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005060 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005061 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5062 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005063 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005064 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005065 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005066 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005067 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005068 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005069};
5070
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005071static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005072 struct mesh_config *cfg,
5073 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005074{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005075 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005076 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005077
Marco Porschea54fba2013-01-07 16:04:48 +01005078#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5079do { \
5080 if (tb[attr]) { \
5081 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5082 return -EINVAL; \
5083 cfg->param = fn(tb[attr]); \
5084 mask |= (1 << (attr - 1)); \
5085 } \
5086} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005087
5088
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005089 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005090 return -EINVAL;
5091 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005092 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005093 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005094 return -EINVAL;
5095
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005096 /* This makes sure that there aren't more than 32 mesh config
5097 * parameters (otherwise our bitfield scheme would not work.) */
5098 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5099
5100 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005101 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005102 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5103 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005104 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005105 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5106 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005107 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005108 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5109 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005110 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005111 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5112 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005113 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005114 mask, NL80211_MESHCONF_MAX_RETRIES,
5115 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005116 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005117 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005118 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005119 mask, NL80211_MESHCONF_ELEMENT_TTL,
5120 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005121 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005122 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5123 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005124 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5125 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005126 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5127 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005128 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005129 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5130 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005131 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005132 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5133 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005134 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005135 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5136 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005137 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5138 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005139 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5140 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005141 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005142 1, 65535, mask,
5143 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005144 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005145 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005146 1, 65535, mask,
5147 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005148 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005149 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005150 dot11MeshHWMPnetDiameterTraversalTime,
5151 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005152 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5153 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005154 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5155 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5156 nla_get_u8);
5157 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5158 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005159 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005160 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005161 dot11MeshGateAnnouncementProtocol, 0, 1,
5162 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005163 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005164 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005165 mask, NL80211_MESHCONF_FORWARDING,
5166 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005167 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005168 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005169 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005170 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005171 mask, NL80211_MESHCONF_HT_OPMODE,
5172 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005173 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005174 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005175 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5176 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005177 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005178 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5179 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005180 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005181 dot11MeshHWMPconfirmationInterval,
5182 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005183 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5184 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005185 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5186 NL80211_MESH_POWER_ACTIVE,
5187 NL80211_MESH_POWER_MAX,
5188 mask, NL80211_MESHCONF_POWER_MODE,
5189 nla_get_u32);
5190 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5191 0, 65535, mask,
5192 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005193 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5194 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5195 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005196 if (mask_out)
5197 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005198
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005199 return 0;
5200
5201#undef FILL_IN_MESH_PARAM_IF_SET
5202}
5203
Javier Cardonac80d5452010-12-16 17:37:49 -08005204static int nl80211_parse_mesh_setup(struct genl_info *info,
5205 struct mesh_setup *setup)
5206{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005207 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005208 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5209
5210 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5211 return -EINVAL;
5212 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5213 info->attrs[NL80211_ATTR_MESH_SETUP],
5214 nl80211_mesh_setup_params_policy))
5215 return -EINVAL;
5216
Javier Cardonad299a1f2012-03-31 11:31:33 -07005217 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5218 setup->sync_method =
5219 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5220 IEEE80211_SYNC_METHOD_VENDOR :
5221 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5222
Javier Cardonac80d5452010-12-16 17:37:49 -08005223 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5224 setup->path_sel_proto =
5225 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5226 IEEE80211_PATH_PROTOCOL_VENDOR :
5227 IEEE80211_PATH_PROTOCOL_HWMP;
5228
5229 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5230 setup->path_metric =
5231 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5232 IEEE80211_PATH_METRIC_VENDOR :
5233 IEEE80211_PATH_METRIC_AIRTIME;
5234
Javier Cardona581a8b02011-04-07 15:08:27 -07005235
5236 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005237 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005238 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005239 if (!is_valid_ie_attr(ieattr))
5240 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005241 setup->ie = nla_data(ieattr);
5242 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005243 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005244 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5245 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5246 return -EINVAL;
5247 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005248 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5249 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005250 if (setup->is_secure)
5251 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005252
Colleen Twitty6e16d902013-05-08 11:45:59 -07005253 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5254 if (!setup->user_mpm)
5255 return -EINVAL;
5256 setup->auth_id =
5257 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5258 }
5259
Javier Cardonac80d5452010-12-16 17:37:49 -08005260 return 0;
5261}
5262
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005263static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005264 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005265{
5266 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5267 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005268 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005269 struct mesh_config cfg;
5270 u32 mask;
5271 int err;
5272
Johannes Berg29cbe682010-12-03 09:20:44 +01005273 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5274 return -EOPNOTSUPP;
5275
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005276 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005277 return -EOPNOTSUPP;
5278
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005279 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005280 if (err)
5281 return err;
5282
Johannes Berg29cbe682010-12-03 09:20:44 +01005283 wdev_lock(wdev);
5284 if (!wdev->mesh_id_len)
5285 err = -ENOLINK;
5286
5287 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005288 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005289
5290 wdev_unlock(wdev);
5291
5292 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005293}
5294
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005295static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5296{
Johannes Berg458f4f92012-12-06 15:47:38 +01005297 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005298 struct sk_buff *msg;
5299 void *hdr = NULL;
5300 struct nlattr *nl_reg_rules;
5301 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005302
5303 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005304 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005305
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005306 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005307 if (!msg)
5308 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005309
Eric W. Biederman15e47302012-09-07 20:12:54 +00005310 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005311 NL80211_CMD_GET_REG);
5312 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005313 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005314
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005315 if (reg_last_request_cell_base() &&
5316 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5317 NL80211_USER_REG_HINT_CELL_BASE))
5318 goto nla_put_failure;
5319
Johannes Berg458f4f92012-12-06 15:47:38 +01005320 rcu_read_lock();
5321 regdom = rcu_dereference(cfg80211_regdomain);
5322
5323 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5324 (regdom->dfs_region &&
5325 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5326 goto nla_put_failure_rcu;
5327
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005328 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5329 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005330 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005331
Johannes Berg458f4f92012-12-06 15:47:38 +01005332 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005333 struct nlattr *nl_reg_rule;
5334 const struct ieee80211_reg_rule *reg_rule;
5335 const struct ieee80211_freq_range *freq_range;
5336 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005337 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005338
Johannes Berg458f4f92012-12-06 15:47:38 +01005339 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005340 freq_range = &reg_rule->freq_range;
5341 power_rule = &reg_rule->power_rule;
5342
5343 nl_reg_rule = nla_nest_start(msg, i);
5344 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005345 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005346
Janusz Dziedzic97524822014-01-30 09:52:20 +01005347 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5348 if (!max_bandwidth_khz)
5349 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5350 reg_rule);
5351
David S. Miller9360ffd2012-03-29 04:41:26 -04005352 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5353 reg_rule->flags) ||
5354 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5355 freq_range->start_freq_khz) ||
5356 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5357 freq_range->end_freq_khz) ||
5358 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005359 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005360 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5361 power_rule->max_antenna_gain) ||
5362 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005363 power_rule->max_eirp) ||
5364 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5365 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005366 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005367
5368 nla_nest_end(msg, nl_reg_rule);
5369 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005370 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005371
5372 nla_nest_end(msg, nl_reg_rules);
5373
5374 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005375 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005376
Johannes Berg458f4f92012-12-06 15:47:38 +01005377nla_put_failure_rcu:
5378 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005379nla_put_failure:
5380 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005381put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005382 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005383 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005384}
5385
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005386static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5387{
5388 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5389 struct nlattr *nl_reg_rule;
5390 char *alpha2 = NULL;
5391 int rem_reg_rules = 0, r = 0;
5392 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005393 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005394 struct ieee80211_regdomain *rd = NULL;
5395
5396 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5397 return -EINVAL;
5398
5399 if (!info->attrs[NL80211_ATTR_REG_RULES])
5400 return -EINVAL;
5401
5402 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5403
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005404 if (info->attrs[NL80211_ATTR_DFS_REGION])
5405 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5406
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005407 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005408 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005409 num_rules++;
5410 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005411 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005412 }
5413
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005414 if (!reg_is_valid_request(alpha2))
5415 return -EINVAL;
5416
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005417 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005418 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005419
5420 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005421 if (!rd)
5422 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005423
5424 rd->n_reg_rules = num_rules;
5425 rd->alpha2[0] = alpha2[0];
5426 rd->alpha2[1] = alpha2[1];
5427
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005428 /*
5429 * Disable DFS master mode if the DFS region was
5430 * not supported or known on this kernel.
5431 */
5432 if (reg_supported_dfs_region(dfs_region))
5433 rd->dfs_region = dfs_region;
5434
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005435 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005436 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005437 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5438 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5439 reg_rule_policy);
5440 if (r)
5441 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005442 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5443 if (r)
5444 goto bad_reg;
5445
5446 rule_idx++;
5447
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005448 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5449 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005450 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005451 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005452 }
5453
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005454 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005455 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005456 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005457
Johannes Bergd2372b32008-10-24 20:32:20 +02005458 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005459 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005460 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005461}
5462
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005463static int validate_scan_freqs(struct nlattr *freqs)
5464{
5465 struct nlattr *attr1, *attr2;
5466 int n_channels = 0, tmp1, tmp2;
5467
5468 nla_for_each_nested(attr1, freqs, tmp1) {
5469 n_channels++;
5470 /*
5471 * Some hardware has a limited channel list for
5472 * scanning, and it is pretty much nonsensical
5473 * to scan for a channel twice, so disallow that
5474 * and don't require drivers to check that the
5475 * channel list they get isn't longer than what
5476 * they can scan, as long as they can scan all
5477 * the channels they registered at once.
5478 */
5479 nla_for_each_nested(attr2, freqs, tmp2)
5480 if (attr1 != attr2 &&
5481 nla_get_u32(attr1) == nla_get_u32(attr2))
5482 return 0;
5483 }
5484
5485 return n_channels;
5486}
5487
Johannes Bergad2b26a2014-06-12 21:39:05 +02005488static int nl80211_parse_random_mac(struct nlattr **attrs,
5489 u8 *mac_addr, u8 *mac_addr_mask)
5490{
5491 int i;
5492
5493 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5494 memset(mac_addr, 0, ETH_ALEN);
5495 memset(mac_addr_mask, 0, ETH_ALEN);
5496 mac_addr[0] = 0x2;
5497 mac_addr_mask[0] = 0x3;
5498
5499 return 0;
5500 }
5501
5502 /* need both or none */
5503 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5504 return -EINVAL;
5505
5506 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5507 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5508
5509 /* don't allow or configure an mcast address */
5510 if (!is_multicast_ether_addr(mac_addr_mask) ||
5511 is_multicast_ether_addr(mac_addr))
5512 return -EINVAL;
5513
5514 /*
5515 * allow users to pass a MAC address that has bits set outside
5516 * of the mask, but don't bother drivers with having to deal
5517 * with such bits
5518 */
5519 for (i = 0; i < ETH_ALEN; i++)
5520 mac_addr[i] &= mac_addr_mask[i];
5521
5522 return 0;
5523}
5524
Johannes Berg2a519312009-02-10 21:25:55 +01005525static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5526{
Johannes Berg4c476992010-10-04 21:36:35 +02005527 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005528 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005529 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005530 struct nlattr *attr;
5531 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005532 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005533 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005534
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005535 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5536 return -EINVAL;
5537
Johannes Berg79c97e92009-07-07 03:56:12 +02005538 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005539
Johannes Berg4c476992010-10-04 21:36:35 +02005540 if (!rdev->ops->scan)
5541 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005542
Johannes Bergf9d15d12014-01-22 11:14:19 +02005543 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005544 err = -EBUSY;
5545 goto unlock;
5546 }
Johannes Berg2a519312009-02-10 21:25:55 +01005547
5548 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005549 n_channels = validate_scan_freqs(
5550 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005551 if (!n_channels) {
5552 err = -EINVAL;
5553 goto unlock;
5554 }
Johannes Berg2a519312009-02-10 21:25:55 +01005555 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005556 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005557 }
5558
5559 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5560 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5561 n_ssids++;
5562
Johannes Bergf9f47522013-03-19 15:04:07 +01005563 if (n_ssids > wiphy->max_scan_ssids) {
5564 err = -EINVAL;
5565 goto unlock;
5566 }
Johannes Berg2a519312009-02-10 21:25:55 +01005567
Jouni Malinen70692ad2009-02-16 19:39:13 +02005568 if (info->attrs[NL80211_ATTR_IE])
5569 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5570 else
5571 ie_len = 0;
5572
Johannes Bergf9f47522013-03-19 15:04:07 +01005573 if (ie_len > wiphy->max_scan_ie_len) {
5574 err = -EINVAL;
5575 goto unlock;
5576 }
Johannes Berg18a83652009-03-31 12:12:05 +02005577
Johannes Berg2a519312009-02-10 21:25:55 +01005578 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005579 + sizeof(*request->ssids) * n_ssids
5580 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005581 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005582 if (!request) {
5583 err = -ENOMEM;
5584 goto unlock;
5585 }
Johannes Berg2a519312009-02-10 21:25:55 +01005586
Johannes Berg2a519312009-02-10 21:25:55 +01005587 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005588 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005589 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005590 if (ie_len) {
5591 if (request->ssids)
5592 request->ie = (void *)(request->ssids + n_ssids);
5593 else
5594 request->ie = (void *)(request->channels + n_channels);
5595 }
Johannes Berg2a519312009-02-10 21:25:55 +01005596
Johannes Berg584991d2009-11-02 13:32:03 +01005597 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005598 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5599 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005600 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005601 struct ieee80211_channel *chan;
5602
5603 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5604
5605 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005606 err = -EINVAL;
5607 goto out_free;
5608 }
Johannes Berg584991d2009-11-02 13:32:03 +01005609
5610 /* ignore disabled channels */
5611 if (chan->flags & IEEE80211_CHAN_DISABLED)
5612 continue;
5613
5614 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005615 i++;
5616 }
5617 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005618 enum ieee80211_band band;
5619
Johannes Berg2a519312009-02-10 21:25:55 +01005620 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005621 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5622 int j;
5623 if (!wiphy->bands[band])
5624 continue;
5625 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005626 struct ieee80211_channel *chan;
5627
5628 chan = &wiphy->bands[band]->channels[j];
5629
5630 if (chan->flags & IEEE80211_CHAN_DISABLED)
5631 continue;
5632
5633 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005634 i++;
5635 }
5636 }
5637 }
5638
Johannes Berg584991d2009-11-02 13:32:03 +01005639 if (!i) {
5640 err = -EINVAL;
5641 goto out_free;
5642 }
5643
5644 request->n_channels = i;
5645
Johannes Berg2a519312009-02-10 21:25:55 +01005646 i = 0;
5647 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5648 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005649 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005650 err = -EINVAL;
5651 goto out_free;
5652 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005653 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005654 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005655 i++;
5656 }
5657 }
5658
Jouni Malinen70692ad2009-02-16 19:39:13 +02005659 if (info->attrs[NL80211_ATTR_IE]) {
5660 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005661 memcpy((void *)request->ie,
5662 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005663 request->ie_len);
5664 }
5665
Johannes Berg34850ab2011-07-18 18:08:35 +02005666 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005667 if (wiphy->bands[i])
5668 request->rates[i] =
5669 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005670
5671 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5672 nla_for_each_nested(attr,
5673 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5674 tmp) {
5675 enum ieee80211_band band = nla_type(attr);
5676
Dan Carpenter84404622011-07-29 11:52:18 +03005677 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005678 err = -EINVAL;
5679 goto out_free;
5680 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005681
5682 if (!wiphy->bands[band])
5683 continue;
5684
Johannes Berg34850ab2011-07-18 18:08:35 +02005685 err = ieee80211_get_ratemask(wiphy->bands[band],
5686 nla_data(attr),
5687 nla_len(attr),
5688 &request->rates[band]);
5689 if (err)
5690 goto out_free;
5691 }
5692 }
5693
Sam Leffler46856bb2012-10-11 21:03:32 -07005694 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005695 request->flags = nla_get_u32(
5696 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005697 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5698 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005699 err = -EOPNOTSUPP;
5700 goto out_free;
5701 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005702
5703 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5704 if (!(wiphy->features &
5705 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5706 err = -EOPNOTSUPP;
5707 goto out_free;
5708 }
5709
5710 if (wdev->current_bss) {
5711 err = -EOPNOTSUPP;
5712 goto out_free;
5713 }
5714
5715 err = nl80211_parse_random_mac(info->attrs,
5716 request->mac_addr,
5717 request->mac_addr_mask);
5718 if (err)
5719 goto out_free;
5720 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005721 }
Sam Lefflered4737712012-10-11 21:03:31 -07005722
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305723 request->no_cck =
5724 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5725
Johannes Bergfd014282012-06-18 19:17:03 +02005726 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005727 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005728 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005729
Johannes Berg79c97e92009-07-07 03:56:12 +02005730 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005731 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005732
Johannes Berg463d0182009-07-14 00:33:35 +02005733 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005734 nl80211_send_scan_start(rdev, wdev);
5735 if (wdev->netdev)
5736 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005737 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005738 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005739 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005740 kfree(request);
5741 }
Johannes Berg3b858752009-03-12 09:55:09 +01005742
Johannes Bergf9f47522013-03-19 15:04:07 +01005743 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005744 return err;
5745}
5746
Luciano Coelho256da022014-11-10 16:13:46 +02005747static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005748nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005749 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005750{
5751 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005752 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005753 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005754 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005755 enum ieee80211_band band;
5756 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005757 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005758 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005759
Luciano Coelho256da022014-11-10 16:13:46 +02005760 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5761 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005762
Luciano Coelho256da022014-11-10 16:13:46 +02005763 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5764 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005765
Luciano Coelho256da022014-11-10 16:13:46 +02005766 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005767 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005768 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005769
Luciano Coelho256da022014-11-10 16:13:46 +02005770 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005771 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005772 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005773 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005774 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005775 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005776 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005777 }
5778
Luciano Coelho256da022014-11-10 16:13:46 +02005779 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5780 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005781 tmp)
5782 n_ssids++;
5783
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005784 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005785 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005786
Johannes Bergea73cbc2014-01-24 10:53:53 +01005787 /*
5788 * First, count the number of 'real' matchsets. Due to an issue with
5789 * the old implementation, matchsets containing only the RSSI attribute
5790 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5791 * RSSI for all matchsets, rather than their own matchset for reporting
5792 * all APs with a strong RSSI. This is needed to be compatible with
5793 * older userspace that treated a matchset with only the RSSI as the
5794 * global RSSI for all other matchsets - if there are other matchsets.
5795 */
Luciano Coelho256da022014-11-10 16:13:46 +02005796 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005797 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005798 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005799 tmp) {
5800 struct nlattr *rssi;
5801
5802 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5803 nla_data(attr), nla_len(attr),
5804 nl80211_match_policy);
5805 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02005806 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005807 /* add other standalone attributes here */
5808 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5809 n_match_sets++;
5810 continue;
5811 }
5812 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5813 if (rssi)
5814 default_match_rssi = nla_get_s32(rssi);
5815 }
5816 }
5817
5818 /* However, if there's no other matchset, add the RSSI one */
5819 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5820 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005821
5822 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02005823 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005824
Luciano Coelho256da022014-11-10 16:13:46 +02005825 if (attrs[NL80211_ATTR_IE])
5826 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005827 else
5828 ie_len = 0;
5829
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005830 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02005831 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005832
Luciano Coelho807f8a82011-05-11 17:09:35 +03005833 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005834 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005835 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005836 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005837 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02005838 if (!request)
5839 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005840
5841 if (n_ssids)
5842 request->ssids = (void *)&request->channels[n_channels];
5843 request->n_ssids = n_ssids;
5844 if (ie_len) {
5845 if (request->ssids)
5846 request->ie = (void *)(request->ssids + n_ssids);
5847 else
5848 request->ie = (void *)(request->channels + n_channels);
5849 }
5850
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005851 if (n_match_sets) {
5852 if (request->ie)
5853 request->match_sets = (void *)(request->ie + ie_len);
5854 else if (request->ssids)
5855 request->match_sets =
5856 (void *)(request->ssids + n_ssids);
5857 else
5858 request->match_sets =
5859 (void *)(request->channels + n_channels);
5860 }
5861 request->n_match_sets = n_match_sets;
5862
Luciano Coelho807f8a82011-05-11 17:09:35 +03005863 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005864 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005865 /* user specified, bail out if channel not found */
5866 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005867 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005868 tmp) {
5869 struct ieee80211_channel *chan;
5870
5871 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5872
5873 if (!chan) {
5874 err = -EINVAL;
5875 goto out_free;
5876 }
5877
5878 /* ignore disabled channels */
5879 if (chan->flags & IEEE80211_CHAN_DISABLED)
5880 continue;
5881
5882 request->channels[i] = chan;
5883 i++;
5884 }
5885 } else {
5886 /* all channels */
5887 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5888 int j;
5889 if (!wiphy->bands[band])
5890 continue;
5891 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5892 struct ieee80211_channel *chan;
5893
5894 chan = &wiphy->bands[band]->channels[j];
5895
5896 if (chan->flags & IEEE80211_CHAN_DISABLED)
5897 continue;
5898
5899 request->channels[i] = chan;
5900 i++;
5901 }
5902 }
5903 }
5904
5905 if (!i) {
5906 err = -EINVAL;
5907 goto out_free;
5908 }
5909
5910 request->n_channels = i;
5911
5912 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005913 if (attrs[NL80211_ATTR_SCAN_SSIDS]) {
5914 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005915 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005916 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005917 err = -EINVAL;
5918 goto out_free;
5919 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005920 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005921 memcpy(request->ssids[i].ssid, nla_data(attr),
5922 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005923 i++;
5924 }
5925 }
5926
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005927 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005928 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005929 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005930 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005931 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005932 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005933
Johannes Bergae811e22014-01-24 10:17:47 +01005934 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5935 nla_data(attr), nla_len(attr),
5936 nl80211_match_policy);
5937 if (err)
5938 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005939 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005940 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005941 if (WARN_ON(i >= n_match_sets)) {
5942 /* this indicates a programming error,
5943 * the loop above should have verified
5944 * things properly
5945 */
5946 err = -EINVAL;
5947 goto out_free;
5948 }
5949
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005950 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5951 err = -EINVAL;
5952 goto out_free;
5953 }
5954 memcpy(request->match_sets[i].ssid.ssid,
5955 nla_data(ssid), nla_len(ssid));
5956 request->match_sets[i].ssid.ssid_len =
5957 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005958 /* special attribute - old implemenation w/a */
5959 request->match_sets[i].rssi_thold =
5960 default_match_rssi;
5961 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5962 if (rssi)
5963 request->match_sets[i].rssi_thold =
5964 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005965 }
5966 i++;
5967 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005968
5969 /* there was no other matchset, so the RSSI one is alone */
5970 if (i == 0)
5971 request->match_sets[0].rssi_thold = default_match_rssi;
5972
5973 request->min_rssi_thold = INT_MAX;
5974 for (i = 0; i < n_match_sets; i++)
5975 request->min_rssi_thold =
5976 min(request->match_sets[i].rssi_thold,
5977 request->min_rssi_thold);
5978 } else {
5979 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005980 }
5981
Johannes Berg9900e482014-02-04 21:01:25 +01005982 if (ie_len) {
5983 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005984 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02005985 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03005986 request->ie_len);
5987 }
5988
Luciano Coelho256da022014-11-10 16:13:46 +02005989 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005990 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02005991 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005992 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5993 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005994 err = -EOPNOTSUPP;
5995 goto out_free;
5996 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005997
5998 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5999 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6000
6001 if (!wdev) /* must be net-detect */
6002 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6003
6004 if (!(wiphy->features & flg)) {
6005 err = -EOPNOTSUPP;
6006 goto out_free;
6007 }
6008
6009 if (wdev && wdev->current_bss) {
6010 err = -EOPNOTSUPP;
6011 goto out_free;
6012 }
6013
6014 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6015 request->mac_addr_mask);
6016 if (err)
6017 goto out_free;
6018 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006019 }
Sam Lefflered4737712012-10-11 21:03:31 -07006020
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006021 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006022 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006023
Luciano Coelho256da022014-11-10 16:13:46 +02006024 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006025
6026out_free:
6027 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006028 return ERR_PTR(err);
6029}
6030
6031static int nl80211_start_sched_scan(struct sk_buff *skb,
6032 struct genl_info *info)
6033{
6034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6035 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006036 struct wireless_dev *wdev = dev->ieee80211_ptr;
Luciano Coelho256da022014-11-10 16:13:46 +02006037 int err;
6038
6039 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6040 !rdev->ops->sched_scan_start)
6041 return -EOPNOTSUPP;
6042
6043 if (rdev->sched_scan_req)
6044 return -EINPROGRESS;
6045
Johannes Bergad2b26a2014-06-12 21:39:05 +02006046 rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006047 info->attrs);
6048 err = PTR_ERR_OR_ZERO(rdev->sched_scan_req);
6049 if (err)
6050 goto out_err;
6051
6052 err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req);
6053 if (err)
6054 goto out_free;
6055
6056 rdev->sched_scan_req->dev = dev;
6057 rdev->sched_scan_req->wiphy = &rdev->wiphy;
6058
6059 nl80211_send_sched_scan(rdev, dev,
6060 NL80211_CMD_START_SCHED_SCAN);
6061 return 0;
6062
6063out_free:
6064 kfree(rdev->sched_scan_req);
6065out_err:
6066 rdev->sched_scan_req = NULL;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006067 return err;
6068}
6069
6070static int nl80211_stop_sched_scan(struct sk_buff *skb,
6071 struct genl_info *info)
6072{
6073 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6074
6075 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6076 !rdev->ops->sched_scan_stop)
6077 return -EOPNOTSUPP;
6078
Johannes Berg5fe231e2013-05-08 21:45:15 +02006079 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006080}
6081
Simon Wunderlich04f39042013-02-08 18:16:19 +01006082static int nl80211_start_radar_detection(struct sk_buff *skb,
6083 struct genl_info *info)
6084{
6085 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6086 struct net_device *dev = info->user_ptr[1];
6087 struct wireless_dev *wdev = dev->ieee80211_ptr;
6088 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006089 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006090 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006091 int err;
6092
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006093 dfs_region = reg_get_dfs_region(wdev->wiphy);
6094 if (dfs_region == NL80211_DFS_UNSET)
6095 return -EINVAL;
6096
Simon Wunderlich04f39042013-02-08 18:16:19 +01006097 err = nl80211_parse_chandef(rdev, info, &chandef);
6098 if (err)
6099 return err;
6100
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006101 if (netif_carrier_ok(dev))
6102 return -EBUSY;
6103
Simon Wunderlich04f39042013-02-08 18:16:19 +01006104 if (wdev->cac_started)
6105 return -EBUSY;
6106
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006107 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006108 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006109 if (err < 0)
6110 return err;
6111
6112 if (err == 0)
6113 return -EINVAL;
6114
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006115 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006116 return -EINVAL;
6117
6118 if (!rdev->ops->start_radar_detection)
6119 return -EOPNOTSUPP;
6120
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006121 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6122 if (WARN_ON(!cac_time_ms))
6123 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6124
6125 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6126 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006127 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006128 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006129 wdev->cac_started = true;
6130 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006131 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006132 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006133 return err;
6134}
6135
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006136static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6137{
6138 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6139 struct net_device *dev = info->user_ptr[1];
6140 struct wireless_dev *wdev = dev->ieee80211_ptr;
6141 struct cfg80211_csa_settings params;
6142 /* csa_attrs is defined static to avoid waste of stack size - this
6143 * function is called under RTNL lock, so this should not be a problem.
6144 */
6145 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006146 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006147 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006148 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006149 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006150
6151 if (!rdev->ops->channel_switch ||
6152 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6153 return -EOPNOTSUPP;
6154
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006155 switch (dev->ieee80211_ptr->iftype) {
6156 case NL80211_IFTYPE_AP:
6157 case NL80211_IFTYPE_P2P_GO:
6158 need_new_beacon = true;
6159
6160 /* useless if AP is not running */
6161 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006162 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006163 break;
6164 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006165 if (!wdev->ssid_len)
6166 return -ENOTCONN;
6167 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006168 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006169 if (!wdev->mesh_id_len)
6170 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006171 break;
6172 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006173 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006174 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006175
6176 memset(&params, 0, sizeof(params));
6177
6178 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6179 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6180 return -EINVAL;
6181
6182 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006183 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006184 return -EINVAL;
6185
Luciano Coelho252e07c2014-10-08 09:48:34 +03006186 /* Even though the attribute is u32, the specification says
6187 * u8, so let's make sure we don't overflow.
6188 */
6189 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6190 if (cs_count > 255)
6191 return -EINVAL;
6192
6193 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006194
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006195 if (!need_new_beacon)
6196 goto skip_beacons;
6197
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006198 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6199 if (err)
6200 return err;
6201
6202 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6203 info->attrs[NL80211_ATTR_CSA_IES],
6204 nl80211_policy);
6205 if (err)
6206 return err;
6207
6208 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6209 if (err)
6210 return err;
6211
6212 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6213 return -EINVAL;
6214
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006215 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6216 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006217 return -EINVAL;
6218
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006219 params.n_counter_offsets_beacon = len / sizeof(u16);
6220 if (rdev->wiphy.max_num_csa_counters &&
6221 (params.n_counter_offsets_beacon >
6222 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006223 return -EINVAL;
6224
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006225 params.counter_offsets_beacon =
6226 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6227
6228 /* sanity checks - counters should fit and be the same */
6229 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6230 u16 offset = params.counter_offsets_beacon[i];
6231
6232 if (offset >= params.beacon_csa.tail_len)
6233 return -EINVAL;
6234
6235 if (params.beacon_csa.tail[offset] != params.count)
6236 return -EINVAL;
6237 }
6238
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006239 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006240 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6241 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006242 return -EINVAL;
6243
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006244 params.n_counter_offsets_presp = len / sizeof(u16);
6245 if (rdev->wiphy.max_num_csa_counters &&
6246 (params.n_counter_offsets_beacon >
6247 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006248 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006249
6250 params.counter_offsets_presp =
6251 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6252
6253 /* sanity checks - counters should fit and be the same */
6254 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6255 u16 offset = params.counter_offsets_presp[i];
6256
6257 if (offset >= params.beacon_csa.probe_resp_len)
6258 return -EINVAL;
6259
6260 if (params.beacon_csa.probe_resp[offset] !=
6261 params.count)
6262 return -EINVAL;
6263 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006264 }
6265
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006266skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006267 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6268 if (err)
6269 return err;
6270
Ilan Peer174e0cd2014-02-23 09:13:01 +02006271 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6272 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006273 return -EINVAL;
6274
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006275 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6276 &params.chandef,
6277 wdev->iftype);
6278 if (err < 0)
6279 return err;
6280
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006281 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006282 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006283
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006284 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6285 params.block_tx = true;
6286
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006287 wdev_lock(wdev);
6288 err = rdev_channel_switch(rdev, dev, &params);
6289 wdev_unlock(wdev);
6290
6291 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006292}
6293
Johannes Berg9720bb32011-06-21 09:45:33 +02006294static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6295 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006296 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006297 struct wireless_dev *wdev,
6298 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006299{
Johannes Berg48ab9052009-07-10 18:42:31 +02006300 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006301 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006302 void *hdr;
6303 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006304
6305 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006306
Eric W. Biederman15e47302012-09-07 20:12:54 +00006307 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006308 NL80211_CMD_NEW_SCAN_RESULTS);
6309 if (!hdr)
6310 return -1;
6311
Johannes Berg9720bb32011-06-21 09:45:33 +02006312 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6313
Johannes Berg97990a02013-04-19 01:02:55 +02006314 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6315 goto nla_put_failure;
6316 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006317 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6318 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006319 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6320 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006321
6322 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6323 if (!bss)
6324 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006325 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006326 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006327 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006328
6329 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006330 /* indicate whether we have probe response data or not */
6331 if (rcu_access_pointer(res->proberesp_ies) &&
6332 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6333 goto fail_unlock_rcu;
6334
6335 /* this pointer prefers to be pointed to probe response data
6336 * but is always valid
6337 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006338 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006339 if (ies) {
6340 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6341 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006342 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6343 ies->len, ies->data))
6344 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006345 }
Johannes Berg0e227082014-08-12 20:34:30 +02006346
6347 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006348 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006349 if (ies && ies->from_beacon) {
6350 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006351 goto fail_unlock_rcu;
6352 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6353 ies->len, ies->data))
6354 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006355 }
6356 rcu_read_unlock();
6357
David S. Miller9360ffd2012-03-29 04:41:26 -04006358 if (res->beacon_interval &&
6359 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6360 goto nla_put_failure;
6361 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6362 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006363 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006364 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6365 jiffies_to_msecs(jiffies - intbss->ts)))
6366 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006367
Johannes Berg77965c92009-02-18 18:45:06 +01006368 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006369 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006370 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6371 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006372 break;
6373 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006374 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6375 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006376 break;
6377 default:
6378 break;
6379 }
6380
Johannes Berg48ab9052009-07-10 18:42:31 +02006381 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006382 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006383 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006384 if (intbss == wdev->current_bss &&
6385 nla_put_u32(msg, NL80211_BSS_STATUS,
6386 NL80211_BSS_STATUS_ASSOCIATED))
6387 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006388 break;
6389 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006390 if (intbss == wdev->current_bss &&
6391 nla_put_u32(msg, NL80211_BSS_STATUS,
6392 NL80211_BSS_STATUS_IBSS_JOINED))
6393 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006394 break;
6395 default:
6396 break;
6397 }
6398
Johannes Berg2a519312009-02-10 21:25:55 +01006399 nla_nest_end(msg, bss);
6400
6401 return genlmsg_end(msg, hdr);
6402
Johannes Berg8cef2c92013-02-05 16:54:31 +01006403 fail_unlock_rcu:
6404 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006405 nla_put_failure:
6406 genlmsg_cancel(msg, hdr);
6407 return -EMSGSIZE;
6408}
6409
Johannes Berg97990a02013-04-19 01:02:55 +02006410static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006411{
Johannes Berg48ab9052009-07-10 18:42:31 +02006412 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006413 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006414 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006415 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006416 int err;
6417
Johannes Berg97990a02013-04-19 01:02:55 +02006418 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006419 if (err)
6420 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006421
Johannes Berg48ab9052009-07-10 18:42:31 +02006422 wdev_lock(wdev);
6423 spin_lock_bh(&rdev->bss_lock);
6424 cfg80211_bss_expire(rdev);
6425
Johannes Berg9720bb32011-06-21 09:45:33 +02006426 cb->seq = rdev->bss_generation;
6427
Johannes Berg48ab9052009-07-10 18:42:31 +02006428 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006429 if (++idx <= start)
6430 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006431 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006432 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006433 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006434 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006435 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006436 }
6437 }
6438
Johannes Berg48ab9052009-07-10 18:42:31 +02006439 spin_unlock_bh(&rdev->bss_lock);
6440 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006441
Johannes Berg97990a02013-04-19 01:02:55 +02006442 cb->args[2] = idx;
6443 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006444
Johannes Berg67748892010-10-04 21:14:06 +02006445 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006446}
6447
Eric W. Biederman15e47302012-09-07 20:12:54 +00006448static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006449 int flags, struct net_device *dev,
6450 struct survey_info *survey)
6451{
6452 void *hdr;
6453 struct nlattr *infoattr;
6454
Eric W. Biederman15e47302012-09-07 20:12:54 +00006455 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006456 NL80211_CMD_NEW_SURVEY_RESULTS);
6457 if (!hdr)
6458 return -ENOMEM;
6459
David S. Miller9360ffd2012-03-29 04:41:26 -04006460 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6461 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006462
6463 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6464 if (!infoattr)
6465 goto nla_put_failure;
6466
David S. Miller9360ffd2012-03-29 04:41:26 -04006467 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6468 survey->channel->center_freq))
6469 goto nla_put_failure;
6470
6471 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6472 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6473 goto nla_put_failure;
6474 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6475 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6476 goto nla_put_failure;
6477 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6478 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6479 survey->channel_time))
6480 goto nla_put_failure;
6481 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6482 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6483 survey->channel_time_busy))
6484 goto nla_put_failure;
6485 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6486 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6487 survey->channel_time_ext_busy))
6488 goto nla_put_failure;
6489 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6490 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6491 survey->channel_time_rx))
6492 goto nla_put_failure;
6493 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6494 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6495 survey->channel_time_tx))
6496 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006497
6498 nla_nest_end(msg, infoattr);
6499
6500 return genlmsg_end(msg, hdr);
6501
6502 nla_put_failure:
6503 genlmsg_cancel(msg, hdr);
6504 return -EMSGSIZE;
6505}
6506
6507static int nl80211_dump_survey(struct sk_buff *skb,
6508 struct netlink_callback *cb)
6509{
6510 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006511 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006512 struct wireless_dev *wdev;
6513 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006514 int res;
6515
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006516 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006517 if (res)
6518 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006519
Johannes Berg97990a02013-04-19 01:02:55 +02006520 if (!wdev->netdev) {
6521 res = -EINVAL;
6522 goto out_err;
6523 }
6524
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006525 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006526 res = -EOPNOTSUPP;
6527 goto out_err;
6528 }
6529
6530 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006531 struct ieee80211_channel *chan;
6532
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006533 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006534 if (res == -ENOENT)
6535 break;
6536 if (res)
6537 goto out_err;
6538
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006539 /* Survey without a channel doesn't make sense */
6540 if (!survey.channel) {
6541 res = -EINVAL;
6542 goto out;
6543 }
6544
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006545 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006546 survey.channel->center_freq);
6547 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6548 survey_idx++;
6549 continue;
6550 }
6551
Holger Schurig61fa7132009-11-11 12:25:40 +01006552 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006553 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006554 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006555 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006556 goto out;
6557 survey_idx++;
6558 }
6559
6560 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006561 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006562 res = skb->len;
6563 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006564 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006565 return res;
6566}
6567
Samuel Ortizb23aa672009-07-01 21:26:54 +02006568static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6569{
6570 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6571 NL80211_WPA_VERSION_2));
6572}
6573
Jouni Malinen636a5d32009-03-19 13:39:22 +02006574static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6575{
Johannes Berg4c476992010-10-04 21:36:35 +02006576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6577 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006578 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006579 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6580 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006581 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006582 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006583 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006584
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006585 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6586 return -EINVAL;
6587
6588 if (!info->attrs[NL80211_ATTR_MAC])
6589 return -EINVAL;
6590
Jouni Malinen17780922009-03-27 20:52:47 +02006591 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6592 return -EINVAL;
6593
Johannes Berg19957bb2009-07-02 17:20:43 +02006594 if (!info->attrs[NL80211_ATTR_SSID])
6595 return -EINVAL;
6596
6597 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6598 return -EINVAL;
6599
Johannes Bergfffd0932009-07-08 14:22:54 +02006600 err = nl80211_parse_key(info, &key);
6601 if (err)
6602 return err;
6603
6604 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006605 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6606 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006607 if (!key.p.key || !key.p.key_len)
6608 return -EINVAL;
6609 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6610 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6611 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6612 key.p.key_len != WLAN_KEY_LEN_WEP104))
6613 return -EINVAL;
6614 if (key.idx > 4)
6615 return -EINVAL;
6616 } else {
6617 key.p.key_len = 0;
6618 key.p.key = NULL;
6619 }
6620
Johannes Bergafea0b72010-08-10 09:46:42 +02006621 if (key.idx >= 0) {
6622 int i;
6623 bool ok = false;
6624 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6625 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6626 ok = true;
6627 break;
6628 }
6629 }
Johannes Berg4c476992010-10-04 21:36:35 +02006630 if (!ok)
6631 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006632 }
6633
Johannes Berg4c476992010-10-04 21:36:35 +02006634 if (!rdev->ops->auth)
6635 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006636
Johannes Berg074ac8d2010-09-16 14:58:22 +02006637 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006638 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6639 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006640
Johannes Berg19957bb2009-07-02 17:20:43 +02006641 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006642 chan = nl80211_get_valid_chan(&rdev->wiphy,
6643 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6644 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006645 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006646
Johannes Berg19957bb2009-07-02 17:20:43 +02006647 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6648 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6649
6650 if (info->attrs[NL80211_ATTR_IE]) {
6651 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6652 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6653 }
6654
6655 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006656 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006657 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006658
Jouni Malinene39e5b52012-09-30 19:29:39 +03006659 if (auth_type == NL80211_AUTHTYPE_SAE &&
6660 !info->attrs[NL80211_ATTR_SAE_DATA])
6661 return -EINVAL;
6662
6663 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6664 if (auth_type != NL80211_AUTHTYPE_SAE)
6665 return -EINVAL;
6666 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6667 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6668 /* need to include at least Auth Transaction and Status Code */
6669 if (sae_data_len < 4)
6670 return -EINVAL;
6671 }
6672
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006673 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6674
Johannes Berg95de8172012-01-20 13:55:25 +01006675 /*
6676 * Since we no longer track auth state, ignore
6677 * requests to only change local state.
6678 */
6679 if (local_state_change)
6680 return 0;
6681
Johannes Berg91bf9b22013-05-15 17:44:01 +02006682 wdev_lock(dev->ieee80211_ptr);
6683 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6684 ssid, ssid_len, ie, ie_len,
6685 key.p.key, key.p.key_len, key.idx,
6686 sae_data, sae_data_len);
6687 wdev_unlock(dev->ieee80211_ptr);
6688 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006689}
6690
Johannes Bergc0692b82010-08-27 14:26:53 +03006691static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6692 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006693 struct cfg80211_crypto_settings *settings,
6694 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006695{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006696 memset(settings, 0, sizeof(*settings));
6697
Samuel Ortizb23aa672009-07-01 21:26:54 +02006698 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6699
Johannes Bergc0692b82010-08-27 14:26:53 +03006700 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6701 u16 proto;
6702 proto = nla_get_u16(
6703 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6704 settings->control_port_ethertype = cpu_to_be16(proto);
6705 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6706 proto != ETH_P_PAE)
6707 return -EINVAL;
6708 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6709 settings->control_port_no_encrypt = true;
6710 } else
6711 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6712
Samuel Ortizb23aa672009-07-01 21:26:54 +02006713 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6714 void *data;
6715 int len, i;
6716
6717 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6718 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6719 settings->n_ciphers_pairwise = len / sizeof(u32);
6720
6721 if (len % sizeof(u32))
6722 return -EINVAL;
6723
Johannes Berg3dc27d22009-07-02 21:36:37 +02006724 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006725 return -EINVAL;
6726
6727 memcpy(settings->ciphers_pairwise, data, len);
6728
6729 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006730 if (!cfg80211_supported_cipher_suite(
6731 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006732 settings->ciphers_pairwise[i]))
6733 return -EINVAL;
6734 }
6735
6736 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6737 settings->cipher_group =
6738 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006739 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6740 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006741 return -EINVAL;
6742 }
6743
6744 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6745 settings->wpa_versions =
6746 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6747 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6748 return -EINVAL;
6749 }
6750
6751 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6752 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006753 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006754
6755 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6756 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6757 settings->n_akm_suites = len / sizeof(u32);
6758
6759 if (len % sizeof(u32))
6760 return -EINVAL;
6761
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006762 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6763 return -EINVAL;
6764
Samuel Ortizb23aa672009-07-01 21:26:54 +02006765 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006766 }
6767
6768 return 0;
6769}
6770
Jouni Malinen636a5d32009-03-19 13:39:22 +02006771static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6772{
Johannes Berg4c476992010-10-04 21:36:35 +02006773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6774 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006775 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006776 struct cfg80211_assoc_request req = {};
6777 const u8 *bssid, *ssid;
6778 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006779
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006780 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6781 return -EINVAL;
6782
6783 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006784 !info->attrs[NL80211_ATTR_SSID] ||
6785 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006786 return -EINVAL;
6787
Johannes Berg4c476992010-10-04 21:36:35 +02006788 if (!rdev->ops->assoc)
6789 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006790
Johannes Berg074ac8d2010-09-16 14:58:22 +02006791 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006792 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6793 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006794
Johannes Berg19957bb2009-07-02 17:20:43 +02006795 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006796
Jouni Malinen664834d2014-01-15 00:01:44 +02006797 chan = nl80211_get_valid_chan(&rdev->wiphy,
6798 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6799 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006800 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006801
Johannes Berg19957bb2009-07-02 17:20:43 +02006802 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6803 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006804
6805 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006806 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6807 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006808 }
6809
Jouni Malinendc6382c2009-05-06 22:09:37 +03006810 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006811 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006812 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006813 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006814 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006815 else if (mfp != NL80211_MFP_NO)
6816 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006817 }
6818
Johannes Berg3e5d7642009-07-07 14:37:26 +02006819 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006820 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006821
Ben Greear7e7c8922011-11-18 11:31:59 -08006822 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006823 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006824
6825 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006826 memcpy(&req.ht_capa_mask,
6827 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6828 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006829
6830 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006831 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006832 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006833 memcpy(&req.ht_capa,
6834 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6835 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006836 }
6837
Johannes Bergee2aca32013-02-21 17:36:01 +01006838 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006839 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006840
6841 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006842 memcpy(&req.vht_capa_mask,
6843 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6844 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006845
6846 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006847 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006848 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006849 memcpy(&req.vht_capa,
6850 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6851 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006852 }
6853
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006854 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6855 if (!(rdev->wiphy.features &
6856 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6857 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6858 return -EINVAL;
6859 req.flags |= ASSOC_REQ_USE_RRM;
6860 }
6861
Johannes Bergf62fab72013-02-21 20:09:09 +01006862 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006863 if (!err) {
6864 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006865 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6866 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006867 wdev_unlock(dev->ieee80211_ptr);
6868 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006869
Jouni Malinen636a5d32009-03-19 13:39:22 +02006870 return err;
6871}
6872
6873static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6874{
Johannes Berg4c476992010-10-04 21:36:35 +02006875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6876 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006877 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006878 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006879 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006880 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006881
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006882 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6883 return -EINVAL;
6884
6885 if (!info->attrs[NL80211_ATTR_MAC])
6886 return -EINVAL;
6887
6888 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6889 return -EINVAL;
6890
Johannes Berg4c476992010-10-04 21:36:35 +02006891 if (!rdev->ops->deauth)
6892 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006893
Johannes Berg074ac8d2010-09-16 14:58:22 +02006894 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006895 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6896 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006897
Johannes Berg19957bb2009-07-02 17:20:43 +02006898 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006899
Johannes Berg19957bb2009-07-02 17:20:43 +02006900 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6901 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006902 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006903 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006904 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006905
6906 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006907 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6908 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006909 }
6910
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006911 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6912
Johannes Berg91bf9b22013-05-15 17:44:01 +02006913 wdev_lock(dev->ieee80211_ptr);
6914 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6915 local_state_change);
6916 wdev_unlock(dev->ieee80211_ptr);
6917 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006918}
6919
6920static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6921{
Johannes Berg4c476992010-10-04 21:36:35 +02006922 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6923 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006924 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006925 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006926 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006927 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006928
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006929 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6930 return -EINVAL;
6931
6932 if (!info->attrs[NL80211_ATTR_MAC])
6933 return -EINVAL;
6934
6935 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6936 return -EINVAL;
6937
Johannes Berg4c476992010-10-04 21:36:35 +02006938 if (!rdev->ops->disassoc)
6939 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006940
Johannes Berg074ac8d2010-09-16 14:58:22 +02006941 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006942 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6943 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006944
Johannes Berg19957bb2009-07-02 17:20:43 +02006945 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006946
Johannes Berg19957bb2009-07-02 17:20:43 +02006947 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6948 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006949 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006950 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006951 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006952
6953 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006954 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6955 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006956 }
6957
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006958 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6959
Johannes Berg91bf9b22013-05-15 17:44:01 +02006960 wdev_lock(dev->ieee80211_ptr);
6961 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6962 local_state_change);
6963 wdev_unlock(dev->ieee80211_ptr);
6964 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006965}
6966
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006967static bool
6968nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6969 int mcast_rate[IEEE80211_NUM_BANDS],
6970 int rateval)
6971{
6972 struct wiphy *wiphy = &rdev->wiphy;
6973 bool found = false;
6974 int band, i;
6975
6976 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6977 struct ieee80211_supported_band *sband;
6978
6979 sband = wiphy->bands[band];
6980 if (!sband)
6981 continue;
6982
6983 for (i = 0; i < sband->n_bitrates; i++) {
6984 if (sband->bitrates[i].bitrate == rateval) {
6985 mcast_rate[band] = i + 1;
6986 found = true;
6987 break;
6988 }
6989 }
6990 }
6991
6992 return found;
6993}
6994
Johannes Berg04a773a2009-04-19 21:24:32 +02006995static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6996{
Johannes Berg4c476992010-10-04 21:36:35 +02006997 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6998 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006999 struct cfg80211_ibss_params ibss;
7000 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007001 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007002 int err;
7003
Johannes Berg8e30bc52009-04-22 17:45:38 +02007004 memset(&ibss, 0, sizeof(ibss));
7005
Johannes Berg04a773a2009-04-19 21:24:32 +02007006 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7007 return -EINVAL;
7008
Johannes Berg683b6d32012-11-08 21:25:48 +01007009 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007010 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7011 return -EINVAL;
7012
Johannes Berg8e30bc52009-04-22 17:45:38 +02007013 ibss.beacon_interval = 100;
7014
7015 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7016 ibss.beacon_interval =
7017 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7018 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7019 return -EINVAL;
7020 }
7021
Johannes Berg4c476992010-10-04 21:36:35 +02007022 if (!rdev->ops->join_ibss)
7023 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007024
Johannes Berg4c476992010-10-04 21:36:35 +02007025 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7026 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007027
Johannes Berg79c97e92009-07-07 03:56:12 +02007028 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007029
Johannes Berg39193492011-09-16 13:45:25 +02007030 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007031 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007032
7033 if (!is_valid_ether_addr(ibss.bssid))
7034 return -EINVAL;
7035 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007036 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7037 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7038
7039 if (info->attrs[NL80211_ATTR_IE]) {
7040 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7041 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7042 }
7043
Johannes Berg683b6d32012-11-08 21:25:48 +01007044 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7045 if (err)
7046 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007047
Ilan Peer174e0cd2014-02-23 09:13:01 +02007048 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7049 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007050 return -EINVAL;
7051
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007052 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007053 case NL80211_CHAN_WIDTH_5:
7054 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007055 case NL80211_CHAN_WIDTH_20_NOHT:
7056 break;
7057 case NL80211_CHAN_WIDTH_20:
7058 case NL80211_CHAN_WIDTH_40:
7059 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
7060 break;
7061 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007062 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007063 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007064
Johannes Berg04a773a2009-04-19 21:24:32 +02007065 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007066 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007067
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007068 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7069 u8 *rates =
7070 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7071 int n_rates =
7072 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7073 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007074 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007075
Johannes Berg34850ab2011-07-18 18:08:35 +02007076 err = ieee80211_get_ratemask(sband, rates, n_rates,
7077 &ibss.basic_rates);
7078 if (err)
7079 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007080 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007081
Simon Wunderlich803768f2013-06-28 10:39:58 +02007082 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7083 memcpy(&ibss.ht_capa_mask,
7084 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7085 sizeof(ibss.ht_capa_mask));
7086
7087 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7088 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7089 return -EINVAL;
7090 memcpy(&ibss.ht_capa,
7091 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7092 sizeof(ibss.ht_capa));
7093 }
7094
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007095 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7096 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7097 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7098 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007099
Johannes Berg4c476992010-10-04 21:36:35 +02007100 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307101 bool no_ht = false;
7102
Johannes Berg4c476992010-10-04 21:36:35 +02007103 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307104 info->attrs[NL80211_ATTR_KEYS],
7105 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007106 if (IS_ERR(connkeys))
7107 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307108
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007109 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7110 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307111 kfree(connkeys);
7112 return -EINVAL;
7113 }
Johannes Berg4c476992010-10-04 21:36:35 +02007114 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007115
Antonio Quartulli267335d2012-01-31 20:25:47 +01007116 ibss.control_port =
7117 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7118
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007119 ibss.userspace_handles_dfs =
7120 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7121
Johannes Berg4c476992010-10-04 21:36:35 +02007122 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007123 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007124 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007125 return err;
7126}
7127
7128static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7129{
Johannes Berg4c476992010-10-04 21:36:35 +02007130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7131 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007132
Johannes Berg4c476992010-10-04 21:36:35 +02007133 if (!rdev->ops->leave_ibss)
7134 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007135
Johannes Berg4c476992010-10-04 21:36:35 +02007136 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7137 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007138
Johannes Berg4c476992010-10-04 21:36:35 +02007139 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007140}
7141
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007142static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7143{
7144 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7145 struct net_device *dev = info->user_ptr[1];
7146 int mcast_rate[IEEE80211_NUM_BANDS];
7147 u32 nla_rate;
7148 int err;
7149
7150 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7151 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7152 return -EOPNOTSUPP;
7153
7154 if (!rdev->ops->set_mcast_rate)
7155 return -EOPNOTSUPP;
7156
7157 memset(mcast_rate, 0, sizeof(mcast_rate));
7158
7159 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7160 return -EINVAL;
7161
7162 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7163 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7164 return -EINVAL;
7165
7166 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7167
7168 return err;
7169}
7170
Johannes Bergad7e7182013-11-13 13:37:47 +01007171static struct sk_buff *
7172__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7173 int approxlen, u32 portid, u32 seq,
7174 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007175 enum nl80211_attrs attr,
7176 const struct nl80211_vendor_cmd_info *info,
7177 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007178{
7179 struct sk_buff *skb;
7180 void *hdr;
7181 struct nlattr *data;
7182
7183 skb = nlmsg_new(approxlen + 100, gfp);
7184 if (!skb)
7185 return NULL;
7186
7187 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7188 if (!hdr) {
7189 kfree_skb(skb);
7190 return NULL;
7191 }
7192
7193 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7194 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007195
7196 if (info) {
7197 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7198 info->vendor_id))
7199 goto nla_put_failure;
7200 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7201 info->subcmd))
7202 goto nla_put_failure;
7203 }
7204
Johannes Bergad7e7182013-11-13 13:37:47 +01007205 data = nla_nest_start(skb, attr);
7206
7207 ((void **)skb->cb)[0] = rdev;
7208 ((void **)skb->cb)[1] = hdr;
7209 ((void **)skb->cb)[2] = data;
7210
7211 return skb;
7212
7213 nla_put_failure:
7214 kfree_skb(skb);
7215 return NULL;
7216}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007217
Johannes Berge03ad6e2014-01-01 17:22:30 +01007218struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7219 enum nl80211_commands cmd,
7220 enum nl80211_attrs attr,
7221 int vendor_event_idx,
7222 int approxlen, gfp_t gfp)
7223{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007224 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007225 const struct nl80211_vendor_cmd_info *info;
7226
7227 switch (cmd) {
7228 case NL80211_CMD_TESTMODE:
7229 if (WARN_ON(vendor_event_idx != -1))
7230 return NULL;
7231 info = NULL;
7232 break;
7233 case NL80211_CMD_VENDOR:
7234 if (WARN_ON(vendor_event_idx < 0 ||
7235 vendor_event_idx >= wiphy->n_vendor_events))
7236 return NULL;
7237 info = &wiphy->vendor_events[vendor_event_idx];
7238 break;
7239 default:
7240 WARN_ON(1);
7241 return NULL;
7242 }
7243
7244 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7245 cmd, attr, info, gfp);
7246}
7247EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7248
7249void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7250{
7251 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7252 void *hdr = ((void **)skb->cb)[1];
7253 struct nlattr *data = ((void **)skb->cb)[2];
7254 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7255
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007256 /* clear CB data for netlink core to own from now on */
7257 memset(skb->cb, 0, sizeof(skb->cb));
7258
Johannes Berge03ad6e2014-01-01 17:22:30 +01007259 nla_nest_end(skb, data);
7260 genlmsg_end(skb, hdr);
7261
7262 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7263 mcgrp = NL80211_MCGRP_VENDOR;
7264
7265 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7266 mcgrp, gfp);
7267}
7268EXPORT_SYMBOL(__cfg80211_send_event_skb);
7269
Johannes Bergaff89a92009-07-01 21:26:51 +02007270#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007271static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7272{
Johannes Berg4c476992010-10-04 21:36:35 +02007273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007274 struct wireless_dev *wdev =
7275 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007276 int err;
7277
David Spinadelfc73f112013-07-31 18:04:15 +03007278 if (!rdev->ops->testmode_cmd)
7279 return -EOPNOTSUPP;
7280
7281 if (IS_ERR(wdev)) {
7282 err = PTR_ERR(wdev);
7283 if (err != -EINVAL)
7284 return err;
7285 wdev = NULL;
7286 } else if (wdev->wiphy != &rdev->wiphy) {
7287 return -EINVAL;
7288 }
7289
Johannes Bergaff89a92009-07-01 21:26:51 +02007290 if (!info->attrs[NL80211_ATTR_TESTDATA])
7291 return -EINVAL;
7292
Johannes Bergad7e7182013-11-13 13:37:47 +01007293 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007294 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007295 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7296 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007297 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007298
Johannes Bergaff89a92009-07-01 21:26:51 +02007299 return err;
7300}
7301
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007302static int nl80211_testmode_dump(struct sk_buff *skb,
7303 struct netlink_callback *cb)
7304{
Johannes Berg00918d32011-12-13 17:22:05 +01007305 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007306 int err;
7307 long phy_idx;
7308 void *data = NULL;
7309 int data_len = 0;
7310
Johannes Berg5fe231e2013-05-08 21:45:15 +02007311 rtnl_lock();
7312
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007313 if (cb->args[0]) {
7314 /*
7315 * 0 is a valid index, but not valid for args[0],
7316 * so we need to offset by 1.
7317 */
7318 phy_idx = cb->args[0] - 1;
7319 } else {
7320 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7321 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7322 nl80211_policy);
7323 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007324 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007325
Johannes Berg2bd7e352012-06-15 14:23:16 +02007326 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7327 nl80211_fam.attrbuf);
7328 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007329 err = PTR_ERR(rdev);
7330 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007331 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007332 phy_idx = rdev->wiphy_idx;
7333 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007334
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007335 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7336 cb->args[1] =
7337 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7338 }
7339
7340 if (cb->args[1]) {
7341 data = nla_data((void *)cb->args[1]);
7342 data_len = nla_len((void *)cb->args[1]);
7343 }
7344
Johannes Berg00918d32011-12-13 17:22:05 +01007345 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7346 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007347 err = -ENOENT;
7348 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007349 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007350
Johannes Berg00918d32011-12-13 17:22:05 +01007351 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007352 err = -EOPNOTSUPP;
7353 goto out_err;
7354 }
7355
7356 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007357 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007358 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7359 NL80211_CMD_TESTMODE);
7360 struct nlattr *tmdata;
7361
Dan Carpentercb35fba2013-08-14 14:50:01 +03007362 if (!hdr)
7363 break;
7364
David S. Miller9360ffd2012-03-29 04:41:26 -04007365 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007366 genlmsg_cancel(skb, hdr);
7367 break;
7368 }
7369
7370 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7371 if (!tmdata) {
7372 genlmsg_cancel(skb, hdr);
7373 break;
7374 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007375 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007376 nla_nest_end(skb, tmdata);
7377
7378 if (err == -ENOBUFS || err == -ENOENT) {
7379 genlmsg_cancel(skb, hdr);
7380 break;
7381 } else if (err) {
7382 genlmsg_cancel(skb, hdr);
7383 goto out_err;
7384 }
7385
7386 genlmsg_end(skb, hdr);
7387 }
7388
7389 err = skb->len;
7390 /* see above */
7391 cb->args[0] = phy_idx + 1;
7392 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007393 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007394 return err;
7395}
Johannes Bergaff89a92009-07-01 21:26:51 +02007396#endif
7397
Samuel Ortizb23aa672009-07-01 21:26:54 +02007398static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7399{
Johannes Berg4c476992010-10-04 21:36:35 +02007400 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7401 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007402 struct cfg80211_connect_params connect;
7403 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007404 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007405 int err;
7406
7407 memset(&connect, 0, sizeof(connect));
7408
7409 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7410 return -EINVAL;
7411
7412 if (!info->attrs[NL80211_ATTR_SSID] ||
7413 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7414 return -EINVAL;
7415
7416 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7417 connect.auth_type =
7418 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007419 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7420 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007421 return -EINVAL;
7422 } else
7423 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7424
7425 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7426
Johannes Bergc0692b82010-08-27 14:26:53 +03007427 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007428 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007429 if (err)
7430 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007431
Johannes Berg074ac8d2010-09-16 14:58:22 +02007432 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007433 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7434 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007435
Johannes Berg79c97e92009-07-07 03:56:12 +02007436 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007437
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307438 connect.bg_scan_period = -1;
7439 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7440 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7441 connect.bg_scan_period =
7442 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7443 }
7444
Samuel Ortizb23aa672009-07-01 21:26:54 +02007445 if (info->attrs[NL80211_ATTR_MAC])
7446 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007447 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7448 connect.bssid_hint =
7449 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007450 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7451 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7452
7453 if (info->attrs[NL80211_ATTR_IE]) {
7454 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7455 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7456 }
7457
Jouni Malinencee00a92013-01-15 17:15:57 +02007458 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7459 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7460 if (connect.mfp != NL80211_MFP_REQUIRED &&
7461 connect.mfp != NL80211_MFP_NO)
7462 return -EINVAL;
7463 } else {
7464 connect.mfp = NL80211_MFP_NO;
7465 }
7466
Samuel Ortizb23aa672009-07-01 21:26:54 +02007467 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007468 connect.channel = nl80211_get_valid_chan(
7469 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7470 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007471 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007472 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007473 connect.channel_hint = nl80211_get_valid_chan(
7474 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7475 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007476 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007477 }
7478
Johannes Bergfffd0932009-07-08 14:22:54 +02007479 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7480 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307481 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007482 if (IS_ERR(connkeys))
7483 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007484 }
7485
Ben Greear7e7c8922011-11-18 11:31:59 -08007486 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7487 connect.flags |= ASSOC_REQ_DISABLE_HT;
7488
7489 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7490 memcpy(&connect.ht_capa_mask,
7491 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7492 sizeof(connect.ht_capa_mask));
7493
7494 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007495 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007496 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007497 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007498 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007499 memcpy(&connect.ht_capa,
7500 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7501 sizeof(connect.ht_capa));
7502 }
7503
Johannes Bergee2aca32013-02-21 17:36:01 +01007504 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7505 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7506
7507 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7508 memcpy(&connect.vht_capa_mask,
7509 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7510 sizeof(connect.vht_capa_mask));
7511
7512 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7513 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007514 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007515 return -EINVAL;
7516 }
7517 memcpy(&connect.vht_capa,
7518 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7519 sizeof(connect.vht_capa));
7520 }
7521
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007522 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7523 if (!(rdev->wiphy.features &
7524 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7525 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7526 return -EINVAL;
7527 connect.flags |= ASSOC_REQ_USE_RRM;
7528 }
7529
Johannes Berg83739b02013-05-15 17:44:01 +02007530 wdev_lock(dev->ieee80211_ptr);
7531 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7532 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007533 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007534 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007535 return err;
7536}
7537
7538static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7539{
Johannes Berg4c476992010-10-04 21:36:35 +02007540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7541 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007542 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007543 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007544
7545 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7546 reason = WLAN_REASON_DEAUTH_LEAVING;
7547 else
7548 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7549
7550 if (reason == 0)
7551 return -EINVAL;
7552
Johannes Berg074ac8d2010-09-16 14:58:22 +02007553 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007554 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7555 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007556
Johannes Berg83739b02013-05-15 17:44:01 +02007557 wdev_lock(dev->ieee80211_ptr);
7558 ret = cfg80211_disconnect(rdev, dev, reason, true);
7559 wdev_unlock(dev->ieee80211_ptr);
7560 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007561}
7562
Johannes Berg463d0182009-07-14 00:33:35 +02007563static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7564{
Johannes Berg4c476992010-10-04 21:36:35 +02007565 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007566 struct net *net;
7567 int err;
7568 u32 pid;
7569
7570 if (!info->attrs[NL80211_ATTR_PID])
7571 return -EINVAL;
7572
7573 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7574
Johannes Berg463d0182009-07-14 00:33:35 +02007575 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007576 if (IS_ERR(net))
7577 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007578
7579 err = 0;
7580
7581 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007582 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7583 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007584
Johannes Berg463d0182009-07-14 00:33:35 +02007585 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007586 return err;
7587}
7588
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007589static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7590{
Johannes Berg4c476992010-10-04 21:36:35 +02007591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007592 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7593 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007594 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007595 struct cfg80211_pmksa pmksa;
7596
7597 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7598
7599 if (!info->attrs[NL80211_ATTR_MAC])
7600 return -EINVAL;
7601
7602 if (!info->attrs[NL80211_ATTR_PMKID])
7603 return -EINVAL;
7604
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007605 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7606 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7607
Johannes Berg074ac8d2010-09-16 14:58:22 +02007608 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007609 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7610 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007611
7612 switch (info->genlhdr->cmd) {
7613 case NL80211_CMD_SET_PMKSA:
7614 rdev_ops = rdev->ops->set_pmksa;
7615 break;
7616 case NL80211_CMD_DEL_PMKSA:
7617 rdev_ops = rdev->ops->del_pmksa;
7618 break;
7619 default:
7620 WARN_ON(1);
7621 break;
7622 }
7623
Johannes Berg4c476992010-10-04 21:36:35 +02007624 if (!rdev_ops)
7625 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007626
Johannes Berg4c476992010-10-04 21:36:35 +02007627 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007628}
7629
7630static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7631{
Johannes Berg4c476992010-10-04 21:36:35 +02007632 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7633 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007634
Johannes Berg074ac8d2010-09-16 14:58:22 +02007635 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007636 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7637 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007638
Johannes Berg4c476992010-10-04 21:36:35 +02007639 if (!rdev->ops->flush_pmksa)
7640 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007641
Hila Gonene35e4d22012-06-27 17:19:42 +03007642 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007643}
7644
Arik Nemtsov109086c2011-09-28 14:12:50 +03007645static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7646{
7647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7648 struct net_device *dev = info->user_ptr[1];
7649 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307650 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007651 u16 status_code;
7652 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007653 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007654
7655 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7656 !rdev->ops->tdls_mgmt)
7657 return -EOPNOTSUPP;
7658
7659 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7660 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7661 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7662 !info->attrs[NL80211_ATTR_IE] ||
7663 !info->attrs[NL80211_ATTR_MAC])
7664 return -EINVAL;
7665
7666 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7667 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7668 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7669 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007670 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307671 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7672 peer_capability =
7673 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007674
Hila Gonene35e4d22012-06-27 17:19:42 +03007675 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307676 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007677 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007678 nla_data(info->attrs[NL80211_ATTR_IE]),
7679 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007680}
7681
7682static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7683{
7684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7685 struct net_device *dev = info->user_ptr[1];
7686 enum nl80211_tdls_operation operation;
7687 u8 *peer;
7688
7689 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7690 !rdev->ops->tdls_oper)
7691 return -EOPNOTSUPP;
7692
7693 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7694 !info->attrs[NL80211_ATTR_MAC])
7695 return -EINVAL;
7696
7697 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7698 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7699
Hila Gonene35e4d22012-06-27 17:19:42 +03007700 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007701}
7702
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007703static int nl80211_remain_on_channel(struct sk_buff *skb,
7704 struct genl_info *info)
7705{
Johannes Berg4c476992010-10-04 21:36:35 +02007706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007707 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007708 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007709 struct sk_buff *msg;
7710 void *hdr;
7711 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007712 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007713 int err;
7714
7715 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7716 !info->attrs[NL80211_ATTR_DURATION])
7717 return -EINVAL;
7718
7719 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7720
Johannes Berg7c4ef712011-11-18 15:33:48 +01007721 if (!rdev->ops->remain_on_channel ||
7722 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007723 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007724
Johannes Bergebf348f2012-06-01 12:50:54 +02007725 /*
7726 * We should be on that channel for at least a minimum amount of
7727 * time (10ms) but no longer than the driver supports.
7728 */
7729 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7730 duration > rdev->wiphy.max_remain_on_channel_duration)
7731 return -EINVAL;
7732
Johannes Berg683b6d32012-11-08 21:25:48 +01007733 err = nl80211_parse_chandef(rdev, info, &chandef);
7734 if (err)
7735 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007736
7737 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007738 if (!msg)
7739 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007740
Eric W. Biederman15e47302012-09-07 20:12:54 +00007741 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007742 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007743 if (!hdr) {
7744 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007745 goto free_msg;
7746 }
7747
Johannes Berg683b6d32012-11-08 21:25:48 +01007748 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7749 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007750
7751 if (err)
7752 goto free_msg;
7753
David S. Miller9360ffd2012-03-29 04:41:26 -04007754 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7755 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007756
7757 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007758
7759 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007760
7761 nla_put_failure:
7762 err = -ENOBUFS;
7763 free_msg:
7764 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007765 return err;
7766}
7767
7768static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7769 struct genl_info *info)
7770{
Johannes Berg4c476992010-10-04 21:36:35 +02007771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007772 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007773 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007774
7775 if (!info->attrs[NL80211_ATTR_COOKIE])
7776 return -EINVAL;
7777
Johannes Berg4c476992010-10-04 21:36:35 +02007778 if (!rdev->ops->cancel_remain_on_channel)
7779 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007780
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007781 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7782
Hila Gonene35e4d22012-06-27 17:19:42 +03007783 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007784}
7785
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007786static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7787 u8 *rates, u8 rates_len)
7788{
7789 u8 i;
7790 u32 mask = 0;
7791
7792 for (i = 0; i < rates_len; i++) {
7793 int rate = (rates[i] & 0x7f) * 5;
7794 int ridx;
7795 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7796 struct ieee80211_rate *srate =
7797 &sband->bitrates[ridx];
7798 if (rate == srate->bitrate) {
7799 mask |= 1 << ridx;
7800 break;
7801 }
7802 }
7803 if (ridx == sband->n_bitrates)
7804 return 0; /* rate not found */
7805 }
7806
7807 return mask;
7808}
7809
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007810static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7811 u8 *rates, u8 rates_len,
7812 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7813{
7814 u8 i;
7815
7816 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7817
7818 for (i = 0; i < rates_len; i++) {
7819 int ridx, rbit;
7820
7821 ridx = rates[i] / 8;
7822 rbit = BIT(rates[i] % 8);
7823
7824 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007825 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007826 return false;
7827
7828 /* check availability */
7829 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7830 mcs[ridx] |= rbit;
7831 else
7832 return false;
7833 }
7834
7835 return true;
7836}
7837
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007838static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7839{
7840 u16 mcs_mask = 0;
7841
7842 switch (vht_mcs_map) {
7843 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7844 break;
7845 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7846 mcs_mask = 0x00FF;
7847 break;
7848 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7849 mcs_mask = 0x01FF;
7850 break;
7851 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7852 mcs_mask = 0x03FF;
7853 break;
7854 default:
7855 break;
7856 }
7857
7858 return mcs_mask;
7859}
7860
7861static void vht_build_mcs_mask(u16 vht_mcs_map,
7862 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7863{
7864 u8 nss;
7865
7866 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7867 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7868 vht_mcs_map >>= 2;
7869 }
7870}
7871
7872static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7873 struct nl80211_txrate_vht *txrate,
7874 u16 mcs[NL80211_VHT_NSS_MAX])
7875{
7876 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7877 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7878 u8 i;
7879
7880 if (!sband->vht_cap.vht_supported)
7881 return false;
7882
7883 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7884
7885 /* Build vht_mcs_mask from VHT capabilities */
7886 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7887
7888 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7889 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7890 mcs[i] = txrate->mcs[i];
7891 else
7892 return false;
7893 }
7894
7895 return true;
7896}
7897
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007898static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007899 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7900 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007901 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7902 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007903 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007904 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007905};
7906
7907static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7908 struct genl_info *info)
7909{
7910 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007912 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007913 int rem, i;
7914 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007915 struct nlattr *tx_rates;
7916 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007917 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007918
Johannes Berg4c476992010-10-04 21:36:35 +02007919 if (!rdev->ops->set_bitrate_mask)
7920 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007921
7922 memset(&mask, 0, sizeof(mask));
7923 /* Default to all rates enabled */
7924 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7925 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007926
7927 if (!sband)
7928 continue;
7929
7930 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007931 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007932 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007933 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007934
7935 if (!sband->vht_cap.vht_supported)
7936 continue;
7937
7938 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7939 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007940 }
7941
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007942 /* if no rates are given set it back to the defaults */
7943 if (!info->attrs[NL80211_ATTR_TX_RATES])
7944 goto out;
7945
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007946 /*
7947 * The nested attribute uses enum nl80211_band as the index. This maps
7948 * directly to the enum ieee80211_band values used in cfg80211.
7949 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007950 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007951 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007952 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007953 int err;
7954
Johannes Berg4c476992010-10-04 21:36:35 +02007955 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7956 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007957 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007958 if (sband == NULL)
7959 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007960 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7961 nla_len(tx_rates), nl80211_txattr_policy);
7962 if (err)
7963 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007964 if (tb[NL80211_TXRATE_LEGACY]) {
7965 mask.control[band].legacy = rateset_to_mask(
7966 sband,
7967 nla_data(tb[NL80211_TXRATE_LEGACY]),
7968 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307969 if ((mask.control[band].legacy == 0) &&
7970 nla_len(tb[NL80211_TXRATE_LEGACY]))
7971 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007972 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007973 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007974 if (!ht_rateset_to_mask(
7975 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007976 nla_data(tb[NL80211_TXRATE_HT]),
7977 nla_len(tb[NL80211_TXRATE_HT]),
7978 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007979 return -EINVAL;
7980 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007981 if (tb[NL80211_TXRATE_VHT]) {
7982 if (!vht_set_mcs_mask(
7983 sband,
7984 nla_data(tb[NL80211_TXRATE_VHT]),
7985 mask.control[band].vht_mcs))
7986 return -EINVAL;
7987 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007988 if (tb[NL80211_TXRATE_GI]) {
7989 mask.control[band].gi =
7990 nla_get_u8(tb[NL80211_TXRATE_GI]);
7991 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7992 return -EINVAL;
7993 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007994
7995 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007996 /* don't allow empty legacy rates if HT or VHT
7997 * are not even supported.
7998 */
7999 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8000 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008001 return -EINVAL;
8002
8003 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008004 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008005 goto out;
8006
8007 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8008 if (mask.control[band].vht_mcs[i])
8009 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008010
8011 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008012 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008013 }
8014 }
8015
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008016out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008017 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008018}
8019
Johannes Berg2e161f72010-08-12 15:38:38 +02008020static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008021{
Johannes Berg4c476992010-10-04 21:36:35 +02008022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008023 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008024 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008025
8026 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8027 return -EINVAL;
8028
Johannes Berg2e161f72010-08-12 15:38:38 +02008029 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8030 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008031
Johannes Berg71bbc992012-06-15 15:30:18 +02008032 switch (wdev->iftype) {
8033 case NL80211_IFTYPE_STATION:
8034 case NL80211_IFTYPE_ADHOC:
8035 case NL80211_IFTYPE_P2P_CLIENT:
8036 case NL80211_IFTYPE_AP:
8037 case NL80211_IFTYPE_AP_VLAN:
8038 case NL80211_IFTYPE_MESH_POINT:
8039 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008040 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008041 break;
8042 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008043 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008044 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008045
8046 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008047 if (!rdev->ops->mgmt_tx)
8048 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008049
Eric W. Biederman15e47302012-09-07 20:12:54 +00008050 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008051 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8052 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008053}
8054
Johannes Berg2e161f72010-08-12 15:38:38 +02008055static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008056{
Johannes Berg4c476992010-10-04 21:36:35 +02008057 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008058 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008059 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008060 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008061 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008062 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008063 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008064 struct cfg80211_mgmt_tx_params params = {
8065 .dont_wait_for_ack =
8066 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8067 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008068
Johannes Berg683b6d32012-11-08 21:25:48 +01008069 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008070 return -EINVAL;
8071
Johannes Berg4c476992010-10-04 21:36:35 +02008072 if (!rdev->ops->mgmt_tx)
8073 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008074
Johannes Berg71bbc992012-06-15 15:30:18 +02008075 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008076 case NL80211_IFTYPE_P2P_DEVICE:
8077 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8078 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008079 case NL80211_IFTYPE_STATION:
8080 case NL80211_IFTYPE_ADHOC:
8081 case NL80211_IFTYPE_P2P_CLIENT:
8082 case NL80211_IFTYPE_AP:
8083 case NL80211_IFTYPE_AP_VLAN:
8084 case NL80211_IFTYPE_MESH_POINT:
8085 case NL80211_IFTYPE_P2P_GO:
8086 break;
8087 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008088 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008089 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008090
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008091 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008092 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008093 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008094 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008095
8096 /*
8097 * We should wait on the channel for at least a minimum amount
8098 * of time (10ms) but no longer than the driver supports.
8099 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008100 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8101 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008102 return -EINVAL;
8103
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008104 }
8105
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008106 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008107
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008108 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008109 return -EINVAL;
8110
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008111 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308112
Antonio Quartulliea141b752013-06-11 14:20:03 +02008113 /* get the channel if any has been specified, otherwise pass NULL to
8114 * the driver. The latter will use the current one
8115 */
8116 chandef.chan = NULL;
8117 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8118 err = nl80211_parse_chandef(rdev, info, &chandef);
8119 if (err)
8120 return err;
8121 }
8122
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008123 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008124 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008125
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008126 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8127 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8128
8129 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8130 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8131 int i;
8132
8133 if (len % sizeof(u16))
8134 return -EINVAL;
8135
8136 params.n_csa_offsets = len / sizeof(u16);
8137 params.csa_offsets =
8138 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8139
8140 /* check that all the offsets fit the frame */
8141 for (i = 0; i < params.n_csa_offsets; i++) {
8142 if (params.csa_offsets[i] >= params.len)
8143 return -EINVAL;
8144 }
8145 }
8146
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008147 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008148 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8149 if (!msg)
8150 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008151
Eric W. Biederman15e47302012-09-07 20:12:54 +00008152 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008153 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008154 if (!hdr) {
8155 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008156 goto free_msg;
8157 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008158 }
Johannes Berge247bd902011-11-04 11:18:21 +01008159
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008160 params.chan = chandef.chan;
8161 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008162 if (err)
8163 goto free_msg;
8164
Johannes Berge247bd902011-11-04 11:18:21 +01008165 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008166 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8167 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008168
Johannes Berge247bd902011-11-04 11:18:21 +01008169 genlmsg_end(msg, hdr);
8170 return genlmsg_reply(msg, info);
8171 }
8172
8173 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008174
8175 nla_put_failure:
8176 err = -ENOBUFS;
8177 free_msg:
8178 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008179 return err;
8180}
8181
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008182static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8183{
8184 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008185 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008186 u64 cookie;
8187
8188 if (!info->attrs[NL80211_ATTR_COOKIE])
8189 return -EINVAL;
8190
8191 if (!rdev->ops->mgmt_tx_cancel_wait)
8192 return -EOPNOTSUPP;
8193
Johannes Berg71bbc992012-06-15 15:30:18 +02008194 switch (wdev->iftype) {
8195 case NL80211_IFTYPE_STATION:
8196 case NL80211_IFTYPE_ADHOC:
8197 case NL80211_IFTYPE_P2P_CLIENT:
8198 case NL80211_IFTYPE_AP:
8199 case NL80211_IFTYPE_AP_VLAN:
8200 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008201 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008202 break;
8203 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008204 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008205 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008206
8207 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8208
Hila Gonene35e4d22012-06-27 17:19:42 +03008209 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008210}
8211
Kalle Valoffb9eb32010-02-17 17:58:10 +02008212static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8213{
Johannes Berg4c476992010-10-04 21:36:35 +02008214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008215 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008216 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008217 u8 ps_state;
8218 bool state;
8219 int err;
8220
Johannes Berg4c476992010-10-04 21:36:35 +02008221 if (!info->attrs[NL80211_ATTR_PS_STATE])
8222 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008223
8224 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8225
Johannes Berg4c476992010-10-04 21:36:35 +02008226 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8227 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008228
8229 wdev = dev->ieee80211_ptr;
8230
Johannes Berg4c476992010-10-04 21:36:35 +02008231 if (!rdev->ops->set_power_mgmt)
8232 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008233
8234 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8235
8236 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008237 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008238
Hila Gonene35e4d22012-06-27 17:19:42 +03008239 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008240 if (!err)
8241 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008242 return err;
8243}
8244
8245static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8246{
Johannes Berg4c476992010-10-04 21:36:35 +02008247 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008248 enum nl80211_ps_state ps_state;
8249 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008250 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008251 struct sk_buff *msg;
8252 void *hdr;
8253 int err;
8254
Kalle Valoffb9eb32010-02-17 17:58:10 +02008255 wdev = dev->ieee80211_ptr;
8256
Johannes Berg4c476992010-10-04 21:36:35 +02008257 if (!rdev->ops->set_power_mgmt)
8258 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008259
8260 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008261 if (!msg)
8262 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008263
Eric W. Biederman15e47302012-09-07 20:12:54 +00008264 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008265 NL80211_CMD_GET_POWER_SAVE);
8266 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008267 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008268 goto free_msg;
8269 }
8270
8271 if (wdev->ps)
8272 ps_state = NL80211_PS_ENABLED;
8273 else
8274 ps_state = NL80211_PS_DISABLED;
8275
David S. Miller9360ffd2012-03-29 04:41:26 -04008276 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8277 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008278
8279 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008280 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008281
Johannes Berg4c476992010-10-04 21:36:35 +02008282 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008283 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008284 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008285 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008286 return err;
8287}
8288
Johannes Berg94e860f2014-01-20 23:58:15 +01008289static const struct nla_policy
8290nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008291 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8292 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8293 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008294 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8295 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8296 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008297};
8298
Thomas Pedersen84f10702012-07-12 16:17:33 -07008299static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008300 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008301{
8302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008303 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008304 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008305
Johannes Bergd9d8b012012-11-26 12:51:52 +01008306 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008307 return -EINVAL;
8308
Thomas Pedersen84f10702012-07-12 16:17:33 -07008309 if (!rdev->ops->set_cqm_txe_config)
8310 return -EOPNOTSUPP;
8311
8312 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8313 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8314 return -EOPNOTSUPP;
8315
Hila Gonene35e4d22012-06-27 17:19:42 +03008316 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008317}
8318
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008319static int nl80211_set_cqm_rssi(struct genl_info *info,
8320 s32 threshold, u32 hysteresis)
8321{
Johannes Berg4c476992010-10-04 21:36:35 +02008322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008323 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008324 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008325
8326 if (threshold > 0)
8327 return -EINVAL;
8328
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008329 /* disabling - hysteresis should also be zero then */
8330 if (threshold == 0)
8331 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008332
Johannes Berg4c476992010-10-04 21:36:35 +02008333 if (!rdev->ops->set_cqm_rssi_config)
8334 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008335
Johannes Berg074ac8d2010-09-16 14:58:22 +02008336 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008337 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8338 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008339
Hila Gonene35e4d22012-06-27 17:19:42 +03008340 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008341}
8342
8343static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8344{
8345 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8346 struct nlattr *cqm;
8347 int err;
8348
8349 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008350 if (!cqm)
8351 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008352
8353 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8354 nl80211_attr_cqm_policy);
8355 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008356 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008357
8358 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8359 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008360 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8361 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008362
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008363 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8364 }
8365
8366 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8367 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8368 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8369 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8370 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8371 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8372
8373 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8374 }
8375
8376 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008377}
8378
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008379static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8380{
8381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8382 struct net_device *dev = info->user_ptr[1];
8383 struct ocb_setup setup = {};
8384 int err;
8385
8386 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8387 if (err)
8388 return err;
8389
8390 return cfg80211_join_ocb(rdev, dev, &setup);
8391}
8392
8393static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8394{
8395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8396 struct net_device *dev = info->user_ptr[1];
8397
8398 return cfg80211_leave_ocb(rdev, dev);
8399}
8400
Johannes Berg29cbe682010-12-03 09:20:44 +01008401static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8402{
8403 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8404 struct net_device *dev = info->user_ptr[1];
8405 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008406 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008407 int err;
8408
8409 /* start with default */
8410 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008411 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008412
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008413 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008414 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008415 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008416 if (err)
8417 return err;
8418 }
8419
8420 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8421 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8422 return -EINVAL;
8423
Javier Cardonac80d5452010-12-16 17:37:49 -08008424 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8425 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8426
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008427 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8428 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8429 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8430 return -EINVAL;
8431
Marco Porsch9bdbf042013-01-07 16:04:51 +01008432 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8433 setup.beacon_interval =
8434 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8435 if (setup.beacon_interval < 10 ||
8436 setup.beacon_interval > 10000)
8437 return -EINVAL;
8438 }
8439
8440 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8441 setup.dtim_period =
8442 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8443 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8444 return -EINVAL;
8445 }
8446
Javier Cardonac80d5452010-12-16 17:37:49 -08008447 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8448 /* parse additional setup parameters if given */
8449 err = nl80211_parse_mesh_setup(info, &setup);
8450 if (err)
8451 return err;
8452 }
8453
Thomas Pedersend37bb182013-03-04 13:06:13 -08008454 if (setup.user_mpm)
8455 cfg.auto_open_plinks = false;
8456
Johannes Bergcc1d2802012-05-16 23:50:20 +02008457 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008458 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8459 if (err)
8460 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008461 } else {
8462 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008463 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008464 }
8465
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008466 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8467 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8468 int n_rates =
8469 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8470 struct ieee80211_supported_band *sband;
8471
8472 if (!setup.chandef.chan)
8473 return -EINVAL;
8474
8475 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8476
8477 err = ieee80211_get_ratemask(sband, rates, n_rates,
8478 &setup.basic_rates);
8479 if (err)
8480 return err;
8481 }
8482
Javier Cardonac80d5452010-12-16 17:37:49 -08008483 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008484}
8485
8486static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8487{
8488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8489 struct net_device *dev = info->user_ptr[1];
8490
8491 return cfg80211_leave_mesh(rdev, dev);
8492}
8493
Johannes Bergdfb89c52012-06-27 09:23:48 +02008494#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008495static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8496 struct cfg80211_registered_device *rdev)
8497{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008498 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008499 struct nlattr *nl_pats, *nl_pat;
8500 int i, pat_len;
8501
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008502 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008503 return 0;
8504
8505 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8506 if (!nl_pats)
8507 return -ENOBUFS;
8508
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008509 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008510 nl_pat = nla_nest_start(msg, i + 1);
8511 if (!nl_pat)
8512 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008513 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008514 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008515 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008516 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8517 wowlan->patterns[i].pattern) ||
8518 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008519 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008520 return -ENOBUFS;
8521 nla_nest_end(msg, nl_pat);
8522 }
8523 nla_nest_end(msg, nl_pats);
8524
8525 return 0;
8526}
8527
Johannes Berg2a0e0472013-01-23 22:57:40 +01008528static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8529 struct cfg80211_wowlan_tcp *tcp)
8530{
8531 struct nlattr *nl_tcp;
8532
8533 if (!tcp)
8534 return 0;
8535
8536 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8537 if (!nl_tcp)
8538 return -ENOBUFS;
8539
8540 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8541 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8542 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8543 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8544 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8545 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8546 tcp->payload_len, tcp->payload) ||
8547 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8548 tcp->data_interval) ||
8549 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8550 tcp->wake_len, tcp->wake_data) ||
8551 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8552 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8553 return -ENOBUFS;
8554
8555 if (tcp->payload_seq.len &&
8556 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8557 sizeof(tcp->payload_seq), &tcp->payload_seq))
8558 return -ENOBUFS;
8559
8560 if (tcp->payload_tok.len &&
8561 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8562 sizeof(tcp->payload_tok) + tcp->tokens_size,
8563 &tcp->payload_tok))
8564 return -ENOBUFS;
8565
Johannes Berge248ad32013-05-16 10:24:28 +02008566 nla_nest_end(msg, nl_tcp);
8567
Johannes Berg2a0e0472013-01-23 22:57:40 +01008568 return 0;
8569}
8570
Johannes Bergff1b6e62011-05-04 15:37:28 +02008571static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8572{
8573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8574 struct sk_buff *msg;
8575 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008576 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008577
Johannes Berg964dc9e2013-06-03 17:25:34 +02008578 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008579 return -EOPNOTSUPP;
8580
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008581 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008582 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008583 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8584 rdev->wiphy.wowlan_config->tcp->payload_len +
8585 rdev->wiphy.wowlan_config->tcp->wake_len +
8586 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008587 }
8588
8589 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008590 if (!msg)
8591 return -ENOMEM;
8592
Eric W. Biederman15e47302012-09-07 20:12:54 +00008593 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008594 NL80211_CMD_GET_WOWLAN);
8595 if (!hdr)
8596 goto nla_put_failure;
8597
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008598 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008599 struct nlattr *nl_wowlan;
8600
8601 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8602 if (!nl_wowlan)
8603 goto nla_put_failure;
8604
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008605 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008606 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008607 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008608 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008609 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008610 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008611 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008612 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008613 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008614 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008615 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008616 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008617 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008618 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8619 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008620
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008621 if (nl80211_send_wowlan_patterns(msg, rdev))
8622 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008623
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008624 if (nl80211_send_wowlan_tcp(msg,
8625 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008626 goto nla_put_failure;
8627
Johannes Bergff1b6e62011-05-04 15:37:28 +02008628 nla_nest_end(msg, nl_wowlan);
8629 }
8630
8631 genlmsg_end(msg, hdr);
8632 return genlmsg_reply(msg, info);
8633
8634nla_put_failure:
8635 nlmsg_free(msg);
8636 return -ENOBUFS;
8637}
8638
Johannes Berg2a0e0472013-01-23 22:57:40 +01008639static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8640 struct nlattr *attr,
8641 struct cfg80211_wowlan *trig)
8642{
8643 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8644 struct cfg80211_wowlan_tcp *cfg;
8645 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8646 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8647 u32 size;
8648 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8649 int err, port;
8650
Johannes Berg964dc9e2013-06-03 17:25:34 +02008651 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008652 return -EINVAL;
8653
8654 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8655 nla_data(attr), nla_len(attr),
8656 nl80211_wowlan_tcp_policy);
8657 if (err)
8658 return err;
8659
8660 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8661 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8662 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8663 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8664 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8665 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8666 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8667 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8668 return -EINVAL;
8669
8670 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008671 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008672 return -EINVAL;
8673
8674 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008675 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008676 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008677 return -EINVAL;
8678
8679 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008680 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008681 return -EINVAL;
8682
8683 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8684 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8685 return -EINVAL;
8686
8687 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8688 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8689
8690 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8691 tokens_size = tokln - sizeof(*tok);
8692
8693 if (!tok->len || tokens_size % tok->len)
8694 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008695 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008696 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008697 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008698 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008699 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008700 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008701 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008702 return -EINVAL;
8703 if (tok->offset + tok->len > data_size)
8704 return -EINVAL;
8705 }
8706
8707 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8708 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008709 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008710 return -EINVAL;
8711 if (seq->len == 0 || seq->len > 4)
8712 return -EINVAL;
8713 if (seq->len + seq->offset > data_size)
8714 return -EINVAL;
8715 }
8716
8717 size = sizeof(*cfg);
8718 size += data_size;
8719 size += wake_size + wake_mask_size;
8720 size += tokens_size;
8721
8722 cfg = kzalloc(size, GFP_KERNEL);
8723 if (!cfg)
8724 return -ENOMEM;
8725 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8726 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8727 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8728 ETH_ALEN);
8729 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8730 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8731 else
8732 port = 0;
8733#ifdef CONFIG_INET
8734 /* allocate a socket and port for it and use it */
8735 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8736 IPPROTO_TCP, &cfg->sock, 1);
8737 if (err) {
8738 kfree(cfg);
8739 return err;
8740 }
8741 if (inet_csk_get_port(cfg->sock->sk, port)) {
8742 sock_release(cfg->sock);
8743 kfree(cfg);
8744 return -EADDRINUSE;
8745 }
8746 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8747#else
8748 if (!port) {
8749 kfree(cfg);
8750 return -EINVAL;
8751 }
8752 cfg->src_port = port;
8753#endif
8754
8755 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8756 cfg->payload_len = data_size;
8757 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8758 memcpy((void *)cfg->payload,
8759 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8760 data_size);
8761 if (seq)
8762 cfg->payload_seq = *seq;
8763 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8764 cfg->wake_len = wake_size;
8765 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8766 memcpy((void *)cfg->wake_data,
8767 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8768 wake_size);
8769 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8770 data_size + wake_size;
8771 memcpy((void *)cfg->wake_mask,
8772 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8773 wake_mask_size);
8774 if (tok) {
8775 cfg->tokens_size = tokens_size;
8776 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8777 }
8778
8779 trig->tcp = cfg;
8780
8781 return 0;
8782}
8783
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008784static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
8785 const struct wiphy_wowlan_support *wowlan,
8786 struct nlattr *attr,
8787 struct cfg80211_wowlan *trig)
8788{
8789 struct nlattr **tb;
8790 int err;
8791
8792 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
8793 if (!tb)
8794 return -ENOMEM;
8795
8796 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
8797 err = -EOPNOTSUPP;
8798 goto out;
8799 }
8800
8801 err = nla_parse(tb, NL80211_ATTR_MAX,
8802 nla_data(attr), nla_len(attr),
8803 nl80211_policy);
8804 if (err)
8805 goto out;
8806
Johannes Bergad2b26a2014-06-12 21:39:05 +02008807 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008808 err = PTR_ERR_OR_ZERO(trig->nd_config);
8809 if (err)
8810 trig->nd_config = NULL;
8811
8812out:
8813 kfree(tb);
8814 return err;
8815}
8816
Johannes Bergff1b6e62011-05-04 15:37:28 +02008817static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8818{
8819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8820 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008821 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008822 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008823 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008824 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008825 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008826
Johannes Berg964dc9e2013-06-03 17:25:34 +02008827 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008828 return -EOPNOTSUPP;
8829
Johannes Bergae33bd82012-07-12 16:25:02 +02008830 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8831 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008832 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008833 goto set_wakeup;
8834 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008835
8836 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8837 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8838 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8839 nl80211_wowlan_policy);
8840 if (err)
8841 return err;
8842
8843 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8844 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8845 return -EINVAL;
8846 new_triggers.any = true;
8847 }
8848
8849 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8850 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8851 return -EINVAL;
8852 new_triggers.disconnect = true;
8853 }
8854
8855 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8856 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8857 return -EINVAL;
8858 new_triggers.magic_pkt = true;
8859 }
8860
Johannes Berg77dbbb12011-07-13 10:48:55 +02008861 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8862 return -EINVAL;
8863
8864 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8865 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8866 return -EINVAL;
8867 new_triggers.gtk_rekey_failure = true;
8868 }
8869
8870 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8871 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8872 return -EINVAL;
8873 new_triggers.eap_identity_req = true;
8874 }
8875
8876 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8877 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8878 return -EINVAL;
8879 new_triggers.four_way_handshake = true;
8880 }
8881
8882 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8883 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8884 return -EINVAL;
8885 new_triggers.rfkill_release = true;
8886 }
8887
Johannes Bergff1b6e62011-05-04 15:37:28 +02008888 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8889 struct nlattr *pat;
8890 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008891 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008892 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008893
8894 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8895 rem)
8896 n_patterns++;
8897 if (n_patterns > wowlan->n_patterns)
8898 return -EINVAL;
8899
8900 new_triggers.patterns = kcalloc(n_patterns,
8901 sizeof(new_triggers.patterns[0]),
8902 GFP_KERNEL);
8903 if (!new_triggers.patterns)
8904 return -ENOMEM;
8905
8906 new_triggers.n_patterns = n_patterns;
8907 i = 0;
8908
8909 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8910 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008911 u8 *mask_pat;
8912
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008913 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8914 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008915 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008916 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8917 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008918 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008919 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008920 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008921 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008922 goto error;
8923 if (pat_len > wowlan->pattern_max_len ||
8924 pat_len < wowlan->pattern_min_len)
8925 goto error;
8926
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008927 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008928 pkt_offset = 0;
8929 else
8930 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008931 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008932 if (pkt_offset > wowlan->max_pkt_offset)
8933 goto error;
8934 new_triggers.patterns[i].pkt_offset = pkt_offset;
8935
Johannes Berg922bd802014-05-19 17:59:50 +02008936 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8937 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008938 err = -ENOMEM;
8939 goto error;
8940 }
Johannes Berg922bd802014-05-19 17:59:50 +02008941 new_triggers.patterns[i].mask = mask_pat;
8942 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008943 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008944 mask_pat += mask_len;
8945 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008946 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008947 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008948 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008949 pat_len);
8950 i++;
8951 }
8952 }
8953
Johannes Berg2a0e0472013-01-23 22:57:40 +01008954 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8955 err = nl80211_parse_wowlan_tcp(
8956 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8957 &new_triggers);
8958 if (err)
8959 goto error;
8960 }
8961
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008962 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
8963 err = nl80211_parse_wowlan_nd(
8964 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
8965 &new_triggers);
8966 if (err)
8967 goto error;
8968 }
8969
Johannes Bergae33bd82012-07-12 16:25:02 +02008970 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8971 if (!ntrig) {
8972 err = -ENOMEM;
8973 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008974 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008975 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008976 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008977
Johannes Bergae33bd82012-07-12 16:25:02 +02008978 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008979 if (rdev->ops->set_wakeup &&
8980 prev_enabled != !!rdev->wiphy.wowlan_config)
8981 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008982
Johannes Bergff1b6e62011-05-04 15:37:28 +02008983 return 0;
8984 error:
8985 for (i = 0; i < new_triggers.n_patterns; i++)
8986 kfree(new_triggers.patterns[i].mask);
8987 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008988 if (new_triggers.tcp && new_triggers.tcp->sock)
8989 sock_release(new_triggers.tcp->sock);
8990 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008991 return err;
8992}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008993#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008994
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008995static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8996 struct cfg80211_registered_device *rdev)
8997{
8998 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8999 int i, j, pat_len;
9000 struct cfg80211_coalesce_rules *rule;
9001
9002 if (!rdev->coalesce->n_rules)
9003 return 0;
9004
9005 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9006 if (!nl_rules)
9007 return -ENOBUFS;
9008
9009 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9010 nl_rule = nla_nest_start(msg, i + 1);
9011 if (!nl_rule)
9012 return -ENOBUFS;
9013
9014 rule = &rdev->coalesce->rules[i];
9015 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9016 rule->delay))
9017 return -ENOBUFS;
9018
9019 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9020 rule->condition))
9021 return -ENOBUFS;
9022
9023 nl_pats = nla_nest_start(msg,
9024 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9025 if (!nl_pats)
9026 return -ENOBUFS;
9027
9028 for (j = 0; j < rule->n_patterns; j++) {
9029 nl_pat = nla_nest_start(msg, j + 1);
9030 if (!nl_pat)
9031 return -ENOBUFS;
9032 pat_len = rule->patterns[j].pattern_len;
9033 if (nla_put(msg, NL80211_PKTPAT_MASK,
9034 DIV_ROUND_UP(pat_len, 8),
9035 rule->patterns[j].mask) ||
9036 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9037 rule->patterns[j].pattern) ||
9038 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9039 rule->patterns[j].pkt_offset))
9040 return -ENOBUFS;
9041 nla_nest_end(msg, nl_pat);
9042 }
9043 nla_nest_end(msg, nl_pats);
9044 nla_nest_end(msg, nl_rule);
9045 }
9046 nla_nest_end(msg, nl_rules);
9047
9048 return 0;
9049}
9050
9051static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9052{
9053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9054 struct sk_buff *msg;
9055 void *hdr;
9056
9057 if (!rdev->wiphy.coalesce)
9058 return -EOPNOTSUPP;
9059
9060 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9061 if (!msg)
9062 return -ENOMEM;
9063
9064 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9065 NL80211_CMD_GET_COALESCE);
9066 if (!hdr)
9067 goto nla_put_failure;
9068
9069 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9070 goto nla_put_failure;
9071
9072 genlmsg_end(msg, hdr);
9073 return genlmsg_reply(msg, info);
9074
9075nla_put_failure:
9076 nlmsg_free(msg);
9077 return -ENOBUFS;
9078}
9079
9080void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9081{
9082 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9083 int i, j;
9084 struct cfg80211_coalesce_rules *rule;
9085
9086 if (!coalesce)
9087 return;
9088
9089 for (i = 0; i < coalesce->n_rules; i++) {
9090 rule = &coalesce->rules[i];
9091 for (j = 0; j < rule->n_patterns; j++)
9092 kfree(rule->patterns[j].mask);
9093 kfree(rule->patterns);
9094 }
9095 kfree(coalesce->rules);
9096 kfree(coalesce);
9097 rdev->coalesce = NULL;
9098}
9099
9100static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9101 struct nlattr *rule,
9102 struct cfg80211_coalesce_rules *new_rule)
9103{
9104 int err, i;
9105 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9106 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9107 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9108 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9109
9110 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9111 nla_len(rule), nl80211_coalesce_policy);
9112 if (err)
9113 return err;
9114
9115 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9116 new_rule->delay =
9117 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9118 if (new_rule->delay > coalesce->max_delay)
9119 return -EINVAL;
9120
9121 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9122 new_rule->condition =
9123 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9124 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9125 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9126 return -EINVAL;
9127
9128 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9129 return -EINVAL;
9130
9131 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9132 rem)
9133 n_patterns++;
9134 if (n_patterns > coalesce->n_patterns)
9135 return -EINVAL;
9136
9137 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9138 GFP_KERNEL);
9139 if (!new_rule->patterns)
9140 return -ENOMEM;
9141
9142 new_rule->n_patterns = n_patterns;
9143 i = 0;
9144
9145 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9146 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009147 u8 *mask_pat;
9148
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009149 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9150 nla_len(pat), NULL);
9151 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9152 !pat_tb[NL80211_PKTPAT_PATTERN])
9153 return -EINVAL;
9154 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9155 mask_len = DIV_ROUND_UP(pat_len, 8);
9156 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9157 return -EINVAL;
9158 if (pat_len > coalesce->pattern_max_len ||
9159 pat_len < coalesce->pattern_min_len)
9160 return -EINVAL;
9161
9162 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9163 pkt_offset = 0;
9164 else
9165 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9166 if (pkt_offset > coalesce->max_pkt_offset)
9167 return -EINVAL;
9168 new_rule->patterns[i].pkt_offset = pkt_offset;
9169
Johannes Berg922bd802014-05-19 17:59:50 +02009170 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9171 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009172 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009173
9174 new_rule->patterns[i].mask = mask_pat;
9175 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9176 mask_len);
9177
9178 mask_pat += mask_len;
9179 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009180 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009181 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9182 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009183 i++;
9184 }
9185
9186 return 0;
9187}
9188
9189static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9190{
9191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9192 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9193 struct cfg80211_coalesce new_coalesce = {};
9194 struct cfg80211_coalesce *n_coalesce;
9195 int err, rem_rule, n_rules = 0, i, j;
9196 struct nlattr *rule;
9197 struct cfg80211_coalesce_rules *tmp_rule;
9198
9199 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9200 return -EOPNOTSUPP;
9201
9202 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9203 cfg80211_rdev_free_coalesce(rdev);
9204 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9205 return 0;
9206 }
9207
9208 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9209 rem_rule)
9210 n_rules++;
9211 if (n_rules > coalesce->n_rules)
9212 return -EINVAL;
9213
9214 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9215 GFP_KERNEL);
9216 if (!new_coalesce.rules)
9217 return -ENOMEM;
9218
9219 new_coalesce.n_rules = n_rules;
9220 i = 0;
9221
9222 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9223 rem_rule) {
9224 err = nl80211_parse_coalesce_rule(rdev, rule,
9225 &new_coalesce.rules[i]);
9226 if (err)
9227 goto error;
9228
9229 i++;
9230 }
9231
9232 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9233 if (err)
9234 goto error;
9235
9236 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9237 if (!n_coalesce) {
9238 err = -ENOMEM;
9239 goto error;
9240 }
9241 cfg80211_rdev_free_coalesce(rdev);
9242 rdev->coalesce = n_coalesce;
9243
9244 return 0;
9245error:
9246 for (i = 0; i < new_coalesce.n_rules; i++) {
9247 tmp_rule = &new_coalesce.rules[i];
9248 for (j = 0; j < tmp_rule->n_patterns; j++)
9249 kfree(tmp_rule->patterns[j].mask);
9250 kfree(tmp_rule->patterns);
9251 }
9252 kfree(new_coalesce.rules);
9253
9254 return err;
9255}
9256
Johannes Berge5497d72011-07-05 16:35:40 +02009257static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9258{
9259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9260 struct net_device *dev = info->user_ptr[1];
9261 struct wireless_dev *wdev = dev->ieee80211_ptr;
9262 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9263 struct cfg80211_gtk_rekey_data rekey_data;
9264 int err;
9265
9266 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9267 return -EINVAL;
9268
9269 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9270 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9271 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9272 nl80211_rekey_policy);
9273 if (err)
9274 return err;
9275
9276 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9277 return -ERANGE;
9278 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9279 return -ERANGE;
9280 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9281 return -ERANGE;
9282
Johannes Berg78f686c2014-09-10 22:28:06 +03009283 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9284 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9285 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009286
9287 wdev_lock(wdev);
9288 if (!wdev->current_bss) {
9289 err = -ENOTCONN;
9290 goto out;
9291 }
9292
9293 if (!rdev->ops->set_rekey_data) {
9294 err = -EOPNOTSUPP;
9295 goto out;
9296 }
9297
Hila Gonene35e4d22012-06-27 17:19:42 +03009298 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009299 out:
9300 wdev_unlock(wdev);
9301 return err;
9302}
9303
Johannes Berg28946da2011-11-04 11:18:12 +01009304static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9305 struct genl_info *info)
9306{
9307 struct net_device *dev = info->user_ptr[1];
9308 struct wireless_dev *wdev = dev->ieee80211_ptr;
9309
9310 if (wdev->iftype != NL80211_IFTYPE_AP &&
9311 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9312 return -EINVAL;
9313
Eric W. Biederman15e47302012-09-07 20:12:54 +00009314 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009315 return -EBUSY;
9316
Eric W. Biederman15e47302012-09-07 20:12:54 +00009317 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009318 return 0;
9319}
9320
Johannes Berg7f6cf312011-11-04 11:18:15 +01009321static int nl80211_probe_client(struct sk_buff *skb,
9322 struct genl_info *info)
9323{
9324 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9325 struct net_device *dev = info->user_ptr[1];
9326 struct wireless_dev *wdev = dev->ieee80211_ptr;
9327 struct sk_buff *msg;
9328 void *hdr;
9329 const u8 *addr;
9330 u64 cookie;
9331 int err;
9332
9333 if (wdev->iftype != NL80211_IFTYPE_AP &&
9334 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9335 return -EOPNOTSUPP;
9336
9337 if (!info->attrs[NL80211_ATTR_MAC])
9338 return -EINVAL;
9339
9340 if (!rdev->ops->probe_client)
9341 return -EOPNOTSUPP;
9342
9343 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9344 if (!msg)
9345 return -ENOMEM;
9346
Eric W. Biederman15e47302012-09-07 20:12:54 +00009347 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009348 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009349 if (!hdr) {
9350 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009351 goto free_msg;
9352 }
9353
9354 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9355
Hila Gonene35e4d22012-06-27 17:19:42 +03009356 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009357 if (err)
9358 goto free_msg;
9359
David S. Miller9360ffd2012-03-29 04:41:26 -04009360 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9361 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009362
9363 genlmsg_end(msg, hdr);
9364
9365 return genlmsg_reply(msg, info);
9366
9367 nla_put_failure:
9368 err = -ENOBUFS;
9369 free_msg:
9370 nlmsg_free(msg);
9371 return err;
9372}
9373
Johannes Berg5e7602302011-11-04 11:18:17 +01009374static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9375{
9376 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009377 struct cfg80211_beacon_registration *reg, *nreg;
9378 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009379
9380 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9381 return -EOPNOTSUPP;
9382
Ben Greear37c73b52012-10-26 14:49:25 -07009383 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9384 if (!nreg)
9385 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01009386
Ben Greear37c73b52012-10-26 14:49:25 -07009387 /* First, check if already registered. */
9388 spin_lock_bh(&rdev->beacon_registrations_lock);
9389 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9390 if (reg->nlportid == info->snd_portid) {
9391 rv = -EALREADY;
9392 goto out_err;
9393 }
9394 }
9395 /* Add it to the list */
9396 nreg->nlportid = info->snd_portid;
9397 list_add(&nreg->list, &rdev->beacon_registrations);
9398
9399 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01009400
9401 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009402out_err:
9403 spin_unlock_bh(&rdev->beacon_registrations_lock);
9404 kfree(nreg);
9405 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009406}
9407
Johannes Berg98104fde2012-06-16 00:19:54 +02009408static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9409{
9410 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9411 struct wireless_dev *wdev = info->user_ptr[1];
9412 int err;
9413
9414 if (!rdev->ops->start_p2p_device)
9415 return -EOPNOTSUPP;
9416
9417 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9418 return -EOPNOTSUPP;
9419
9420 if (wdev->p2p_started)
9421 return 0;
9422
Luciano Coelhob6a55012014-02-27 11:07:21 +02009423 if (rfkill_blocked(rdev->rfkill))
9424 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009425
Johannes Bergeeb126e2012-10-23 15:16:50 +02009426 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009427 if (err)
9428 return err;
9429
9430 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009431 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009432
9433 return 0;
9434}
9435
9436static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9437{
9438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9439 struct wireless_dev *wdev = info->user_ptr[1];
9440
9441 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9442 return -EOPNOTSUPP;
9443
9444 if (!rdev->ops->stop_p2p_device)
9445 return -EOPNOTSUPP;
9446
Johannes Bergf9f47522013-03-19 15:04:07 +01009447 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009448
9449 return 0;
9450}
9451
Johannes Berg3713b4e2013-02-14 16:19:38 +01009452static int nl80211_get_protocol_features(struct sk_buff *skb,
9453 struct genl_info *info)
9454{
9455 void *hdr;
9456 struct sk_buff *msg;
9457
9458 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9459 if (!msg)
9460 return -ENOMEM;
9461
9462 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9463 NL80211_CMD_GET_PROTOCOL_FEATURES);
9464 if (!hdr)
9465 goto nla_put_failure;
9466
9467 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9468 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9469 goto nla_put_failure;
9470
9471 genlmsg_end(msg, hdr);
9472 return genlmsg_reply(msg, info);
9473
9474 nla_put_failure:
9475 kfree_skb(msg);
9476 return -ENOBUFS;
9477}
9478
Jouni Malinen355199e2013-02-27 17:14:27 +02009479static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9480{
9481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9482 struct cfg80211_update_ft_ies_params ft_params;
9483 struct net_device *dev = info->user_ptr[1];
9484
9485 if (!rdev->ops->update_ft_ies)
9486 return -EOPNOTSUPP;
9487
9488 if (!info->attrs[NL80211_ATTR_MDID] ||
9489 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9490 return -EINVAL;
9491
9492 memset(&ft_params, 0, sizeof(ft_params));
9493 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9494 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9495 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9496
9497 return rdev_update_ft_ies(rdev, dev, &ft_params);
9498}
9499
Arend van Spriel5de17982013-04-18 15:49:00 +02009500static int nl80211_crit_protocol_start(struct sk_buff *skb,
9501 struct genl_info *info)
9502{
9503 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9504 struct wireless_dev *wdev = info->user_ptr[1];
9505 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9506 u16 duration;
9507 int ret;
9508
9509 if (!rdev->ops->crit_proto_start)
9510 return -EOPNOTSUPP;
9511
9512 if (WARN_ON(!rdev->ops->crit_proto_stop))
9513 return -EINVAL;
9514
9515 if (rdev->crit_proto_nlportid)
9516 return -EBUSY;
9517
9518 /* determine protocol if provided */
9519 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9520 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9521
9522 if (proto >= NUM_NL80211_CRIT_PROTO)
9523 return -EINVAL;
9524
9525 /* timeout must be provided */
9526 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9527 return -EINVAL;
9528
9529 duration =
9530 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9531
9532 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9533 return -ERANGE;
9534
9535 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9536 if (!ret)
9537 rdev->crit_proto_nlportid = info->snd_portid;
9538
9539 return ret;
9540}
9541
9542static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9543 struct genl_info *info)
9544{
9545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9546 struct wireless_dev *wdev = info->user_ptr[1];
9547
9548 if (!rdev->ops->crit_proto_stop)
9549 return -EOPNOTSUPP;
9550
9551 if (rdev->crit_proto_nlportid) {
9552 rdev->crit_proto_nlportid = 0;
9553 rdev_crit_proto_stop(rdev, wdev);
9554 }
9555 return 0;
9556}
9557
Johannes Bergad7e7182013-11-13 13:37:47 +01009558static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9559{
9560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9561 struct wireless_dev *wdev =
9562 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9563 int i, err;
9564 u32 vid, subcmd;
9565
9566 if (!rdev->wiphy.vendor_commands)
9567 return -EOPNOTSUPP;
9568
9569 if (IS_ERR(wdev)) {
9570 err = PTR_ERR(wdev);
9571 if (err != -EINVAL)
9572 return err;
9573 wdev = NULL;
9574 } else if (wdev->wiphy != &rdev->wiphy) {
9575 return -EINVAL;
9576 }
9577
9578 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9579 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9580 return -EINVAL;
9581
9582 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9583 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9584 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9585 const struct wiphy_vendor_command *vcmd;
9586 void *data = NULL;
9587 int len = 0;
9588
9589 vcmd = &rdev->wiphy.vendor_commands[i];
9590
9591 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9592 continue;
9593
9594 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9595 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9596 if (!wdev)
9597 return -EINVAL;
9598 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9599 !wdev->netdev)
9600 return -EINVAL;
9601
9602 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9603 if (wdev->netdev &&
9604 !netif_running(wdev->netdev))
9605 return -ENETDOWN;
9606 if (!wdev->netdev && !wdev->p2p_started)
9607 return -ENETDOWN;
9608 }
9609 } else {
9610 wdev = NULL;
9611 }
9612
9613 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9614 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9615 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9616 }
9617
9618 rdev->cur_cmd_info = info;
9619 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9620 data, len);
9621 rdev->cur_cmd_info = NULL;
9622 return err;
9623 }
9624
9625 return -EOPNOTSUPP;
9626}
9627
9628struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9629 enum nl80211_commands cmd,
9630 enum nl80211_attrs attr,
9631 int approxlen)
9632{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009633 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009634
9635 if (WARN_ON(!rdev->cur_cmd_info))
9636 return NULL;
9637
9638 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9639 rdev->cur_cmd_info->snd_portid,
9640 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009641 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009642}
9643EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9644
9645int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9646{
9647 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9648 void *hdr = ((void **)skb->cb)[1];
9649 struct nlattr *data = ((void **)skb->cb)[2];
9650
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009651 /* clear CB data for netlink core to own from now on */
9652 memset(skb->cb, 0, sizeof(skb->cb));
9653
Johannes Bergad7e7182013-11-13 13:37:47 +01009654 if (WARN_ON(!rdev->cur_cmd_info)) {
9655 kfree_skb(skb);
9656 return -EINVAL;
9657 }
9658
9659 nla_nest_end(skb, data);
9660 genlmsg_end(skb, hdr);
9661 return genlmsg_reply(skb, rdev->cur_cmd_info);
9662}
9663EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9664
9665
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009666static int nl80211_set_qos_map(struct sk_buff *skb,
9667 struct genl_info *info)
9668{
9669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9670 struct cfg80211_qos_map *qos_map = NULL;
9671 struct net_device *dev = info->user_ptr[1];
9672 u8 *pos, len, num_des, des_len, des;
9673 int ret;
9674
9675 if (!rdev->ops->set_qos_map)
9676 return -EOPNOTSUPP;
9677
9678 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9679 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9680 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9681
9682 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9683 len > IEEE80211_QOS_MAP_LEN_MAX)
9684 return -EINVAL;
9685
9686 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9687 if (!qos_map)
9688 return -ENOMEM;
9689
9690 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9691 if (num_des) {
9692 des_len = num_des *
9693 sizeof(struct cfg80211_dscp_exception);
9694 memcpy(qos_map->dscp_exception, pos, des_len);
9695 qos_map->num_des = num_des;
9696 for (des = 0; des < num_des; des++) {
9697 if (qos_map->dscp_exception[des].up > 7) {
9698 kfree(qos_map);
9699 return -EINVAL;
9700 }
9701 }
9702 pos += des_len;
9703 }
9704 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9705 }
9706
9707 wdev_lock(dev->ieee80211_ptr);
9708 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9709 if (!ret)
9710 ret = rdev_set_qos_map(rdev, dev, qos_map);
9711 wdev_unlock(dev->ieee80211_ptr);
9712
9713 kfree(qos_map);
9714 return ret;
9715}
9716
Johannes Berg960d01a2014-09-09 22:55:35 +03009717static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9718{
9719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9720 struct net_device *dev = info->user_ptr[1];
9721 struct wireless_dev *wdev = dev->ieee80211_ptr;
9722 const u8 *peer;
9723 u8 tsid, up;
9724 u16 admitted_time = 0;
9725 int err;
9726
Johannes Berg723e73a2014-10-22 09:25:06 +02009727 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009728 return -EOPNOTSUPP;
9729
9730 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9731 !info->attrs[NL80211_ATTR_USER_PRIO])
9732 return -EINVAL;
9733
9734 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9735 if (tsid >= IEEE80211_NUM_TIDS)
9736 return -EINVAL;
9737
9738 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9739 if (up >= IEEE80211_NUM_UPS)
9740 return -EINVAL;
9741
9742 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009743 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009744 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009745 * need more attributes for that (e.g. BA session requirement);
9746 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009747 */
9748 return -EINVAL;
9749 }
9750
9751 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9752
9753 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9754 admitted_time =
9755 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9756 if (!admitted_time)
9757 return -EINVAL;
9758 }
9759
9760 wdev_lock(wdev);
9761 switch (wdev->iftype) {
9762 case NL80211_IFTYPE_STATION:
9763 case NL80211_IFTYPE_P2P_CLIENT:
9764 if (wdev->current_bss)
9765 break;
9766 err = -ENOTCONN;
9767 goto out;
9768 default:
9769 err = -EOPNOTSUPP;
9770 goto out;
9771 }
9772
9773 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9774
9775 out:
9776 wdev_unlock(wdev);
9777 return err;
9778}
9779
9780static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9781{
9782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9783 struct net_device *dev = info->user_ptr[1];
9784 struct wireless_dev *wdev = dev->ieee80211_ptr;
9785 const u8 *peer;
9786 u8 tsid;
9787 int err;
9788
9789 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9790 return -EINVAL;
9791
9792 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9793 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9794
9795 wdev_lock(wdev);
9796 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9797 wdev_unlock(wdev);
9798
9799 return err;
9800}
9801
Arik Nemtsov1057d352014-11-19 12:54:26 +02009802static int nl80211_tdls_channel_switch(struct sk_buff *skb,
9803 struct genl_info *info)
9804{
9805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9806 struct net_device *dev = info->user_ptr[1];
9807 struct wireless_dev *wdev = dev->ieee80211_ptr;
9808 struct cfg80211_chan_def chandef = {};
9809 const u8 *addr;
9810 u8 oper_class;
9811 int err;
9812
9813 if (!rdev->ops->tdls_channel_switch ||
9814 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9815 return -EOPNOTSUPP;
9816
9817 switch (dev->ieee80211_ptr->iftype) {
9818 case NL80211_IFTYPE_STATION:
9819 case NL80211_IFTYPE_P2P_CLIENT:
9820 break;
9821 default:
9822 return -EOPNOTSUPP;
9823 }
9824
9825 if (!info->attrs[NL80211_ATTR_MAC] ||
9826 !info->attrs[NL80211_ATTR_OPER_CLASS])
9827 return -EINVAL;
9828
9829 err = nl80211_parse_chandef(rdev, info, &chandef);
9830 if (err)
9831 return err;
9832
9833 /*
9834 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
9835 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
9836 * specification is not defined for them.
9837 */
9838 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
9839 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
9840 chandef.width != NL80211_CHAN_WIDTH_20)
9841 return -EINVAL;
9842
9843 /* we will be active on the TDLS link */
9844 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
9845 return -EINVAL;
9846
9847 /* don't allow switching to DFS channels */
9848 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
9849 return -EINVAL;
9850
9851 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9852 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
9853
9854 wdev_lock(wdev);
9855 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
9856 wdev_unlock(wdev);
9857
9858 return err;
9859}
9860
9861static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
9862 struct genl_info *info)
9863{
9864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9865 struct net_device *dev = info->user_ptr[1];
9866 struct wireless_dev *wdev = dev->ieee80211_ptr;
9867 const u8 *addr;
9868
9869 if (!rdev->ops->tdls_channel_switch ||
9870 !rdev->ops->tdls_cancel_channel_switch ||
9871 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9872 return -EOPNOTSUPP;
9873
9874 switch (dev->ieee80211_ptr->iftype) {
9875 case NL80211_IFTYPE_STATION:
9876 case NL80211_IFTYPE_P2P_CLIENT:
9877 break;
9878 default:
9879 return -EOPNOTSUPP;
9880 }
9881
9882 if (!info->attrs[NL80211_ATTR_MAC])
9883 return -EINVAL;
9884
9885 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9886
9887 wdev_lock(wdev);
9888 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
9889 wdev_unlock(wdev);
9890
9891 return 0;
9892}
9893
Johannes Berg4c476992010-10-04 21:36:35 +02009894#define NL80211_FLAG_NEED_WIPHY 0x01
9895#define NL80211_FLAG_NEED_NETDEV 0x02
9896#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009897#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9898#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9899 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009900#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009901/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009902#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9903 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +03009904#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +02009905
Johannes Bergf84f7712013-11-14 17:14:45 +01009906static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009907 struct genl_info *info)
9908{
9909 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009910 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009911 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009912 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9913
9914 if (rtnl)
9915 rtnl_lock();
9916
9917 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009918 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009919 if (IS_ERR(rdev)) {
9920 if (rtnl)
9921 rtnl_unlock();
9922 return PTR_ERR(rdev);
9923 }
9924 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009925 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9926 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009927 ASSERT_RTNL();
9928
Johannes Berg89a54e42012-06-15 14:33:17 +02009929 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9930 info->attrs);
9931 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009932 if (rtnl)
9933 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009934 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009935 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009936
Johannes Berg89a54e42012-06-15 14:33:17 +02009937 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009938 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009939
Johannes Berg1bf614e2012-06-15 15:23:36 +02009940 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9941 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009942 if (rtnl)
9943 rtnl_unlock();
9944 return -EINVAL;
9945 }
9946
9947 info->user_ptr[1] = dev;
9948 } else {
9949 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009950 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009951
Johannes Berg1bf614e2012-06-15 15:23:36 +02009952 if (dev) {
9953 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9954 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009955 if (rtnl)
9956 rtnl_unlock();
9957 return -ENETDOWN;
9958 }
9959
9960 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009961 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9962 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009963 if (rtnl)
9964 rtnl_unlock();
9965 return -ENETDOWN;
9966 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009967 }
9968
Johannes Berg4c476992010-10-04 21:36:35 +02009969 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009970 }
9971
9972 return 0;
9973}
9974
Johannes Bergf84f7712013-11-14 17:14:45 +01009975static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009976 struct genl_info *info)
9977{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009978 if (info->user_ptr[1]) {
9979 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9980 struct wireless_dev *wdev = info->user_ptr[1];
9981
9982 if (wdev->netdev)
9983 dev_put(wdev->netdev);
9984 } else {
9985 dev_put(info->user_ptr[1]);
9986 }
9987 }
Johannes Berg5393b912014-09-10 15:00:16 +03009988
Johannes Berg4c476992010-10-04 21:36:35 +02009989 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9990 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +03009991
9992 /* If needed, clear the netlink message payload from the SKB
9993 * as it might contain key data that shouldn't stick around on
9994 * the heap after the SKB is freed. The netlink message header
9995 * is still needed for further processing, so leave it intact.
9996 */
9997 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
9998 struct nlmsghdr *nlh = nlmsg_hdr(skb);
9999
10000 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10001 }
Johannes Berg4c476992010-10-04 21:36:35 +020010002}
10003
Johannes Berg4534de82013-11-14 17:14:46 +010010004static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010005 {
10006 .cmd = NL80211_CMD_GET_WIPHY,
10007 .doit = nl80211_get_wiphy,
10008 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010009 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010010 .policy = nl80211_policy,
10011 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010012 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10013 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010014 },
10015 {
10016 .cmd = NL80211_CMD_SET_WIPHY,
10017 .doit = nl80211_set_wiphy,
10018 .policy = nl80211_policy,
10019 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010020 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010021 },
10022 {
10023 .cmd = NL80211_CMD_GET_INTERFACE,
10024 .doit = nl80211_get_interface,
10025 .dumpit = nl80211_dump_interface,
10026 .policy = nl80211_policy,
10027 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010028 .internal_flags = NL80211_FLAG_NEED_WDEV |
10029 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010030 },
10031 {
10032 .cmd = NL80211_CMD_SET_INTERFACE,
10033 .doit = nl80211_set_interface,
10034 .policy = nl80211_policy,
10035 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010036 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10037 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010038 },
10039 {
10040 .cmd = NL80211_CMD_NEW_INTERFACE,
10041 .doit = nl80211_new_interface,
10042 .policy = nl80211_policy,
10043 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010044 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10045 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010046 },
10047 {
10048 .cmd = NL80211_CMD_DEL_INTERFACE,
10049 .doit = nl80211_del_interface,
10050 .policy = nl80211_policy,
10051 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010052 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010053 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010054 },
Johannes Berg41ade002007-12-19 02:03:29 +010010055 {
10056 .cmd = NL80211_CMD_GET_KEY,
10057 .doit = nl80211_get_key,
10058 .policy = nl80211_policy,
10059 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010060 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010061 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010062 },
10063 {
10064 .cmd = NL80211_CMD_SET_KEY,
10065 .doit = nl80211_set_key,
10066 .policy = nl80211_policy,
10067 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010068 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010069 NL80211_FLAG_NEED_RTNL |
10070 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010071 },
10072 {
10073 .cmd = NL80211_CMD_NEW_KEY,
10074 .doit = nl80211_new_key,
10075 .policy = nl80211_policy,
10076 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010077 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010078 NL80211_FLAG_NEED_RTNL |
10079 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010080 },
10081 {
10082 .cmd = NL80211_CMD_DEL_KEY,
10083 .doit = nl80211_del_key,
10084 .policy = nl80211_policy,
10085 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010086 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010087 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010088 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010089 {
10090 .cmd = NL80211_CMD_SET_BEACON,
10091 .policy = nl80211_policy,
10092 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010093 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010094 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010095 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010096 },
10097 {
Johannes Berg88600202012-02-13 15:17:18 +010010098 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010099 .policy = nl80211_policy,
10100 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010101 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010102 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010103 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010104 },
10105 {
Johannes Berg88600202012-02-13 15:17:18 +010010106 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010107 .policy = nl80211_policy,
10108 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010109 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010110 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010111 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010112 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010113 {
10114 .cmd = NL80211_CMD_GET_STATION,
10115 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010116 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010117 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010118 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10119 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010120 },
10121 {
10122 .cmd = NL80211_CMD_SET_STATION,
10123 .doit = nl80211_set_station,
10124 .policy = nl80211_policy,
10125 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010126 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010127 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010128 },
10129 {
10130 .cmd = NL80211_CMD_NEW_STATION,
10131 .doit = nl80211_new_station,
10132 .policy = nl80211_policy,
10133 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010134 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010135 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010136 },
10137 {
10138 .cmd = NL80211_CMD_DEL_STATION,
10139 .doit = nl80211_del_station,
10140 .policy = nl80211_policy,
10141 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010142 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010143 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010144 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010145 {
10146 .cmd = NL80211_CMD_GET_MPATH,
10147 .doit = nl80211_get_mpath,
10148 .dumpit = nl80211_dump_mpath,
10149 .policy = nl80211_policy,
10150 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010151 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010152 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010153 },
10154 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010155 .cmd = NL80211_CMD_GET_MPP,
10156 .doit = nl80211_get_mpp,
10157 .dumpit = nl80211_dump_mpp,
10158 .policy = nl80211_policy,
10159 .flags = GENL_ADMIN_PERM,
10160 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10161 NL80211_FLAG_NEED_RTNL,
10162 },
10163 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010164 .cmd = NL80211_CMD_SET_MPATH,
10165 .doit = nl80211_set_mpath,
10166 .policy = nl80211_policy,
10167 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010168 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010169 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010170 },
10171 {
10172 .cmd = NL80211_CMD_NEW_MPATH,
10173 .doit = nl80211_new_mpath,
10174 .policy = nl80211_policy,
10175 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010177 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010178 },
10179 {
10180 .cmd = NL80211_CMD_DEL_MPATH,
10181 .doit = nl80211_del_mpath,
10182 .policy = nl80211_policy,
10183 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010184 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010185 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010186 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010187 {
10188 .cmd = NL80211_CMD_SET_BSS,
10189 .doit = nl80211_set_bss,
10190 .policy = nl80211_policy,
10191 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010193 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010194 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010195 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010196 .cmd = NL80211_CMD_GET_REG,
10197 .doit = nl80211_get_reg,
10198 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010199 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010200 /* can be retrieved by unprivileged users */
10201 },
10202 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010203 .cmd = NL80211_CMD_SET_REG,
10204 .doit = nl80211_set_reg,
10205 .policy = nl80211_policy,
10206 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010207 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010208 },
10209 {
10210 .cmd = NL80211_CMD_REQ_SET_REG,
10211 .doit = nl80211_req_set_reg,
10212 .policy = nl80211_policy,
10213 .flags = GENL_ADMIN_PERM,
10214 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010215 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010216 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10217 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010218 .policy = nl80211_policy,
10219 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010220 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010221 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010222 },
10223 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010224 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10225 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010226 .policy = nl80211_policy,
10227 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010228 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010229 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010230 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010231 {
Johannes Berg2a519312009-02-10 21:25:55 +010010232 .cmd = NL80211_CMD_TRIGGER_SCAN,
10233 .doit = nl80211_trigger_scan,
10234 .policy = nl80211_policy,
10235 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010236 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010237 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010238 },
10239 {
10240 .cmd = NL80211_CMD_GET_SCAN,
10241 .policy = nl80211_policy,
10242 .dumpit = nl80211_dump_scan,
10243 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010244 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010245 .cmd = NL80211_CMD_START_SCHED_SCAN,
10246 .doit = nl80211_start_sched_scan,
10247 .policy = nl80211_policy,
10248 .flags = GENL_ADMIN_PERM,
10249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10250 NL80211_FLAG_NEED_RTNL,
10251 },
10252 {
10253 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10254 .doit = nl80211_stop_sched_scan,
10255 .policy = nl80211_policy,
10256 .flags = GENL_ADMIN_PERM,
10257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10258 NL80211_FLAG_NEED_RTNL,
10259 },
10260 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010261 .cmd = NL80211_CMD_AUTHENTICATE,
10262 .doit = nl80211_authenticate,
10263 .policy = nl80211_policy,
10264 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010265 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010266 NL80211_FLAG_NEED_RTNL |
10267 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010268 },
10269 {
10270 .cmd = NL80211_CMD_ASSOCIATE,
10271 .doit = nl80211_associate,
10272 .policy = nl80211_policy,
10273 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010275 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010276 },
10277 {
10278 .cmd = NL80211_CMD_DEAUTHENTICATE,
10279 .doit = nl80211_deauthenticate,
10280 .policy = nl80211_policy,
10281 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010283 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010284 },
10285 {
10286 .cmd = NL80211_CMD_DISASSOCIATE,
10287 .doit = nl80211_disassociate,
10288 .policy = nl80211_policy,
10289 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010290 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010291 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010292 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010293 {
10294 .cmd = NL80211_CMD_JOIN_IBSS,
10295 .doit = nl80211_join_ibss,
10296 .policy = nl80211_policy,
10297 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010299 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010300 },
10301 {
10302 .cmd = NL80211_CMD_LEAVE_IBSS,
10303 .doit = nl80211_leave_ibss,
10304 .policy = nl80211_policy,
10305 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010307 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010308 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010309#ifdef CONFIG_NL80211_TESTMODE
10310 {
10311 .cmd = NL80211_CMD_TESTMODE,
10312 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010313 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010314 .policy = nl80211_policy,
10315 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010316 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10317 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010318 },
10319#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010320 {
10321 .cmd = NL80211_CMD_CONNECT,
10322 .doit = nl80211_connect,
10323 .policy = nl80211_policy,
10324 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010325 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010326 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010327 },
10328 {
10329 .cmd = NL80211_CMD_DISCONNECT,
10330 .doit = nl80211_disconnect,
10331 .policy = nl80211_policy,
10332 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010333 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010334 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010335 },
Johannes Berg463d0182009-07-14 00:33:35 +020010336 {
10337 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10338 .doit = nl80211_wiphy_netns,
10339 .policy = nl80211_policy,
10340 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010341 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10342 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010343 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010344 {
10345 .cmd = NL80211_CMD_GET_SURVEY,
10346 .policy = nl80211_policy,
10347 .dumpit = nl80211_dump_survey,
10348 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010349 {
10350 .cmd = NL80211_CMD_SET_PMKSA,
10351 .doit = nl80211_setdel_pmksa,
10352 .policy = nl80211_policy,
10353 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010354 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010355 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010356 },
10357 {
10358 .cmd = NL80211_CMD_DEL_PMKSA,
10359 .doit = nl80211_setdel_pmksa,
10360 .policy = nl80211_policy,
10361 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010362 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010363 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010364 },
10365 {
10366 .cmd = NL80211_CMD_FLUSH_PMKSA,
10367 .doit = nl80211_flush_pmksa,
10368 .policy = nl80211_policy,
10369 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010371 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010372 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010373 {
10374 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10375 .doit = nl80211_remain_on_channel,
10376 .policy = nl80211_policy,
10377 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010378 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010379 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010380 },
10381 {
10382 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10383 .doit = nl80211_cancel_remain_on_channel,
10384 .policy = nl80211_policy,
10385 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010386 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010387 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010388 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010389 {
10390 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10391 .doit = nl80211_set_tx_bitrate_mask,
10392 .policy = nl80211_policy,
10393 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010394 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10395 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010396 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010397 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010398 .cmd = NL80211_CMD_REGISTER_FRAME,
10399 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010400 .policy = nl80211_policy,
10401 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010402 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010403 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010404 },
10405 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010406 .cmd = NL80211_CMD_FRAME,
10407 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010408 .policy = nl80211_policy,
10409 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010410 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010411 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010412 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010413 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010414 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10415 .doit = nl80211_tx_mgmt_cancel_wait,
10416 .policy = nl80211_policy,
10417 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010418 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010419 NL80211_FLAG_NEED_RTNL,
10420 },
10421 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010422 .cmd = NL80211_CMD_SET_POWER_SAVE,
10423 .doit = nl80211_set_power_save,
10424 .policy = nl80211_policy,
10425 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010426 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10427 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010428 },
10429 {
10430 .cmd = NL80211_CMD_GET_POWER_SAVE,
10431 .doit = nl80211_get_power_save,
10432 .policy = nl80211_policy,
10433 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010434 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10435 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010436 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010437 {
10438 .cmd = NL80211_CMD_SET_CQM,
10439 .doit = nl80211_set_cqm,
10440 .policy = nl80211_policy,
10441 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010442 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10443 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010444 },
Johannes Bergf444de02010-05-05 15:25:02 +020010445 {
10446 .cmd = NL80211_CMD_SET_CHANNEL,
10447 .doit = nl80211_set_channel,
10448 .policy = nl80211_policy,
10449 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010450 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10451 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010452 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010453 {
10454 .cmd = NL80211_CMD_SET_WDS_PEER,
10455 .doit = nl80211_set_wds_peer,
10456 .policy = nl80211_policy,
10457 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010458 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10459 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010460 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010461 {
10462 .cmd = NL80211_CMD_JOIN_MESH,
10463 .doit = nl80211_join_mesh,
10464 .policy = nl80211_policy,
10465 .flags = GENL_ADMIN_PERM,
10466 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10467 NL80211_FLAG_NEED_RTNL,
10468 },
10469 {
10470 .cmd = NL80211_CMD_LEAVE_MESH,
10471 .doit = nl80211_leave_mesh,
10472 .policy = nl80211_policy,
10473 .flags = GENL_ADMIN_PERM,
10474 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10475 NL80211_FLAG_NEED_RTNL,
10476 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010477 {
10478 .cmd = NL80211_CMD_JOIN_OCB,
10479 .doit = nl80211_join_ocb,
10480 .policy = nl80211_policy,
10481 .flags = GENL_ADMIN_PERM,
10482 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10483 NL80211_FLAG_NEED_RTNL,
10484 },
10485 {
10486 .cmd = NL80211_CMD_LEAVE_OCB,
10487 .doit = nl80211_leave_ocb,
10488 .policy = nl80211_policy,
10489 .flags = GENL_ADMIN_PERM,
10490 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10491 NL80211_FLAG_NEED_RTNL,
10492 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010493#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010494 {
10495 .cmd = NL80211_CMD_GET_WOWLAN,
10496 .doit = nl80211_get_wowlan,
10497 .policy = nl80211_policy,
10498 /* can be retrieved by unprivileged users */
10499 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10500 NL80211_FLAG_NEED_RTNL,
10501 },
10502 {
10503 .cmd = NL80211_CMD_SET_WOWLAN,
10504 .doit = nl80211_set_wowlan,
10505 .policy = nl80211_policy,
10506 .flags = GENL_ADMIN_PERM,
10507 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10508 NL80211_FLAG_NEED_RTNL,
10509 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010510#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010511 {
10512 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10513 .doit = nl80211_set_rekey_data,
10514 .policy = nl80211_policy,
10515 .flags = GENL_ADMIN_PERM,
10516 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010517 NL80211_FLAG_NEED_RTNL |
10518 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010519 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010520 {
10521 .cmd = NL80211_CMD_TDLS_MGMT,
10522 .doit = nl80211_tdls_mgmt,
10523 .policy = nl80211_policy,
10524 .flags = GENL_ADMIN_PERM,
10525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10526 NL80211_FLAG_NEED_RTNL,
10527 },
10528 {
10529 .cmd = NL80211_CMD_TDLS_OPER,
10530 .doit = nl80211_tdls_oper,
10531 .policy = nl80211_policy,
10532 .flags = GENL_ADMIN_PERM,
10533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10534 NL80211_FLAG_NEED_RTNL,
10535 },
Johannes Berg28946da2011-11-04 11:18:12 +010010536 {
10537 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10538 .doit = nl80211_register_unexpected_frame,
10539 .policy = nl80211_policy,
10540 .flags = GENL_ADMIN_PERM,
10541 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10542 NL80211_FLAG_NEED_RTNL,
10543 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010544 {
10545 .cmd = NL80211_CMD_PROBE_CLIENT,
10546 .doit = nl80211_probe_client,
10547 .policy = nl80211_policy,
10548 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010549 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010550 NL80211_FLAG_NEED_RTNL,
10551 },
Johannes Berg5e7602302011-11-04 11:18:17 +010010552 {
10553 .cmd = NL80211_CMD_REGISTER_BEACONS,
10554 .doit = nl80211_register_beacons,
10555 .policy = nl80211_policy,
10556 .flags = GENL_ADMIN_PERM,
10557 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10558 NL80211_FLAG_NEED_RTNL,
10559 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010560 {
10561 .cmd = NL80211_CMD_SET_NOACK_MAP,
10562 .doit = nl80211_set_noack_map,
10563 .policy = nl80211_policy,
10564 .flags = GENL_ADMIN_PERM,
10565 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10566 NL80211_FLAG_NEED_RTNL,
10567 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010568 {
10569 .cmd = NL80211_CMD_START_P2P_DEVICE,
10570 .doit = nl80211_start_p2p_device,
10571 .policy = nl80211_policy,
10572 .flags = GENL_ADMIN_PERM,
10573 .internal_flags = NL80211_FLAG_NEED_WDEV |
10574 NL80211_FLAG_NEED_RTNL,
10575 },
10576 {
10577 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10578 .doit = nl80211_stop_p2p_device,
10579 .policy = nl80211_policy,
10580 .flags = GENL_ADMIN_PERM,
10581 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10582 NL80211_FLAG_NEED_RTNL,
10583 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010584 {
10585 .cmd = NL80211_CMD_SET_MCAST_RATE,
10586 .doit = nl80211_set_mcast_rate,
10587 .policy = nl80211_policy,
10588 .flags = GENL_ADMIN_PERM,
10589 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10590 NL80211_FLAG_NEED_RTNL,
10591 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010592 {
10593 .cmd = NL80211_CMD_SET_MAC_ACL,
10594 .doit = nl80211_set_mac_acl,
10595 .policy = nl80211_policy,
10596 .flags = GENL_ADMIN_PERM,
10597 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10598 NL80211_FLAG_NEED_RTNL,
10599 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010600 {
10601 .cmd = NL80211_CMD_RADAR_DETECT,
10602 .doit = nl80211_start_radar_detection,
10603 .policy = nl80211_policy,
10604 .flags = GENL_ADMIN_PERM,
10605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10606 NL80211_FLAG_NEED_RTNL,
10607 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010608 {
10609 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10610 .doit = nl80211_get_protocol_features,
10611 .policy = nl80211_policy,
10612 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010613 {
10614 .cmd = NL80211_CMD_UPDATE_FT_IES,
10615 .doit = nl80211_update_ft_ies,
10616 .policy = nl80211_policy,
10617 .flags = GENL_ADMIN_PERM,
10618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10619 NL80211_FLAG_NEED_RTNL,
10620 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010621 {
10622 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10623 .doit = nl80211_crit_protocol_start,
10624 .policy = nl80211_policy,
10625 .flags = GENL_ADMIN_PERM,
10626 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10627 NL80211_FLAG_NEED_RTNL,
10628 },
10629 {
10630 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10631 .doit = nl80211_crit_protocol_stop,
10632 .policy = nl80211_policy,
10633 .flags = GENL_ADMIN_PERM,
10634 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10635 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010636 },
10637 {
10638 .cmd = NL80211_CMD_GET_COALESCE,
10639 .doit = nl80211_get_coalesce,
10640 .policy = nl80211_policy,
10641 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10642 NL80211_FLAG_NEED_RTNL,
10643 },
10644 {
10645 .cmd = NL80211_CMD_SET_COALESCE,
10646 .doit = nl80211_set_coalesce,
10647 .policy = nl80211_policy,
10648 .flags = GENL_ADMIN_PERM,
10649 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10650 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010651 },
10652 {
10653 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10654 .doit = nl80211_channel_switch,
10655 .policy = nl80211_policy,
10656 .flags = GENL_ADMIN_PERM,
10657 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10658 NL80211_FLAG_NEED_RTNL,
10659 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010660 {
10661 .cmd = NL80211_CMD_VENDOR,
10662 .doit = nl80211_vendor_cmd,
10663 .policy = nl80211_policy,
10664 .flags = GENL_ADMIN_PERM,
10665 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10666 NL80211_FLAG_NEED_RTNL,
10667 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010668 {
10669 .cmd = NL80211_CMD_SET_QOS_MAP,
10670 .doit = nl80211_set_qos_map,
10671 .policy = nl80211_policy,
10672 .flags = GENL_ADMIN_PERM,
10673 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10674 NL80211_FLAG_NEED_RTNL,
10675 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010676 {
10677 .cmd = NL80211_CMD_ADD_TX_TS,
10678 .doit = nl80211_add_tx_ts,
10679 .policy = nl80211_policy,
10680 .flags = GENL_ADMIN_PERM,
10681 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10682 NL80211_FLAG_NEED_RTNL,
10683 },
10684 {
10685 .cmd = NL80211_CMD_DEL_TX_TS,
10686 .doit = nl80211_del_tx_ts,
10687 .policy = nl80211_policy,
10688 .flags = GENL_ADMIN_PERM,
10689 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10690 NL80211_FLAG_NEED_RTNL,
10691 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020010692 {
10693 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
10694 .doit = nl80211_tdls_channel_switch,
10695 .policy = nl80211_policy,
10696 .flags = GENL_ADMIN_PERM,
10697 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10698 NL80211_FLAG_NEED_RTNL,
10699 },
10700 {
10701 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
10702 .doit = nl80211_tdls_cancel_channel_switch,
10703 .policy = nl80211_policy,
10704 .flags = GENL_ADMIN_PERM,
10705 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10706 NL80211_FLAG_NEED_RTNL,
10707 },
Johannes Berg55682962007-09-20 13:09:35 -040010708};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010709
Johannes Berg55682962007-09-20 13:09:35 -040010710/* notification functions */
10711
Johannes Berg3bb20552014-05-26 13:52:25 +020010712void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10713 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010714{
10715 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010716 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010717
Johannes Berg3bb20552014-05-26 13:52:25 +020010718 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10719 cmd != NL80211_CMD_DEL_WIPHY);
10720
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010721 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010722 if (!msg)
10723 return;
10724
Johannes Berg3bb20552014-05-26 13:52:25 +020010725 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010726 nlmsg_free(msg);
10727 return;
10728 }
10729
Johannes Berg68eb5502013-11-19 15:19:38 +010010730 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010731 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010732}
10733
Johannes Berg362a4152009-05-24 16:43:15 +020010734static int nl80211_add_scan_req(struct sk_buff *msg,
10735 struct cfg80211_registered_device *rdev)
10736{
10737 struct cfg80211_scan_request *req = rdev->scan_req;
10738 struct nlattr *nest;
10739 int i;
10740
10741 if (WARN_ON(!req))
10742 return 0;
10743
10744 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10745 if (!nest)
10746 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010747 for (i = 0; i < req->n_ssids; i++) {
10748 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10749 goto nla_put_failure;
10750 }
Johannes Berg362a4152009-05-24 16:43:15 +020010751 nla_nest_end(msg, nest);
10752
10753 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10754 if (!nest)
10755 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010756 for (i = 0; i < req->n_channels; i++) {
10757 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10758 goto nla_put_failure;
10759 }
Johannes Berg362a4152009-05-24 16:43:15 +020010760 nla_nest_end(msg, nest);
10761
David S. Miller9360ffd2012-03-29 04:41:26 -040010762 if (req->ie &&
10763 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10764 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010765
Johannes Bergae917c92013-10-25 11:05:22 +020010766 if (req->flags &&
10767 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10768 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010769
Johannes Berg362a4152009-05-24 16:43:15 +020010770 return 0;
10771 nla_put_failure:
10772 return -ENOBUFS;
10773}
10774
Johannes Berga538e2d2009-06-16 19:56:42 +020010775static int nl80211_send_scan_msg(struct sk_buff *msg,
10776 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010777 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010778 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010779 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010780{
10781 void *hdr;
10782
Eric W. Biederman15e47302012-09-07 20:12:54 +000010783 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010784 if (!hdr)
10785 return -1;
10786
David S. Miller9360ffd2012-03-29 04:41:26 -040010787 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010788 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10789 wdev->netdev->ifindex)) ||
10790 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010791 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010792
Johannes Berg362a4152009-05-24 16:43:15 +020010793 /* ignore errors and send incomplete event anyway */
10794 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010795
10796 return genlmsg_end(msg, hdr);
10797
10798 nla_put_failure:
10799 genlmsg_cancel(msg, hdr);
10800 return -EMSGSIZE;
10801}
10802
Luciano Coelho807f8a82011-05-11 17:09:35 +030010803static int
10804nl80211_send_sched_scan_msg(struct sk_buff *msg,
10805 struct cfg80211_registered_device *rdev,
10806 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010807 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010808{
10809 void *hdr;
10810
Eric W. Biederman15e47302012-09-07 20:12:54 +000010811 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010812 if (!hdr)
10813 return -1;
10814
David S. Miller9360ffd2012-03-29 04:41:26 -040010815 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10816 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10817 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010818
10819 return genlmsg_end(msg, hdr);
10820
10821 nla_put_failure:
10822 genlmsg_cancel(msg, hdr);
10823 return -EMSGSIZE;
10824}
10825
Johannes Berga538e2d2009-06-16 19:56:42 +020010826void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010827 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010828{
10829 struct sk_buff *msg;
10830
Thomas Graf58050fc2012-06-28 03:57:45 +000010831 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010832 if (!msg)
10833 return;
10834
Johannes Bergfd014282012-06-18 19:17:03 +020010835 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010836 NL80211_CMD_TRIGGER_SCAN) < 0) {
10837 nlmsg_free(msg);
10838 return;
10839 }
10840
Johannes Berg68eb5502013-11-19 15:19:38 +010010841 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010842 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010843}
10844
Johannes Bergf9d15d12014-01-22 11:14:19 +020010845struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10846 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010847{
10848 struct sk_buff *msg;
10849
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010851 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010852 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010853
Johannes Bergfd014282012-06-18 19:17:03 +020010854 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010855 aborted ? NL80211_CMD_SCAN_ABORTED :
10856 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010857 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010858 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010859 }
10860
Johannes Bergf9d15d12014-01-22 11:14:19 +020010861 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010862}
10863
Johannes Bergf9d15d12014-01-22 11:14:19 +020010864void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10865 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010866{
Johannes Berg2a519312009-02-10 21:25:55 +010010867 if (!msg)
10868 return;
10869
Johannes Berg68eb5502013-11-19 15:19:38 +010010870 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010871 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010872}
10873
Luciano Coelho807f8a82011-05-11 17:09:35 +030010874void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10875 struct net_device *netdev)
10876{
10877 struct sk_buff *msg;
10878
10879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10880 if (!msg)
10881 return;
10882
10883 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10884 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10885 nlmsg_free(msg);
10886 return;
10887 }
10888
Johannes Berg68eb5502013-11-19 15:19:38 +010010889 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010890 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010891}
10892
10893void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10894 struct net_device *netdev, u32 cmd)
10895{
10896 struct sk_buff *msg;
10897
Thomas Graf58050fc2012-06-28 03:57:45 +000010898 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010899 if (!msg)
10900 return;
10901
10902 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10903 nlmsg_free(msg);
10904 return;
10905 }
10906
Johannes Berg68eb5502013-11-19 15:19:38 +010010907 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010908 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010909}
10910
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010911/*
10912 * This can happen on global regulatory changes or device specific settings
10913 * based on custom world regulatory domains.
10914 */
10915void nl80211_send_reg_change_event(struct regulatory_request *request)
10916{
10917 struct sk_buff *msg;
10918 void *hdr;
10919
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010920 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010921 if (!msg)
10922 return;
10923
10924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10925 if (!hdr) {
10926 nlmsg_free(msg);
10927 return;
10928 }
10929
10930 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010931 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10932 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010933
David S. Miller9360ffd2012-03-29 04:41:26 -040010934 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10935 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10936 NL80211_REGDOM_TYPE_WORLD))
10937 goto nla_put_failure;
10938 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10939 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10940 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10941 goto nla_put_failure;
10942 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10943 request->intersect) {
10944 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10945 NL80211_REGDOM_TYPE_INTERSECTION))
10946 goto nla_put_failure;
10947 } else {
10948 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10949 NL80211_REGDOM_TYPE_COUNTRY) ||
10950 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10951 request->alpha2))
10952 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010953 }
10954
Johannes Bergf4173762012-12-03 18:23:37 +010010955 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010956 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10957 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010958
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010959 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010960
Johannes Bergbc43b282009-07-25 10:54:13 +020010961 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010962 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010963 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010964 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010965
10966 return;
10967
10968nla_put_failure:
10969 genlmsg_cancel(msg, hdr);
10970 nlmsg_free(msg);
10971}
10972
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010973static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10974 struct net_device *netdev,
10975 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010976 enum nl80211_commands cmd, gfp_t gfp,
10977 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010978{
10979 struct sk_buff *msg;
10980 void *hdr;
10981
Johannes Berge6d6e342009-07-01 21:26:47 +020010982 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010983 if (!msg)
10984 return;
10985
10986 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10987 if (!hdr) {
10988 nlmsg_free(msg);
10989 return;
10990 }
10991
David S. Miller9360ffd2012-03-29 04:41:26 -040010992 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10993 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10994 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10995 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010996
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010997 if (uapsd_queues >= 0) {
10998 struct nlattr *nla_wmm =
10999 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11000 if (!nla_wmm)
11001 goto nla_put_failure;
11002
11003 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11004 uapsd_queues))
11005 goto nla_put_failure;
11006
11007 nla_nest_end(msg, nla_wmm);
11008 }
11009
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011010 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011011
Johannes Berg68eb5502013-11-19 15:19:38 +010011012 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011013 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011014 return;
11015
11016 nla_put_failure:
11017 genlmsg_cancel(msg, hdr);
11018 nlmsg_free(msg);
11019}
11020
11021void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011022 struct net_device *netdev, const u8 *buf,
11023 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011024{
11025 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011026 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011027}
11028
11029void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11030 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011031 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011032{
Johannes Berge6d6e342009-07-01 21:26:47 +020011033 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011034 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011035}
11036
Jouni Malinen53b46b82009-03-27 20:53:56 +020011037void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011038 struct net_device *netdev, const u8 *buf,
11039 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011040{
11041 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011042 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011043}
11044
Jouni Malinen53b46b82009-03-27 20:53:56 +020011045void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11046 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011047 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011048{
11049 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011050 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011051}
11052
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011053void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11054 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011055{
Johannes Berg947add32013-02-22 22:05:20 +010011056 struct wireless_dev *wdev = dev->ieee80211_ptr;
11057 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011058 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011059 const struct ieee80211_mgmt *mgmt = (void *)buf;
11060 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011061
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011062 if (WARN_ON(len < 2))
11063 return;
11064
11065 if (ieee80211_is_deauth(mgmt->frame_control))
11066 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11067 else
11068 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11069
11070 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011071 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011072}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011073EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011074
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011075static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11076 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011077 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011078{
11079 struct sk_buff *msg;
11080 void *hdr;
11081
Johannes Berge6d6e342009-07-01 21:26:47 +020011082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011083 if (!msg)
11084 return;
11085
11086 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11087 if (!hdr) {
11088 nlmsg_free(msg);
11089 return;
11090 }
11091
David S. Miller9360ffd2012-03-29 04:41:26 -040011092 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11093 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11094 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11095 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11096 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011097
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011098 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011099
Johannes Berg68eb5502013-11-19 15:19:38 +010011100 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011101 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011102 return;
11103
11104 nla_put_failure:
11105 genlmsg_cancel(msg, hdr);
11106 nlmsg_free(msg);
11107}
11108
11109void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011110 struct net_device *netdev, const u8 *addr,
11111 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011112{
11113 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011114 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011115}
11116
11117void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011118 struct net_device *netdev, const u8 *addr,
11119 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011120{
Johannes Berge6d6e342009-07-01 21:26:47 +020011121 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11122 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011123}
11124
Samuel Ortizb23aa672009-07-01 21:26:54 +020011125void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11126 struct net_device *netdev, const u8 *bssid,
11127 const u8 *req_ie, size_t req_ie_len,
11128 const u8 *resp_ie, size_t resp_ie_len,
11129 u16 status, gfp_t gfp)
11130{
11131 struct sk_buff *msg;
11132 void *hdr;
11133
Thomas Graf58050fc2012-06-28 03:57:45 +000011134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011135 if (!msg)
11136 return;
11137
11138 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11139 if (!hdr) {
11140 nlmsg_free(msg);
11141 return;
11142 }
11143
David S. Miller9360ffd2012-03-29 04:41:26 -040011144 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11145 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11146 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11147 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11148 (req_ie &&
11149 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11150 (resp_ie &&
11151 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11152 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011153
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011154 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011155
Johannes Berg68eb5502013-11-19 15:19:38 +010011156 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011157 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011158 return;
11159
11160 nla_put_failure:
11161 genlmsg_cancel(msg, hdr);
11162 nlmsg_free(msg);
11163
11164}
11165
11166void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11167 struct net_device *netdev, const u8 *bssid,
11168 const u8 *req_ie, size_t req_ie_len,
11169 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11170{
11171 struct sk_buff *msg;
11172 void *hdr;
11173
Thomas Graf58050fc2012-06-28 03:57:45 +000011174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011175 if (!msg)
11176 return;
11177
11178 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11179 if (!hdr) {
11180 nlmsg_free(msg);
11181 return;
11182 }
11183
David S. Miller9360ffd2012-03-29 04:41:26 -040011184 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11185 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11186 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11187 (req_ie &&
11188 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11189 (resp_ie &&
11190 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11191 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011192
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011193 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011194
Johannes Berg68eb5502013-11-19 15:19:38 +010011195 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011196 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011197 return;
11198
11199 nla_put_failure:
11200 genlmsg_cancel(msg, hdr);
11201 nlmsg_free(msg);
11202
11203}
11204
11205void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11206 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011207 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011208{
11209 struct sk_buff *msg;
11210 void *hdr;
11211
Thomas Graf58050fc2012-06-28 03:57:45 +000011212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011213 if (!msg)
11214 return;
11215
11216 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11217 if (!hdr) {
11218 nlmsg_free(msg);
11219 return;
11220 }
11221
David S. Miller9360ffd2012-03-29 04:41:26 -040011222 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11223 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11224 (from_ap && reason &&
11225 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11226 (from_ap &&
11227 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11228 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11229 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011230
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011231 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011232
Johannes Berg68eb5502013-11-19 15:19:38 +010011233 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011234 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011235 return;
11236
11237 nla_put_failure:
11238 genlmsg_cancel(msg, hdr);
11239 nlmsg_free(msg);
11240
11241}
11242
Johannes Berg04a773a2009-04-19 21:24:32 +020011243void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11244 struct net_device *netdev, const u8 *bssid,
11245 gfp_t gfp)
11246{
11247 struct sk_buff *msg;
11248 void *hdr;
11249
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011250 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011251 if (!msg)
11252 return;
11253
11254 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11255 if (!hdr) {
11256 nlmsg_free(msg);
11257 return;
11258 }
11259
David S. Miller9360ffd2012-03-29 04:41:26 -040011260 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11261 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11262 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11263 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011264
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011265 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011266
Johannes Berg68eb5502013-11-19 15:19:38 +010011267 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011268 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011269 return;
11270
11271 nla_put_failure:
11272 genlmsg_cancel(msg, hdr);
11273 nlmsg_free(msg);
11274}
11275
Johannes Berg947add32013-02-22 22:05:20 +010011276void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11277 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011278{
Johannes Berg947add32013-02-22 22:05:20 +010011279 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011280 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011281 struct sk_buff *msg;
11282 void *hdr;
11283
Johannes Berg947add32013-02-22 22:05:20 +010011284 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11285 return;
11286
11287 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11288
Javier Cardonac93b5e72011-04-07 15:08:34 -070011289 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11290 if (!msg)
11291 return;
11292
11293 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11294 if (!hdr) {
11295 nlmsg_free(msg);
11296 return;
11297 }
11298
David S. Miller9360ffd2012-03-29 04:41:26 -040011299 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011300 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11301 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011302 (ie_len && ie &&
11303 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11304 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011305
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011306 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011307
Johannes Berg68eb5502013-11-19 15:19:38 +010011308 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011309 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011310 return;
11311
11312 nla_put_failure:
11313 genlmsg_cancel(msg, hdr);
11314 nlmsg_free(msg);
11315}
Johannes Berg947add32013-02-22 22:05:20 +010011316EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011317
Jouni Malinena3b8b052009-03-27 21:59:49 +020011318void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11319 struct net_device *netdev, const u8 *addr,
11320 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011321 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011322{
11323 struct sk_buff *msg;
11324 void *hdr;
11325
Johannes Berge6d6e342009-07-01 21:26:47 +020011326 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011327 if (!msg)
11328 return;
11329
11330 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11331 if (!hdr) {
11332 nlmsg_free(msg);
11333 return;
11334 }
11335
David S. Miller9360ffd2012-03-29 04:41:26 -040011336 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11337 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11338 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11339 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11340 (key_id != -1 &&
11341 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11342 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11343 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011344
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011345 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011346
Johannes Berg68eb5502013-11-19 15:19:38 +010011347 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011348 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011349 return;
11350
11351 nla_put_failure:
11352 genlmsg_cancel(msg, hdr);
11353 nlmsg_free(msg);
11354}
11355
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011356void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11357 struct ieee80211_channel *channel_before,
11358 struct ieee80211_channel *channel_after)
11359{
11360 struct sk_buff *msg;
11361 void *hdr;
11362 struct nlattr *nl_freq;
11363
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011364 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011365 if (!msg)
11366 return;
11367
11368 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11369 if (!hdr) {
11370 nlmsg_free(msg);
11371 return;
11372 }
11373
11374 /*
11375 * Since we are applying the beacon hint to a wiphy we know its
11376 * wiphy_idx is valid
11377 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011378 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11379 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011380
11381 /* Before */
11382 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11383 if (!nl_freq)
11384 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011385 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011386 goto nla_put_failure;
11387 nla_nest_end(msg, nl_freq);
11388
11389 /* After */
11390 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11391 if (!nl_freq)
11392 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011393 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011394 goto nla_put_failure;
11395 nla_nest_end(msg, nl_freq);
11396
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011397 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011398
Johannes Berg463d0182009-07-14 00:33:35 +020011399 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011400 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011401 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011402 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011403
11404 return;
11405
11406nla_put_failure:
11407 genlmsg_cancel(msg, hdr);
11408 nlmsg_free(msg);
11409}
11410
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011411static void nl80211_send_remain_on_chan_event(
11412 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011413 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011414 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011415 unsigned int duration, gfp_t gfp)
11416{
11417 struct sk_buff *msg;
11418 void *hdr;
11419
11420 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11421 if (!msg)
11422 return;
11423
11424 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11425 if (!hdr) {
11426 nlmsg_free(msg);
11427 return;
11428 }
11429
David S. Miller9360ffd2012-03-29 04:41:26 -040011430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011431 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11432 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011433 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011434 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011435 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11436 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011437 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11438 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011439
David S. Miller9360ffd2012-03-29 04:41:26 -040011440 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11441 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11442 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011443
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011444 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011445
Johannes Berg68eb5502013-11-19 15:19:38 +010011446 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011447 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011448 return;
11449
11450 nla_put_failure:
11451 genlmsg_cancel(msg, hdr);
11452 nlmsg_free(msg);
11453}
11454
Johannes Berg947add32013-02-22 22:05:20 +010011455void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11456 struct ieee80211_channel *chan,
11457 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011458{
Johannes Berg947add32013-02-22 22:05:20 +010011459 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011460 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011461
11462 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011463 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011464 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011465 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011466}
Johannes Berg947add32013-02-22 22:05:20 +010011467EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011468
Johannes Berg947add32013-02-22 22:05:20 +010011469void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11470 struct ieee80211_channel *chan,
11471 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011472{
Johannes Berg947add32013-02-22 22:05:20 +010011473 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011474 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011475
11476 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011477 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011478 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011479}
Johannes Berg947add32013-02-22 22:05:20 +010011480EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011481
Johannes Berg947add32013-02-22 22:05:20 +010011482void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11483 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011484{
Johannes Berg947add32013-02-22 22:05:20 +010011485 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011486 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011487 struct sk_buff *msg;
11488
Johannes Berg947add32013-02-22 22:05:20 +010011489 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11490
Thomas Graf58050fc2012-06-28 03:57:45 +000011491 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011492 if (!msg)
11493 return;
11494
John W. Linville66266b32012-03-15 13:25:41 -040011495 if (nl80211_send_station(msg, 0, 0, 0,
11496 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011497 nlmsg_free(msg);
11498 return;
11499 }
11500
Johannes Berg68eb5502013-11-19 15:19:38 +010011501 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011502 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011503}
Johannes Berg947add32013-02-22 22:05:20 +010011504EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011505
Johannes Berg947add32013-02-22 22:05:20 +010011506void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011507{
Johannes Berg947add32013-02-22 22:05:20 +010011508 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011509 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011510 struct sk_buff *msg;
11511 void *hdr;
11512
Johannes Berg947add32013-02-22 22:05:20 +010011513 trace_cfg80211_del_sta(dev, mac_addr);
11514
Thomas Graf58050fc2012-06-28 03:57:45 +000011515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011516 if (!msg)
11517 return;
11518
11519 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11520 if (!hdr) {
11521 nlmsg_free(msg);
11522 return;
11523 }
11524
David S. Miller9360ffd2012-03-29 04:41:26 -040011525 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11526 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11527 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011528
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011529 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011530
Johannes Berg68eb5502013-11-19 15:19:38 +010011531 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011532 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011533 return;
11534
11535 nla_put_failure:
11536 genlmsg_cancel(msg, hdr);
11537 nlmsg_free(msg);
11538}
Johannes Berg947add32013-02-22 22:05:20 +010011539EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011540
Johannes Berg947add32013-02-22 22:05:20 +010011541void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11542 enum nl80211_connect_failed_reason reason,
11543 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011544{
Johannes Berg947add32013-02-22 22:05:20 +010011545 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011546 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011547 struct sk_buff *msg;
11548 void *hdr;
11549
11550 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11551 if (!msg)
11552 return;
11553
11554 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11555 if (!hdr) {
11556 nlmsg_free(msg);
11557 return;
11558 }
11559
11560 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11561 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11562 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11563 goto nla_put_failure;
11564
11565 genlmsg_end(msg, hdr);
11566
Johannes Berg68eb5502013-11-19 15:19:38 +010011567 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011568 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011569 return;
11570
11571 nla_put_failure:
11572 genlmsg_cancel(msg, hdr);
11573 nlmsg_free(msg);
11574}
Johannes Berg947add32013-02-22 22:05:20 +010011575EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011576
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011577static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11578 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011579{
11580 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011581 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011582 struct sk_buff *msg;
11583 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011584 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011585
Eric W. Biederman15e47302012-09-07 20:12:54 +000011586 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011587 return false;
11588
11589 msg = nlmsg_new(100, gfp);
11590 if (!msg)
11591 return true;
11592
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011593 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011594 if (!hdr) {
11595 nlmsg_free(msg);
11596 return true;
11597 }
11598
David S. Miller9360ffd2012-03-29 04:41:26 -040011599 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11600 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11601 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11602 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011603
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011604 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011605 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011606 return true;
11607
11608 nla_put_failure:
11609 genlmsg_cancel(msg, hdr);
11610 nlmsg_free(msg);
11611 return true;
11612}
11613
Johannes Berg947add32013-02-22 22:05:20 +010011614bool cfg80211_rx_spurious_frame(struct net_device *dev,
11615 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011616{
Johannes Berg947add32013-02-22 22:05:20 +010011617 struct wireless_dev *wdev = dev->ieee80211_ptr;
11618 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011619
Johannes Berg947add32013-02-22 22:05:20 +010011620 trace_cfg80211_rx_spurious_frame(dev, addr);
11621
11622 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11623 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11624 trace_cfg80211_return_bool(false);
11625 return false;
11626 }
11627 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11628 addr, gfp);
11629 trace_cfg80211_return_bool(ret);
11630 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011631}
Johannes Berg947add32013-02-22 22:05:20 +010011632EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11633
11634bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11635 const u8 *addr, gfp_t gfp)
11636{
11637 struct wireless_dev *wdev = dev->ieee80211_ptr;
11638 bool ret;
11639
11640 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11641
11642 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11643 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11644 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11645 trace_cfg80211_return_bool(false);
11646 return false;
11647 }
11648 ret = __nl80211_unexpected_frame(dev,
11649 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11650 addr, gfp);
11651 trace_cfg80211_return_bool(ret);
11652 return ret;
11653}
11654EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011655
Johannes Berg2e161f72010-08-12 15:38:38 +020011656int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011657 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011658 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011659 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011660{
Johannes Berg71bbc992012-06-15 15:30:18 +020011661 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011662 struct sk_buff *msg;
11663 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011664
11665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11666 if (!msg)
11667 return -ENOMEM;
11668
Johannes Berg2e161f72010-08-12 15:38:38 +020011669 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011670 if (!hdr) {
11671 nlmsg_free(msg);
11672 return -ENOMEM;
11673 }
11674
David S. Miller9360ffd2012-03-29 04:41:26 -040011675 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011676 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11677 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011678 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011679 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11680 (sig_dbm &&
11681 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011682 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11683 (flags &&
11684 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011685 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011686
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011687 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011688
Eric W. Biederman15e47302012-09-07 20:12:54 +000011689 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011690
11691 nla_put_failure:
11692 genlmsg_cancel(msg, hdr);
11693 nlmsg_free(msg);
11694 return -ENOBUFS;
11695}
11696
Johannes Berg947add32013-02-22 22:05:20 +010011697void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11698 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011699{
Johannes Berg947add32013-02-22 22:05:20 +010011700 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011701 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011702 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011703 struct sk_buff *msg;
11704 void *hdr;
11705
Johannes Berg947add32013-02-22 22:05:20 +010011706 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11707
Jouni Malinen026331c2010-02-15 12:53:10 +020011708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11709 if (!msg)
11710 return;
11711
Johannes Berg2e161f72010-08-12 15:38:38 +020011712 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011713 if (!hdr) {
11714 nlmsg_free(msg);
11715 return;
11716 }
11717
David S. Miller9360ffd2012-03-29 04:41:26 -040011718 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011719 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11720 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011721 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011722 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11723 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11724 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11725 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011726
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011727 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011728
Johannes Berg68eb5502013-11-19 15:19:38 +010011729 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011730 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011731 return;
11732
11733 nla_put_failure:
11734 genlmsg_cancel(msg, hdr);
11735 nlmsg_free(msg);
11736}
Johannes Berg947add32013-02-22 22:05:20 +010011737EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011738
Johannes Berg947add32013-02-22 22:05:20 +010011739void cfg80211_cqm_rssi_notify(struct net_device *dev,
11740 enum nl80211_cqm_rssi_threshold_event rssi_event,
11741 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011742{
Johannes Berg947add32013-02-22 22:05:20 +010011743 struct wireless_dev *wdev = dev->ieee80211_ptr;
11744 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011745 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011746 struct sk_buff *msg;
11747 struct nlattr *pinfoattr;
11748 void *hdr;
11749
Johannes Berg947add32013-02-22 22:05:20 +010011750 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11751
Thomas Graf58050fc2012-06-28 03:57:45 +000011752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011753 if (!msg)
11754 return;
11755
11756 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11757 if (!hdr) {
11758 nlmsg_free(msg);
11759 return;
11760 }
11761
David S. Miller9360ffd2012-03-29 04:41:26 -040011762 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011763 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011764 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011765
11766 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11767 if (!pinfoattr)
11768 goto nla_put_failure;
11769
David S. Miller9360ffd2012-03-29 04:41:26 -040011770 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11771 rssi_event))
11772 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011773
11774 nla_nest_end(msg, pinfoattr);
11775
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011776 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011777
Johannes Berg68eb5502013-11-19 15:19:38 +010011778 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011779 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011780 return;
11781
11782 nla_put_failure:
11783 genlmsg_cancel(msg, hdr);
11784 nlmsg_free(msg);
11785}
Johannes Berg947add32013-02-22 22:05:20 +010011786EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011787
Johannes Berg947add32013-02-22 22:05:20 +010011788static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11789 struct net_device *netdev, const u8 *bssid,
11790 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011791{
11792 struct sk_buff *msg;
11793 struct nlattr *rekey_attr;
11794 void *hdr;
11795
Thomas Graf58050fc2012-06-28 03:57:45 +000011796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011797 if (!msg)
11798 return;
11799
11800 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11801 if (!hdr) {
11802 nlmsg_free(msg);
11803 return;
11804 }
11805
David S. Miller9360ffd2012-03-29 04:41:26 -040011806 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11807 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11808 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11809 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011810
11811 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11812 if (!rekey_attr)
11813 goto nla_put_failure;
11814
David S. Miller9360ffd2012-03-29 04:41:26 -040011815 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11816 NL80211_REPLAY_CTR_LEN, replay_ctr))
11817 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011818
11819 nla_nest_end(msg, rekey_attr);
11820
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011821 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011822
Johannes Berg68eb5502013-11-19 15:19:38 +010011823 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011824 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011825 return;
11826
11827 nla_put_failure:
11828 genlmsg_cancel(msg, hdr);
11829 nlmsg_free(msg);
11830}
11831
Johannes Berg947add32013-02-22 22:05:20 +010011832void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11833 const u8 *replay_ctr, gfp_t gfp)
11834{
11835 struct wireless_dev *wdev = dev->ieee80211_ptr;
11836 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011837 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011838
11839 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11840 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11841}
11842EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11843
11844static void
11845nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11846 struct net_device *netdev, int index,
11847 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011848{
11849 struct sk_buff *msg;
11850 struct nlattr *attr;
11851 void *hdr;
11852
Thomas Graf58050fc2012-06-28 03:57:45 +000011853 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011854 if (!msg)
11855 return;
11856
11857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11858 if (!hdr) {
11859 nlmsg_free(msg);
11860 return;
11861 }
11862
David S. Miller9360ffd2012-03-29 04:41:26 -040011863 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11864 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11865 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011866
11867 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11868 if (!attr)
11869 goto nla_put_failure;
11870
David S. Miller9360ffd2012-03-29 04:41:26 -040011871 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11872 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11873 (preauth &&
11874 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11875 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011876
11877 nla_nest_end(msg, attr);
11878
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011879 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011880
Johannes Berg68eb5502013-11-19 15:19:38 +010011881 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011882 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011883 return;
11884
11885 nla_put_failure:
11886 genlmsg_cancel(msg, hdr);
11887 nlmsg_free(msg);
11888}
11889
Johannes Berg947add32013-02-22 22:05:20 +010011890void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11891 const u8 *bssid, bool preauth, gfp_t gfp)
11892{
11893 struct wireless_dev *wdev = dev->ieee80211_ptr;
11894 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011895 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011896
11897 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11898 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11899}
11900EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11901
11902static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11903 struct net_device *netdev,
11904 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020011905 gfp_t gfp,
11906 enum nl80211_commands notif,
11907 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070011908{
11909 struct sk_buff *msg;
11910 void *hdr;
11911
Thomas Graf58050fc2012-06-28 03:57:45 +000011912 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011913 if (!msg)
11914 return;
11915
Luciano Coelhof8d75522014-11-07 14:31:35 +020011916 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070011917 if (!hdr) {
11918 nlmsg_free(msg);
11919 return;
11920 }
11921
Johannes Berg683b6d32012-11-08 21:25:48 +010011922 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11923 goto nla_put_failure;
11924
11925 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011926 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011927
Luciano Coelhof8d75522014-11-07 14:31:35 +020011928 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
11929 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
11930 goto nla_put_failure;
11931
Thomas Pedersen53145262012-04-06 13:35:47 -070011932 genlmsg_end(msg, hdr);
11933
Johannes Berg68eb5502013-11-19 15:19:38 +010011934 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011935 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011936 return;
11937
11938 nla_put_failure:
11939 genlmsg_cancel(msg, hdr);
11940 nlmsg_free(msg);
11941}
11942
Johannes Berg947add32013-02-22 22:05:20 +010011943void cfg80211_ch_switch_notify(struct net_device *dev,
11944 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011945{
Johannes Berg947add32013-02-22 22:05:20 +010011946 struct wireless_dev *wdev = dev->ieee80211_ptr;
11947 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011948 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011949
Simon Wunderliche487eae2013-11-21 18:19:51 +010011950 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011951
Simon Wunderliche487eae2013-11-21 18:19:51 +010011952 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011953
Michal Kazior9e0e2962014-01-29 14:22:27 +010011954 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011955 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020011956 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
11957 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010011958}
11959EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11960
Luciano Coelhof8d75522014-11-07 14:31:35 +020011961void cfg80211_ch_switch_started_notify(struct net_device *dev,
11962 struct cfg80211_chan_def *chandef,
11963 u8 count)
11964{
11965 struct wireless_dev *wdev = dev->ieee80211_ptr;
11966 struct wiphy *wiphy = wdev->wiphy;
11967 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11968
11969 trace_cfg80211_ch_switch_started_notify(dev, chandef);
11970
11971 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
11972 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
11973}
11974EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
11975
Johannes Berg947add32013-02-22 22:05:20 +010011976void cfg80211_cqm_txe_notify(struct net_device *dev,
11977 const u8 *peer, u32 num_packets,
11978 u32 rate, u32 intvl, gfp_t gfp)
11979{
11980 struct wireless_dev *wdev = dev->ieee80211_ptr;
11981 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011982 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011983 struct sk_buff *msg;
11984 struct nlattr *pinfoattr;
11985 void *hdr;
11986
11987 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11988 if (!msg)
11989 return;
11990
11991 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11992 if (!hdr) {
11993 nlmsg_free(msg);
11994 return;
11995 }
11996
11997 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011998 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011999 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
12000 goto nla_put_failure;
12001
12002 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
12003 if (!pinfoattr)
12004 goto nla_put_failure;
12005
12006 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12007 goto nla_put_failure;
12008
12009 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12010 goto nla_put_failure;
12011
12012 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12013 goto nla_put_failure;
12014
12015 nla_nest_end(msg, pinfoattr);
12016
12017 genlmsg_end(msg, hdr);
12018
Johannes Berg68eb5502013-11-19 15:19:38 +010012019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012020 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070012021 return;
12022
12023 nla_put_failure:
12024 genlmsg_cancel(msg, hdr);
12025 nlmsg_free(msg);
12026}
Johannes Berg947add32013-02-22 22:05:20 +010012027EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070012028
12029void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012030nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012031 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012032 enum nl80211_radar_event event,
12033 struct net_device *netdev, gfp_t gfp)
12034{
12035 struct sk_buff *msg;
12036 void *hdr;
12037
12038 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12039 if (!msg)
12040 return;
12041
12042 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12043 if (!hdr) {
12044 nlmsg_free(msg);
12045 return;
12046 }
12047
12048 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12049 goto nla_put_failure;
12050
12051 /* NOP and radar events don't need a netdev parameter */
12052 if (netdev) {
12053 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12054
12055 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12056 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12057 goto nla_put_failure;
12058 }
12059
12060 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12061 goto nla_put_failure;
12062
12063 if (nl80211_send_chandef(msg, chandef))
12064 goto nla_put_failure;
12065
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012066 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012067
Johannes Berg68eb5502013-11-19 15:19:38 +010012068 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012069 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012070 return;
12071
12072 nla_put_failure:
12073 genlmsg_cancel(msg, hdr);
12074 nlmsg_free(msg);
12075}
12076
Johannes Berg947add32013-02-22 22:05:20 +010012077void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12078 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010012079{
Johannes Berg947add32013-02-22 22:05:20 +010012080 struct wireless_dev *wdev = dev->ieee80211_ptr;
12081 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012082 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012083 struct sk_buff *msg;
12084 struct nlattr *pinfoattr;
12085 void *hdr;
12086
Johannes Berg947add32013-02-22 22:05:20 +010012087 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12088
Thomas Graf58050fc2012-06-28 03:57:45 +000012089 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012090 if (!msg)
12091 return;
12092
12093 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12094 if (!hdr) {
12095 nlmsg_free(msg);
12096 return;
12097 }
12098
David S. Miller9360ffd2012-03-29 04:41:26 -040012099 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012100 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012101 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
12102 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010012103
12104 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
12105 if (!pinfoattr)
12106 goto nla_put_failure;
12107
David S. Miller9360ffd2012-03-29 04:41:26 -040012108 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12109 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010012110
12111 nla_nest_end(msg, pinfoattr);
12112
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012113 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012114
Johannes Berg68eb5502013-11-19 15:19:38 +010012115 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012116 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012117 return;
12118
12119 nla_put_failure:
12120 genlmsg_cancel(msg, hdr);
12121 nlmsg_free(msg);
12122}
Johannes Berg947add32013-02-22 22:05:20 +010012123EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012124
Johannes Berg7f6cf312011-11-04 11:18:15 +010012125void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12126 u64 cookie, bool acked, gfp_t gfp)
12127{
12128 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012129 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012130 struct sk_buff *msg;
12131 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012132
Beni Lev4ee3e062012-08-27 12:49:39 +030012133 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12134
Thomas Graf58050fc2012-06-28 03:57:45 +000012135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012136
Johannes Berg7f6cf312011-11-04 11:18:15 +010012137 if (!msg)
12138 return;
12139
12140 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12141 if (!hdr) {
12142 nlmsg_free(msg);
12143 return;
12144 }
12145
David S. Miller9360ffd2012-03-29 04:41:26 -040012146 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12147 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12148 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12149 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12150 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12151 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012152
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012153 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012154
Johannes Berg68eb5502013-11-19 15:19:38 +010012155 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012156 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012157 return;
12158
12159 nla_put_failure:
12160 genlmsg_cancel(msg, hdr);
12161 nlmsg_free(msg);
12162}
12163EXPORT_SYMBOL(cfg80211_probe_status);
12164
Johannes Berg5e7602302011-11-04 11:18:17 +010012165void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12166 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012167 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010012168{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012169 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010012170 struct sk_buff *msg;
12171 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012172 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010012173
Beni Lev4ee3e062012-08-27 12:49:39 +030012174 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12175
Ben Greear37c73b52012-10-26 14:49:25 -070012176 spin_lock_bh(&rdev->beacon_registrations_lock);
12177 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12178 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12179 if (!msg) {
12180 spin_unlock_bh(&rdev->beacon_registrations_lock);
12181 return;
12182 }
Johannes Berg5e7602302011-11-04 11:18:17 +010012183
Ben Greear37c73b52012-10-26 14:49:25 -070012184 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12185 if (!hdr)
12186 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010012187
Ben Greear37c73b52012-10-26 14:49:25 -070012188 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12189 (freq &&
12190 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12191 (sig_dbm &&
12192 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12193 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12194 goto nla_put_failure;
12195
12196 genlmsg_end(msg, hdr);
12197
12198 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010012199 }
Ben Greear37c73b52012-10-26 14:49:25 -070012200 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010012201 return;
12202
12203 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012204 spin_unlock_bh(&rdev->beacon_registrations_lock);
12205 if (hdr)
12206 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010012207 nlmsg_free(msg);
12208}
12209EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12210
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012211#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012212static int cfg80211_net_detect_results(struct sk_buff *msg,
12213 struct cfg80211_wowlan_wakeup *wakeup)
12214{
12215 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12216 struct nlattr *nl_results, *nl_match, *nl_freqs;
12217 int i, j;
12218
12219 nl_results = nla_nest_start(
12220 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12221 if (!nl_results)
12222 return -EMSGSIZE;
12223
12224 for (i = 0; i < nd->n_matches; i++) {
12225 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12226
12227 nl_match = nla_nest_start(msg, i);
12228 if (!nl_match)
12229 break;
12230
12231 /* The SSID attribute is optional in nl80211, but for
12232 * simplicity reasons it's always present in the
12233 * cfg80211 structure. If a driver can't pass the
12234 * SSID, that needs to be changed. A zero length SSID
12235 * is still a valid SSID (wildcard), so it cannot be
12236 * used for this purpose.
12237 */
12238 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12239 match->ssid.ssid)) {
12240 nla_nest_cancel(msg, nl_match);
12241 goto out;
12242 }
12243
12244 if (match->n_channels) {
12245 nl_freqs = nla_nest_start(
12246 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12247 if (!nl_freqs) {
12248 nla_nest_cancel(msg, nl_match);
12249 goto out;
12250 }
12251
12252 for (j = 0; j < match->n_channels; j++) {
12253 if (nla_put_u32(msg,
12254 NL80211_ATTR_WIPHY_FREQ,
12255 match->channels[j])) {
12256 nla_nest_cancel(msg, nl_freqs);
12257 nla_nest_cancel(msg, nl_match);
12258 goto out;
12259 }
12260 }
12261
12262 nla_nest_end(msg, nl_freqs);
12263 }
12264
12265 nla_nest_end(msg, nl_match);
12266 }
12267
12268out:
12269 nla_nest_end(msg, nl_results);
12270 return 0;
12271}
12272
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012273void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12274 struct cfg80211_wowlan_wakeup *wakeup,
12275 gfp_t gfp)
12276{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012277 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012278 struct sk_buff *msg;
12279 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012280 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012281
12282 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12283
12284 if (wakeup)
12285 size += wakeup->packet_present_len;
12286
12287 msg = nlmsg_new(size, gfp);
12288 if (!msg)
12289 return;
12290
12291 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12292 if (!hdr)
12293 goto free_msg;
12294
12295 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12296 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12297 goto free_msg;
12298
12299 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12300 wdev->netdev->ifindex))
12301 goto free_msg;
12302
12303 if (wakeup) {
12304 struct nlattr *reasons;
12305
12306 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012307 if (!reasons)
12308 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012309
12310 if (wakeup->disconnect &&
12311 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12312 goto free_msg;
12313 if (wakeup->magic_pkt &&
12314 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12315 goto free_msg;
12316 if (wakeup->gtk_rekey_failure &&
12317 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12318 goto free_msg;
12319 if (wakeup->eap_identity_req &&
12320 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12321 goto free_msg;
12322 if (wakeup->four_way_handshake &&
12323 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12324 goto free_msg;
12325 if (wakeup->rfkill_release &&
12326 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12327 goto free_msg;
12328
12329 if (wakeup->pattern_idx >= 0 &&
12330 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12331 wakeup->pattern_idx))
12332 goto free_msg;
12333
Johannes Bergae917c92013-10-25 11:05:22 +020012334 if (wakeup->tcp_match &&
12335 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12336 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012337
Johannes Bergae917c92013-10-25 11:05:22 +020012338 if (wakeup->tcp_connlost &&
12339 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12340 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012341
Johannes Bergae917c92013-10-25 11:05:22 +020012342 if (wakeup->tcp_nomoretokens &&
12343 nla_put_flag(msg,
12344 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12345 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012346
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012347 if (wakeup->packet) {
12348 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12349 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12350
12351 if (!wakeup->packet_80211) {
12352 pkt_attr =
12353 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12354 len_attr =
12355 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12356 }
12357
12358 if (wakeup->packet_len &&
12359 nla_put_u32(msg, len_attr, wakeup->packet_len))
12360 goto free_msg;
12361
12362 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12363 wakeup->packet))
12364 goto free_msg;
12365 }
12366
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012367 if (wakeup->net_detect &&
12368 cfg80211_net_detect_results(msg, wakeup))
12369 goto free_msg;
12370
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012371 nla_nest_end(msg, reasons);
12372 }
12373
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012374 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012375
Johannes Berg68eb5502013-11-19 15:19:38 +010012376 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012377 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012378 return;
12379
12380 free_msg:
12381 nlmsg_free(msg);
12382}
12383EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12384#endif
12385
Jouni Malinen3475b092012-11-16 22:49:57 +020012386void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12387 enum nl80211_tdls_operation oper,
12388 u16 reason_code, gfp_t gfp)
12389{
12390 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012391 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012392 struct sk_buff *msg;
12393 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012394
12395 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12396 reason_code);
12397
12398 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12399 if (!msg)
12400 return;
12401
12402 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12403 if (!hdr) {
12404 nlmsg_free(msg);
12405 return;
12406 }
12407
12408 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12409 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12410 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12411 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12412 (reason_code > 0 &&
12413 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12414 goto nla_put_failure;
12415
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012416 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012417
Johannes Berg68eb5502013-11-19 15:19:38 +010012418 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012419 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012420 return;
12421
12422 nla_put_failure:
12423 genlmsg_cancel(msg, hdr);
12424 nlmsg_free(msg);
12425}
12426EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12427
Jouni Malinen026331c2010-02-15 12:53:10 +020012428static int nl80211_netlink_notify(struct notifier_block * nb,
12429 unsigned long state,
12430 void *_notify)
12431{
12432 struct netlink_notify *notify = _notify;
12433 struct cfg80211_registered_device *rdev;
12434 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012435 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012436
12437 if (state != NETLINK_URELEASE)
12438 return NOTIFY_DONE;
12439
12440 rcu_read_lock();
12441
Johannes Berg5e7602302011-11-04 11:18:17 +010012442 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012443 bool schedule_destroy_work = false;
12444
12445 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012446 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012447
Johannes Berg78f22b62014-03-24 17:57:27 +010012448 if (wdev->owner_nlportid == notify->portid)
12449 schedule_destroy_work = true;
12450 }
12451
Ben Greear37c73b52012-10-26 14:49:25 -070012452 spin_lock_bh(&rdev->beacon_registrations_lock);
12453 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12454 list) {
12455 if (reg->nlportid == notify->portid) {
12456 list_del(&reg->list);
12457 kfree(reg);
12458 break;
12459 }
12460 }
12461 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012462
12463 if (schedule_destroy_work) {
12464 struct cfg80211_iface_destroy *destroy;
12465
12466 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12467 if (destroy) {
12468 destroy->nlportid = notify->portid;
12469 spin_lock(&rdev->destroy_list_lock);
12470 list_add(&destroy->list, &rdev->destroy_list);
12471 spin_unlock(&rdev->destroy_list_lock);
12472 schedule_work(&rdev->destroy_work);
12473 }
12474 }
Johannes Berg5e7602302011-11-04 11:18:17 +010012475 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012476
12477 rcu_read_unlock();
12478
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012479 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012480}
12481
12482static struct notifier_block nl80211_netlink_notifier = {
12483 .notifier_call = nl80211_netlink_notify,
12484};
12485
Jouni Malinen355199e2013-02-27 17:14:27 +020012486void cfg80211_ft_event(struct net_device *netdev,
12487 struct cfg80211_ft_event_params *ft_event)
12488{
12489 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012490 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012491 struct sk_buff *msg;
12492 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012493
12494 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12495
12496 if (!ft_event->target_ap)
12497 return;
12498
12499 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12500 if (!msg)
12501 return;
12502
12503 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012504 if (!hdr)
12505 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012506
Johannes Bergae917c92013-10-25 11:05:22 +020012507 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12508 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12509 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12510 goto out;
12511
12512 if (ft_event->ies &&
12513 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12514 goto out;
12515 if (ft_event->ric_ies &&
12516 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12517 ft_event->ric_ies))
12518 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012519
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012520 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012521
Johannes Berg68eb5502013-11-19 15:19:38 +010012522 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012523 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012524 return;
12525 out:
12526 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012527}
12528EXPORT_SYMBOL(cfg80211_ft_event);
12529
Arend van Spriel5de17982013-04-18 15:49:00 +020012530void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12531{
12532 struct cfg80211_registered_device *rdev;
12533 struct sk_buff *msg;
12534 void *hdr;
12535 u32 nlportid;
12536
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012537 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012538 if (!rdev->crit_proto_nlportid)
12539 return;
12540
12541 nlportid = rdev->crit_proto_nlportid;
12542 rdev->crit_proto_nlportid = 0;
12543
12544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12545 if (!msg)
12546 return;
12547
12548 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12549 if (!hdr)
12550 goto nla_put_failure;
12551
12552 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12553 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12554 goto nla_put_failure;
12555
12556 genlmsg_end(msg, hdr);
12557
12558 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12559 return;
12560
12561 nla_put_failure:
12562 if (hdr)
12563 genlmsg_cancel(msg, hdr);
12564 nlmsg_free(msg);
12565
12566}
12567EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12568
Johannes Berg348baf02014-01-24 14:06:29 +010012569void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12570{
12571 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012572 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012573 struct sk_buff *msg;
12574 void *hdr;
12575
12576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12577 if (!msg)
12578 return;
12579
12580 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12581 if (!hdr)
12582 goto out;
12583
12584 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12585 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12586 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12587 goto out;
12588
12589 genlmsg_end(msg, hdr);
12590
12591 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12592 NL80211_MCGRP_MLME, GFP_KERNEL);
12593 return;
12594 out:
12595 nlmsg_free(msg);
12596}
12597
Johannes Berg55682962007-09-20 13:09:35 -040012598/* initialisation/exit functions */
12599
12600int nl80211_init(void)
12601{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012602 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012603
Johannes Berg2a94fe42013-11-19 15:19:39 +010012604 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12605 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012606 if (err)
12607 return err;
12608
Jouni Malinen026331c2010-02-15 12:53:10 +020012609 err = netlink_register_notifier(&nl80211_netlink_notifier);
12610 if (err)
12611 goto err_out;
12612
Johannes Berg55682962007-09-20 13:09:35 -040012613 return 0;
12614 err_out:
12615 genl_unregister_family(&nl80211_fam);
12616 return err;
12617}
12618
12619void nl80211_exit(void)
12620{
Jouni Malinen026331c2010-02-15 12:53:10 +020012621 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012622 genl_unregister_family(&nl80211_fam);
12623}