blob: 3ec7dc5579605dae57ae28391fc38c095e45a49d [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 Malinen36aedc92008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100391 [NL80211_ATTR_IFACE_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 Berg55682962007-09-20 13:09:35 -0400398};
399
Johannes Berge31b8212010-10-05 19:39:30 +0200400/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000401static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200402 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200403 [NL80211_KEY_IDX] = { .type = NLA_U8 },
404 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200405 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200406 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
407 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200408 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100409 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
410};
411
412/* policy for the key default flags */
413static const struct nla_policy
414nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
415 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
416 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200417};
418
Johannes Bergff1b6e62011-05-04 15:37:28 +0200419/* policy for WoWLAN attributes */
420static const struct nla_policy
421nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
422 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
423 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
424 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200426 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
427 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100430 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300431 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100432};
433
434static const struct nla_policy
435nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
436 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
437 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
438 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
439 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
440 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
441 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
442 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
443 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
444 },
445 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
446 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
447 },
448 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
449 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
450 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200451};
452
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700453/* policy for coalesce rule attributes */
454static const struct nla_policy
455nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
456 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
457 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
458 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
459};
460
Johannes Berge5497d72011-07-05 16:35:40 +0200461/* policy for GTK rekey offload attributes */
462static const struct nla_policy
463nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
464 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
465 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
466 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
467};
468
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300469static const struct nla_policy
470nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200471 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300472 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700473 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474};
475
Johannes Berg97990a02013-04-19 01:02:55 +0200476static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
477 struct netlink_callback *cb,
478 struct cfg80211_registered_device **rdev,
479 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100480{
Johannes Berg67748892010-10-04 21:14:06 +0200481 int err;
482
Johannes Berg67748892010-10-04 21:14:06 +0200483 rtnl_lock();
484
Johannes Berg97990a02013-04-19 01:02:55 +0200485 if (!cb->args[0]) {
486 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
487 nl80211_fam.attrbuf, nl80211_fam.maxattr,
488 nl80211_policy);
489 if (err)
490 goto out_unlock;
491
492 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
493 nl80211_fam.attrbuf);
494 if (IS_ERR(*wdev)) {
495 err = PTR_ERR(*wdev);
496 goto out_unlock;
497 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800498 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200499 /* 0 is the first index - add 1 to parse only once */
500 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200501 cb->args[1] = (*wdev)->identifier;
502 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200503 /* subtract the 1 again here */
504 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200505 struct wireless_dev *tmp;
506
507 if (!wiphy) {
508 err = -ENODEV;
509 goto out_unlock;
510 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800511 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200512 *wdev = NULL;
513
Johannes Berg97990a02013-04-19 01:02:55 +0200514 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
515 if (tmp->identifier == cb->args[1]) {
516 *wdev = tmp;
517 break;
518 }
519 }
Johannes Berg97990a02013-04-19 01:02:55 +0200520
521 if (!*wdev) {
522 err = -ENODEV;
523 goto out_unlock;
524 }
Johannes Berg67748892010-10-04 21:14:06 +0200525 }
526
Johannes Berg67748892010-10-04 21:14:06 +0200527 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200528 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200529 rtnl_unlock();
530 return err;
531}
532
Johannes Berg97990a02013-04-19 01:02:55 +0200533static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200534{
Johannes Berg67748892010-10-04 21:14:06 +0200535 rtnl_unlock();
536}
537
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100538/* IE validation */
539static bool is_valid_ie_attr(const struct nlattr *attr)
540{
541 const u8 *pos;
542 int len;
543
544 if (!attr)
545 return true;
546
547 pos = nla_data(attr);
548 len = nla_len(attr);
549
550 while (len) {
551 u8 elemlen;
552
553 if (len < 2)
554 return false;
555 len -= 2;
556
557 elemlen = pos[1];
558 if (elemlen > len)
559 return false;
560
561 len -= elemlen;
562 pos += 2 + elemlen;
563 }
564
565 return true;
566}
567
Johannes Berg55682962007-09-20 13:09:35 -0400568/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000569static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400570 int flags, u8 cmd)
571{
572 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000573 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400574}
575
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400576static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100577 struct ieee80211_channel *chan,
578 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400579{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200580 /* Some channels must be completely excluded from the
581 * list to protect old user-space tools from breaking
582 */
583 if (!large && chan->flags &
584 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
585 return 0;
586
David S. Miller9360ffd2012-03-29 04:41:26 -0400587 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
588 chan->center_freq))
589 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400590
David S. Miller9360ffd2012-03-29 04:41:26 -0400591 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
592 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
593 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200594 if (chan->flags & IEEE80211_CHAN_NO_IR) {
595 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
596 goto nla_put_failure;
597 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
598 goto nla_put_failure;
599 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100600 if (chan->flags & IEEE80211_CHAN_RADAR) {
601 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
602 goto nla_put_failure;
603 if (large) {
604 u32 time;
605
606 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
607
608 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
609 chan->dfs_state))
610 goto nla_put_failure;
611 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
612 time))
613 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100614 if (nla_put_u32(msg,
615 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
616 chan->dfs_cac_ms))
617 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100618 }
619 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400620
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100621 if (large) {
622 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
623 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
624 goto nla_put_failure;
625 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
626 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
627 goto nla_put_failure;
628 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
629 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
630 goto nla_put_failure;
631 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
632 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
633 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200634 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
635 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
636 goto nla_put_failure;
637 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
638 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
639 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200640 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
641 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
642 goto nla_put_failure;
643 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
644 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
645 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100646 }
647
David S. Miller9360ffd2012-03-29 04:41:26 -0400648 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
649 DBM_TO_MBM(chan->max_power)))
650 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400651
652 return 0;
653
654 nla_put_failure:
655 return -ENOBUFS;
656}
657
Johannes Berg55682962007-09-20 13:09:35 -0400658/* netlink command implementations */
659
Johannes Bergb9454e82009-07-08 13:29:08 +0200660struct key_parse {
661 struct key_params p;
662 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200663 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200664 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100665 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200666};
667
668static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
669{
670 struct nlattr *tb[NL80211_KEY_MAX + 1];
671 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
672 nl80211_key_policy);
673 if (err)
674 return err;
675
676 k->def = !!tb[NL80211_KEY_DEFAULT];
677 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
678
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100679 if (k->def) {
680 k->def_uni = true;
681 k->def_multi = true;
682 }
683 if (k->defmgmt)
684 k->def_multi = true;
685
Johannes Bergb9454e82009-07-08 13:29:08 +0200686 if (tb[NL80211_KEY_IDX])
687 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
688
689 if (tb[NL80211_KEY_DATA]) {
690 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
691 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
692 }
693
694 if (tb[NL80211_KEY_SEQ]) {
695 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
696 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
697 }
698
699 if (tb[NL80211_KEY_CIPHER])
700 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
701
Johannes Berge31b8212010-10-05 19:39:30 +0200702 if (tb[NL80211_KEY_TYPE]) {
703 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
704 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
705 return -EINVAL;
706 }
707
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100708 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
709 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100710 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
711 tb[NL80211_KEY_DEFAULT_TYPES],
712 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100713 if (err)
714 return err;
715
716 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
717 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
718 }
719
Johannes Bergb9454e82009-07-08 13:29:08 +0200720 return 0;
721}
722
723static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
724{
725 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
726 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
727 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
728 }
729
730 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
731 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
732 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
733 }
734
735 if (info->attrs[NL80211_ATTR_KEY_IDX])
736 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
737
738 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
739 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
740
741 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
742 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
743
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100744 if (k->def) {
745 k->def_uni = true;
746 k->def_multi = true;
747 }
748 if (k->defmgmt)
749 k->def_multi = true;
750
Johannes Berge31b8212010-10-05 19:39:30 +0200751 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
752 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
753 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
754 return -EINVAL;
755 }
756
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100757 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
758 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
759 int err = nla_parse_nested(
760 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
761 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
762 nl80211_key_default_policy);
763 if (err)
764 return err;
765
766 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
767 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
768 }
769
Johannes Bergb9454e82009-07-08 13:29:08 +0200770 return 0;
771}
772
773static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
774{
775 int err;
776
777 memset(k, 0, sizeof(*k));
778 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200779 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200780
781 if (info->attrs[NL80211_ATTR_KEY])
782 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
783 else
784 err = nl80211_parse_key_old(info, k);
785
786 if (err)
787 return err;
788
789 if (k->def && k->defmgmt)
790 return -EINVAL;
791
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100792 if (k->defmgmt) {
793 if (k->def_uni || !k->def_multi)
794 return -EINVAL;
795 }
796
Johannes Bergb9454e82009-07-08 13:29:08 +0200797 if (k->idx != -1) {
798 if (k->defmgmt) {
799 if (k->idx < 4 || k->idx > 5)
800 return -EINVAL;
801 } else if (k->def) {
802 if (k->idx < 0 || k->idx > 3)
803 return -EINVAL;
804 } else {
805 if (k->idx < 0 || k->idx > 5)
806 return -EINVAL;
807 }
808 }
809
810 return 0;
811}
812
Johannes Bergfffd0932009-07-08 14:22:54 +0200813static struct cfg80211_cached_keys *
814nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530815 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200816{
817 struct key_parse parse;
818 struct nlattr *key;
819 struct cfg80211_cached_keys *result;
820 int rem, err, def = 0;
821
822 result = kzalloc(sizeof(*result), GFP_KERNEL);
823 if (!result)
824 return ERR_PTR(-ENOMEM);
825
826 result->def = -1;
827 result->defmgmt = -1;
828
829 nla_for_each_nested(key, keys, rem) {
830 memset(&parse, 0, sizeof(parse));
831 parse.idx = -1;
832
833 err = nl80211_parse_key_new(key, &parse);
834 if (err)
835 goto error;
836 err = -EINVAL;
837 if (!parse.p.key)
838 goto error;
839 if (parse.idx < 0 || parse.idx > 4)
840 goto error;
841 if (parse.def) {
842 if (def)
843 goto error;
844 def = 1;
845 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100846 if (!parse.def_uni || !parse.def_multi)
847 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200848 } else if (parse.defmgmt)
849 goto error;
850 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200851 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200852 if (err)
853 goto error;
854 result->params[parse.idx].cipher = parse.p.cipher;
855 result->params[parse.idx].key_len = parse.p.key_len;
856 result->params[parse.idx].key = result->data[parse.idx];
857 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530858
859 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
860 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
861 if (no_ht)
862 *no_ht = true;
863 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200864 }
865
866 return result;
867 error:
868 kfree(result);
869 return ERR_PTR(err);
870}
871
872static int nl80211_key_allowed(struct wireless_dev *wdev)
873{
874 ASSERT_WDEV_LOCK(wdev);
875
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 switch (wdev->iftype) {
877 case NL80211_IFTYPE_AP:
878 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200879 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700880 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200881 break;
882 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200883 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200884 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200885 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200886 return -ENOLINK;
887 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100888 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100889 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100890 case NL80211_IFTYPE_MONITOR:
891 case NL80211_IFTYPE_P2P_DEVICE:
892 case NL80211_IFTYPE_WDS:
893 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200894 return -EINVAL;
895 }
896
897 return 0;
898}
899
Jouni Malinen664834d2014-01-15 00:01:44 +0200900static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
901 struct nlattr *tb)
902{
903 struct ieee80211_channel *chan;
904
905 if (tb == NULL)
906 return NULL;
907 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
908 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
909 return NULL;
910 return chan;
911}
912
Johannes Berg7527a782011-05-13 10:58:57 +0200913static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
914{
915 struct nlattr *nl_modes = nla_nest_start(msg, attr);
916 int i;
917
918 if (!nl_modes)
919 goto nla_put_failure;
920
921 i = 0;
922 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400923 if ((ifmodes & 1) && nla_put_flag(msg, i))
924 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200925 ifmodes >>= 1;
926 i++;
927 }
928
929 nla_nest_end(msg, nl_modes);
930 return 0;
931
932nla_put_failure:
933 return -ENOBUFS;
934}
935
936static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100937 struct sk_buff *msg,
938 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200939{
940 struct nlattr *nl_combis;
941 int i, j;
942
943 nl_combis = nla_nest_start(msg,
944 NL80211_ATTR_INTERFACE_COMBINATIONS);
945 if (!nl_combis)
946 goto nla_put_failure;
947
948 for (i = 0; i < wiphy->n_iface_combinations; i++) {
949 const struct ieee80211_iface_combination *c;
950 struct nlattr *nl_combi, *nl_limits;
951
952 c = &wiphy->iface_combinations[i];
953
954 nl_combi = nla_nest_start(msg, i + 1);
955 if (!nl_combi)
956 goto nla_put_failure;
957
958 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
959 if (!nl_limits)
960 goto nla_put_failure;
961
962 for (j = 0; j < c->n_limits; j++) {
963 struct nlattr *nl_limit;
964
965 nl_limit = nla_nest_start(msg, j + 1);
966 if (!nl_limit)
967 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400968 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
969 c->limits[j].max))
970 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200971 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
972 c->limits[j].types))
973 goto nla_put_failure;
974 nla_nest_end(msg, nl_limit);
975 }
976
977 nla_nest_end(msg, nl_limits);
978
David S. Miller9360ffd2012-03-29 04:41:26 -0400979 if (c->beacon_int_infra_match &&
980 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
981 goto nla_put_failure;
982 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
983 c->num_different_channels) ||
984 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
985 c->max_interfaces))
986 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100987 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200988 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
989 c->radar_detect_widths) ||
990 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
991 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100992 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200993
994 nla_nest_end(msg, nl_combi);
995 }
996
997 nla_nest_end(msg, nl_combis);
998
999 return 0;
1000nla_put_failure:
1001 return -ENOBUFS;
1002}
1003
Johannes Berg3713b4e2013-02-14 16:19:38 +01001004#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001005static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1006 struct sk_buff *msg)
1007{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001008 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001009 struct nlattr *nl_tcp;
1010
1011 if (!tcp)
1012 return 0;
1013
1014 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1015 if (!nl_tcp)
1016 return -ENOBUFS;
1017
1018 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1019 tcp->data_payload_max))
1020 return -ENOBUFS;
1021
1022 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1023 tcp->data_payload_max))
1024 return -ENOBUFS;
1025
1026 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1027 return -ENOBUFS;
1028
1029 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1030 sizeof(*tcp->tok), tcp->tok))
1031 return -ENOBUFS;
1032
1033 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1034 tcp->data_interval_max))
1035 return -ENOBUFS;
1036
1037 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1038 tcp->wake_payload_max))
1039 return -ENOBUFS;
1040
1041 nla_nest_end(msg, nl_tcp);
1042 return 0;
1043}
1044
Johannes Berg3713b4e2013-02-14 16:19:38 +01001045static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001046 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001047 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001048{
1049 struct nlattr *nl_wowlan;
1050
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001052 return 0;
1053
1054 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1055 if (!nl_wowlan)
1056 return -ENOBUFS;
1057
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001058 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001060 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001067 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001068 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001073 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1074 return -ENOBUFS;
1075
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001077 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001078 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1079 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1080 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1081 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001082 };
1083
1084 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1085 sizeof(pat), &pat))
1086 return -ENOBUFS;
1087 }
1088
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001089 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001090 return -ENOBUFS;
1091
Luciano Coelho8cd4d452014-09-17 11:55:28 +03001092 /* TODO: send wowlan net detect */
1093
Johannes Berg3713b4e2013-02-14 16:19:38 +01001094 nla_nest_end(msg, nl_wowlan);
1095
1096 return 0;
1097}
1098#endif
1099
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001100static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001101 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001102{
1103 struct nl80211_coalesce_rule_support rule;
1104
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001105 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001106 return 0;
1107
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001108 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1109 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1110 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1111 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1112 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1113 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001114
1115 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1116 return -ENOBUFS;
1117
1118 return 0;
1119}
1120
Johannes Berg3713b4e2013-02-14 16:19:38 +01001121static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1122 struct ieee80211_supported_band *sband)
1123{
1124 struct nlattr *nl_rates, *nl_rate;
1125 struct ieee80211_rate *rate;
1126 int i;
1127
1128 /* add HT info */
1129 if (sband->ht_cap.ht_supported &&
1130 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1131 sizeof(sband->ht_cap.mcs),
1132 &sband->ht_cap.mcs) ||
1133 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1134 sband->ht_cap.cap) ||
1135 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1136 sband->ht_cap.ampdu_factor) ||
1137 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1138 sband->ht_cap.ampdu_density)))
1139 return -ENOBUFS;
1140
1141 /* add VHT info */
1142 if (sband->vht_cap.vht_supported &&
1143 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1144 sizeof(sband->vht_cap.vht_mcs),
1145 &sband->vht_cap.vht_mcs) ||
1146 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1147 sband->vht_cap.cap)))
1148 return -ENOBUFS;
1149
1150 /* add bitrates */
1151 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1152 if (!nl_rates)
1153 return -ENOBUFS;
1154
1155 for (i = 0; i < sband->n_bitrates; i++) {
1156 nl_rate = nla_nest_start(msg, i);
1157 if (!nl_rate)
1158 return -ENOBUFS;
1159
1160 rate = &sband->bitrates[i];
1161 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1162 rate->bitrate))
1163 return -ENOBUFS;
1164 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1165 nla_put_flag(msg,
1166 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1167 return -ENOBUFS;
1168
1169 nla_nest_end(msg, nl_rate);
1170 }
1171
1172 nla_nest_end(msg, nl_rates);
1173
1174 return 0;
1175}
1176
1177static int
1178nl80211_send_mgmt_stypes(struct sk_buff *msg,
1179 const struct ieee80211_txrx_stypes *mgmt_stypes)
1180{
1181 u16 stypes;
1182 struct nlattr *nl_ftypes, *nl_ifs;
1183 enum nl80211_iftype ift;
1184 int i;
1185
1186 if (!mgmt_stypes)
1187 return 0;
1188
1189 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1190 if (!nl_ifs)
1191 return -ENOBUFS;
1192
1193 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1194 nl_ftypes = nla_nest_start(msg, ift);
1195 if (!nl_ftypes)
1196 return -ENOBUFS;
1197 i = 0;
1198 stypes = mgmt_stypes[ift].tx;
1199 while (stypes) {
1200 if ((stypes & 1) &&
1201 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1202 (i << 4) | IEEE80211_FTYPE_MGMT))
1203 return -ENOBUFS;
1204 stypes >>= 1;
1205 i++;
1206 }
1207 nla_nest_end(msg, nl_ftypes);
1208 }
1209
1210 nla_nest_end(msg, nl_ifs);
1211
1212 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1213 if (!nl_ifs)
1214 return -ENOBUFS;
1215
1216 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1217 nl_ftypes = nla_nest_start(msg, ift);
1218 if (!nl_ftypes)
1219 return -ENOBUFS;
1220 i = 0;
1221 stypes = mgmt_stypes[ift].rx;
1222 while (stypes) {
1223 if ((stypes & 1) &&
1224 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1225 (i << 4) | IEEE80211_FTYPE_MGMT))
1226 return -ENOBUFS;
1227 stypes >>= 1;
1228 i++;
1229 }
1230 nla_nest_end(msg, nl_ftypes);
1231 }
1232 nla_nest_end(msg, nl_ifs);
1233
1234 return 0;
1235}
1236
Johannes Berg86e8cf92013-06-19 10:57:22 +02001237struct nl80211_dump_wiphy_state {
1238 s64 filter_wiphy;
1239 long start;
1240 long split_start, band_start, chan_start;
1241 bool split;
1242};
1243
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001244static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001245 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001246 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001247 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001248{
1249 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001250 struct nlattr *nl_bands, *nl_band;
1251 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001252 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001253 enum ieee80211_band band;
1254 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001255 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001256 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001257 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001258 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001259
Johannes Berg3bb20552014-05-26 13:52:25 +02001260 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001261 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 return -ENOBUFS;
1263
Johannes Berg86e8cf92013-06-19 10:57:22 +02001264 if (WARN_ON(!state))
1265 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001266
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001270 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001272 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001273
Johannes Berg3bb20552014-05-26 13:52:25 +02001274 if (cmd != NL80211_CMD_NEW_WIPHY)
1275 goto finish;
1276
Johannes Berg86e8cf92013-06-19 10:57:22 +02001277 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 case 0:
1279 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001280 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001299 goto nla_put_failure;
1300
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1303 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1306 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1309 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001310 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1312 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1315 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001318 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001319 state->split_start++;
1320 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 break;
1322 case 1:
1323 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1325 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001326 goto nla_put_failure;
1327
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001330 goto nla_put_failure;
1331
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1334 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001335
Johannes Berg3713b4e2013-02-14 16:19:38 +01001336 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001341
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001342 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001344 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001346
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001347 if ((rdev->wiphy.available_antennas_tx ||
1348 rdev->wiphy.available_antennas_rx) &&
1349 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 u32 tx_ant = 0, rx_ant = 0;
1351 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 if (!res) {
1354 if (nla_put_u32(msg,
1355 NL80211_ATTR_WIPHY_ANTENNA_TX,
1356 tx_ant) ||
1357 nla_put_u32(msg,
1358 NL80211_ATTR_WIPHY_ANTENNA_RX,
1359 rx_ant))
1360 goto nla_put_failure;
1361 }
Johannes Bergee688b002008-01-24 19:38:39 +01001362 }
1363
Johannes Berg86e8cf92013-06-19 10:57:22 +02001364 state->split_start++;
1365 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 break;
1367 case 2:
1368 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001369 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001371 state->split_start++;
1372 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 break;
1374 case 3:
1375 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1376 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001377 goto nla_put_failure;
1378
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 for (band = state->band_start;
1380 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 struct ieee80211_supported_band *sband;
1382
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001383 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384
1385 if (!sband)
1386 continue;
1387
1388 nl_band = nla_nest_start(msg, band);
1389 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001390 goto nla_put_failure;
1391
Johannes Berg86e8cf92013-06-19 10:57:22 +02001392 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 case 0:
1394 if (nl80211_send_band_rateinfo(msg, sband))
1395 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001396 state->chan_start++;
1397 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001398 break;
1399 default:
1400 /* add frequencies */
1401 nl_freqs = nla_nest_start(
1402 msg, NL80211_BAND_ATTR_FREQS);
1403 if (!nl_freqs)
1404 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001405
Johannes Berg86e8cf92013-06-19 10:57:22 +02001406 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001407 i < sband->n_channels;
1408 i++) {
1409 nl_freq = nla_nest_start(msg, i);
1410 if (!nl_freq)
1411 goto nla_put_failure;
1412
1413 chan = &sband->channels[i];
1414
Johannes Berg86e8cf92013-06-19 10:57:22 +02001415 if (nl80211_msg_put_channel(
1416 msg, chan,
1417 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001418 goto nla_put_failure;
1419
1420 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001421 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 break;
1423 }
1424 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 nla_nest_end(msg, nl_freqs);
1429 }
1430
1431 nla_nest_end(msg, nl_band);
1432
Johannes Berg86e8cf92013-06-19 10:57:22 +02001433 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 band--;
1437 break;
1438 }
Johannes Bergee688b002008-01-24 19:38:39 +01001439 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001441
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001443 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001445 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001446
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 if (state->band_start == 0 && state->chan_start == 0)
1449 state->split_start++;
1450 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 break;
1452 case 4:
1453 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1454 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001455 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001456
1457 i = 0;
1458#define CMD(op, n) \
1459 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001460 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 i++; \
1462 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1463 goto nla_put_failure; \
1464 } \
1465 } while (0)
1466
1467 CMD(add_virtual_intf, NEW_INTERFACE);
1468 CMD(change_virtual_intf, SET_INTERFACE);
1469 CMD(add_key, NEW_KEY);
1470 CMD(start_ap, START_AP);
1471 CMD(add_station, NEW_STATION);
1472 CMD(add_mpath, NEW_MPATH);
1473 CMD(update_mesh_config, SET_MESH_CONFIG);
1474 CMD(change_bss, SET_BSS);
1475 CMD(auth, AUTHENTICATE);
1476 CMD(assoc, ASSOCIATE);
1477 CMD(deauth, DEAUTHENTICATE);
1478 CMD(disassoc, DISASSOCIATE);
1479 CMD(join_ibss, JOIN_IBSS);
1480 CMD(join_mesh, JOIN_MESH);
1481 CMD(set_pmksa, SET_PMKSA);
1482 CMD(del_pmksa, DEL_PMKSA);
1483 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001484 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001485 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1486 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1487 CMD(mgmt_tx, FRAME);
1488 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001489 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001490 i++;
1491 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1492 goto nla_put_failure;
1493 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1495 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 i++;
1497 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1498 goto nla_put_failure;
1499 }
1500 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001501 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 CMD(tdls_mgmt, TDLS_MGMT);
1503 CMD(tdls_oper, TDLS_OPER);
1504 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001505 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 CMD(sched_scan_start, START_SCHED_SCAN);
1507 CMD(probe_client, PROBE_CLIENT);
1508 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001509 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 i++;
1511 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1512 goto nla_put_failure;
1513 }
1514 CMD(start_p2p_device, START_P2P_DEVICE);
1515 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001516#ifdef CONFIG_NL80211_TESTMODE
1517 CMD(testmode_cmd, TESTMODE);
1518#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001519 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001520 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1521 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001523 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001524 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001525 if (rdev->wiphy.features &
1526 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001527 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001528 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001529 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001530#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001531
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001532 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001533 i++;
1534 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001535 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001536 }
1537
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 i++;
1540 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1541 goto nla_put_failure;
1542 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001543
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001545 state->split_start++;
1546 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547 break;
1548 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (rdev->ops->remain_on_channel &&
1550 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 nla_put_u32(msg,
1552 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001553 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001554 goto nla_put_failure;
1555
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001556 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1558 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001559
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1561 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001562 state->split_start++;
1563 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 break;
1565 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001566#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001567 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001569 state->split_start++;
1570 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571 break;
1572#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001573 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574#endif
1575 case 7:
1576 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001578 goto nla_put_failure;
1579
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001580 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001583
Johannes Berg86e8cf92013-06-19 10:57:22 +02001584 state->split_start++;
1585 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 break;
1587 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001590 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 goto nla_put_failure;
1592
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001594 /*
1595 * We can only add the per-channel limit information if the
1596 * dump is split, otherwise it makes it too big. Therefore
1597 * only advertise it in that case.
1598 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001599 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001600 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1601 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001602 goto nla_put_failure;
1603
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001604 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001605 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001606 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1607 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 goto nla_put_failure;
1609
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1611 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001614 goto nla_put_failure;
1615
1616 /*
1617 * Any information below this point is only available to
1618 * applications that can deal with it being split. This
1619 * helps ensure that newly added capabilities don't break
1620 * older tools by overrunning their buffers.
1621 *
1622 * We still increment split_start so that in the split
1623 * case we'll continue with more data in the next round,
1624 * but break unconditionally so unsplit data stops here.
1625 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001626 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 break;
1628 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001629 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001630 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 rdev->wiphy.extended_capabilities_len,
1632 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001633 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001634 rdev->wiphy.extended_capabilities_len,
1635 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001636 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001637
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001638 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001639 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1641 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001642 goto nla_put_failure;
1643
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001644 state->split_start++;
1645 break;
1646 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001648 goto nla_put_failure;
1649
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001651 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1652 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1653 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001654
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001656 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001657 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001658 goto nla_put_failure;
1659
Johannes Bergad7e7182013-11-13 13:37:47 +01001660 state->split_start++;
1661 break;
1662 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001664 const struct nl80211_vendor_cmd_info *info;
1665 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001666
Johannes Berg567ffc32013-12-18 14:43:31 +01001667 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1668 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001669 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1672 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001673 if (nla_put(msg, i + 1, sizeof(*info), info))
1674 goto nla_put_failure;
1675 }
1676 nla_nest_end(msg, nested);
1677 }
1678
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001679 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001680 const struct nl80211_vendor_cmd_info *info;
1681 struct nlattr *nested;
1682
1683 nested = nla_nest_start(msg,
1684 NL80211_ATTR_VENDOR_EVENTS);
1685 if (!nested)
1686 goto nla_put_failure;
1687
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1689 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001690 if (nla_put(msg, i + 1, sizeof(*info), info))
1691 goto nla_put_failure;
1692 }
1693 nla_nest_end(msg, nested);
1694 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001695 state->split_start++;
1696 break;
1697 case 12:
1698 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1699 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1700 rdev->wiphy.max_num_csa_counters))
1701 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001702
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001704 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001705 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001706 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001707 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001708 return genlmsg_end(msg, hdr);
1709
1710 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001711 genlmsg_cancel(msg, hdr);
1712 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001713}
1714
Johannes Berg86e8cf92013-06-19 10:57:22 +02001715static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1716 struct netlink_callback *cb,
1717 struct nl80211_dump_wiphy_state *state)
1718{
1719 struct nlattr **tb = nl80211_fam.attrbuf;
1720 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1721 tb, nl80211_fam.maxattr, nl80211_policy);
1722 /* ignore parse errors for backward compatibility */
1723 if (ret)
1724 return 0;
1725
1726 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1727 if (tb[NL80211_ATTR_WIPHY])
1728 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1729 if (tb[NL80211_ATTR_WDEV])
1730 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1731 if (tb[NL80211_ATTR_IFINDEX]) {
1732 struct net_device *netdev;
1733 struct cfg80211_registered_device *rdev;
1734 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1735
Ying Xue7f2b8562014-01-15 10:23:45 +08001736 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001737 if (!netdev)
1738 return -ENODEV;
1739 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001740 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001741 netdev->ieee80211_ptr->wiphy);
1742 state->filter_wiphy = rdev->wiphy_idx;
1743 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 }
1745
1746 return 0;
1747}
1748
Johannes Berg55682962007-09-20 13:09:35 -04001749static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1750{
Johannes Berg645e77d2013-03-01 14:03:49 +01001751 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001753 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001754
Johannes Berg5fe231e2013-05-08 21:45:15 +02001755 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001756 if (!state) {
1757 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001758 if (!state) {
1759 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001760 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001761 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762 state->filter_wiphy = -1;
1763 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1764 if (ret) {
1765 kfree(state);
1766 rtnl_unlock();
1767 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001768 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001769 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001770 }
1771
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001772 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1773 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001774 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001775 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001776 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001777 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001778 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 continue;
1780 /* attempt to fit multiple wiphy data chunks into the skb */
1781 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001782 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1783 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001784 NETLINK_CB(cb->skb).portid,
1785 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001786 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001787 if (ret < 0) {
1788 /*
1789 * If sending the wiphy data didn't fit (ENOBUFS
1790 * or EMSGSIZE returned), this SKB is still
1791 * empty (so it's not too big because another
1792 * wiphy dataset is already in the skb) and
1793 * we've not tried to adjust the dump allocation
1794 * yet ... then adjust the alloc size to be
1795 * bigger, and return 1 but with the empty skb.
1796 * This results in an empty message being RX'ed
1797 * in userspace, but that is ignored.
1798 *
1799 * We can then retry with the larger buffer.
1800 */
1801 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001802 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001803 cb->min_dump_alloc < 4096) {
1804 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001805 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001806 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001807 return 1;
1808 }
1809 idx--;
1810 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001811 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001812 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001813 break;
Johannes Berg55682962007-09-20 13:09:35 -04001814 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001815 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001816
Johannes Berg86e8cf92013-06-19 10:57:22 +02001817 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001818
1819 return skb->len;
1820}
1821
Johannes Berg86e8cf92013-06-19 10:57:22 +02001822static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1823{
1824 kfree((void *)cb->args[0]);
1825 return 0;
1826}
1827
Johannes Berg55682962007-09-20 13:09:35 -04001828static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1829{
1830 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001831 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001832 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001833
Johannes Berg645e77d2013-03-01 14:03:49 +01001834 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001835 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001836 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001837
Johannes Berg3bb20552014-05-26 13:52:25 +02001838 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1839 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001840 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001841 nlmsg_free(msg);
1842 return -ENOBUFS;
1843 }
Johannes Berg55682962007-09-20 13:09:35 -04001844
Johannes Berg134e6372009-07-10 09:51:34 +00001845 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001846}
1847
Jouni Malinen31888482008-10-30 16:59:24 +02001848static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1849 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1850 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1851 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1852 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1853 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1854};
1855
1856static int parse_txq_params(struct nlattr *tb[],
1857 struct ieee80211_txq_params *txq_params)
1858{
Johannes Berga3304b02012-03-28 11:04:24 +02001859 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001860 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1861 !tb[NL80211_TXQ_ATTR_AIFS])
1862 return -EINVAL;
1863
Johannes Berga3304b02012-03-28 11:04:24 +02001864 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001865 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1866 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1867 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1868 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1869
Johannes Berga3304b02012-03-28 11:04:24 +02001870 if (txq_params->ac >= NL80211_NUM_ACS)
1871 return -EINVAL;
1872
Jouni Malinen31888482008-10-30 16:59:24 +02001873 return 0;
1874}
1875
Johannes Bergf444de02010-05-05 15:25:02 +02001876static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1877{
1878 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001879 * You can only set the channel explicitly for WDS interfaces,
1880 * all others have their channel managed via their respective
1881 * "establish a connection" command (connect, join, ...)
1882 *
1883 * For AP/GO and mesh mode, the channel can be set with the
1884 * channel userspace API, but is only stored and passed to the
1885 * low-level driver when the AP starts or the mesh is joined.
1886 * This is for backward compatibility, userspace can also give
1887 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001888 *
1889 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001890 * whatever else is going on, so they have their own special
1891 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001892 */
1893 return !wdev ||
1894 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001895 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001896 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1897 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001898}
1899
Johannes Berg683b6d32012-11-08 21:25:48 +01001900static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1901 struct genl_info *info,
1902 struct cfg80211_chan_def *chandef)
1903{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301904 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001905
1906 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1907 return -EINVAL;
1908
1909 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1910
1911 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001912 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1913 chandef->center_freq1 = control_freq;
1914 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001915
1916 /* Primary channel not allowed */
1917 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1918 return -EINVAL;
1919
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001920 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1921 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001922
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001923 chantype = nla_get_u32(
1924 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1925
1926 switch (chantype) {
1927 case NL80211_CHAN_NO_HT:
1928 case NL80211_CHAN_HT20:
1929 case NL80211_CHAN_HT40PLUS:
1930 case NL80211_CHAN_HT40MINUS:
1931 cfg80211_chandef_create(chandef, chandef->chan,
1932 chantype);
1933 break;
1934 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001935 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001936 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001937 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1938 chandef->width =
1939 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1940 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1941 chandef->center_freq1 =
1942 nla_get_u32(
1943 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1944 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1945 chandef->center_freq2 =
1946 nla_get_u32(
1947 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1948 }
1949
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001950 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001951 return -EINVAL;
1952
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001953 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1954 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001955 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001956
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001957 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1958 chandef->width == NL80211_CHAN_WIDTH_10) &&
1959 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1960 return -EINVAL;
1961
Johannes Berg683b6d32012-11-08 21:25:48 +01001962 return 0;
1963}
1964
Johannes Bergf444de02010-05-05 15:25:02 +02001965static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001966 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001967 struct genl_info *info)
1968{
Johannes Berg683b6d32012-11-08 21:25:48 +01001969 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001970 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001971 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001972 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001973
Jouni Malinene16821b2014-04-28 11:22:08 +03001974 if (dev)
1975 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001976 if (!nl80211_can_set_dev_channel(wdev))
1977 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001978 if (wdev)
1979 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001980
Johannes Berg683b6d32012-11-08 21:25:48 +01001981 result = nl80211_parse_chandef(rdev, info, &chandef);
1982 if (result)
1983 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001984
Johannes Berge8c9bd52012-06-06 08:18:22 +02001985 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001986 case NL80211_IFTYPE_AP:
1987 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001988 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001989 result = -EINVAL;
1990 break;
1991 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001992 if (wdev->beacon_interval) {
1993 if (!dev || !rdev->ops->set_ap_chanwidth ||
1994 !(rdev->wiphy.features &
1995 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1996 result = -EBUSY;
1997 break;
1998 }
1999
2000 /* Only allow dynamic channel width changes */
2001 if (chandef.chan != wdev->preset_chandef.chan) {
2002 result = -EBUSY;
2003 break;
2004 }
2005 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2006 if (result)
2007 break;
2008 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002009 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002010 result = 0;
2011 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002012 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002013 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002014 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002015 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002016 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002017 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002018 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002019 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002020 }
Johannes Bergf444de02010-05-05 15:25:02 +02002021
2022 return result;
2023}
2024
2025static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2026{
Johannes Berg4c476992010-10-04 21:36:35 +02002027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2028 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002029
Jouni Malinene16821b2014-04-28 11:22:08 +03002030 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002031}
2032
Bill Jordane8347eb2010-10-01 13:54:28 -04002033static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2034{
Johannes Berg43b19952010-10-07 13:10:30 +02002035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2036 struct net_device *dev = info->user_ptr[1];
2037 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002038 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002039
2040 if (!info->attrs[NL80211_ATTR_MAC])
2041 return -EINVAL;
2042
Johannes Berg43b19952010-10-07 13:10:30 +02002043 if (netif_running(dev))
2044 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002045
Johannes Berg43b19952010-10-07 13:10:30 +02002046 if (!rdev->ops->set_wds_peer)
2047 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002048
Johannes Berg43b19952010-10-07 13:10:30 +02002049 if (wdev->iftype != NL80211_IFTYPE_WDS)
2050 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002051
2052 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002053 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002054}
2055
2056
Johannes Berg55682962007-09-20 13:09:35 -04002057static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2058{
2059 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002060 struct net_device *netdev = NULL;
2061 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002062 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002063 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002064 u32 changed;
2065 u8 retry_short = 0, retry_long = 0;
2066 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002067 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002068
Johannes Berg5fe231e2013-05-08 21:45:15 +02002069 ASSERT_RTNL();
2070
Johannes Bergf444de02010-05-05 15:25:02 +02002071 /*
2072 * Try to find the wiphy and netdev. Normally this
2073 * function shouldn't need the netdev, but this is
2074 * done for backward compatibility -- previously
2075 * setting the channel was done per wiphy, but now
2076 * it is per netdev. Previous userland like hostapd
2077 * also passed a netdev to set_wiphy, so that it is
2078 * possible to let that go to the right netdev!
2079 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002080
Johannes Bergf444de02010-05-05 15:25:02 +02002081 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2082 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2083
Ying Xue7f2b8562014-01-15 10:23:45 +08002084 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002085 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002086 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002087 else
Johannes Bergf444de02010-05-05 15:25:02 +02002088 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002089 }
2090
Johannes Bergf444de02010-05-05 15:25:02 +02002091 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002092 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2093 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002094 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002095 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002096 wdev = NULL;
2097 netdev = NULL;
2098 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002099 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002100 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002101
2102 /*
2103 * end workaround code, by now the rdev is available
2104 * and locked, and wdev may or may not be NULL.
2105 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002106
2107 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002108 result = cfg80211_dev_rename(
2109 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002110
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002111 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002112 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002113
Jouni Malinen31888482008-10-30 16:59:24 +02002114 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2115 struct ieee80211_txq_params txq_params;
2116 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2117
Ying Xue7f2b8562014-01-15 10:23:45 +08002118 if (!rdev->ops->set_txq_params)
2119 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002120
Ying Xue7f2b8562014-01-15 10:23:45 +08002121 if (!netdev)
2122 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002123
Johannes Berg133a3ff2011-11-03 14:50:13 +01002124 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002125 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2126 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002127
Ying Xue7f2b8562014-01-15 10:23:45 +08002128 if (!netif_running(netdev))
2129 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002130
Jouni Malinen31888482008-10-30 16:59:24 +02002131 nla_for_each_nested(nl_txq_params,
2132 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2133 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002134 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2135 nla_data(nl_txq_params),
2136 nla_len(nl_txq_params),
2137 txq_params_policy);
2138 if (result)
2139 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002140 result = parse_txq_params(tb, &txq_params);
2141 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002142 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002143
Hila Gonene35e4d22012-06-27 17:19:42 +03002144 result = rdev_set_txq_params(rdev, netdev,
2145 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002146 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002147 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002148 }
2149 }
2150
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002151 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002152 result = __nl80211_set_channel(
2153 rdev,
2154 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2155 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002156 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002157 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002158 }
2159
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002160 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002161 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002162 enum nl80211_tx_power_setting type;
2163 int idx, mbm = 0;
2164
Johannes Bergc8442112012-10-24 10:17:18 +02002165 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2166 txp_wdev = NULL;
2167
Ying Xue7f2b8562014-01-15 10:23:45 +08002168 if (!rdev->ops->set_tx_power)
2169 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002170
2171 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2172 type = nla_get_u32(info->attrs[idx]);
2173
2174 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 (type != NL80211_TX_POWER_AUTOMATIC))
2176 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002177
2178 if (type != NL80211_TX_POWER_AUTOMATIC) {
2179 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2180 mbm = nla_get_u32(info->attrs[idx]);
2181 }
2182
Johannes Bergc8442112012-10-24 10:17:18 +02002183 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002184 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002185 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002186 }
2187
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002188 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2189 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2190 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002191 if ((!rdev->wiphy.available_antennas_tx &&
2192 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002193 !rdev->ops->set_antenna)
2194 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002195
2196 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2197 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2198
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002199 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002200 * available antenna masks, except for the "all" mask */
2201 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002202 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2203 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002204
Bruno Randolf7f531e02010-12-16 11:30:22 +09002205 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2206 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002207
Hila Gonene35e4d22012-06-27 17:19:42 +03002208 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002209 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002211 }
2212
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002213 changed = 0;
2214
2215 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2216 retry_short = nla_get_u8(
2217 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002218 if (retry_short == 0)
2219 return -EINVAL;
2220
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002221 changed |= WIPHY_PARAM_RETRY_SHORT;
2222 }
2223
2224 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2225 retry_long = nla_get_u8(
2226 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002227 if (retry_long == 0)
2228 return -EINVAL;
2229
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002230 changed |= WIPHY_PARAM_RETRY_LONG;
2231 }
2232
2233 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2234 frag_threshold = nla_get_u32(
2235 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002236 if (frag_threshold < 256)
2237 return -EINVAL;
2238
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002239 if (frag_threshold != (u32) -1) {
2240 /*
2241 * Fragments (apart from the last one) are required to
2242 * have even length. Make the fragmentation code
2243 * simpler by stripping LSB should someone try to use
2244 * odd threshold value.
2245 */
2246 frag_threshold &= ~0x1;
2247 }
2248 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2249 }
2250
2251 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2252 rts_threshold = nla_get_u32(
2253 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2254 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2255 }
2256
Lukáš Turek81077e82009-12-21 22:50:47 +01002257 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002258 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2259 return -EINVAL;
2260
Lukáš Turek81077e82009-12-21 22:50:47 +01002261 coverage_class = nla_get_u8(
2262 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2263 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2264 }
2265
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002266 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2267 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2268 return -EOPNOTSUPP;
2269
2270 changed |= WIPHY_PARAM_DYN_ACK;
2271 }
2272
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002273 if (changed) {
2274 u8 old_retry_short, old_retry_long;
2275 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002276 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002277
Ying Xue7f2b8562014-01-15 10:23:45 +08002278 if (!rdev->ops->set_wiphy_params)
2279 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002280
2281 old_retry_short = rdev->wiphy.retry_short;
2282 old_retry_long = rdev->wiphy.retry_long;
2283 old_frag_threshold = rdev->wiphy.frag_threshold;
2284 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002285 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002286
2287 if (changed & WIPHY_PARAM_RETRY_SHORT)
2288 rdev->wiphy.retry_short = retry_short;
2289 if (changed & WIPHY_PARAM_RETRY_LONG)
2290 rdev->wiphy.retry_long = retry_long;
2291 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2292 rdev->wiphy.frag_threshold = frag_threshold;
2293 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2294 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002295 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2296 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002297
Hila Gonene35e4d22012-06-27 17:19:42 +03002298 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002299 if (result) {
2300 rdev->wiphy.retry_short = old_retry_short;
2301 rdev->wiphy.retry_long = old_retry_long;
2302 rdev->wiphy.frag_threshold = old_frag_threshold;
2303 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002304 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002305 }
2306 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002307 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002308}
2309
Johannes Berg71bbc992012-06-15 15:30:18 +02002310static inline u64 wdev_id(struct wireless_dev *wdev)
2311{
2312 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002313 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002314}
Johannes Berg55682962007-09-20 13:09:35 -04002315
Johannes Berg683b6d32012-11-08 21:25:48 +01002316static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002317 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002318{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002319 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002320
Johannes Berg683b6d32012-11-08 21:25:48 +01002321 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2322 chandef->chan->center_freq))
2323 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002324 switch (chandef->width) {
2325 case NL80211_CHAN_WIDTH_20_NOHT:
2326 case NL80211_CHAN_WIDTH_20:
2327 case NL80211_CHAN_WIDTH_40:
2328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2329 cfg80211_get_chandef_type(chandef)))
2330 return -ENOBUFS;
2331 break;
2332 default:
2333 break;
2334 }
2335 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2336 return -ENOBUFS;
2337 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2338 return -ENOBUFS;
2339 if (chandef->center_freq2 &&
2340 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002341 return -ENOBUFS;
2342 return 0;
2343}
2344
Eric W. Biederman15e47302012-09-07 20:12:54 +00002345static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002346 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002347 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002348{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002349 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002350 void *hdr;
2351
Eric W. Biederman15e47302012-09-07 20:12:54 +00002352 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002353 if (!hdr)
2354 return -1;
2355
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002356 if (dev &&
2357 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002358 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002359 goto nla_put_failure;
2360
2361 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2362 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002363 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002364 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002365 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2366 rdev->devlist_generation ^
2367 (cfg80211_rdev_list_generation << 2)))
2368 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002369
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002370 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002371 int ret;
2372 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002373
Johannes Berg683b6d32012-11-08 21:25:48 +01002374 ret = rdev_get_channel(rdev, wdev, &chandef);
2375 if (ret == 0) {
2376 if (nl80211_send_chandef(msg, &chandef))
2377 goto nla_put_failure;
2378 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002379 }
2380
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002381 if (wdev->ssid_len) {
2382 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2383 goto nla_put_failure;
2384 }
2385
Johannes Berg55682962007-09-20 13:09:35 -04002386 return genlmsg_end(msg, hdr);
2387
2388 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002389 genlmsg_cancel(msg, hdr);
2390 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002391}
2392
2393static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2394{
2395 int wp_idx = 0;
2396 int if_idx = 0;
2397 int wp_start = cb->args[0];
2398 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002399 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002400 struct wireless_dev *wdev;
2401
Johannes Berg5fe231e2013-05-08 21:45:15 +02002402 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002403 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2404 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002405 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002406 if (wp_idx < wp_start) {
2407 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002408 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002409 }
Johannes Berg55682962007-09-20 13:09:35 -04002410 if_idx = 0;
2411
Johannes Berg89a54e42012-06-15 14:33:17 +02002412 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002413 if (if_idx < if_start) {
2414 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002415 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002416 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002417 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002418 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002419 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002420 goto out;
2421 }
2422 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002423 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002424
2425 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002426 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002427 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002428 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002429
2430 cb->args[0] = wp_idx;
2431 cb->args[1] = if_idx;
2432
2433 return skb->len;
2434}
2435
2436static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2437{
2438 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002439 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002440 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002441
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002442 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002443 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002444 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002445
Eric W. Biederman15e47302012-09-07 20:12:54 +00002446 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002447 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002448 nlmsg_free(msg);
2449 return -ENOBUFS;
2450 }
Johannes Berg55682962007-09-20 13:09:35 -04002451
Johannes Berg134e6372009-07-10 09:51:34 +00002452 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002453}
2454
Michael Wu66f7ac52008-01-31 19:48:22 +01002455static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2456 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2457 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2458 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2459 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2460 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002461 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002462};
2463
2464static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2465{
2466 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2467 int flag;
2468
2469 *mntrflags = 0;
2470
2471 if (!nla)
2472 return -EINVAL;
2473
2474 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2475 nla, mntr_flags_policy))
2476 return -EINVAL;
2477
2478 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2479 if (flags[flag])
2480 *mntrflags |= (1<<flag);
2481
2482 return 0;
2483}
2484
Johannes Berg9bc383d2009-11-19 11:55:19 +01002485static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002486 struct net_device *netdev, u8 use_4addr,
2487 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002488{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002489 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002490 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002491 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002492 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002493 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002494
2495 switch (iftype) {
2496 case NL80211_IFTYPE_AP_VLAN:
2497 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2498 return 0;
2499 break;
2500 case NL80211_IFTYPE_STATION:
2501 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2502 return 0;
2503 break;
2504 default:
2505 break;
2506 }
2507
2508 return -EOPNOTSUPP;
2509}
2510
Johannes Berg55682962007-09-20 13:09:35 -04002511static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2512{
Johannes Berg4c476992010-10-04 21:36:35 +02002513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002514 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002515 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002516 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002517 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002518 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002519 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002520
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002521 memset(&params, 0, sizeof(params));
2522
Johannes Berg04a773a2009-04-19 21:24:32 +02002523 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002524
Johannes Berg723b0382008-09-16 20:22:09 +02002525 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002526 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002527 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002528 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002529 if (ntype > NL80211_IFTYPE_MAX)
2530 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002531 }
2532
Johannes Berg92ffe052008-09-16 20:39:36 +02002533 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002534 struct wireless_dev *wdev = dev->ieee80211_ptr;
2535
Johannes Berg4c476992010-10-04 21:36:35 +02002536 if (ntype != NL80211_IFTYPE_MESH_POINT)
2537 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002538 if (netif_running(dev))
2539 return -EBUSY;
2540
2541 wdev_lock(wdev);
2542 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2543 IEEE80211_MAX_MESH_ID_LEN);
2544 wdev->mesh_id_up_len =
2545 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2546 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2547 wdev->mesh_id_up_len);
2548 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002549 }
2550
Felix Fietkau8b787642009-11-10 18:53:10 +01002551 if (info->attrs[NL80211_ATTR_4ADDR]) {
2552 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2553 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002554 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002555 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002556 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002557 } else {
2558 params.use_4addr = -1;
2559 }
2560
Johannes Berg92ffe052008-09-16 20:39:36 +02002561 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002562 if (ntype != NL80211_IFTYPE_MONITOR)
2563 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002564 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2565 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002566 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002567 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002568
2569 flags = &_flags;
2570 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002571 }
Johannes Berg3b858752009-03-12 09:55:09 +01002572
Luciano Coelho18003292013-08-29 13:26:57 +03002573 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002574 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2575 return -EOPNOTSUPP;
2576
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002577 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002578 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002579 else
2580 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002581
Johannes Berg9bc383d2009-11-19 11:55:19 +01002582 if (!err && params.use_4addr != -1)
2583 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2584
Johannes Berg55682962007-09-20 13:09:35 -04002585 return err;
2586}
2587
2588static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2589{
Johannes Berg4c476992010-10-04 21:36:35 +02002590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002591 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002592 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002593 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002594 int err;
2595 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002596 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002597
Johannes Berg78f22b62014-03-24 17:57:27 +01002598 /* to avoid failing a new interface creation due to pending removal */
2599 cfg80211_destroy_ifaces(rdev);
2600
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002601 memset(&params, 0, sizeof(params));
2602
Johannes Berg55682962007-09-20 13:09:35 -04002603 if (!info->attrs[NL80211_ATTR_IFNAME])
2604 return -EINVAL;
2605
2606 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2607 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2608 if (type > NL80211_IFTYPE_MAX)
2609 return -EINVAL;
2610 }
2611
Johannes Berg79c97e92009-07-07 03:56:12 +02002612 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002613 !(rdev->wiphy.interface_modes & (1 << type)))
2614 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002615
Ben Greeare8f479b2014-10-22 12:23:05 -07002616 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2617 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2618 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002619 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2620 ETH_ALEN);
2621 if (!is_valid_ether_addr(params.macaddr))
2622 return -EADDRNOTAVAIL;
2623 }
2624
Johannes Berg9bc383d2009-11-19 11:55:19 +01002625 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002626 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002627 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002628 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002629 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002630 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002631
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002632 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2633 if (!msg)
2634 return -ENOMEM;
2635
Michael Wu66f7ac52008-01-31 19:48:22 +01002636 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2637 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2638 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002639
Luciano Coelho18003292013-08-29 13:26:57 +03002640 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002641 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2642 return -EOPNOTSUPP;
2643
Hila Gonene35e4d22012-06-27 17:19:42 +03002644 wdev = rdev_add_virtual_intf(rdev,
2645 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2646 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002647 if (IS_ERR(wdev)) {
2648 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002649 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002650 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002651
Johannes Berg78f22b62014-03-24 17:57:27 +01002652 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2653 wdev->owner_nlportid = info->snd_portid;
2654
Johannes Berg98104fde2012-06-16 00:19:54 +02002655 switch (type) {
2656 case NL80211_IFTYPE_MESH_POINT:
2657 if (!info->attrs[NL80211_ATTR_MESH_ID])
2658 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002659 wdev_lock(wdev);
2660 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2661 IEEE80211_MAX_MESH_ID_LEN);
2662 wdev->mesh_id_up_len =
2663 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2664 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2665 wdev->mesh_id_up_len);
2666 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002667 break;
2668 case NL80211_IFTYPE_P2P_DEVICE:
2669 /*
2670 * P2P Device doesn't have a netdev, so doesn't go
2671 * through the netdev notifier and must be added here
2672 */
2673 mutex_init(&wdev->mtx);
2674 INIT_LIST_HEAD(&wdev->event_list);
2675 spin_lock_init(&wdev->event_lock);
2676 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2677 spin_lock_init(&wdev->mgmt_registrations_lock);
2678
Johannes Berg98104fde2012-06-16 00:19:54 +02002679 wdev->identifier = ++rdev->wdev_id;
2680 list_add_rcu(&wdev->list, &rdev->wdev_list);
2681 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002682 break;
2683 default:
2684 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002685 }
2686
Eric W. Biederman15e47302012-09-07 20:12:54 +00002687 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002688 rdev, wdev) < 0) {
2689 nlmsg_free(msg);
2690 return -ENOBUFS;
2691 }
2692
2693 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002694}
2695
2696static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2697{
Johannes Berg4c476992010-10-04 21:36:35 +02002698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002699 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002700
Johannes Berg4c476992010-10-04 21:36:35 +02002701 if (!rdev->ops->del_virtual_intf)
2702 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002703
Johannes Berg84efbb82012-06-16 00:00:26 +02002704 /*
2705 * If we remove a wireless device without a netdev then clear
2706 * user_ptr[1] so that nl80211_post_doit won't dereference it
2707 * to check if it needs to do dev_put(). Otherwise it crashes
2708 * since the wdev has been freed, unlike with a netdev where
2709 * we need the dev_put() for the netdev to really be freed.
2710 */
2711 if (!wdev->netdev)
2712 info->user_ptr[1] = NULL;
2713
Hila Gonene35e4d22012-06-27 17:19:42 +03002714 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002715}
2716
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002717static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2718{
2719 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2720 struct net_device *dev = info->user_ptr[1];
2721 u16 noack_map;
2722
2723 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2724 return -EINVAL;
2725
2726 if (!rdev->ops->set_noack_map)
2727 return -EOPNOTSUPP;
2728
2729 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2730
Hila Gonene35e4d22012-06-27 17:19:42 +03002731 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002732}
2733
Johannes Berg41ade002007-12-19 02:03:29 +01002734struct get_key_cookie {
2735 struct sk_buff *msg;
2736 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002737 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002738};
2739
2740static void get_key_callback(void *c, struct key_params *params)
2741{
Johannes Bergb9454e82009-07-08 13:29:08 +02002742 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002743 struct get_key_cookie *cookie = c;
2744
David S. Miller9360ffd2012-03-29 04:41:26 -04002745 if ((params->key &&
2746 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2747 params->key_len, params->key)) ||
2748 (params->seq &&
2749 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2750 params->seq_len, params->seq)) ||
2751 (params->cipher &&
2752 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2753 params->cipher)))
2754 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002755
Johannes Bergb9454e82009-07-08 13:29:08 +02002756 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2757 if (!key)
2758 goto nla_put_failure;
2759
David S. Miller9360ffd2012-03-29 04:41:26 -04002760 if ((params->key &&
2761 nla_put(cookie->msg, NL80211_KEY_DATA,
2762 params->key_len, params->key)) ||
2763 (params->seq &&
2764 nla_put(cookie->msg, NL80211_KEY_SEQ,
2765 params->seq_len, params->seq)) ||
2766 (params->cipher &&
2767 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2768 params->cipher)))
2769 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002770
David S. Miller9360ffd2012-03-29 04:41:26 -04002771 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2772 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002773
2774 nla_nest_end(cookie->msg, key);
2775
Johannes Berg41ade002007-12-19 02:03:29 +01002776 return;
2777 nla_put_failure:
2778 cookie->error = 1;
2779}
2780
2781static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2782{
Johannes Berg4c476992010-10-04 21:36:35 +02002783 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002784 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002785 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002786 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002787 const u8 *mac_addr = NULL;
2788 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002789 struct get_key_cookie cookie = {
2790 .error = 0,
2791 };
2792 void *hdr;
2793 struct sk_buff *msg;
2794
2795 if (info->attrs[NL80211_ATTR_KEY_IDX])
2796 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2797
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002798 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002799 return -EINVAL;
2800
2801 if (info->attrs[NL80211_ATTR_MAC])
2802 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2803
Johannes Berge31b8212010-10-05 19:39:30 +02002804 pairwise = !!mac_addr;
2805 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2806 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2807 if (kt >= NUM_NL80211_KEYTYPES)
2808 return -EINVAL;
2809 if (kt != NL80211_KEYTYPE_GROUP &&
2810 kt != NL80211_KEYTYPE_PAIRWISE)
2811 return -EINVAL;
2812 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2813 }
2814
Johannes Berg4c476992010-10-04 21:36:35 +02002815 if (!rdev->ops->get_key)
2816 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002817
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002818 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002819 if (!msg)
2820 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002821
Eric W. Biederman15e47302012-09-07 20:12:54 +00002822 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002823 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002824 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002825 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002826
2827 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002828 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002829
David S. Miller9360ffd2012-03-29 04:41:26 -04002830 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2831 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2832 goto nla_put_failure;
2833 if (mac_addr &&
2834 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2835 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002836
Johannes Berge31b8212010-10-05 19:39:30 +02002837 if (pairwise && mac_addr &&
2838 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2839 return -ENOENT;
2840
Hila Gonene35e4d22012-06-27 17:19:42 +03002841 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2842 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002843
2844 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002845 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002846
2847 if (cookie.error)
2848 goto nla_put_failure;
2849
2850 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002851 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002852
2853 nla_put_failure:
2854 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002855 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002856 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002857 return err;
2858}
2859
2860static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2861{
Johannes Berg4c476992010-10-04 21:36:35 +02002862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002863 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002864 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002865 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002866
Johannes Bergb9454e82009-07-08 13:29:08 +02002867 err = nl80211_parse_key(info, &key);
2868 if (err)
2869 return err;
2870
2871 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002872 return -EINVAL;
2873
Johannes Bergb9454e82009-07-08 13:29:08 +02002874 /* only support setting default key */
2875 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002876 return -EINVAL;
2877
Johannes Bergfffd0932009-07-08 14:22:54 +02002878 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002879
2880 if (key.def) {
2881 if (!rdev->ops->set_default_key) {
2882 err = -EOPNOTSUPP;
2883 goto out;
2884 }
2885
2886 err = nl80211_key_allowed(dev->ieee80211_ptr);
2887 if (err)
2888 goto out;
2889
Hila Gonene35e4d22012-06-27 17:19:42 +03002890 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002891 key.def_uni, key.def_multi);
2892
2893 if (err)
2894 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002895
Johannes Berg3d23e342009-09-29 23:27:28 +02002896#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002897 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002898#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002899 } else {
2900 if (key.def_uni || !key.def_multi) {
2901 err = -EINVAL;
2902 goto out;
2903 }
2904
2905 if (!rdev->ops->set_default_mgmt_key) {
2906 err = -EOPNOTSUPP;
2907 goto out;
2908 }
2909
2910 err = nl80211_key_allowed(dev->ieee80211_ptr);
2911 if (err)
2912 goto out;
2913
Hila Gonene35e4d22012-06-27 17:19:42 +03002914 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002915 if (err)
2916 goto out;
2917
2918#ifdef CONFIG_CFG80211_WEXT
2919 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2920#endif
2921 }
2922
2923 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002924 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002925
Johannes Berg41ade002007-12-19 02:03:29 +01002926 return err;
2927}
2928
2929static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2930{
Johannes Berg4c476992010-10-04 21:36:35 +02002931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002932 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002933 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002934 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002935 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002936
Johannes Bergb9454e82009-07-08 13:29:08 +02002937 err = nl80211_parse_key(info, &key);
2938 if (err)
2939 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002940
Johannes Bergb9454e82009-07-08 13:29:08 +02002941 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002942 return -EINVAL;
2943
Johannes Berg41ade002007-12-19 02:03:29 +01002944 if (info->attrs[NL80211_ATTR_MAC])
2945 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2946
Johannes Berge31b8212010-10-05 19:39:30 +02002947 if (key.type == -1) {
2948 if (mac_addr)
2949 key.type = NL80211_KEYTYPE_PAIRWISE;
2950 else
2951 key.type = NL80211_KEYTYPE_GROUP;
2952 }
2953
2954 /* for now */
2955 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2956 key.type != NL80211_KEYTYPE_GROUP)
2957 return -EINVAL;
2958
Johannes Berg4c476992010-10-04 21:36:35 +02002959 if (!rdev->ops->add_key)
2960 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002961
Johannes Berge31b8212010-10-05 19:39:30 +02002962 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2963 key.type == NL80211_KEYTYPE_PAIRWISE,
2964 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002965 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002966
2967 wdev_lock(dev->ieee80211_ptr);
2968 err = nl80211_key_allowed(dev->ieee80211_ptr);
2969 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002970 err = rdev_add_key(rdev, dev, key.idx,
2971 key.type == NL80211_KEYTYPE_PAIRWISE,
2972 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002973 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002974
Johannes Berg41ade002007-12-19 02:03:29 +01002975 return err;
2976}
2977
2978static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2979{
Johannes Berg4c476992010-10-04 21:36:35 +02002980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002981 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002982 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002983 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002984 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002985
Johannes Bergb9454e82009-07-08 13:29:08 +02002986 err = nl80211_parse_key(info, &key);
2987 if (err)
2988 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002989
2990 if (info->attrs[NL80211_ATTR_MAC])
2991 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2992
Johannes Berge31b8212010-10-05 19:39:30 +02002993 if (key.type == -1) {
2994 if (mac_addr)
2995 key.type = NL80211_KEYTYPE_PAIRWISE;
2996 else
2997 key.type = NL80211_KEYTYPE_GROUP;
2998 }
2999
3000 /* for now */
3001 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3002 key.type != NL80211_KEYTYPE_GROUP)
3003 return -EINVAL;
3004
Johannes Berg4c476992010-10-04 21:36:35 +02003005 if (!rdev->ops->del_key)
3006 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003007
Johannes Bergfffd0932009-07-08 14:22:54 +02003008 wdev_lock(dev->ieee80211_ptr);
3009 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003010
3011 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3012 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3013 err = -ENOENT;
3014
Johannes Bergfffd0932009-07-08 14:22:54 +02003015 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003016 err = rdev_del_key(rdev, dev, key.idx,
3017 key.type == NL80211_KEYTYPE_PAIRWISE,
3018 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003019
Johannes Berg3d23e342009-09-29 23:27:28 +02003020#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003021 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003022 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003023 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003024 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003025 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3026 }
3027#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003028 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003029
Johannes Berg41ade002007-12-19 02:03:29 +01003030 return err;
3031}
3032
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303033/* This function returns an error or the number of nested attributes */
3034static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3035{
3036 struct nlattr *attr;
3037 int n_entries = 0, tmp;
3038
3039 nla_for_each_nested(attr, nl_attr, tmp) {
3040 if (nla_len(attr) != ETH_ALEN)
3041 return -EINVAL;
3042
3043 n_entries++;
3044 }
3045
3046 return n_entries;
3047}
3048
3049/*
3050 * This function parses ACL information and allocates memory for ACL data.
3051 * On successful return, the calling function is responsible to free the
3052 * ACL buffer returned by this function.
3053 */
3054static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3055 struct genl_info *info)
3056{
3057 enum nl80211_acl_policy acl_policy;
3058 struct nlattr *attr;
3059 struct cfg80211_acl_data *acl;
3060 int i = 0, n_entries, tmp;
3061
3062 if (!wiphy->max_acl_mac_addrs)
3063 return ERR_PTR(-EOPNOTSUPP);
3064
3065 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3066 return ERR_PTR(-EINVAL);
3067
3068 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3069 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3070 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3071 return ERR_PTR(-EINVAL);
3072
3073 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3074 return ERR_PTR(-EINVAL);
3075
3076 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3077 if (n_entries < 0)
3078 return ERR_PTR(n_entries);
3079
3080 if (n_entries > wiphy->max_acl_mac_addrs)
3081 return ERR_PTR(-ENOTSUPP);
3082
3083 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3084 GFP_KERNEL);
3085 if (!acl)
3086 return ERR_PTR(-ENOMEM);
3087
3088 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3089 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3090 i++;
3091 }
3092
3093 acl->n_acl_entries = n_entries;
3094 acl->acl_policy = acl_policy;
3095
3096 return acl;
3097}
3098
3099static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3100{
3101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3102 struct net_device *dev = info->user_ptr[1];
3103 struct cfg80211_acl_data *acl;
3104 int err;
3105
3106 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3107 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3108 return -EOPNOTSUPP;
3109
3110 if (!dev->ieee80211_ptr->beacon_interval)
3111 return -EINVAL;
3112
3113 acl = parse_acl_data(&rdev->wiphy, info);
3114 if (IS_ERR(acl))
3115 return PTR_ERR(acl);
3116
3117 err = rdev_set_mac_acl(rdev, dev, acl);
3118
3119 kfree(acl);
3120
3121 return err;
3122}
3123
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003124static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003125 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003126{
Johannes Berg88600202012-02-13 15:17:18 +01003127 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003128
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003129 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3130 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3131 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3132 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003133 return -EINVAL;
3134
Johannes Berg88600202012-02-13 15:17:18 +01003135 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003136
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003137 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3138 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3139 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003140 if (!bcn->head_len)
3141 return -EINVAL;
3142 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003143 }
3144
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003145 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3146 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3147 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003148 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003149 }
3150
Johannes Berg4c476992010-10-04 21:36:35 +02003151 if (!haveinfo)
3152 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003153
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003154 if (attrs[NL80211_ATTR_IE]) {
3155 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3156 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003157 }
3158
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003159 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003160 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003161 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003162 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003163 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003164 }
3165
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003166 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003167 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003168 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003169 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003170 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003171 }
3172
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003173 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3174 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3175 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003176 }
3177
Johannes Berg88600202012-02-13 15:17:18 +01003178 return 0;
3179}
3180
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003181static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3182 struct cfg80211_ap_settings *params)
3183{
3184 struct wireless_dev *wdev;
3185 bool ret = false;
3186
Johannes Berg89a54e42012-06-15 14:33:17 +02003187 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003188 if (wdev->iftype != NL80211_IFTYPE_AP &&
3189 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3190 continue;
3191
Johannes Berg683b6d32012-11-08 21:25:48 +01003192 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003193 continue;
3194
Johannes Berg683b6d32012-11-08 21:25:48 +01003195 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003196 ret = true;
3197 break;
3198 }
3199
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003200 return ret;
3201}
3202
Jouni Malinene39e5b52012-09-30 19:29:39 +03003203static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3204 enum nl80211_auth_type auth_type,
3205 enum nl80211_commands cmd)
3206{
3207 if (auth_type > NL80211_AUTHTYPE_MAX)
3208 return false;
3209
3210 switch (cmd) {
3211 case NL80211_CMD_AUTHENTICATE:
3212 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3213 auth_type == NL80211_AUTHTYPE_SAE)
3214 return false;
3215 return true;
3216 case NL80211_CMD_CONNECT:
3217 case NL80211_CMD_START_AP:
3218 /* SAE not supported yet */
3219 if (auth_type == NL80211_AUTHTYPE_SAE)
3220 return false;
3221 return true;
3222 default:
3223 return false;
3224 }
3225}
3226
Johannes Berg88600202012-02-13 15:17:18 +01003227static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3228{
3229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3230 struct net_device *dev = info->user_ptr[1];
3231 struct wireless_dev *wdev = dev->ieee80211_ptr;
3232 struct cfg80211_ap_settings params;
3233 int err;
3234
3235 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3236 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3237 return -EOPNOTSUPP;
3238
3239 if (!rdev->ops->start_ap)
3240 return -EOPNOTSUPP;
3241
3242 if (wdev->beacon_interval)
3243 return -EALREADY;
3244
3245 memset(&params, 0, sizeof(params));
3246
3247 /* these are required for START_AP */
3248 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3249 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3250 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3251 return -EINVAL;
3252
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003253 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003254 if (err)
3255 return err;
3256
3257 params.beacon_interval =
3258 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3259 params.dtim_period =
3260 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3261
3262 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3263 if (err)
3264 return err;
3265
3266 /*
3267 * In theory, some of these attributes should be required here
3268 * but since they were not used when the command was originally
3269 * added, keep them optional for old user space programs to let
3270 * them continue to work with drivers that do not need the
3271 * additional information -- drivers must check!
3272 */
3273 if (info->attrs[NL80211_ATTR_SSID]) {
3274 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3275 params.ssid_len =
3276 nla_len(info->attrs[NL80211_ATTR_SSID]);
3277 if (params.ssid_len == 0 ||
3278 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3279 return -EINVAL;
3280 }
3281
3282 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3283 params.hidden_ssid = nla_get_u32(
3284 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3285 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3286 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3287 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3288 return -EINVAL;
3289 }
3290
3291 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3292
3293 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3294 params.auth_type = nla_get_u32(
3295 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003296 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3297 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003298 return -EINVAL;
3299 } else
3300 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3301
3302 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3303 NL80211_MAX_NR_CIPHER_SUITES);
3304 if (err)
3305 return err;
3306
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303307 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3308 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3309 return -EOPNOTSUPP;
3310 params.inactivity_timeout = nla_get_u16(
3311 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3312 }
3313
Johannes Berg53cabad2012-11-14 15:17:28 +01003314 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3315 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3316 return -EINVAL;
3317 params.p2p_ctwindow =
3318 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3319 if (params.p2p_ctwindow > 127)
3320 return -EINVAL;
3321 if (params.p2p_ctwindow != 0 &&
3322 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3323 return -EINVAL;
3324 }
3325
3326 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3327 u8 tmp;
3328
3329 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3330 return -EINVAL;
3331 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3332 if (tmp > 1)
3333 return -EINVAL;
3334 params.p2p_opp_ps = tmp;
3335 if (params.p2p_opp_ps != 0 &&
3336 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3337 return -EINVAL;
3338 }
3339
Johannes Bergaa430da2012-05-16 23:50:18 +02003340 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003341 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3342 if (err)
3343 return err;
3344 } else if (wdev->preset_chandef.chan) {
3345 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003346 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003347 return -EINVAL;
3348
Ilan Peer174e0cd2014-02-23 09:13:01 +02003349 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3350 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003351 return -EINVAL;
3352
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303353 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3354 params.acl = parse_acl_data(&rdev->wiphy, info);
3355 if (IS_ERR(params.acl))
3356 return PTR_ERR(params.acl);
3357 }
3358
Eliad Peller18998c32014-09-10 14:07:34 +03003359 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3360 params.smps_mode =
3361 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3362 switch (params.smps_mode) {
3363 case NL80211_SMPS_OFF:
3364 break;
3365 case NL80211_SMPS_STATIC:
3366 if (!(rdev->wiphy.features &
3367 NL80211_FEATURE_STATIC_SMPS))
3368 return -EINVAL;
3369 break;
3370 case NL80211_SMPS_DYNAMIC:
3371 if (!(rdev->wiphy.features &
3372 NL80211_FEATURE_DYNAMIC_SMPS))
3373 return -EINVAL;
3374 break;
3375 default:
3376 return -EINVAL;
3377 }
3378 } else {
3379 params.smps_mode = NL80211_SMPS_OFF;
3380 }
3381
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003382 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003383 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003384 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003385 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003386 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003387 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003388 wdev->ssid_len = params.ssid_len;
3389 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003390 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003391 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303392
3393 kfree(params.acl);
3394
Johannes Berg56d18932011-05-09 18:41:15 +02003395 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003396}
3397
Johannes Berg88600202012-02-13 15:17:18 +01003398static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3399{
3400 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3401 struct net_device *dev = info->user_ptr[1];
3402 struct wireless_dev *wdev = dev->ieee80211_ptr;
3403 struct cfg80211_beacon_data params;
3404 int err;
3405
3406 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3407 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3408 return -EOPNOTSUPP;
3409
3410 if (!rdev->ops->change_beacon)
3411 return -EOPNOTSUPP;
3412
3413 if (!wdev->beacon_interval)
3414 return -EINVAL;
3415
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003416 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003417 if (err)
3418 return err;
3419
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003420 wdev_lock(wdev);
3421 err = rdev_change_beacon(rdev, dev, &params);
3422 wdev_unlock(wdev);
3423
3424 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003425}
3426
3427static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003428{
Johannes Berg4c476992010-10-04 21:36:35 +02003429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3430 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003431
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003432 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003433}
3434
Johannes Berg5727ef12007-12-19 02:03:34 +01003435static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3436 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3437 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3438 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003439 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003440 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003441 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003442};
3443
Johannes Bergeccb8e82009-05-11 21:57:56 +03003444static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003445 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003446 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003447{
3448 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003449 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003450 int flag;
3451
Johannes Bergeccb8e82009-05-11 21:57:56 +03003452 /*
3453 * Try parsing the new attribute first so userspace
3454 * can specify both for older kernels.
3455 */
3456 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3457 if (nla) {
3458 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003459
Johannes Bergeccb8e82009-05-11 21:57:56 +03003460 sta_flags = nla_data(nla);
3461 params->sta_flags_mask = sta_flags->mask;
3462 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003463 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003464 if ((params->sta_flags_mask |
3465 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3466 return -EINVAL;
3467 return 0;
3468 }
3469
3470 /* if present, parse the old attribute */
3471
3472 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003473 if (!nla)
3474 return 0;
3475
3476 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3477 nla, sta_flags_policy))
3478 return -EINVAL;
3479
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003480 /*
3481 * Only allow certain flags for interface types so that
3482 * other attributes are silently ignored. Remember that
3483 * this is backward compatibility code with old userspace
3484 * and shouldn't be hit in other cases anyway.
3485 */
3486 switch (iftype) {
3487 case NL80211_IFTYPE_AP:
3488 case NL80211_IFTYPE_AP_VLAN:
3489 case NL80211_IFTYPE_P2P_GO:
3490 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3491 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3492 BIT(NL80211_STA_FLAG_WME) |
3493 BIT(NL80211_STA_FLAG_MFP);
3494 break;
3495 case NL80211_IFTYPE_P2P_CLIENT:
3496 case NL80211_IFTYPE_STATION:
3497 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3498 BIT(NL80211_STA_FLAG_TDLS_PEER);
3499 break;
3500 case NL80211_IFTYPE_MESH_POINT:
3501 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3502 BIT(NL80211_STA_FLAG_MFP) |
3503 BIT(NL80211_STA_FLAG_AUTHORIZED);
3504 default:
3505 return -EINVAL;
3506 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003507
Johannes Berg3383b5a2012-05-10 20:14:43 +02003508 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3509 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003510 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003511
Johannes Berg3383b5a2012-05-10 20:14:43 +02003512 /* no longer support new API additions in old API */
3513 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3514 return -EINVAL;
3515 }
3516 }
3517
Johannes Berg5727ef12007-12-19 02:03:34 +01003518 return 0;
3519}
3520
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003521static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3522 int attr)
3523{
3524 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003525 u32 bitrate;
3526 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003527
3528 rate = nla_nest_start(msg, attr);
3529 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003530 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003531
3532 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3533 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003534 /* report 16-bit bitrate only if we can */
3535 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003536 if (bitrate > 0 &&
3537 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3538 return false;
3539 if (bitrate_compat > 0 &&
3540 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3541 return false;
3542
3543 if (info->flags & RATE_INFO_FLAGS_MCS) {
3544 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3545 return false;
3546 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3547 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3548 return false;
3549 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3550 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3551 return false;
3552 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3553 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3554 return false;
3555 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3556 return false;
3557 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3558 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3559 return false;
3560 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3561 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3562 return false;
3563 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3564 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3565 return false;
3566 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3567 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3568 return false;
3569 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3570 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3571 return false;
3572 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003573
3574 nla_nest_end(msg, rate);
3575 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003576}
3577
Felix Fietkau119363c2013-04-22 16:29:30 +02003578static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3579 int id)
3580{
3581 void *attr;
3582 int i = 0;
3583
3584 if (!mask)
3585 return true;
3586
3587 attr = nla_nest_start(msg, id);
3588 if (!attr)
3589 return false;
3590
3591 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3592 if (!(mask & BIT(i)))
3593 continue;
3594
3595 if (nla_put_u8(msg, i, signal[i]))
3596 return false;
3597 }
3598
3599 nla_nest_end(msg, attr);
3600
3601 return true;
3602}
3603
Eric W. Biederman15e47302012-09-07 20:12:54 +00003604static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003605 int flags,
3606 struct cfg80211_registered_device *rdev,
3607 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003608 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003609{
3610 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003611 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003612
Eric W. Biederman15e47302012-09-07 20:12:54 +00003613 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003614 if (!hdr)
3615 return -1;
3616
David S. Miller9360ffd2012-03-29 04:41:26 -04003617 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3618 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3619 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3620 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003621
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003622 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3623 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003624 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003625 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3626 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3627 sinfo->connected_time))
3628 goto nla_put_failure;
3629 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3630 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3631 sinfo->inactive_time))
3632 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003633 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3634 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003635 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003636 (u32)sinfo->rx_bytes))
3637 goto nla_put_failure;
3638 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003639 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003640 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3641 (u32)sinfo->tx_bytes))
3642 goto nla_put_failure;
3643 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3644 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003645 sinfo->rx_bytes))
3646 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003647 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3648 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003649 sinfo->tx_bytes))
3650 goto nla_put_failure;
3651 if ((sinfo->filled & STATION_INFO_LLID) &&
3652 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3653 goto nla_put_failure;
3654 if ((sinfo->filled & STATION_INFO_PLID) &&
3655 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3656 goto nla_put_failure;
3657 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3658 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3659 sinfo->plink_state))
3660 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003661 switch (rdev->wiphy.signal_type) {
3662 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003663 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3664 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3665 sinfo->signal))
3666 goto nla_put_failure;
3667 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3668 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3669 sinfo->signal_avg))
3670 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003671 break;
3672 default:
3673 break;
3674 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003675 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3676 if (!nl80211_put_signal(msg, sinfo->chains,
3677 sinfo->chain_signal,
3678 NL80211_STA_INFO_CHAIN_SIGNAL))
3679 goto nla_put_failure;
3680 }
3681 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3682 if (!nl80211_put_signal(msg, sinfo->chains,
3683 sinfo->chain_signal_avg,
3684 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3685 goto nla_put_failure;
3686 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003687 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003688 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3689 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003690 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003691 }
3692 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3693 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3694 NL80211_STA_INFO_RX_BITRATE))
3695 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003696 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003697 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3698 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3699 sinfo->rx_packets))
3700 goto nla_put_failure;
3701 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3702 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3703 sinfo->tx_packets))
3704 goto nla_put_failure;
3705 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3706 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3707 sinfo->tx_retries))
3708 goto nla_put_failure;
3709 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3710 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3711 sinfo->tx_failed))
3712 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003713 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3714 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3715 sinfo->expected_throughput))
3716 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003717 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3718 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3719 sinfo->beacon_loss_count))
3720 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003721 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3722 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3723 sinfo->local_pm))
3724 goto nla_put_failure;
3725 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3726 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3727 sinfo->peer_pm))
3728 goto nla_put_failure;
3729 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3730 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3731 sinfo->nonpeer_pm))
3732 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003733 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3734 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3735 if (!bss_param)
3736 goto nla_put_failure;
3737
David S. Miller9360ffd2012-03-29 04:41:26 -04003738 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3739 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3740 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3741 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3742 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3743 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3744 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3745 sinfo->bss_param.dtim_period) ||
3746 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3747 sinfo->bss_param.beacon_interval))
3748 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003749
3750 nla_nest_end(msg, bss_param);
3751 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003752 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3753 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3754 sizeof(struct nl80211_sta_flag_update),
3755 &sinfo->sta_flags))
3756 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003757 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3758 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3759 sinfo->t_offset))
3760 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003761 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003762
David S. Miller9360ffd2012-03-29 04:41:26 -04003763 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3764 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3765 sinfo->assoc_req_ies))
3766 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003767
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003768 return genlmsg_end(msg, hdr);
3769
3770 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003771 genlmsg_cancel(msg, hdr);
3772 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003773}
3774
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003775static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003776 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003777{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003778 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003779 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003780 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003781 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003782 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003783 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003784
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003785 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003786 if (err)
3787 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003788
Johannes Berg97990a02013-04-19 01:02:55 +02003789 if (!wdev->netdev) {
3790 err = -EINVAL;
3791 goto out_err;
3792 }
3793
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003794 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003795 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003796 goto out_err;
3797 }
3798
Johannes Bergbba95fe2008-07-29 13:22:51 +02003799 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003800 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003801 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003802 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003803 if (err == -ENOENT)
3804 break;
3805 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003806 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003807
3808 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003809 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003810 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003811 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003812 &sinfo) < 0)
3813 goto out;
3814
3815 sta_idx++;
3816 }
3817
3818
3819 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003820 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003821 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003822 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003823 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003824
3825 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003826}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003827
Johannes Berg5727ef12007-12-19 02:03:34 +01003828static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3829{
Johannes Berg4c476992010-10-04 21:36:35 +02003830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3831 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003832 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003833 struct sk_buff *msg;
3834 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003835 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003836
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003837 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003838
3839 if (!info->attrs[NL80211_ATTR_MAC])
3840 return -EINVAL;
3841
3842 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3843
Johannes Berg4c476992010-10-04 21:36:35 +02003844 if (!rdev->ops->get_station)
3845 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003846
Hila Gonene35e4d22012-06-27 17:19:42 +03003847 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003848 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003849 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003850
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003852 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003853 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003854
Eric W. Biederman15e47302012-09-07 20:12:54 +00003855 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003856 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003857 nlmsg_free(msg);
3858 return -ENOBUFS;
3859 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003860
Johannes Berg4c476992010-10-04 21:36:35 +02003861 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003862}
3863
Johannes Berg77ee7c82013-02-15 00:48:33 +01003864int cfg80211_check_station_change(struct wiphy *wiphy,
3865 struct station_parameters *params,
3866 enum cfg80211_station_type statype)
3867{
3868 if (params->listen_interval != -1)
3869 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003870 if (params->aid &&
3871 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003872 return -EINVAL;
3873
3874 /* When you run into this, adjust the code below for the new flag */
3875 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3876
3877 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003878 case CFG80211_STA_MESH_PEER_KERNEL:
3879 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003880 /*
3881 * No ignoring the TDLS flag here -- the userspace mesh
3882 * code doesn't have the bug of including TDLS in the
3883 * mask everywhere.
3884 */
3885 if (params->sta_flags_mask &
3886 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3887 BIT(NL80211_STA_FLAG_MFP) |
3888 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3889 return -EINVAL;
3890 break;
3891 case CFG80211_STA_TDLS_PEER_SETUP:
3892 case CFG80211_STA_TDLS_PEER_ACTIVE:
3893 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3894 return -EINVAL;
3895 /* ignore since it can't change */
3896 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3897 break;
3898 default:
3899 /* disallow mesh-specific things */
3900 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3901 return -EINVAL;
3902 if (params->local_pm)
3903 return -EINVAL;
3904 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3905 return -EINVAL;
3906 }
3907
3908 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3909 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3910 /* TDLS can't be set, ... */
3911 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3912 return -EINVAL;
3913 /*
3914 * ... but don't bother the driver with it. This works around
3915 * a hostapd/wpa_supplicant issue -- it always includes the
3916 * TLDS_PEER flag in the mask even for AP mode.
3917 */
3918 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3919 }
3920
3921 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3922 /* reject other things that can't change */
3923 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3924 return -EINVAL;
3925 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3926 return -EINVAL;
3927 if (params->supported_rates)
3928 return -EINVAL;
3929 if (params->ext_capab || params->ht_capa || params->vht_capa)
3930 return -EINVAL;
3931 }
3932
3933 if (statype != CFG80211_STA_AP_CLIENT) {
3934 if (params->vlan)
3935 return -EINVAL;
3936 }
3937
3938 switch (statype) {
3939 case CFG80211_STA_AP_MLME_CLIENT:
3940 /* Use this only for authorizing/unauthorizing a station */
3941 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3942 return -EOPNOTSUPP;
3943 break;
3944 case CFG80211_STA_AP_CLIENT:
3945 /* accept only the listed bits */
3946 if (params->sta_flags_mask &
3947 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3948 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3949 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3950 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3951 BIT(NL80211_STA_FLAG_WME) |
3952 BIT(NL80211_STA_FLAG_MFP)))
3953 return -EINVAL;
3954
3955 /* but authenticated/associated only if driver handles it */
3956 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3957 params->sta_flags_mask &
3958 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3959 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3960 return -EINVAL;
3961 break;
3962 case CFG80211_STA_IBSS:
3963 case CFG80211_STA_AP_STA:
3964 /* reject any changes other than AUTHORIZED */
3965 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3966 return -EINVAL;
3967 break;
3968 case CFG80211_STA_TDLS_PEER_SETUP:
3969 /* reject any changes other than AUTHORIZED or WME */
3970 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3971 BIT(NL80211_STA_FLAG_WME)))
3972 return -EINVAL;
3973 /* force (at least) rates when authorizing */
3974 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3975 !params->supported_rates)
3976 return -EINVAL;
3977 break;
3978 case CFG80211_STA_TDLS_PEER_ACTIVE:
3979 /* reject any changes */
3980 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003981 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003982 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3983 return -EINVAL;
3984 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003985 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003986 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3987 return -EINVAL;
3988 break;
3989 }
3990
3991 return 0;
3992}
3993EXPORT_SYMBOL(cfg80211_check_station_change);
3994
Johannes Berg5727ef12007-12-19 02:03:34 +01003995/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003996 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003997 */
Johannes Berg80b99892011-11-18 16:23:01 +01003998static struct net_device *get_vlan(struct genl_info *info,
3999 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004000{
Johannes Berg463d0182009-07-14 00:33:35 +02004001 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004002 struct net_device *v;
4003 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004004
Johannes Berg80b99892011-11-18 16:23:01 +01004005 if (!vlanattr)
4006 return NULL;
4007
4008 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4009 if (!v)
4010 return ERR_PTR(-ENODEV);
4011
4012 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4013 ret = -EINVAL;
4014 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004015 }
Johannes Berg80b99892011-11-18 16:23:01 +01004016
Johannes Berg77ee7c82013-02-15 00:48:33 +01004017 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4018 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4019 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4020 ret = -EINVAL;
4021 goto error;
4022 }
4023
Johannes Berg80b99892011-11-18 16:23:01 +01004024 if (!netif_running(v)) {
4025 ret = -ENETDOWN;
4026 goto error;
4027 }
4028
4029 return v;
4030 error:
4031 dev_put(v);
4032 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004033}
4034
Johannes Berg94e860f2014-01-20 23:58:15 +01004035static const struct nla_policy
4036nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004037 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4038 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4039};
4040
Johannes Bergff276692013-02-15 00:09:01 +01004041static int nl80211_parse_sta_wme(struct genl_info *info,
4042 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004043{
Jouni Malinendf881292013-02-14 21:10:54 +02004044 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4045 struct nlattr *nla;
4046 int err;
4047
Jouni Malinendf881292013-02-14 21:10:54 +02004048 /* parse WME attributes if present */
4049 if (!info->attrs[NL80211_ATTR_STA_WME])
4050 return 0;
4051
4052 nla = info->attrs[NL80211_ATTR_STA_WME];
4053 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4054 nl80211_sta_wme_policy);
4055 if (err)
4056 return err;
4057
4058 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4059 params->uapsd_queues = nla_get_u8(
4060 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4061 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4062 return -EINVAL;
4063
4064 if (tb[NL80211_STA_WME_MAX_SP])
4065 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4066
4067 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4068 return -EINVAL;
4069
4070 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4071
4072 return 0;
4073}
4074
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304075static int nl80211_parse_sta_channel_info(struct genl_info *info,
4076 struct station_parameters *params)
4077{
4078 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4079 params->supported_channels =
4080 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4081 params->supported_channels_len =
4082 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4083 /*
4084 * Need to include at least one (first channel, number of
4085 * channels) tuple for each subband, and must have proper
4086 * tuples for the rest of the data as well.
4087 */
4088 if (params->supported_channels_len < 2)
4089 return -EINVAL;
4090 if (params->supported_channels_len % 2)
4091 return -EINVAL;
4092 }
4093
4094 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4095 params->supported_oper_classes =
4096 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4097 params->supported_oper_classes_len =
4098 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4099 /*
4100 * The value of the Length field of the Supported Operating
4101 * Classes element is between 2 and 253.
4102 */
4103 if (params->supported_oper_classes_len < 2 ||
4104 params->supported_oper_classes_len > 253)
4105 return -EINVAL;
4106 }
4107 return 0;
4108}
4109
Johannes Bergff276692013-02-15 00:09:01 +01004110static int nl80211_set_station_tdls(struct genl_info *info,
4111 struct station_parameters *params)
4112{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304113 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004114 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004115 if (info->attrs[NL80211_ATTR_PEER_AID])
4116 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004117 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4118 params->ht_capa =
4119 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4120 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4121 params->vht_capa =
4122 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4123
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304124 err = nl80211_parse_sta_channel_info(info, params);
4125 if (err)
4126 return err;
4127
Johannes Bergff276692013-02-15 00:09:01 +01004128 return nl80211_parse_sta_wme(info, params);
4129}
4130
Johannes Berg5727ef12007-12-19 02:03:34 +01004131static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4132{
Johannes Berg4c476992010-10-04 21:36:35 +02004133 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004134 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004135 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004136 u8 *mac_addr;
4137 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004138
4139 memset(&params, 0, sizeof(params));
4140
4141 params.listen_interval = -1;
4142
Johannes Berg77ee7c82013-02-15 00:48:33 +01004143 if (!rdev->ops->change_station)
4144 return -EOPNOTSUPP;
4145
Johannes Berg5727ef12007-12-19 02:03:34 +01004146 if (info->attrs[NL80211_ATTR_STA_AID])
4147 return -EINVAL;
4148
4149 if (!info->attrs[NL80211_ATTR_MAC])
4150 return -EINVAL;
4151
4152 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4153
4154 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4155 params.supported_rates =
4156 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4157 params.supported_rates_len =
4158 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4159 }
4160
Jouni Malinen9d62a982013-02-14 21:10:13 +02004161 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4162 params.capability =
4163 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4164 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4165 }
4166
4167 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4168 params.ext_capab =
4169 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4170 params.ext_capab_len =
4171 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4172 }
4173
Jouni Malinendf881292013-02-14 21:10:54 +02004174 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004175 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004176
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004177 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004178 return -EINVAL;
4179
Johannes Bergf8bacc22013-02-14 23:27:01 +01004180 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004181 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004182 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4183 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4184 return -EINVAL;
4185 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004186
Johannes Bergf8bacc22013-02-14 23:27:01 +01004187 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004188 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004189 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4190 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4191 return -EINVAL;
4192 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4193 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004194
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004195 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4196 enum nl80211_mesh_power_mode pm = nla_get_u32(
4197 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4198
4199 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4200 pm > NL80211_MESH_POWER_MAX)
4201 return -EINVAL;
4202
4203 params.local_pm = pm;
4204 }
4205
Johannes Berg77ee7c82013-02-15 00:48:33 +01004206 /* Include parameters for TDLS peer (will check later) */
4207 err = nl80211_set_station_tdls(info, &params);
4208 if (err)
4209 return err;
4210
4211 params.vlan = get_vlan(info, rdev);
4212 if (IS_ERR(params.vlan))
4213 return PTR_ERR(params.vlan);
4214
Johannes Berga97f4422009-06-18 17:23:43 +02004215 switch (dev->ieee80211_ptr->iftype) {
4216 case NL80211_IFTYPE_AP:
4217 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004218 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004219 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004220 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004221 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004222 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004223 break;
4224 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004225 err = -EOPNOTSUPP;
4226 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004227 }
4228
Johannes Berg77ee7c82013-02-15 00:48:33 +01004229 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004230 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004231
Johannes Berg77ee7c82013-02-15 00:48:33 +01004232 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004233 if (params.vlan)
4234 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004235
Johannes Berg5727ef12007-12-19 02:03:34 +01004236 return err;
4237}
4238
4239static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4240{
Johannes Berg4c476992010-10-04 21:36:35 +02004241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004242 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004243 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004244 struct station_parameters params;
4245 u8 *mac_addr = NULL;
4246
4247 memset(&params, 0, sizeof(params));
4248
Johannes Berg984c3112013-02-14 23:43:25 +01004249 if (!rdev->ops->add_station)
4250 return -EOPNOTSUPP;
4251
Johannes Berg5727ef12007-12-19 02:03:34 +01004252 if (!info->attrs[NL80211_ATTR_MAC])
4253 return -EINVAL;
4254
Johannes Berg5727ef12007-12-19 02:03:34 +01004255 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4256 return -EINVAL;
4257
4258 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4259 return -EINVAL;
4260
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004261 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4262 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004263 return -EINVAL;
4264
Johannes Berg5727ef12007-12-19 02:03:34 +01004265 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4266 params.supported_rates =
4267 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4268 params.supported_rates_len =
4269 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4270 params.listen_interval =
4271 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004272
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004273 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004274 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004275 else
4276 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004277 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4278 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004279
Jouni Malinen9d62a982013-02-14 21:10:13 +02004280 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4281 params.capability =
4282 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4283 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4284 }
4285
4286 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4287 params.ext_capab =
4288 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4289 params.ext_capab_len =
4290 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4291 }
4292
Jouni Malinen36aedc92008-08-25 11:58:58 +03004293 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4294 params.ht_capa =
4295 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004296
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004297 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4298 params.vht_capa =
4299 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4300
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004301 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4302 params.opmode_notif_used = true;
4303 params.opmode_notif =
4304 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4305 }
4306
Johannes Bergf8bacc22013-02-14 23:27:01 +01004307 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004308 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004309 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4310 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4311 return -EINVAL;
4312 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004313
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304314 err = nl80211_parse_sta_channel_info(info, &params);
4315 if (err)
4316 return err;
4317
Johannes Bergff276692013-02-15 00:09:01 +01004318 err = nl80211_parse_sta_wme(info, &params);
4319 if (err)
4320 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004321
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004322 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004323 return -EINVAL;
4324
Johannes Berg77ee7c82013-02-15 00:48:33 +01004325 /* When you run into this, adjust the code below for the new flag */
4326 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4327
Johannes Bergbdd90d52011-12-14 12:20:27 +01004328 switch (dev->ieee80211_ptr->iftype) {
4329 case NL80211_IFTYPE_AP:
4330 case NL80211_IFTYPE_AP_VLAN:
4331 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004332 /* ignore WME attributes if iface/sta is not capable */
4333 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4334 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4335 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004336
Johannes Bergbdd90d52011-12-14 12:20:27 +01004337 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004338 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4339 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004340 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004341 /* but don't bother the driver with it */
4342 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004343
Johannes Bergd582cff2012-10-26 17:53:44 +02004344 /* allow authenticated/associated only if driver handles it */
4345 if (!(rdev->wiphy.features &
4346 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4347 params.sta_flags_mask &
4348 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4349 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4350 return -EINVAL;
4351
Johannes Bergbdd90d52011-12-14 12:20:27 +01004352 /* must be last in here for error handling */
4353 params.vlan = get_vlan(info, rdev);
4354 if (IS_ERR(params.vlan))
4355 return PTR_ERR(params.vlan);
4356 break;
4357 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004358 /* ignore uAPSD data */
4359 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4360
Johannes Bergd582cff2012-10-26 17:53:44 +02004361 /* associated is disallowed */
4362 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4363 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004364 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004365 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4366 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004367 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004368 break;
4369 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004370 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004371 /* ignore uAPSD data */
4372 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4373
Johannes Berg77ee7c82013-02-15 00:48:33 +01004374 /* these are disallowed */
4375 if (params.sta_flags_mask &
4376 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4377 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004378 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004379 /* Only TDLS peers can be added */
4380 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4381 return -EINVAL;
4382 /* Can only add if TDLS ... */
4383 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4384 return -EOPNOTSUPP;
4385 /* ... with external setup is supported */
4386 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4387 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004388 /*
4389 * Older wpa_supplicant versions always mark the TDLS peer
4390 * as authorized, but it shouldn't yet be.
4391 */
4392 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004393 break;
4394 default:
4395 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004396 }
4397
Johannes Bergbdd90d52011-12-14 12:20:27 +01004398 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004399
Hila Gonene35e4d22012-06-27 17:19:42 +03004400 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004401
Johannes Berg5727ef12007-12-19 02:03:34 +01004402 if (params.vlan)
4403 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004404 return err;
4405}
4406
4407static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4408{
Johannes Berg4c476992010-10-04 21:36:35 +02004409 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4410 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004411 struct station_del_parameters params;
4412
4413 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004414
4415 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004416 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004417
Johannes Berge80cf852009-05-11 14:43:13 +02004418 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004419 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004420 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004421 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4422 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004423
Johannes Berg4c476992010-10-04 21:36:35 +02004424 if (!rdev->ops->del_station)
4425 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004426
Jouni Malinen98856862014-10-20 13:20:45 +03004427 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4428 params.subtype =
4429 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4430 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4431 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4432 return -EINVAL;
4433 } else {
4434 /* Default to Deauthentication frame */
4435 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4436 }
4437
4438 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4439 params.reason_code =
4440 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4441 if (params.reason_code == 0)
4442 return -EINVAL; /* 0 is reserved */
4443 } else {
4444 /* Default to reason code 2 */
4445 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4446 }
4447
Jouni Malinen89c771e2014-10-10 20:52:40 +03004448 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004449}
4450
Eric W. Biederman15e47302012-09-07 20:12:54 +00004451static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004452 int flags, struct net_device *dev,
4453 u8 *dst, u8 *next_hop,
4454 struct mpath_info *pinfo)
4455{
4456 void *hdr;
4457 struct nlattr *pinfoattr;
4458
Henning Rogge1ef4c852014-11-04 16:14:58 +01004459 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004460 if (!hdr)
4461 return -1;
4462
David S. Miller9360ffd2012-03-29 04:41:26 -04004463 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4464 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4465 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4466 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4467 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004468
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004469 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4470 if (!pinfoattr)
4471 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004472 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4473 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4474 pinfo->frame_qlen))
4475 goto nla_put_failure;
4476 if (((pinfo->filled & MPATH_INFO_SN) &&
4477 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4478 ((pinfo->filled & MPATH_INFO_METRIC) &&
4479 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4480 pinfo->metric)) ||
4481 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4482 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4483 pinfo->exptime)) ||
4484 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4485 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4486 pinfo->flags)) ||
4487 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4488 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4489 pinfo->discovery_timeout)) ||
4490 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4491 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4492 pinfo->discovery_retries)))
4493 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004494
4495 nla_nest_end(msg, pinfoattr);
4496
4497 return genlmsg_end(msg, hdr);
4498
4499 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004500 genlmsg_cancel(msg, hdr);
4501 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004502}
4503
4504static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004505 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004507 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004508 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004509 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004510 u8 dst[ETH_ALEN];
4511 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004512 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004513 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004514
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004515 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004516 if (err)
4517 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004518
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004519 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004520 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004521 goto out_err;
4522 }
4523
Johannes Berg97990a02013-04-19 01:02:55 +02004524 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004525 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004526 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004527 }
4528
Johannes Bergbba95fe2008-07-29 13:22:51 +02004529 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004530 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004531 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004532 if (err == -ENOENT)
4533 break;
4534 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004535 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004536
Eric W. Biederman15e47302012-09-07 20:12:54 +00004537 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004538 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004539 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004540 &pinfo) < 0)
4541 goto out;
4542
4543 path_idx++;
4544 }
4545
4546
4547 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004548 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004549 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004550 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004551 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004552 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004553}
4554
4555static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4556{
Johannes Berg4c476992010-10-04 21:36:35 +02004557 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004558 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004559 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004560 struct mpath_info pinfo;
4561 struct sk_buff *msg;
4562 u8 *dst = NULL;
4563 u8 next_hop[ETH_ALEN];
4564
4565 memset(&pinfo, 0, sizeof(pinfo));
4566
4567 if (!info->attrs[NL80211_ATTR_MAC])
4568 return -EINVAL;
4569
4570 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4571
Johannes Berg4c476992010-10-04 21:36:35 +02004572 if (!rdev->ops->get_mpath)
4573 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004574
Johannes Berg4c476992010-10-04 21:36:35 +02004575 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4576 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004577
Hila Gonene35e4d22012-06-27 17:19:42 +03004578 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004579 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004580 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004581
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004583 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004584 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004585
Eric W. Biederman15e47302012-09-07 20:12:54 +00004586 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004587 dev, dst, next_hop, &pinfo) < 0) {
4588 nlmsg_free(msg);
4589 return -ENOBUFS;
4590 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004591
Johannes Berg4c476992010-10-04 21:36:35 +02004592 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004593}
4594
4595static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4596{
Johannes Berg4c476992010-10-04 21:36:35 +02004597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4598 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004599 u8 *dst = NULL;
4600 u8 *next_hop = NULL;
4601
4602 if (!info->attrs[NL80211_ATTR_MAC])
4603 return -EINVAL;
4604
4605 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4606 return -EINVAL;
4607
4608 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4609 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4610
Johannes Berg4c476992010-10-04 21:36:35 +02004611 if (!rdev->ops->change_mpath)
4612 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004613
Johannes Berg4c476992010-10-04 21:36:35 +02004614 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4615 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004616
Hila Gonene35e4d22012-06-27 17:19:42 +03004617 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004618}
Johannes Berg4c476992010-10-04 21:36:35 +02004619
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004620static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4621{
Johannes Berg4c476992010-10-04 21:36:35 +02004622 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4623 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004624 u8 *dst = NULL;
4625 u8 *next_hop = NULL;
4626
4627 if (!info->attrs[NL80211_ATTR_MAC])
4628 return -EINVAL;
4629
4630 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4631 return -EINVAL;
4632
4633 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4634 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4635
Johannes Berg4c476992010-10-04 21:36:35 +02004636 if (!rdev->ops->add_mpath)
4637 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004638
Johannes Berg4c476992010-10-04 21:36:35 +02004639 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4640 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004641
Hila Gonene35e4d22012-06-27 17:19:42 +03004642 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004643}
4644
4645static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4646{
Johannes Berg4c476992010-10-04 21:36:35 +02004647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4648 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004649 u8 *dst = NULL;
4650
4651 if (info->attrs[NL80211_ATTR_MAC])
4652 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4653
Johannes Berg4c476992010-10-04 21:36:35 +02004654 if (!rdev->ops->del_mpath)
4655 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004656
Hila Gonene35e4d22012-06-27 17:19:42 +03004657 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004658}
4659
Henning Rogge66be7d22014-09-12 08:58:49 +02004660static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4661{
4662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4663 int err;
4664 struct net_device *dev = info->user_ptr[1];
4665 struct mpath_info pinfo;
4666 struct sk_buff *msg;
4667 u8 *dst = NULL;
4668 u8 mpp[ETH_ALEN];
4669
4670 memset(&pinfo, 0, sizeof(pinfo));
4671
4672 if (!info->attrs[NL80211_ATTR_MAC])
4673 return -EINVAL;
4674
4675 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4676
4677 if (!rdev->ops->get_mpp)
4678 return -EOPNOTSUPP;
4679
4680 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4681 return -EOPNOTSUPP;
4682
4683 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4684 if (err)
4685 return err;
4686
4687 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4688 if (!msg)
4689 return -ENOMEM;
4690
4691 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4692 dev, dst, mpp, &pinfo) < 0) {
4693 nlmsg_free(msg);
4694 return -ENOBUFS;
4695 }
4696
4697 return genlmsg_reply(msg, info);
4698}
4699
4700static int nl80211_dump_mpp(struct sk_buff *skb,
4701 struct netlink_callback *cb)
4702{
4703 struct mpath_info pinfo;
4704 struct cfg80211_registered_device *rdev;
4705 struct wireless_dev *wdev;
4706 u8 dst[ETH_ALEN];
4707 u8 mpp[ETH_ALEN];
4708 int path_idx = cb->args[2];
4709 int err;
4710
4711 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4712 if (err)
4713 return err;
4714
4715 if (!rdev->ops->dump_mpp) {
4716 err = -EOPNOTSUPP;
4717 goto out_err;
4718 }
4719
4720 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4721 err = -EOPNOTSUPP;
4722 goto out_err;
4723 }
4724
4725 while (1) {
4726 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4727 mpp, &pinfo);
4728 if (err == -ENOENT)
4729 break;
4730 if (err)
4731 goto out_err;
4732
4733 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4734 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4735 wdev->netdev, dst, mpp,
4736 &pinfo) < 0)
4737 goto out;
4738
4739 path_idx++;
4740 }
4741
4742 out:
4743 cb->args[2] = path_idx;
4744 err = skb->len;
4745 out_err:
4746 nl80211_finish_wdev_dump(rdev);
4747 return err;
4748}
4749
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004750static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4751{
Johannes Berg4c476992010-10-04 21:36:35 +02004752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4753 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004754 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004755 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004756 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004757
4758 memset(&params, 0, sizeof(params));
4759 /* default to not changing parameters */
4760 params.use_cts_prot = -1;
4761 params.use_short_preamble = -1;
4762 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004763 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004764 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004765 params.p2p_ctwindow = -1;
4766 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004767
4768 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4769 params.use_cts_prot =
4770 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4771 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4772 params.use_short_preamble =
4773 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4774 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4775 params.use_short_slot_time =
4776 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004777 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4778 params.basic_rates =
4779 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4780 params.basic_rates_len =
4781 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4782 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004783 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4784 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004785 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4786 params.ht_opmode =
4787 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004788
Johannes Berg53cabad2012-11-14 15:17:28 +01004789 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4790 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4791 return -EINVAL;
4792 params.p2p_ctwindow =
4793 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4794 if (params.p2p_ctwindow < 0)
4795 return -EINVAL;
4796 if (params.p2p_ctwindow != 0 &&
4797 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4798 return -EINVAL;
4799 }
4800
4801 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4802 u8 tmp;
4803
4804 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4805 return -EINVAL;
4806 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4807 if (tmp > 1)
4808 return -EINVAL;
4809 params.p2p_opp_ps = tmp;
4810 if (params.p2p_opp_ps &&
4811 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4812 return -EINVAL;
4813 }
4814
Johannes Berg4c476992010-10-04 21:36:35 +02004815 if (!rdev->ops->change_bss)
4816 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004817
Johannes Berg074ac8d2010-09-16 14:58:22 +02004818 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004819 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4820 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004821
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004822 wdev_lock(wdev);
4823 err = rdev_change_bss(rdev, dev, &params);
4824 wdev_unlock(wdev);
4825
4826 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004827}
4828
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004829static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004830 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4831 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4832 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4833 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4834 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4835 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004836 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004837};
4838
4839static int parse_reg_rule(struct nlattr *tb[],
4840 struct ieee80211_reg_rule *reg_rule)
4841{
4842 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4843 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4844
4845 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4846 return -EINVAL;
4847 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4848 return -EINVAL;
4849 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4850 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004851 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4852 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004853 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4854 return -EINVAL;
4855
4856 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4857
4858 freq_range->start_freq_khz =
4859 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4860 freq_range->end_freq_khz =
4861 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004862 freq_range->max_bandwidth_khz =
4863 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004864
4865 power_rule->max_eirp =
4866 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4867
4868 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4869 power_rule->max_antenna_gain =
4870 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4871
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004872 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4873 reg_rule->dfs_cac_ms =
4874 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4875
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004876 return 0;
4877}
4878
4879static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4880{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004881 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004882 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004883
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004884 /*
4885 * You should only get this when cfg80211 hasn't yet initialized
4886 * completely when built-in to the kernel right between the time
4887 * window between nl80211_init() and regulatory_init(), if that is
4888 * even possible.
4889 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004890 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004891 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004892
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004893 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4894 user_reg_hint_type =
4895 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4896 else
4897 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4898
4899 switch (user_reg_hint_type) {
4900 case NL80211_USER_REG_HINT_USER:
4901 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004902 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4903 return -EINVAL;
4904
4905 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4906 return regulatory_hint_user(data, user_reg_hint_type);
4907 case NL80211_USER_REG_HINT_INDOOR:
4908 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004909 default:
4910 return -EINVAL;
4911 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004912}
4913
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004914static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004915 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004916{
Johannes Berg4c476992010-10-04 21:36:35 +02004917 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004918 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004919 struct wireless_dev *wdev = dev->ieee80211_ptr;
4920 struct mesh_config cur_params;
4921 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004922 void *hdr;
4923 struct nlattr *pinfoattr;
4924 struct sk_buff *msg;
4925
Johannes Berg29cbe682010-12-03 09:20:44 +01004926 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4927 return -EOPNOTSUPP;
4928
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004929 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004930 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004931
Johannes Berg29cbe682010-12-03 09:20:44 +01004932 wdev_lock(wdev);
4933 /* If not connected, get default parameters */
4934 if (!wdev->mesh_id_len)
4935 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4936 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004937 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004938 wdev_unlock(wdev);
4939
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004940 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004941 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004942
4943 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004944 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004945 if (!msg)
4946 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004947 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004948 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004949 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004950 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004951 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004952 if (!pinfoattr)
4953 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004954 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4955 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4956 cur_params.dot11MeshRetryTimeout) ||
4957 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4958 cur_params.dot11MeshConfirmTimeout) ||
4959 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4960 cur_params.dot11MeshHoldingTimeout) ||
4961 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4962 cur_params.dot11MeshMaxPeerLinks) ||
4963 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4964 cur_params.dot11MeshMaxRetries) ||
4965 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4966 cur_params.dot11MeshTTL) ||
4967 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4968 cur_params.element_ttl) ||
4969 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4970 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004971 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4972 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004973 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4974 cur_params.dot11MeshHWMPmaxPREQretries) ||
4975 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4976 cur_params.path_refresh_time) ||
4977 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4978 cur_params.min_discovery_timeout) ||
4979 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4980 cur_params.dot11MeshHWMPactivePathTimeout) ||
4981 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4982 cur_params.dot11MeshHWMPpreqMinInterval) ||
4983 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4984 cur_params.dot11MeshHWMPperrMinInterval) ||
4985 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4986 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4987 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4988 cur_params.dot11MeshHWMPRootMode) ||
4989 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4990 cur_params.dot11MeshHWMPRannInterval) ||
4991 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4992 cur_params.dot11MeshGateAnnouncementProtocol) ||
4993 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4994 cur_params.dot11MeshForwarding) ||
4995 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004996 cur_params.rssi_threshold) ||
4997 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004998 cur_params.ht_opmode) ||
4999 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5000 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5001 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005002 cur_params.dot11MeshHWMProotInterval) ||
5003 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005004 cur_params.dot11MeshHWMPconfirmationInterval) ||
5005 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5006 cur_params.power_mode) ||
5007 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005008 cur_params.dot11MeshAwakeWindowDuration) ||
5009 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5010 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005011 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005012 nla_nest_end(msg, pinfoattr);
5013 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005014 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005015
Johannes Berg3b858752009-03-12 09:55:09 +01005016 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005017 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005018 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005019 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005020 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005021}
5022
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005023static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005024 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5025 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5026 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5027 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5028 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5029 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005030 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005031 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005032 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005033 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5034 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5035 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5036 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5037 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005038 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005039 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005040 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005041 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005042 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005043 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005044 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5045 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005046 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5047 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005048 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005049 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5050 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005051 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005052};
5053
Javier Cardonac80d5452010-12-16 17:37:49 -08005054static const struct nla_policy
5055 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005056 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005057 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5058 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005059 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005060 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005061 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005062 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005063 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005064 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005065};
5066
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005067static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005068 struct mesh_config *cfg,
5069 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005070{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005071 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005072 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005073
Marco Porschea54fba2013-01-07 16:04:48 +01005074#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5075do { \
5076 if (tb[attr]) { \
5077 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5078 return -EINVAL; \
5079 cfg->param = fn(tb[attr]); \
5080 mask |= (1 << (attr - 1)); \
5081 } \
5082} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005083
5084
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005085 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005086 return -EINVAL;
5087 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005088 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005089 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005090 return -EINVAL;
5091
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005092 /* This makes sure that there aren't more than 32 mesh config
5093 * parameters (otherwise our bitfield scheme would not work.) */
5094 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5095
5096 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005097 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005098 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5099 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005100 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005101 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5102 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005103 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005104 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5105 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005107 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5108 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005109 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005110 mask, NL80211_MESHCONF_MAX_RETRIES,
5111 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005112 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005113 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005114 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005115 mask, NL80211_MESHCONF_ELEMENT_TTL,
5116 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005117 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005118 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5119 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005120 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5121 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005122 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5123 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005124 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005125 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5126 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005127 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005128 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5129 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005130 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005131 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5132 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005133 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5134 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005135 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5136 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005137 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005138 1, 65535, mask,
5139 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005140 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005141 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005142 1, 65535, mask,
5143 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005144 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005145 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005146 dot11MeshHWMPnetDiameterTraversalTime,
5147 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005148 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5149 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005150 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5151 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5152 nla_get_u8);
5153 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5154 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005155 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005156 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005157 dot11MeshGateAnnouncementProtocol, 0, 1,
5158 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005159 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005160 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005161 mask, NL80211_MESHCONF_FORWARDING,
5162 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005163 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005164 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005165 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005166 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005167 mask, NL80211_MESHCONF_HT_OPMODE,
5168 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005169 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005170 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005171 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5172 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005173 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005174 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5175 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005176 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005177 dot11MeshHWMPconfirmationInterval,
5178 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005179 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5180 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005181 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5182 NL80211_MESH_POWER_ACTIVE,
5183 NL80211_MESH_POWER_MAX,
5184 mask, NL80211_MESHCONF_POWER_MODE,
5185 nla_get_u32);
5186 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5187 0, 65535, mask,
5188 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005189 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5190 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5191 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005192 if (mask_out)
5193 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005194
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005195 return 0;
5196
5197#undef FILL_IN_MESH_PARAM_IF_SET
5198}
5199
Javier Cardonac80d5452010-12-16 17:37:49 -08005200static int nl80211_parse_mesh_setup(struct genl_info *info,
5201 struct mesh_setup *setup)
5202{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005203 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005204 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5205
5206 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5207 return -EINVAL;
5208 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5209 info->attrs[NL80211_ATTR_MESH_SETUP],
5210 nl80211_mesh_setup_params_policy))
5211 return -EINVAL;
5212
Javier Cardonad299a1f2012-03-31 11:31:33 -07005213 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5214 setup->sync_method =
5215 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5216 IEEE80211_SYNC_METHOD_VENDOR :
5217 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5218
Javier Cardonac80d5452010-12-16 17:37:49 -08005219 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5220 setup->path_sel_proto =
5221 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5222 IEEE80211_PATH_PROTOCOL_VENDOR :
5223 IEEE80211_PATH_PROTOCOL_HWMP;
5224
5225 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5226 setup->path_metric =
5227 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5228 IEEE80211_PATH_METRIC_VENDOR :
5229 IEEE80211_PATH_METRIC_AIRTIME;
5230
Javier Cardona581a8b02011-04-07 15:08:27 -07005231
5232 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005233 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005234 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005235 if (!is_valid_ie_attr(ieattr))
5236 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005237 setup->ie = nla_data(ieattr);
5238 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005239 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005240 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5241 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5242 return -EINVAL;
5243 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005244 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5245 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005246 if (setup->is_secure)
5247 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005248
Colleen Twitty6e16d902013-05-08 11:45:59 -07005249 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5250 if (!setup->user_mpm)
5251 return -EINVAL;
5252 setup->auth_id =
5253 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5254 }
5255
Javier Cardonac80d5452010-12-16 17:37:49 -08005256 return 0;
5257}
5258
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005259static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005260 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005261{
5262 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5263 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005264 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005265 struct mesh_config cfg;
5266 u32 mask;
5267 int err;
5268
Johannes Berg29cbe682010-12-03 09:20:44 +01005269 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5270 return -EOPNOTSUPP;
5271
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005272 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005273 return -EOPNOTSUPP;
5274
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005275 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005276 if (err)
5277 return err;
5278
Johannes Berg29cbe682010-12-03 09:20:44 +01005279 wdev_lock(wdev);
5280 if (!wdev->mesh_id_len)
5281 err = -ENOLINK;
5282
5283 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005284 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005285
5286 wdev_unlock(wdev);
5287
5288 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005289}
5290
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005291static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5292{
Johannes Berg458f4f92012-12-06 15:47:38 +01005293 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005294 struct sk_buff *msg;
5295 void *hdr = NULL;
5296 struct nlattr *nl_reg_rules;
5297 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005298
5299 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005300 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005301
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005302 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005303 if (!msg)
5304 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005305
Eric W. Biederman15e47302012-09-07 20:12:54 +00005306 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005307 NL80211_CMD_GET_REG);
5308 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005309 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005310
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005311 if (reg_last_request_cell_base() &&
5312 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5313 NL80211_USER_REG_HINT_CELL_BASE))
5314 goto nla_put_failure;
5315
Johannes Berg458f4f92012-12-06 15:47:38 +01005316 rcu_read_lock();
5317 regdom = rcu_dereference(cfg80211_regdomain);
5318
5319 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5320 (regdom->dfs_region &&
5321 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5322 goto nla_put_failure_rcu;
5323
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005324 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5325 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005326 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005327
Johannes Berg458f4f92012-12-06 15:47:38 +01005328 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005329 struct nlattr *nl_reg_rule;
5330 const struct ieee80211_reg_rule *reg_rule;
5331 const struct ieee80211_freq_range *freq_range;
5332 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005333 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005334
Johannes Berg458f4f92012-12-06 15:47:38 +01005335 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005336 freq_range = &reg_rule->freq_range;
5337 power_rule = &reg_rule->power_rule;
5338
5339 nl_reg_rule = nla_nest_start(msg, i);
5340 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005341 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005342
Janusz Dziedzic97524822014-01-30 09:52:20 +01005343 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5344 if (!max_bandwidth_khz)
5345 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5346 reg_rule);
5347
David S. Miller9360ffd2012-03-29 04:41:26 -04005348 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5349 reg_rule->flags) ||
5350 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5351 freq_range->start_freq_khz) ||
5352 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5353 freq_range->end_freq_khz) ||
5354 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005355 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005356 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5357 power_rule->max_antenna_gain) ||
5358 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005359 power_rule->max_eirp) ||
5360 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5361 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005362 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005363
5364 nla_nest_end(msg, nl_reg_rule);
5365 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005366 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005367
5368 nla_nest_end(msg, nl_reg_rules);
5369
5370 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005371 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005372
Johannes Berg458f4f92012-12-06 15:47:38 +01005373nla_put_failure_rcu:
5374 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005375nla_put_failure:
5376 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005377put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005378 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005379 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005380}
5381
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005382static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5383{
5384 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5385 struct nlattr *nl_reg_rule;
5386 char *alpha2 = NULL;
5387 int rem_reg_rules = 0, r = 0;
5388 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005389 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005390 struct ieee80211_regdomain *rd = NULL;
5391
5392 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5393 return -EINVAL;
5394
5395 if (!info->attrs[NL80211_ATTR_REG_RULES])
5396 return -EINVAL;
5397
5398 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5399
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005400 if (info->attrs[NL80211_ATTR_DFS_REGION])
5401 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5402
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005403 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005404 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005405 num_rules++;
5406 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005407 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005408 }
5409
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005410 if (!reg_is_valid_request(alpha2))
5411 return -EINVAL;
5412
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005413 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005414 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005415
5416 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005417 if (!rd)
5418 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005419
5420 rd->n_reg_rules = num_rules;
5421 rd->alpha2[0] = alpha2[0];
5422 rd->alpha2[1] = alpha2[1];
5423
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005424 /*
5425 * Disable DFS master mode if the DFS region was
5426 * not supported or known on this kernel.
5427 */
5428 if (reg_supported_dfs_region(dfs_region))
5429 rd->dfs_region = dfs_region;
5430
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005431 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005432 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005433 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5434 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5435 reg_rule_policy);
5436 if (r)
5437 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005438 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5439 if (r)
5440 goto bad_reg;
5441
5442 rule_idx++;
5443
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005444 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5445 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005446 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005447 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005448 }
5449
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005450 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005451 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005452 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005453
Johannes Bergd2372b32008-10-24 20:32:20 +02005454 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005455 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005456 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005457}
5458
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005459static int validate_scan_freqs(struct nlattr *freqs)
5460{
5461 struct nlattr *attr1, *attr2;
5462 int n_channels = 0, tmp1, tmp2;
5463
5464 nla_for_each_nested(attr1, freqs, tmp1) {
5465 n_channels++;
5466 /*
5467 * Some hardware has a limited channel list for
5468 * scanning, and it is pretty much nonsensical
5469 * to scan for a channel twice, so disallow that
5470 * and don't require drivers to check that the
5471 * channel list they get isn't longer than what
5472 * they can scan, as long as they can scan all
5473 * the channels they registered at once.
5474 */
5475 nla_for_each_nested(attr2, freqs, tmp2)
5476 if (attr1 != attr2 &&
5477 nla_get_u32(attr1) == nla_get_u32(attr2))
5478 return 0;
5479 }
5480
5481 return n_channels;
5482}
5483
Johannes Berg2a519312009-02-10 21:25:55 +01005484static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5485{
Johannes Berg4c476992010-10-04 21:36:35 +02005486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005487 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005488 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005489 struct nlattr *attr;
5490 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005491 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005492 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005493
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005494 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5495 return -EINVAL;
5496
Johannes Berg79c97e92009-07-07 03:56:12 +02005497 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005498
Johannes Berg4c476992010-10-04 21:36:35 +02005499 if (!rdev->ops->scan)
5500 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005501
Johannes Bergf9d15d12014-01-22 11:14:19 +02005502 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005503 err = -EBUSY;
5504 goto unlock;
5505 }
Johannes Berg2a519312009-02-10 21:25:55 +01005506
5507 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005508 n_channels = validate_scan_freqs(
5509 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005510 if (!n_channels) {
5511 err = -EINVAL;
5512 goto unlock;
5513 }
Johannes Berg2a519312009-02-10 21:25:55 +01005514 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005515 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005516 }
5517
5518 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5519 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5520 n_ssids++;
5521
Johannes Bergf9f47522013-03-19 15:04:07 +01005522 if (n_ssids > wiphy->max_scan_ssids) {
5523 err = -EINVAL;
5524 goto unlock;
5525 }
Johannes Berg2a519312009-02-10 21:25:55 +01005526
Jouni Malinen70692ad2009-02-16 19:39:13 +02005527 if (info->attrs[NL80211_ATTR_IE])
5528 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5529 else
5530 ie_len = 0;
5531
Johannes Bergf9f47522013-03-19 15:04:07 +01005532 if (ie_len > wiphy->max_scan_ie_len) {
5533 err = -EINVAL;
5534 goto unlock;
5535 }
Johannes Berg18a83652009-03-31 12:12:05 +02005536
Johannes Berg2a519312009-02-10 21:25:55 +01005537 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005538 + sizeof(*request->ssids) * n_ssids
5539 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005540 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005541 if (!request) {
5542 err = -ENOMEM;
5543 goto unlock;
5544 }
Johannes Berg2a519312009-02-10 21:25:55 +01005545
Johannes Berg2a519312009-02-10 21:25:55 +01005546 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005547 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005548 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005549 if (ie_len) {
5550 if (request->ssids)
5551 request->ie = (void *)(request->ssids + n_ssids);
5552 else
5553 request->ie = (void *)(request->channels + n_channels);
5554 }
Johannes Berg2a519312009-02-10 21:25:55 +01005555
Johannes Berg584991d2009-11-02 13:32:03 +01005556 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005557 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5558 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005559 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005560 struct ieee80211_channel *chan;
5561
5562 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5563
5564 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005565 err = -EINVAL;
5566 goto out_free;
5567 }
Johannes Berg584991d2009-11-02 13:32:03 +01005568
5569 /* ignore disabled channels */
5570 if (chan->flags & IEEE80211_CHAN_DISABLED)
5571 continue;
5572
5573 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005574 i++;
5575 }
5576 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005577 enum ieee80211_band band;
5578
Johannes Berg2a519312009-02-10 21:25:55 +01005579 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005580 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5581 int j;
5582 if (!wiphy->bands[band])
5583 continue;
5584 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005585 struct ieee80211_channel *chan;
5586
5587 chan = &wiphy->bands[band]->channels[j];
5588
5589 if (chan->flags & IEEE80211_CHAN_DISABLED)
5590 continue;
5591
5592 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005593 i++;
5594 }
5595 }
5596 }
5597
Johannes Berg584991d2009-11-02 13:32:03 +01005598 if (!i) {
5599 err = -EINVAL;
5600 goto out_free;
5601 }
5602
5603 request->n_channels = i;
5604
Johannes Berg2a519312009-02-10 21:25:55 +01005605 i = 0;
5606 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5607 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005608 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005609 err = -EINVAL;
5610 goto out_free;
5611 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005612 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005613 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005614 i++;
5615 }
5616 }
5617
Jouni Malinen70692ad2009-02-16 19:39:13 +02005618 if (info->attrs[NL80211_ATTR_IE]) {
5619 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005620 memcpy((void *)request->ie,
5621 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005622 request->ie_len);
5623 }
5624
Johannes Berg34850ab2011-07-18 18:08:35 +02005625 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005626 if (wiphy->bands[i])
5627 request->rates[i] =
5628 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005629
5630 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5631 nla_for_each_nested(attr,
5632 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5633 tmp) {
5634 enum ieee80211_band band = nla_type(attr);
5635
Dan Carpenter84404622011-07-29 11:52:18 +03005636 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005637 err = -EINVAL;
5638 goto out_free;
5639 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005640
5641 if (!wiphy->bands[band])
5642 continue;
5643
Johannes Berg34850ab2011-07-18 18:08:35 +02005644 err = ieee80211_get_ratemask(wiphy->bands[band],
5645 nla_data(attr),
5646 nla_len(attr),
5647 &request->rates[band]);
5648 if (err)
5649 goto out_free;
5650 }
5651 }
5652
Sam Leffler46856bb2012-10-11 21:03:32 -07005653 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005654 request->flags = nla_get_u32(
5655 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005656 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5657 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005658 err = -EOPNOTSUPP;
5659 goto out_free;
5660 }
5661 }
Sam Lefflered4737712012-10-11 21:03:31 -07005662
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305663 request->no_cck =
5664 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5665
Johannes Bergfd014282012-06-18 19:17:03 +02005666 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005667 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005668 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005669
Johannes Berg79c97e92009-07-07 03:56:12 +02005670 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005671 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005672
Johannes Berg463d0182009-07-14 00:33:35 +02005673 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005674 nl80211_send_scan_start(rdev, wdev);
5675 if (wdev->netdev)
5676 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005677 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005678 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005679 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005680 kfree(request);
5681 }
Johannes Berg3b858752009-03-12 09:55:09 +01005682
Johannes Bergf9f47522013-03-19 15:04:07 +01005683 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005684 return err;
5685}
5686
Luciano Coelho256da022014-11-10 16:13:46 +02005687static struct cfg80211_sched_scan_request *
5688nl80211_parse_sched_scan(struct wiphy *wiphy,
5689 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005690{
5691 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005692 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005693 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005694 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005695 enum ieee80211_band band;
5696 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005697 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005698 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005699
Luciano Coelho256da022014-11-10 16:13:46 +02005700 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5701 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005702
Luciano Coelho256da022014-11-10 16:13:46 +02005703 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5704 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005705
Luciano Coelho256da022014-11-10 16:13:46 +02005706 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005707 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005708 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005709
Luciano Coelho256da022014-11-10 16:13:46 +02005710 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005711 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005712 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005713 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005714 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005715 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005716 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005717 }
5718
Luciano Coelho256da022014-11-10 16:13:46 +02005719 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5720 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005721 tmp)
5722 n_ssids++;
5723
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005724 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005725 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005726
Johannes Bergea73cbc2014-01-24 10:53:53 +01005727 /*
5728 * First, count the number of 'real' matchsets. Due to an issue with
5729 * the old implementation, matchsets containing only the RSSI attribute
5730 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5731 * RSSI for all matchsets, rather than their own matchset for reporting
5732 * all APs with a strong RSSI. This is needed to be compatible with
5733 * older userspace that treated a matchset with only the RSSI as the
5734 * global RSSI for all other matchsets - if there are other matchsets.
5735 */
Luciano Coelho256da022014-11-10 16:13:46 +02005736 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005737 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005738 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005739 tmp) {
5740 struct nlattr *rssi;
5741
5742 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5743 nla_data(attr), nla_len(attr),
5744 nl80211_match_policy);
5745 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02005746 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005747 /* add other standalone attributes here */
5748 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5749 n_match_sets++;
5750 continue;
5751 }
5752 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5753 if (rssi)
5754 default_match_rssi = nla_get_s32(rssi);
5755 }
5756 }
5757
5758 /* However, if there's no other matchset, add the RSSI one */
5759 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5760 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005761
5762 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02005763 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005764
Luciano Coelho256da022014-11-10 16:13:46 +02005765 if (attrs[NL80211_ATTR_IE])
5766 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005767 else
5768 ie_len = 0;
5769
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005770 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02005771 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005772
Luciano Coelho807f8a82011-05-11 17:09:35 +03005773 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005774 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005775 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005776 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005777 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02005778 if (!request)
5779 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005780
5781 if (n_ssids)
5782 request->ssids = (void *)&request->channels[n_channels];
5783 request->n_ssids = n_ssids;
5784 if (ie_len) {
5785 if (request->ssids)
5786 request->ie = (void *)(request->ssids + n_ssids);
5787 else
5788 request->ie = (void *)(request->channels + n_channels);
5789 }
5790
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005791 if (n_match_sets) {
5792 if (request->ie)
5793 request->match_sets = (void *)(request->ie + ie_len);
5794 else if (request->ssids)
5795 request->match_sets =
5796 (void *)(request->ssids + n_ssids);
5797 else
5798 request->match_sets =
5799 (void *)(request->channels + n_channels);
5800 }
5801 request->n_match_sets = n_match_sets;
5802
Luciano Coelho807f8a82011-05-11 17:09:35 +03005803 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005804 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005805 /* user specified, bail out if channel not found */
5806 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005807 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005808 tmp) {
5809 struct ieee80211_channel *chan;
5810
5811 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5812
5813 if (!chan) {
5814 err = -EINVAL;
5815 goto out_free;
5816 }
5817
5818 /* ignore disabled channels */
5819 if (chan->flags & IEEE80211_CHAN_DISABLED)
5820 continue;
5821
5822 request->channels[i] = chan;
5823 i++;
5824 }
5825 } else {
5826 /* all channels */
5827 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5828 int j;
5829 if (!wiphy->bands[band])
5830 continue;
5831 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5832 struct ieee80211_channel *chan;
5833
5834 chan = &wiphy->bands[band]->channels[j];
5835
5836 if (chan->flags & IEEE80211_CHAN_DISABLED)
5837 continue;
5838
5839 request->channels[i] = chan;
5840 i++;
5841 }
5842 }
5843 }
5844
5845 if (!i) {
5846 err = -EINVAL;
5847 goto out_free;
5848 }
5849
5850 request->n_channels = i;
5851
5852 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005853 if (attrs[NL80211_ATTR_SCAN_SSIDS]) {
5854 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005855 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005856 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005857 err = -EINVAL;
5858 goto out_free;
5859 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005860 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005861 memcpy(request->ssids[i].ssid, nla_data(attr),
5862 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005863 i++;
5864 }
5865 }
5866
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005867 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005868 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005869 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005870 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005871 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005872 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005873
Johannes Bergae811e22014-01-24 10:17:47 +01005874 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5875 nla_data(attr), nla_len(attr),
5876 nl80211_match_policy);
5877 if (err)
5878 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005879 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005880 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005881 if (WARN_ON(i >= n_match_sets)) {
5882 /* this indicates a programming error,
5883 * the loop above should have verified
5884 * things properly
5885 */
5886 err = -EINVAL;
5887 goto out_free;
5888 }
5889
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005890 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5891 err = -EINVAL;
5892 goto out_free;
5893 }
5894 memcpy(request->match_sets[i].ssid.ssid,
5895 nla_data(ssid), nla_len(ssid));
5896 request->match_sets[i].ssid.ssid_len =
5897 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005898 /* special attribute - old implemenation w/a */
5899 request->match_sets[i].rssi_thold =
5900 default_match_rssi;
5901 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5902 if (rssi)
5903 request->match_sets[i].rssi_thold =
5904 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005905 }
5906 i++;
5907 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005908
5909 /* there was no other matchset, so the RSSI one is alone */
5910 if (i == 0)
5911 request->match_sets[0].rssi_thold = default_match_rssi;
5912
5913 request->min_rssi_thold = INT_MAX;
5914 for (i = 0; i < n_match_sets; i++)
5915 request->min_rssi_thold =
5916 min(request->match_sets[i].rssi_thold,
5917 request->min_rssi_thold);
5918 } else {
5919 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005920 }
5921
Johannes Berg9900e482014-02-04 21:01:25 +01005922 if (ie_len) {
5923 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005924 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02005925 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03005926 request->ie_len);
5927 }
5928
Luciano Coelho256da022014-11-10 16:13:46 +02005929 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005930 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02005931 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005932 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5933 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005934 err = -EOPNOTSUPP;
5935 goto out_free;
5936 }
5937 }
Sam Lefflered4737712012-10-11 21:03:31 -07005938
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005939 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005940 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005941
Luciano Coelho256da022014-11-10 16:13:46 +02005942 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005943
5944out_free:
5945 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02005946 return ERR_PTR(err);
5947}
5948
5949static int nl80211_start_sched_scan(struct sk_buff *skb,
5950 struct genl_info *info)
5951{
5952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5953 struct net_device *dev = info->user_ptr[1];
5954 int err;
5955
5956 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5957 !rdev->ops->sched_scan_start)
5958 return -EOPNOTSUPP;
5959
5960 if (rdev->sched_scan_req)
5961 return -EINPROGRESS;
5962
5963 rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy,
5964 info->attrs);
5965 err = PTR_ERR_OR_ZERO(rdev->sched_scan_req);
5966 if (err)
5967 goto out_err;
5968
5969 err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req);
5970 if (err)
5971 goto out_free;
5972
5973 rdev->sched_scan_req->dev = dev;
5974 rdev->sched_scan_req->wiphy = &rdev->wiphy;
5975
5976 nl80211_send_sched_scan(rdev, dev,
5977 NL80211_CMD_START_SCHED_SCAN);
5978 return 0;
5979
5980out_free:
5981 kfree(rdev->sched_scan_req);
5982out_err:
5983 rdev->sched_scan_req = NULL;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005984 return err;
5985}
5986
5987static int nl80211_stop_sched_scan(struct sk_buff *skb,
5988 struct genl_info *info)
5989{
5990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5991
5992 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5993 !rdev->ops->sched_scan_stop)
5994 return -EOPNOTSUPP;
5995
Johannes Berg5fe231e2013-05-08 21:45:15 +02005996 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005997}
5998
Simon Wunderlich04f39042013-02-08 18:16:19 +01005999static int nl80211_start_radar_detection(struct sk_buff *skb,
6000 struct genl_info *info)
6001{
6002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6003 struct net_device *dev = info->user_ptr[1];
6004 struct wireless_dev *wdev = dev->ieee80211_ptr;
6005 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006006 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006007 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006008 int err;
6009
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006010 dfs_region = reg_get_dfs_region(wdev->wiphy);
6011 if (dfs_region == NL80211_DFS_UNSET)
6012 return -EINVAL;
6013
Simon Wunderlich04f39042013-02-08 18:16:19 +01006014 err = nl80211_parse_chandef(rdev, info, &chandef);
6015 if (err)
6016 return err;
6017
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006018 if (netif_carrier_ok(dev))
6019 return -EBUSY;
6020
Simon Wunderlich04f39042013-02-08 18:16:19 +01006021 if (wdev->cac_started)
6022 return -EBUSY;
6023
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006024 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006025 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006026 if (err < 0)
6027 return err;
6028
6029 if (err == 0)
6030 return -EINVAL;
6031
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006032 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006033 return -EINVAL;
6034
6035 if (!rdev->ops->start_radar_detection)
6036 return -EOPNOTSUPP;
6037
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006038 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6039 if (WARN_ON(!cac_time_ms))
6040 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6041
6042 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6043 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006044 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006045 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006046 wdev->cac_started = true;
6047 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006048 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006049 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006050 return err;
6051}
6052
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006053static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6054{
6055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6056 struct net_device *dev = info->user_ptr[1];
6057 struct wireless_dev *wdev = dev->ieee80211_ptr;
6058 struct cfg80211_csa_settings params;
6059 /* csa_attrs is defined static to avoid waste of stack size - this
6060 * function is called under RTNL lock, so this should not be a problem.
6061 */
6062 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006063 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006064 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006065 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006066 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006067
6068 if (!rdev->ops->channel_switch ||
6069 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6070 return -EOPNOTSUPP;
6071
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006072 switch (dev->ieee80211_ptr->iftype) {
6073 case NL80211_IFTYPE_AP:
6074 case NL80211_IFTYPE_P2P_GO:
6075 need_new_beacon = true;
6076
6077 /* useless if AP is not running */
6078 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006079 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006080 break;
6081 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006082 if (!wdev->ssid_len)
6083 return -ENOTCONN;
6084 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006085 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006086 if (!wdev->mesh_id_len)
6087 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006088 break;
6089 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006090 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006091 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006092
6093 memset(&params, 0, sizeof(params));
6094
6095 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6096 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6097 return -EINVAL;
6098
6099 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006100 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006101 return -EINVAL;
6102
Luciano Coelho252e07c2014-10-08 09:48:34 +03006103 /* Even though the attribute is u32, the specification says
6104 * u8, so let's make sure we don't overflow.
6105 */
6106 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6107 if (cs_count > 255)
6108 return -EINVAL;
6109
6110 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006111
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006112 if (!need_new_beacon)
6113 goto skip_beacons;
6114
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006115 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6116 if (err)
6117 return err;
6118
6119 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6120 info->attrs[NL80211_ATTR_CSA_IES],
6121 nl80211_policy);
6122 if (err)
6123 return err;
6124
6125 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6126 if (err)
6127 return err;
6128
6129 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6130 return -EINVAL;
6131
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006132 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6133 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006134 return -EINVAL;
6135
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006136 params.n_counter_offsets_beacon = len / sizeof(u16);
6137 if (rdev->wiphy.max_num_csa_counters &&
6138 (params.n_counter_offsets_beacon >
6139 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006140 return -EINVAL;
6141
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006142 params.counter_offsets_beacon =
6143 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6144
6145 /* sanity checks - counters should fit and be the same */
6146 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6147 u16 offset = params.counter_offsets_beacon[i];
6148
6149 if (offset >= params.beacon_csa.tail_len)
6150 return -EINVAL;
6151
6152 if (params.beacon_csa.tail[offset] != params.count)
6153 return -EINVAL;
6154 }
6155
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006156 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006157 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6158 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006159 return -EINVAL;
6160
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006161 params.n_counter_offsets_presp = len / sizeof(u16);
6162 if (rdev->wiphy.max_num_csa_counters &&
6163 (params.n_counter_offsets_beacon >
6164 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006165 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006166
6167 params.counter_offsets_presp =
6168 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6169
6170 /* sanity checks - counters should fit and be the same */
6171 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6172 u16 offset = params.counter_offsets_presp[i];
6173
6174 if (offset >= params.beacon_csa.probe_resp_len)
6175 return -EINVAL;
6176
6177 if (params.beacon_csa.probe_resp[offset] !=
6178 params.count)
6179 return -EINVAL;
6180 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006181 }
6182
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006183skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006184 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6185 if (err)
6186 return err;
6187
Ilan Peer174e0cd2014-02-23 09:13:01 +02006188 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6189 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006190 return -EINVAL;
6191
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006192 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6193 &params.chandef,
6194 wdev->iftype);
6195 if (err < 0)
6196 return err;
6197
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006198 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006199 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006200
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006201 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6202 params.block_tx = true;
6203
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006204 wdev_lock(wdev);
6205 err = rdev_channel_switch(rdev, dev, &params);
6206 wdev_unlock(wdev);
6207
6208 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006209}
6210
Johannes Berg9720bb32011-06-21 09:45:33 +02006211static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6212 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006213 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006214 struct wireless_dev *wdev,
6215 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006216{
Johannes Berg48ab9052009-07-10 18:42:31 +02006217 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006218 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006219 void *hdr;
6220 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006221
6222 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006223
Eric W. Biederman15e47302012-09-07 20:12:54 +00006224 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006225 NL80211_CMD_NEW_SCAN_RESULTS);
6226 if (!hdr)
6227 return -1;
6228
Johannes Berg9720bb32011-06-21 09:45:33 +02006229 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6230
Johannes Berg97990a02013-04-19 01:02:55 +02006231 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6232 goto nla_put_failure;
6233 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006234 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6235 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006236 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6237 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006238
6239 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6240 if (!bss)
6241 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006242 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006243 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006244 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006245
6246 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006247 /* indicate whether we have probe response data or not */
6248 if (rcu_access_pointer(res->proberesp_ies) &&
6249 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6250 goto fail_unlock_rcu;
6251
6252 /* this pointer prefers to be pointed to probe response data
6253 * but is always valid
6254 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006255 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006256 if (ies) {
6257 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6258 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006259 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6260 ies->len, ies->data))
6261 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006262 }
Johannes Berg0e227082014-08-12 20:34:30 +02006263
6264 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006265 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006266 if (ies && ies->from_beacon) {
6267 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006268 goto fail_unlock_rcu;
6269 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6270 ies->len, ies->data))
6271 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006272 }
6273 rcu_read_unlock();
6274
David S. Miller9360ffd2012-03-29 04:41:26 -04006275 if (res->beacon_interval &&
6276 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6277 goto nla_put_failure;
6278 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6279 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006280 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006281 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6282 jiffies_to_msecs(jiffies - intbss->ts)))
6283 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006284
Johannes Berg77965c92009-02-18 18:45:06 +01006285 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006286 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006287 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6288 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006289 break;
6290 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006291 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6292 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006293 break;
6294 default:
6295 break;
6296 }
6297
Johannes Berg48ab9052009-07-10 18:42:31 +02006298 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006299 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006300 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006301 if (intbss == wdev->current_bss &&
6302 nla_put_u32(msg, NL80211_BSS_STATUS,
6303 NL80211_BSS_STATUS_ASSOCIATED))
6304 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006305 break;
6306 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006307 if (intbss == wdev->current_bss &&
6308 nla_put_u32(msg, NL80211_BSS_STATUS,
6309 NL80211_BSS_STATUS_IBSS_JOINED))
6310 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006311 break;
6312 default:
6313 break;
6314 }
6315
Johannes Berg2a519312009-02-10 21:25:55 +01006316 nla_nest_end(msg, bss);
6317
6318 return genlmsg_end(msg, hdr);
6319
Johannes Berg8cef2c92013-02-05 16:54:31 +01006320 fail_unlock_rcu:
6321 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006322 nla_put_failure:
6323 genlmsg_cancel(msg, hdr);
6324 return -EMSGSIZE;
6325}
6326
Johannes Berg97990a02013-04-19 01:02:55 +02006327static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006328{
Johannes Berg48ab9052009-07-10 18:42:31 +02006329 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006330 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006331 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006332 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006333 int err;
6334
Johannes Berg97990a02013-04-19 01:02:55 +02006335 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006336 if (err)
6337 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006338
Johannes Berg48ab9052009-07-10 18:42:31 +02006339 wdev_lock(wdev);
6340 spin_lock_bh(&rdev->bss_lock);
6341 cfg80211_bss_expire(rdev);
6342
Johannes Berg9720bb32011-06-21 09:45:33 +02006343 cb->seq = rdev->bss_generation;
6344
Johannes Berg48ab9052009-07-10 18:42:31 +02006345 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006346 if (++idx <= start)
6347 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006348 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006349 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006350 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006351 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006352 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006353 }
6354 }
6355
Johannes Berg48ab9052009-07-10 18:42:31 +02006356 spin_unlock_bh(&rdev->bss_lock);
6357 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006358
Johannes Berg97990a02013-04-19 01:02:55 +02006359 cb->args[2] = idx;
6360 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006361
Johannes Berg67748892010-10-04 21:14:06 +02006362 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006363}
6364
Eric W. Biederman15e47302012-09-07 20:12:54 +00006365static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006366 int flags, struct net_device *dev,
6367 struct survey_info *survey)
6368{
6369 void *hdr;
6370 struct nlattr *infoattr;
6371
Eric W. Biederman15e47302012-09-07 20:12:54 +00006372 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006373 NL80211_CMD_NEW_SURVEY_RESULTS);
6374 if (!hdr)
6375 return -ENOMEM;
6376
David S. Miller9360ffd2012-03-29 04:41:26 -04006377 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6378 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006379
6380 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6381 if (!infoattr)
6382 goto nla_put_failure;
6383
David S. Miller9360ffd2012-03-29 04:41:26 -04006384 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6385 survey->channel->center_freq))
6386 goto nla_put_failure;
6387
6388 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6389 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6390 goto nla_put_failure;
6391 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6392 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6393 goto nla_put_failure;
6394 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6395 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6396 survey->channel_time))
6397 goto nla_put_failure;
6398 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6399 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6400 survey->channel_time_busy))
6401 goto nla_put_failure;
6402 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6403 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6404 survey->channel_time_ext_busy))
6405 goto nla_put_failure;
6406 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6407 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6408 survey->channel_time_rx))
6409 goto nla_put_failure;
6410 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6411 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6412 survey->channel_time_tx))
6413 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006414
6415 nla_nest_end(msg, infoattr);
6416
6417 return genlmsg_end(msg, hdr);
6418
6419 nla_put_failure:
6420 genlmsg_cancel(msg, hdr);
6421 return -EMSGSIZE;
6422}
6423
6424static int nl80211_dump_survey(struct sk_buff *skb,
6425 struct netlink_callback *cb)
6426{
6427 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006428 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006429 struct wireless_dev *wdev;
6430 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006431 int res;
6432
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006433 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006434 if (res)
6435 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006436
Johannes Berg97990a02013-04-19 01:02:55 +02006437 if (!wdev->netdev) {
6438 res = -EINVAL;
6439 goto out_err;
6440 }
6441
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006442 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006443 res = -EOPNOTSUPP;
6444 goto out_err;
6445 }
6446
6447 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006448 struct ieee80211_channel *chan;
6449
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006450 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006451 if (res == -ENOENT)
6452 break;
6453 if (res)
6454 goto out_err;
6455
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006456 /* Survey without a channel doesn't make sense */
6457 if (!survey.channel) {
6458 res = -EINVAL;
6459 goto out;
6460 }
6461
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006462 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006463 survey.channel->center_freq);
6464 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6465 survey_idx++;
6466 continue;
6467 }
6468
Holger Schurig61fa7132009-11-11 12:25:40 +01006469 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006470 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006471 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006472 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006473 goto out;
6474 survey_idx++;
6475 }
6476
6477 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006478 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006479 res = skb->len;
6480 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006481 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006482 return res;
6483}
6484
Samuel Ortizb23aa672009-07-01 21:26:54 +02006485static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6486{
6487 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6488 NL80211_WPA_VERSION_2));
6489}
6490
Jouni Malinen636a5d32009-03-19 13:39:22 +02006491static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6492{
Johannes Berg4c476992010-10-04 21:36:35 +02006493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6494 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006495 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006496 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6497 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006498 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006499 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006500 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006501
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006502 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6503 return -EINVAL;
6504
6505 if (!info->attrs[NL80211_ATTR_MAC])
6506 return -EINVAL;
6507
Jouni Malinen17780922009-03-27 20:52:47 +02006508 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6509 return -EINVAL;
6510
Johannes Berg19957bb2009-07-02 17:20:43 +02006511 if (!info->attrs[NL80211_ATTR_SSID])
6512 return -EINVAL;
6513
6514 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6515 return -EINVAL;
6516
Johannes Bergfffd0932009-07-08 14:22:54 +02006517 err = nl80211_parse_key(info, &key);
6518 if (err)
6519 return err;
6520
6521 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006522 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6523 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006524 if (!key.p.key || !key.p.key_len)
6525 return -EINVAL;
6526 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6527 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6528 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6529 key.p.key_len != WLAN_KEY_LEN_WEP104))
6530 return -EINVAL;
6531 if (key.idx > 4)
6532 return -EINVAL;
6533 } else {
6534 key.p.key_len = 0;
6535 key.p.key = NULL;
6536 }
6537
Johannes Bergafea0b72010-08-10 09:46:42 +02006538 if (key.idx >= 0) {
6539 int i;
6540 bool ok = false;
6541 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6542 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6543 ok = true;
6544 break;
6545 }
6546 }
Johannes Berg4c476992010-10-04 21:36:35 +02006547 if (!ok)
6548 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006549 }
6550
Johannes Berg4c476992010-10-04 21:36:35 +02006551 if (!rdev->ops->auth)
6552 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006553
Johannes Berg074ac8d2010-09-16 14:58:22 +02006554 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006555 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6556 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006557
Johannes Berg19957bb2009-07-02 17:20:43 +02006558 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006559 chan = nl80211_get_valid_chan(&rdev->wiphy,
6560 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6561 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006562 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006563
Johannes Berg19957bb2009-07-02 17:20:43 +02006564 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6565 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6566
6567 if (info->attrs[NL80211_ATTR_IE]) {
6568 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6569 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6570 }
6571
6572 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006573 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006574 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006575
Jouni Malinene39e5b52012-09-30 19:29:39 +03006576 if (auth_type == NL80211_AUTHTYPE_SAE &&
6577 !info->attrs[NL80211_ATTR_SAE_DATA])
6578 return -EINVAL;
6579
6580 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6581 if (auth_type != NL80211_AUTHTYPE_SAE)
6582 return -EINVAL;
6583 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6584 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6585 /* need to include at least Auth Transaction and Status Code */
6586 if (sae_data_len < 4)
6587 return -EINVAL;
6588 }
6589
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006590 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6591
Johannes Berg95de8172012-01-20 13:55:25 +01006592 /*
6593 * Since we no longer track auth state, ignore
6594 * requests to only change local state.
6595 */
6596 if (local_state_change)
6597 return 0;
6598
Johannes Berg91bf9b22013-05-15 17:44:01 +02006599 wdev_lock(dev->ieee80211_ptr);
6600 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6601 ssid, ssid_len, ie, ie_len,
6602 key.p.key, key.p.key_len, key.idx,
6603 sae_data, sae_data_len);
6604 wdev_unlock(dev->ieee80211_ptr);
6605 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006606}
6607
Johannes Bergc0692b82010-08-27 14:26:53 +03006608static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6609 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006610 struct cfg80211_crypto_settings *settings,
6611 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006612{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006613 memset(settings, 0, sizeof(*settings));
6614
Samuel Ortizb23aa672009-07-01 21:26:54 +02006615 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6616
Johannes Bergc0692b82010-08-27 14:26:53 +03006617 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6618 u16 proto;
6619 proto = nla_get_u16(
6620 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6621 settings->control_port_ethertype = cpu_to_be16(proto);
6622 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6623 proto != ETH_P_PAE)
6624 return -EINVAL;
6625 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6626 settings->control_port_no_encrypt = true;
6627 } else
6628 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6629
Samuel Ortizb23aa672009-07-01 21:26:54 +02006630 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6631 void *data;
6632 int len, i;
6633
6634 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6635 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6636 settings->n_ciphers_pairwise = len / sizeof(u32);
6637
6638 if (len % sizeof(u32))
6639 return -EINVAL;
6640
Johannes Berg3dc27d22009-07-02 21:36:37 +02006641 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006642 return -EINVAL;
6643
6644 memcpy(settings->ciphers_pairwise, data, len);
6645
6646 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006647 if (!cfg80211_supported_cipher_suite(
6648 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006649 settings->ciphers_pairwise[i]))
6650 return -EINVAL;
6651 }
6652
6653 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6654 settings->cipher_group =
6655 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006656 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6657 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006658 return -EINVAL;
6659 }
6660
6661 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6662 settings->wpa_versions =
6663 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6664 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6665 return -EINVAL;
6666 }
6667
6668 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6669 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006670 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006671
6672 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6673 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6674 settings->n_akm_suites = len / sizeof(u32);
6675
6676 if (len % sizeof(u32))
6677 return -EINVAL;
6678
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006679 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6680 return -EINVAL;
6681
Samuel Ortizb23aa672009-07-01 21:26:54 +02006682 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006683 }
6684
6685 return 0;
6686}
6687
Jouni Malinen636a5d32009-03-19 13:39:22 +02006688static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6689{
Johannes Berg4c476992010-10-04 21:36:35 +02006690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6691 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006692 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006693 struct cfg80211_assoc_request req = {};
6694 const u8 *bssid, *ssid;
6695 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006696
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006697 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6698 return -EINVAL;
6699
6700 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006701 !info->attrs[NL80211_ATTR_SSID] ||
6702 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006703 return -EINVAL;
6704
Johannes Berg4c476992010-10-04 21:36:35 +02006705 if (!rdev->ops->assoc)
6706 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006707
Johannes Berg074ac8d2010-09-16 14:58:22 +02006708 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006709 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6710 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006711
Johannes Berg19957bb2009-07-02 17:20:43 +02006712 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006713
Jouni Malinen664834d2014-01-15 00:01:44 +02006714 chan = nl80211_get_valid_chan(&rdev->wiphy,
6715 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6716 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006717 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006718
Johannes Berg19957bb2009-07-02 17:20:43 +02006719 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6720 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006721
6722 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006723 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6724 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006725 }
6726
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006727 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006728 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006729 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006730 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006731 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006732 else if (mfp != NL80211_MFP_NO)
6733 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006734 }
6735
Johannes Berg3e5d7642009-07-07 14:37:26 +02006736 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006737 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006738
Ben Greear7e7c8922011-11-18 11:31:59 -08006739 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006740 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006741
6742 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006743 memcpy(&req.ht_capa_mask,
6744 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6745 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006746
6747 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006748 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006749 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006750 memcpy(&req.ht_capa,
6751 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6752 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006753 }
6754
Johannes Bergee2aca32013-02-21 17:36:01 +01006755 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006756 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006757
6758 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006759 memcpy(&req.vht_capa_mask,
6760 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6761 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006762
6763 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006764 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006765 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006766 memcpy(&req.vht_capa,
6767 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6768 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006769 }
6770
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006771 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6772 if (!(rdev->wiphy.features &
6773 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6774 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6775 return -EINVAL;
6776 req.flags |= ASSOC_REQ_USE_RRM;
6777 }
6778
Johannes Bergf62fab72013-02-21 20:09:09 +01006779 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006780 if (!err) {
6781 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006782 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6783 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006784 wdev_unlock(dev->ieee80211_ptr);
6785 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006786
Jouni Malinen636a5d32009-03-19 13:39:22 +02006787 return err;
6788}
6789
6790static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6791{
Johannes Berg4c476992010-10-04 21:36:35 +02006792 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6793 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006794 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006795 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006796 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006797 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006798
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006799 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6800 return -EINVAL;
6801
6802 if (!info->attrs[NL80211_ATTR_MAC])
6803 return -EINVAL;
6804
6805 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6806 return -EINVAL;
6807
Johannes Berg4c476992010-10-04 21:36:35 +02006808 if (!rdev->ops->deauth)
6809 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006810
Johannes Berg074ac8d2010-09-16 14:58:22 +02006811 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006812 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6813 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006814
Johannes Berg19957bb2009-07-02 17:20:43 +02006815 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006816
Johannes Berg19957bb2009-07-02 17:20:43 +02006817 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6818 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006819 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006820 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006821 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006822
6823 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006824 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6825 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006826 }
6827
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006828 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6829
Johannes Berg91bf9b22013-05-15 17:44:01 +02006830 wdev_lock(dev->ieee80211_ptr);
6831 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6832 local_state_change);
6833 wdev_unlock(dev->ieee80211_ptr);
6834 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006835}
6836
6837static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6838{
Johannes Berg4c476992010-10-04 21:36:35 +02006839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6840 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006841 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006842 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006843 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006844 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006845
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006846 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6847 return -EINVAL;
6848
6849 if (!info->attrs[NL80211_ATTR_MAC])
6850 return -EINVAL;
6851
6852 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6853 return -EINVAL;
6854
Johannes Berg4c476992010-10-04 21:36:35 +02006855 if (!rdev->ops->disassoc)
6856 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006857
Johannes Berg074ac8d2010-09-16 14:58:22 +02006858 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006859 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6860 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006861
Johannes Berg19957bb2009-07-02 17:20:43 +02006862 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006863
Johannes Berg19957bb2009-07-02 17:20:43 +02006864 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6865 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006866 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006867 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006868 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006869
6870 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006871 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6872 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006873 }
6874
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006875 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6876
Johannes Berg91bf9b22013-05-15 17:44:01 +02006877 wdev_lock(dev->ieee80211_ptr);
6878 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6879 local_state_change);
6880 wdev_unlock(dev->ieee80211_ptr);
6881 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006882}
6883
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006884static bool
6885nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6886 int mcast_rate[IEEE80211_NUM_BANDS],
6887 int rateval)
6888{
6889 struct wiphy *wiphy = &rdev->wiphy;
6890 bool found = false;
6891 int band, i;
6892
6893 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6894 struct ieee80211_supported_band *sband;
6895
6896 sband = wiphy->bands[band];
6897 if (!sband)
6898 continue;
6899
6900 for (i = 0; i < sband->n_bitrates; i++) {
6901 if (sband->bitrates[i].bitrate == rateval) {
6902 mcast_rate[band] = i + 1;
6903 found = true;
6904 break;
6905 }
6906 }
6907 }
6908
6909 return found;
6910}
6911
Johannes Berg04a773a2009-04-19 21:24:32 +02006912static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6913{
Johannes Berg4c476992010-10-04 21:36:35 +02006914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6915 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006916 struct cfg80211_ibss_params ibss;
6917 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006918 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006919 int err;
6920
Johannes Berg8e30bc52009-04-22 17:45:38 +02006921 memset(&ibss, 0, sizeof(ibss));
6922
Johannes Berg04a773a2009-04-19 21:24:32 +02006923 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6924 return -EINVAL;
6925
Johannes Berg683b6d32012-11-08 21:25:48 +01006926 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006927 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6928 return -EINVAL;
6929
Johannes Berg8e30bc52009-04-22 17:45:38 +02006930 ibss.beacon_interval = 100;
6931
6932 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6933 ibss.beacon_interval =
6934 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6935 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6936 return -EINVAL;
6937 }
6938
Johannes Berg4c476992010-10-04 21:36:35 +02006939 if (!rdev->ops->join_ibss)
6940 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006941
Johannes Berg4c476992010-10-04 21:36:35 +02006942 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6943 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006944
Johannes Berg79c97e92009-07-07 03:56:12 +02006945 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006946
Johannes Berg39193492011-09-16 13:45:25 +02006947 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006948 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006949
6950 if (!is_valid_ether_addr(ibss.bssid))
6951 return -EINVAL;
6952 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006953 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6954 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6955
6956 if (info->attrs[NL80211_ATTR_IE]) {
6957 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6958 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6959 }
6960
Johannes Berg683b6d32012-11-08 21:25:48 +01006961 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6962 if (err)
6963 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006964
Ilan Peer174e0cd2014-02-23 09:13:01 +02006965 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6966 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006967 return -EINVAL;
6968
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006969 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006970 case NL80211_CHAN_WIDTH_5:
6971 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006972 case NL80211_CHAN_WIDTH_20_NOHT:
6973 break;
6974 case NL80211_CHAN_WIDTH_20:
6975 case NL80211_CHAN_WIDTH_40:
6976 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6977 break;
6978 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006979 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006980 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006981
Johannes Berg04a773a2009-04-19 21:24:32 +02006982 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006983 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006984
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006985 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6986 u8 *rates =
6987 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6988 int n_rates =
6989 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6990 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006991 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006992
Johannes Berg34850ab2011-07-18 18:08:35 +02006993 err = ieee80211_get_ratemask(sband, rates, n_rates,
6994 &ibss.basic_rates);
6995 if (err)
6996 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006997 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006998
Simon Wunderlich803768f2013-06-28 10:39:58 +02006999 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7000 memcpy(&ibss.ht_capa_mask,
7001 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7002 sizeof(ibss.ht_capa_mask));
7003
7004 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7005 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7006 return -EINVAL;
7007 memcpy(&ibss.ht_capa,
7008 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7009 sizeof(ibss.ht_capa));
7010 }
7011
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007012 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7013 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7014 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7015 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007016
Johannes Berg4c476992010-10-04 21:36:35 +02007017 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307018 bool no_ht = false;
7019
Johannes Berg4c476992010-10-04 21:36:35 +02007020 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307021 info->attrs[NL80211_ATTR_KEYS],
7022 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007023 if (IS_ERR(connkeys))
7024 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307025
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007026 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7027 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307028 kfree(connkeys);
7029 return -EINVAL;
7030 }
Johannes Berg4c476992010-10-04 21:36:35 +02007031 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007032
Antonio Quartulli267335d2012-01-31 20:25:47 +01007033 ibss.control_port =
7034 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7035
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007036 ibss.userspace_handles_dfs =
7037 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7038
Johannes Berg4c476992010-10-04 21:36:35 +02007039 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007040 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007041 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007042 return err;
7043}
7044
7045static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7046{
Johannes Berg4c476992010-10-04 21:36:35 +02007047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7048 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007049
Johannes Berg4c476992010-10-04 21:36:35 +02007050 if (!rdev->ops->leave_ibss)
7051 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007052
Johannes Berg4c476992010-10-04 21:36:35 +02007053 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7054 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007055
Johannes Berg4c476992010-10-04 21:36:35 +02007056 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007057}
7058
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007059static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7060{
7061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7062 struct net_device *dev = info->user_ptr[1];
7063 int mcast_rate[IEEE80211_NUM_BANDS];
7064 u32 nla_rate;
7065 int err;
7066
7067 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7068 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7069 return -EOPNOTSUPP;
7070
7071 if (!rdev->ops->set_mcast_rate)
7072 return -EOPNOTSUPP;
7073
7074 memset(mcast_rate, 0, sizeof(mcast_rate));
7075
7076 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7077 return -EINVAL;
7078
7079 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7080 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7081 return -EINVAL;
7082
7083 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7084
7085 return err;
7086}
7087
Johannes Bergad7e7182013-11-13 13:37:47 +01007088static struct sk_buff *
7089__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7090 int approxlen, u32 portid, u32 seq,
7091 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007092 enum nl80211_attrs attr,
7093 const struct nl80211_vendor_cmd_info *info,
7094 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007095{
7096 struct sk_buff *skb;
7097 void *hdr;
7098 struct nlattr *data;
7099
7100 skb = nlmsg_new(approxlen + 100, gfp);
7101 if (!skb)
7102 return NULL;
7103
7104 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7105 if (!hdr) {
7106 kfree_skb(skb);
7107 return NULL;
7108 }
7109
7110 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7111 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007112
7113 if (info) {
7114 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7115 info->vendor_id))
7116 goto nla_put_failure;
7117 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7118 info->subcmd))
7119 goto nla_put_failure;
7120 }
7121
Johannes Bergad7e7182013-11-13 13:37:47 +01007122 data = nla_nest_start(skb, attr);
7123
7124 ((void **)skb->cb)[0] = rdev;
7125 ((void **)skb->cb)[1] = hdr;
7126 ((void **)skb->cb)[2] = data;
7127
7128 return skb;
7129
7130 nla_put_failure:
7131 kfree_skb(skb);
7132 return NULL;
7133}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007134
Johannes Berge03ad6e2014-01-01 17:22:30 +01007135struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7136 enum nl80211_commands cmd,
7137 enum nl80211_attrs attr,
7138 int vendor_event_idx,
7139 int approxlen, gfp_t gfp)
7140{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007141 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007142 const struct nl80211_vendor_cmd_info *info;
7143
7144 switch (cmd) {
7145 case NL80211_CMD_TESTMODE:
7146 if (WARN_ON(vendor_event_idx != -1))
7147 return NULL;
7148 info = NULL;
7149 break;
7150 case NL80211_CMD_VENDOR:
7151 if (WARN_ON(vendor_event_idx < 0 ||
7152 vendor_event_idx >= wiphy->n_vendor_events))
7153 return NULL;
7154 info = &wiphy->vendor_events[vendor_event_idx];
7155 break;
7156 default:
7157 WARN_ON(1);
7158 return NULL;
7159 }
7160
7161 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7162 cmd, attr, info, gfp);
7163}
7164EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7165
7166void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7167{
7168 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7169 void *hdr = ((void **)skb->cb)[1];
7170 struct nlattr *data = ((void **)skb->cb)[2];
7171 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7172
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007173 /* clear CB data for netlink core to own from now on */
7174 memset(skb->cb, 0, sizeof(skb->cb));
7175
Johannes Berge03ad6e2014-01-01 17:22:30 +01007176 nla_nest_end(skb, data);
7177 genlmsg_end(skb, hdr);
7178
7179 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7180 mcgrp = NL80211_MCGRP_VENDOR;
7181
7182 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7183 mcgrp, gfp);
7184}
7185EXPORT_SYMBOL(__cfg80211_send_event_skb);
7186
Johannes Bergaff89a92009-07-01 21:26:51 +02007187#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007188static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7189{
Johannes Berg4c476992010-10-04 21:36:35 +02007190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007191 struct wireless_dev *wdev =
7192 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007193 int err;
7194
David Spinadelfc73f112013-07-31 18:04:15 +03007195 if (!rdev->ops->testmode_cmd)
7196 return -EOPNOTSUPP;
7197
7198 if (IS_ERR(wdev)) {
7199 err = PTR_ERR(wdev);
7200 if (err != -EINVAL)
7201 return err;
7202 wdev = NULL;
7203 } else if (wdev->wiphy != &rdev->wiphy) {
7204 return -EINVAL;
7205 }
7206
Johannes Bergaff89a92009-07-01 21:26:51 +02007207 if (!info->attrs[NL80211_ATTR_TESTDATA])
7208 return -EINVAL;
7209
Johannes Bergad7e7182013-11-13 13:37:47 +01007210 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007211 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007212 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7213 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007214 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007215
Johannes Bergaff89a92009-07-01 21:26:51 +02007216 return err;
7217}
7218
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007219static int nl80211_testmode_dump(struct sk_buff *skb,
7220 struct netlink_callback *cb)
7221{
Johannes Berg00918d32011-12-13 17:22:05 +01007222 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007223 int err;
7224 long phy_idx;
7225 void *data = NULL;
7226 int data_len = 0;
7227
Johannes Berg5fe231e2013-05-08 21:45:15 +02007228 rtnl_lock();
7229
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007230 if (cb->args[0]) {
7231 /*
7232 * 0 is a valid index, but not valid for args[0],
7233 * so we need to offset by 1.
7234 */
7235 phy_idx = cb->args[0] - 1;
7236 } else {
7237 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7238 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7239 nl80211_policy);
7240 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007241 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007242
Johannes Berg2bd7e352012-06-15 14:23:16 +02007243 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7244 nl80211_fam.attrbuf);
7245 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007246 err = PTR_ERR(rdev);
7247 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007248 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007249 phy_idx = rdev->wiphy_idx;
7250 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007251
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007252 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7253 cb->args[1] =
7254 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7255 }
7256
7257 if (cb->args[1]) {
7258 data = nla_data((void *)cb->args[1]);
7259 data_len = nla_len((void *)cb->args[1]);
7260 }
7261
Johannes Berg00918d32011-12-13 17:22:05 +01007262 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7263 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007264 err = -ENOENT;
7265 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007266 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007267
Johannes Berg00918d32011-12-13 17:22:05 +01007268 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007269 err = -EOPNOTSUPP;
7270 goto out_err;
7271 }
7272
7273 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007274 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007275 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7276 NL80211_CMD_TESTMODE);
7277 struct nlattr *tmdata;
7278
Dan Carpentercb35fba2013-08-14 14:50:01 +03007279 if (!hdr)
7280 break;
7281
David S. Miller9360ffd2012-03-29 04:41:26 -04007282 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007283 genlmsg_cancel(skb, hdr);
7284 break;
7285 }
7286
7287 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7288 if (!tmdata) {
7289 genlmsg_cancel(skb, hdr);
7290 break;
7291 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007292 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007293 nla_nest_end(skb, tmdata);
7294
7295 if (err == -ENOBUFS || err == -ENOENT) {
7296 genlmsg_cancel(skb, hdr);
7297 break;
7298 } else if (err) {
7299 genlmsg_cancel(skb, hdr);
7300 goto out_err;
7301 }
7302
7303 genlmsg_end(skb, hdr);
7304 }
7305
7306 err = skb->len;
7307 /* see above */
7308 cb->args[0] = phy_idx + 1;
7309 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007310 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007311 return err;
7312}
Johannes Bergaff89a92009-07-01 21:26:51 +02007313#endif
7314
Samuel Ortizb23aa672009-07-01 21:26:54 +02007315static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7316{
Johannes Berg4c476992010-10-04 21:36:35 +02007317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7318 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007319 struct cfg80211_connect_params connect;
7320 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007321 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007322 int err;
7323
7324 memset(&connect, 0, sizeof(connect));
7325
7326 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7327 return -EINVAL;
7328
7329 if (!info->attrs[NL80211_ATTR_SSID] ||
7330 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7331 return -EINVAL;
7332
7333 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7334 connect.auth_type =
7335 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007336 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7337 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007338 return -EINVAL;
7339 } else
7340 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7341
7342 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7343
Johannes Bergc0692b82010-08-27 14:26:53 +03007344 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007345 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007346 if (err)
7347 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007348
Johannes Berg074ac8d2010-09-16 14:58:22 +02007349 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007350 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7351 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007352
Johannes Berg79c97e92009-07-07 03:56:12 +02007353 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007354
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307355 connect.bg_scan_period = -1;
7356 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7357 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7358 connect.bg_scan_period =
7359 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7360 }
7361
Samuel Ortizb23aa672009-07-01 21:26:54 +02007362 if (info->attrs[NL80211_ATTR_MAC])
7363 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007364 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7365 connect.bssid_hint =
7366 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007367 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7368 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7369
7370 if (info->attrs[NL80211_ATTR_IE]) {
7371 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7372 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7373 }
7374
Jouni Malinencee00a92013-01-15 17:15:57 +02007375 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7376 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7377 if (connect.mfp != NL80211_MFP_REQUIRED &&
7378 connect.mfp != NL80211_MFP_NO)
7379 return -EINVAL;
7380 } else {
7381 connect.mfp = NL80211_MFP_NO;
7382 }
7383
Samuel Ortizb23aa672009-07-01 21:26:54 +02007384 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007385 connect.channel = nl80211_get_valid_chan(
7386 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7387 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007388 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007389 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007390 connect.channel_hint = nl80211_get_valid_chan(
7391 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7392 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007393 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007394 }
7395
Johannes Bergfffd0932009-07-08 14:22:54 +02007396 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7397 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307398 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007399 if (IS_ERR(connkeys))
7400 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007401 }
7402
Ben Greear7e7c8922011-11-18 11:31:59 -08007403 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7404 connect.flags |= ASSOC_REQ_DISABLE_HT;
7405
7406 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7407 memcpy(&connect.ht_capa_mask,
7408 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7409 sizeof(connect.ht_capa_mask));
7410
7411 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007412 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007413 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007414 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007415 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007416 memcpy(&connect.ht_capa,
7417 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7418 sizeof(connect.ht_capa));
7419 }
7420
Johannes Bergee2aca32013-02-21 17:36:01 +01007421 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7422 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7423
7424 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7425 memcpy(&connect.vht_capa_mask,
7426 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7427 sizeof(connect.vht_capa_mask));
7428
7429 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7430 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007431 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007432 return -EINVAL;
7433 }
7434 memcpy(&connect.vht_capa,
7435 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7436 sizeof(connect.vht_capa));
7437 }
7438
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007439 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7440 if (!(rdev->wiphy.features &
7441 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7442 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7443 return -EINVAL;
7444 connect.flags |= ASSOC_REQ_USE_RRM;
7445 }
7446
Johannes Berg83739b02013-05-15 17:44:01 +02007447 wdev_lock(dev->ieee80211_ptr);
7448 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7449 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007450 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007451 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007452 return err;
7453}
7454
7455static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7456{
Johannes Berg4c476992010-10-04 21:36:35 +02007457 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7458 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007459 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007460 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007461
7462 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7463 reason = WLAN_REASON_DEAUTH_LEAVING;
7464 else
7465 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7466
7467 if (reason == 0)
7468 return -EINVAL;
7469
Johannes Berg074ac8d2010-09-16 14:58:22 +02007470 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007471 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7472 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007473
Johannes Berg83739b02013-05-15 17:44:01 +02007474 wdev_lock(dev->ieee80211_ptr);
7475 ret = cfg80211_disconnect(rdev, dev, reason, true);
7476 wdev_unlock(dev->ieee80211_ptr);
7477 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007478}
7479
Johannes Berg463d0182009-07-14 00:33:35 +02007480static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7481{
Johannes Berg4c476992010-10-04 21:36:35 +02007482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007483 struct net *net;
7484 int err;
7485 u32 pid;
7486
7487 if (!info->attrs[NL80211_ATTR_PID])
7488 return -EINVAL;
7489
7490 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7491
Johannes Berg463d0182009-07-14 00:33:35 +02007492 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007493 if (IS_ERR(net))
7494 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007495
7496 err = 0;
7497
7498 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007499 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7500 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007501
Johannes Berg463d0182009-07-14 00:33:35 +02007502 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007503 return err;
7504}
7505
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007506static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7507{
Johannes Berg4c476992010-10-04 21:36:35 +02007508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007509 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7510 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007511 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007512 struct cfg80211_pmksa pmksa;
7513
7514 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7515
7516 if (!info->attrs[NL80211_ATTR_MAC])
7517 return -EINVAL;
7518
7519 if (!info->attrs[NL80211_ATTR_PMKID])
7520 return -EINVAL;
7521
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007522 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7523 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7524
Johannes Berg074ac8d2010-09-16 14:58:22 +02007525 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007526 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7527 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007528
7529 switch (info->genlhdr->cmd) {
7530 case NL80211_CMD_SET_PMKSA:
7531 rdev_ops = rdev->ops->set_pmksa;
7532 break;
7533 case NL80211_CMD_DEL_PMKSA:
7534 rdev_ops = rdev->ops->del_pmksa;
7535 break;
7536 default:
7537 WARN_ON(1);
7538 break;
7539 }
7540
Johannes Berg4c476992010-10-04 21:36:35 +02007541 if (!rdev_ops)
7542 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007543
Johannes Berg4c476992010-10-04 21:36:35 +02007544 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007545}
7546
7547static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7548{
Johannes Berg4c476992010-10-04 21:36:35 +02007549 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7550 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007551
Johannes Berg074ac8d2010-09-16 14:58:22 +02007552 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007553 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7554 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007555
Johannes Berg4c476992010-10-04 21:36:35 +02007556 if (!rdev->ops->flush_pmksa)
7557 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007558
Hila Gonene35e4d22012-06-27 17:19:42 +03007559 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007560}
7561
Arik Nemtsov109086c2011-09-28 14:12:50 +03007562static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7563{
7564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7565 struct net_device *dev = info->user_ptr[1];
7566 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307567 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007568 u16 status_code;
7569 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007570 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007571
7572 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7573 !rdev->ops->tdls_mgmt)
7574 return -EOPNOTSUPP;
7575
7576 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7577 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7578 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7579 !info->attrs[NL80211_ATTR_IE] ||
7580 !info->attrs[NL80211_ATTR_MAC])
7581 return -EINVAL;
7582
7583 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7584 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7585 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7586 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007587 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307588 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7589 peer_capability =
7590 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007591
Hila Gonene35e4d22012-06-27 17:19:42 +03007592 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307593 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007594 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007595 nla_data(info->attrs[NL80211_ATTR_IE]),
7596 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007597}
7598
7599static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7600{
7601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7602 struct net_device *dev = info->user_ptr[1];
7603 enum nl80211_tdls_operation operation;
7604 u8 *peer;
7605
7606 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7607 !rdev->ops->tdls_oper)
7608 return -EOPNOTSUPP;
7609
7610 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7611 !info->attrs[NL80211_ATTR_MAC])
7612 return -EINVAL;
7613
7614 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7615 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7616
Hila Gonene35e4d22012-06-27 17:19:42 +03007617 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007618}
7619
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007620static int nl80211_remain_on_channel(struct sk_buff *skb,
7621 struct genl_info *info)
7622{
Johannes Berg4c476992010-10-04 21:36:35 +02007623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007624 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007625 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007626 struct sk_buff *msg;
7627 void *hdr;
7628 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007629 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007630 int err;
7631
7632 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7633 !info->attrs[NL80211_ATTR_DURATION])
7634 return -EINVAL;
7635
7636 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7637
Johannes Berg7c4ef712011-11-18 15:33:48 +01007638 if (!rdev->ops->remain_on_channel ||
7639 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007640 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007641
Johannes Bergebf348f2012-06-01 12:50:54 +02007642 /*
7643 * We should be on that channel for at least a minimum amount of
7644 * time (10ms) but no longer than the driver supports.
7645 */
7646 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7647 duration > rdev->wiphy.max_remain_on_channel_duration)
7648 return -EINVAL;
7649
Johannes Berg683b6d32012-11-08 21:25:48 +01007650 err = nl80211_parse_chandef(rdev, info, &chandef);
7651 if (err)
7652 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007653
7654 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007655 if (!msg)
7656 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007657
Eric W. Biederman15e47302012-09-07 20:12:54 +00007658 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007659 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007660 if (!hdr) {
7661 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007662 goto free_msg;
7663 }
7664
Johannes Berg683b6d32012-11-08 21:25:48 +01007665 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7666 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007667
7668 if (err)
7669 goto free_msg;
7670
David S. Miller9360ffd2012-03-29 04:41:26 -04007671 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7672 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007673
7674 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007675
7676 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007677
7678 nla_put_failure:
7679 err = -ENOBUFS;
7680 free_msg:
7681 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007682 return err;
7683}
7684
7685static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7686 struct genl_info *info)
7687{
Johannes Berg4c476992010-10-04 21:36:35 +02007688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007689 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007690 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007691
7692 if (!info->attrs[NL80211_ATTR_COOKIE])
7693 return -EINVAL;
7694
Johannes Berg4c476992010-10-04 21:36:35 +02007695 if (!rdev->ops->cancel_remain_on_channel)
7696 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007697
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007698 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7699
Hila Gonene35e4d22012-06-27 17:19:42 +03007700 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007701}
7702
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007703static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7704 u8 *rates, u8 rates_len)
7705{
7706 u8 i;
7707 u32 mask = 0;
7708
7709 for (i = 0; i < rates_len; i++) {
7710 int rate = (rates[i] & 0x7f) * 5;
7711 int ridx;
7712 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7713 struct ieee80211_rate *srate =
7714 &sband->bitrates[ridx];
7715 if (rate == srate->bitrate) {
7716 mask |= 1 << ridx;
7717 break;
7718 }
7719 }
7720 if (ridx == sband->n_bitrates)
7721 return 0; /* rate not found */
7722 }
7723
7724 return mask;
7725}
7726
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007727static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7728 u8 *rates, u8 rates_len,
7729 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7730{
7731 u8 i;
7732
7733 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7734
7735 for (i = 0; i < rates_len; i++) {
7736 int ridx, rbit;
7737
7738 ridx = rates[i] / 8;
7739 rbit = BIT(rates[i] % 8);
7740
7741 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007742 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007743 return false;
7744
7745 /* check availability */
7746 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7747 mcs[ridx] |= rbit;
7748 else
7749 return false;
7750 }
7751
7752 return true;
7753}
7754
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007755static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7756{
7757 u16 mcs_mask = 0;
7758
7759 switch (vht_mcs_map) {
7760 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7761 break;
7762 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7763 mcs_mask = 0x00FF;
7764 break;
7765 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7766 mcs_mask = 0x01FF;
7767 break;
7768 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7769 mcs_mask = 0x03FF;
7770 break;
7771 default:
7772 break;
7773 }
7774
7775 return mcs_mask;
7776}
7777
7778static void vht_build_mcs_mask(u16 vht_mcs_map,
7779 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7780{
7781 u8 nss;
7782
7783 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7784 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7785 vht_mcs_map >>= 2;
7786 }
7787}
7788
7789static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7790 struct nl80211_txrate_vht *txrate,
7791 u16 mcs[NL80211_VHT_NSS_MAX])
7792{
7793 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7794 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7795 u8 i;
7796
7797 if (!sband->vht_cap.vht_supported)
7798 return false;
7799
7800 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7801
7802 /* Build vht_mcs_mask from VHT capabilities */
7803 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7804
7805 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7806 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7807 mcs[i] = txrate->mcs[i];
7808 else
7809 return false;
7810 }
7811
7812 return true;
7813}
7814
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007815static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007816 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7817 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007818 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7819 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007820 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007821 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007822};
7823
7824static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7825 struct genl_info *info)
7826{
7827 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007829 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007830 int rem, i;
7831 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007832 struct nlattr *tx_rates;
7833 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007834 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007835
Johannes Berg4c476992010-10-04 21:36:35 +02007836 if (!rdev->ops->set_bitrate_mask)
7837 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007838
7839 memset(&mask, 0, sizeof(mask));
7840 /* Default to all rates enabled */
7841 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7842 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007843
7844 if (!sband)
7845 continue;
7846
7847 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007848 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007849 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007850 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007851
7852 if (!sband->vht_cap.vht_supported)
7853 continue;
7854
7855 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7856 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007857 }
7858
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007859 /* if no rates are given set it back to the defaults */
7860 if (!info->attrs[NL80211_ATTR_TX_RATES])
7861 goto out;
7862
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007863 /*
7864 * The nested attribute uses enum nl80211_band as the index. This maps
7865 * directly to the enum ieee80211_band values used in cfg80211.
7866 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007867 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007868 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007869 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007870 int err;
7871
Johannes Berg4c476992010-10-04 21:36:35 +02007872 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7873 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007874 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007875 if (sband == NULL)
7876 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007877 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7878 nla_len(tx_rates), nl80211_txattr_policy);
7879 if (err)
7880 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007881 if (tb[NL80211_TXRATE_LEGACY]) {
7882 mask.control[band].legacy = rateset_to_mask(
7883 sband,
7884 nla_data(tb[NL80211_TXRATE_LEGACY]),
7885 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307886 if ((mask.control[band].legacy == 0) &&
7887 nla_len(tb[NL80211_TXRATE_LEGACY]))
7888 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007889 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007890 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007891 if (!ht_rateset_to_mask(
7892 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007893 nla_data(tb[NL80211_TXRATE_HT]),
7894 nla_len(tb[NL80211_TXRATE_HT]),
7895 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007896 return -EINVAL;
7897 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007898 if (tb[NL80211_TXRATE_VHT]) {
7899 if (!vht_set_mcs_mask(
7900 sband,
7901 nla_data(tb[NL80211_TXRATE_VHT]),
7902 mask.control[band].vht_mcs))
7903 return -EINVAL;
7904 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007905 if (tb[NL80211_TXRATE_GI]) {
7906 mask.control[band].gi =
7907 nla_get_u8(tb[NL80211_TXRATE_GI]);
7908 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7909 return -EINVAL;
7910 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007911
7912 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007913 /* don't allow empty legacy rates if HT or VHT
7914 * are not even supported.
7915 */
7916 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7917 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007918 return -EINVAL;
7919
7920 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007921 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007922 goto out;
7923
7924 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7925 if (mask.control[band].vht_mcs[i])
7926 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007927
7928 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007929 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007930 }
7931 }
7932
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007933out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007934 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007935}
7936
Johannes Berg2e161f72010-08-12 15:38:38 +02007937static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007938{
Johannes Berg4c476992010-10-04 21:36:35 +02007939 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007940 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007941 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007942
7943 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7944 return -EINVAL;
7945
Johannes Berg2e161f72010-08-12 15:38:38 +02007946 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7947 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007948
Johannes Berg71bbc992012-06-15 15:30:18 +02007949 switch (wdev->iftype) {
7950 case NL80211_IFTYPE_STATION:
7951 case NL80211_IFTYPE_ADHOC:
7952 case NL80211_IFTYPE_P2P_CLIENT:
7953 case NL80211_IFTYPE_AP:
7954 case NL80211_IFTYPE_AP_VLAN:
7955 case NL80211_IFTYPE_MESH_POINT:
7956 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007957 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007958 break;
7959 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007960 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007961 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007962
7963 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007964 if (!rdev->ops->mgmt_tx)
7965 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007966
Eric W. Biederman15e47302012-09-07 20:12:54 +00007967 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007968 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7969 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007970}
7971
Johannes Berg2e161f72010-08-12 15:38:38 +02007972static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007973{
Johannes Berg4c476992010-10-04 21:36:35 +02007974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007975 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007976 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007977 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007978 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007979 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007980 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007981 struct cfg80211_mgmt_tx_params params = {
7982 .dont_wait_for_ack =
7983 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7984 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007985
Johannes Berg683b6d32012-11-08 21:25:48 +01007986 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007987 return -EINVAL;
7988
Johannes Berg4c476992010-10-04 21:36:35 +02007989 if (!rdev->ops->mgmt_tx)
7990 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007991
Johannes Berg71bbc992012-06-15 15:30:18 +02007992 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007993 case NL80211_IFTYPE_P2P_DEVICE:
7994 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7995 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007996 case NL80211_IFTYPE_STATION:
7997 case NL80211_IFTYPE_ADHOC:
7998 case NL80211_IFTYPE_P2P_CLIENT:
7999 case NL80211_IFTYPE_AP:
8000 case NL80211_IFTYPE_AP_VLAN:
8001 case NL80211_IFTYPE_MESH_POINT:
8002 case NL80211_IFTYPE_P2P_GO:
8003 break;
8004 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008005 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008006 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008007
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008008 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008009 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008010 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008011 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008012
8013 /*
8014 * We should wait on the channel for at least a minimum amount
8015 * of time (10ms) but no longer than the driver supports.
8016 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008017 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8018 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008019 return -EINVAL;
8020
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008021 }
8022
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008023 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008024
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008025 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008026 return -EINVAL;
8027
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008028 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308029
Antonio Quartulliea141b752013-06-11 14:20:03 +02008030 /* get the channel if any has been specified, otherwise pass NULL to
8031 * the driver. The latter will use the current one
8032 */
8033 chandef.chan = NULL;
8034 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8035 err = nl80211_parse_chandef(rdev, info, &chandef);
8036 if (err)
8037 return err;
8038 }
8039
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008040 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008041 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008042
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008043 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8044 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8045
8046 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8047 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8048 int i;
8049
8050 if (len % sizeof(u16))
8051 return -EINVAL;
8052
8053 params.n_csa_offsets = len / sizeof(u16);
8054 params.csa_offsets =
8055 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8056
8057 /* check that all the offsets fit the frame */
8058 for (i = 0; i < params.n_csa_offsets; i++) {
8059 if (params.csa_offsets[i] >= params.len)
8060 return -EINVAL;
8061 }
8062 }
8063
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008064 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008065 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8066 if (!msg)
8067 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008068
Eric W. Biederman15e47302012-09-07 20:12:54 +00008069 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008070 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008071 if (!hdr) {
8072 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008073 goto free_msg;
8074 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008075 }
Johannes Berge247bd902011-11-04 11:18:21 +01008076
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008077 params.chan = chandef.chan;
8078 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008079 if (err)
8080 goto free_msg;
8081
Johannes Berge247bd902011-11-04 11:18:21 +01008082 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008083 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8084 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008085
Johannes Berge247bd902011-11-04 11:18:21 +01008086 genlmsg_end(msg, hdr);
8087 return genlmsg_reply(msg, info);
8088 }
8089
8090 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008091
8092 nla_put_failure:
8093 err = -ENOBUFS;
8094 free_msg:
8095 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008096 return err;
8097}
8098
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008099static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8100{
8101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008102 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008103 u64 cookie;
8104
8105 if (!info->attrs[NL80211_ATTR_COOKIE])
8106 return -EINVAL;
8107
8108 if (!rdev->ops->mgmt_tx_cancel_wait)
8109 return -EOPNOTSUPP;
8110
Johannes Berg71bbc992012-06-15 15:30:18 +02008111 switch (wdev->iftype) {
8112 case NL80211_IFTYPE_STATION:
8113 case NL80211_IFTYPE_ADHOC:
8114 case NL80211_IFTYPE_P2P_CLIENT:
8115 case NL80211_IFTYPE_AP:
8116 case NL80211_IFTYPE_AP_VLAN:
8117 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008118 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008119 break;
8120 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008121 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008122 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008123
8124 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8125
Hila Gonene35e4d22012-06-27 17:19:42 +03008126 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008127}
8128
Kalle Valoffb9eb32010-02-17 17:58:10 +02008129static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8130{
Johannes Berg4c476992010-10-04 21:36:35 +02008131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008132 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008133 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008134 u8 ps_state;
8135 bool state;
8136 int err;
8137
Johannes Berg4c476992010-10-04 21:36:35 +02008138 if (!info->attrs[NL80211_ATTR_PS_STATE])
8139 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008140
8141 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8142
Johannes Berg4c476992010-10-04 21:36:35 +02008143 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8144 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008145
8146 wdev = dev->ieee80211_ptr;
8147
Johannes Berg4c476992010-10-04 21:36:35 +02008148 if (!rdev->ops->set_power_mgmt)
8149 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008150
8151 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8152
8153 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008154 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008155
Hila Gonene35e4d22012-06-27 17:19:42 +03008156 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008157 if (!err)
8158 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008159 return err;
8160}
8161
8162static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8163{
Johannes Berg4c476992010-10-04 21:36:35 +02008164 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008165 enum nl80211_ps_state ps_state;
8166 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008167 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008168 struct sk_buff *msg;
8169 void *hdr;
8170 int err;
8171
Kalle Valoffb9eb32010-02-17 17:58:10 +02008172 wdev = dev->ieee80211_ptr;
8173
Johannes Berg4c476992010-10-04 21:36:35 +02008174 if (!rdev->ops->set_power_mgmt)
8175 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008176
8177 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008178 if (!msg)
8179 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008180
Eric W. Biederman15e47302012-09-07 20:12:54 +00008181 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008182 NL80211_CMD_GET_POWER_SAVE);
8183 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008184 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008185 goto free_msg;
8186 }
8187
8188 if (wdev->ps)
8189 ps_state = NL80211_PS_ENABLED;
8190 else
8191 ps_state = NL80211_PS_DISABLED;
8192
David S. Miller9360ffd2012-03-29 04:41:26 -04008193 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8194 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008195
8196 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008197 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008198
Johannes Berg4c476992010-10-04 21:36:35 +02008199 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008200 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008201 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008202 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008203 return err;
8204}
8205
Johannes Berg94e860f2014-01-20 23:58:15 +01008206static const struct nla_policy
8207nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008208 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8209 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8210 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008211 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8212 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8213 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008214};
8215
Thomas Pedersen84f10702012-07-12 16:17:33 -07008216static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008217 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008218{
8219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008220 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008221 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008222
Johannes Bergd9d8b012012-11-26 12:51:52 +01008223 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008224 return -EINVAL;
8225
Thomas Pedersen84f10702012-07-12 16:17:33 -07008226 if (!rdev->ops->set_cqm_txe_config)
8227 return -EOPNOTSUPP;
8228
8229 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8230 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8231 return -EOPNOTSUPP;
8232
Hila Gonene35e4d22012-06-27 17:19:42 +03008233 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008234}
8235
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008236static int nl80211_set_cqm_rssi(struct genl_info *info,
8237 s32 threshold, u32 hysteresis)
8238{
Johannes Berg4c476992010-10-04 21:36:35 +02008239 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008240 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008241 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008242
8243 if (threshold > 0)
8244 return -EINVAL;
8245
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008246 /* disabling - hysteresis should also be zero then */
8247 if (threshold == 0)
8248 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008249
Johannes Berg4c476992010-10-04 21:36:35 +02008250 if (!rdev->ops->set_cqm_rssi_config)
8251 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008252
Johannes Berg074ac8d2010-09-16 14:58:22 +02008253 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008254 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8255 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008256
Hila Gonene35e4d22012-06-27 17:19:42 +03008257 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008258}
8259
8260static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8261{
8262 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8263 struct nlattr *cqm;
8264 int err;
8265
8266 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008267 if (!cqm)
8268 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008269
8270 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8271 nl80211_attr_cqm_policy);
8272 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008273 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008274
8275 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8276 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008277 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8278 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008279
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008280 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8281 }
8282
8283 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8284 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8285 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8286 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8287 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8288 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8289
8290 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8291 }
8292
8293 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008294}
8295
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008296static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8297{
8298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8299 struct net_device *dev = info->user_ptr[1];
8300 struct ocb_setup setup = {};
8301 int err;
8302
8303 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8304 if (err)
8305 return err;
8306
8307 return cfg80211_join_ocb(rdev, dev, &setup);
8308}
8309
8310static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8311{
8312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8313 struct net_device *dev = info->user_ptr[1];
8314
8315 return cfg80211_leave_ocb(rdev, dev);
8316}
8317
Johannes Berg29cbe682010-12-03 09:20:44 +01008318static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8319{
8320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8321 struct net_device *dev = info->user_ptr[1];
8322 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008323 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008324 int err;
8325
8326 /* start with default */
8327 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008328 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008329
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008330 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008331 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008332 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008333 if (err)
8334 return err;
8335 }
8336
8337 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8338 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8339 return -EINVAL;
8340
Javier Cardonac80d5452010-12-16 17:37:49 -08008341 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8342 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8343
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008344 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8345 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8346 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8347 return -EINVAL;
8348
Marco Porsch9bdbf042013-01-07 16:04:51 +01008349 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8350 setup.beacon_interval =
8351 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8352 if (setup.beacon_interval < 10 ||
8353 setup.beacon_interval > 10000)
8354 return -EINVAL;
8355 }
8356
8357 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8358 setup.dtim_period =
8359 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8360 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8361 return -EINVAL;
8362 }
8363
Javier Cardonac80d5452010-12-16 17:37:49 -08008364 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8365 /* parse additional setup parameters if given */
8366 err = nl80211_parse_mesh_setup(info, &setup);
8367 if (err)
8368 return err;
8369 }
8370
Thomas Pedersend37bb182013-03-04 13:06:13 -08008371 if (setup.user_mpm)
8372 cfg.auto_open_plinks = false;
8373
Johannes Bergcc1d2802012-05-16 23:50:20 +02008374 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008375 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8376 if (err)
8377 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008378 } else {
8379 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008380 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008381 }
8382
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008383 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8384 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8385 int n_rates =
8386 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8387 struct ieee80211_supported_band *sband;
8388
8389 if (!setup.chandef.chan)
8390 return -EINVAL;
8391
8392 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8393
8394 err = ieee80211_get_ratemask(sband, rates, n_rates,
8395 &setup.basic_rates);
8396 if (err)
8397 return err;
8398 }
8399
Javier Cardonac80d5452010-12-16 17:37:49 -08008400 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008401}
8402
8403static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8404{
8405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8406 struct net_device *dev = info->user_ptr[1];
8407
8408 return cfg80211_leave_mesh(rdev, dev);
8409}
8410
Johannes Bergdfb89c52012-06-27 09:23:48 +02008411#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008412static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8413 struct cfg80211_registered_device *rdev)
8414{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008415 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008416 struct nlattr *nl_pats, *nl_pat;
8417 int i, pat_len;
8418
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008419 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008420 return 0;
8421
8422 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8423 if (!nl_pats)
8424 return -ENOBUFS;
8425
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008426 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008427 nl_pat = nla_nest_start(msg, i + 1);
8428 if (!nl_pat)
8429 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008430 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008431 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008432 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008433 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8434 wowlan->patterns[i].pattern) ||
8435 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008436 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008437 return -ENOBUFS;
8438 nla_nest_end(msg, nl_pat);
8439 }
8440 nla_nest_end(msg, nl_pats);
8441
8442 return 0;
8443}
8444
Johannes Berg2a0e0472013-01-23 22:57:40 +01008445static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8446 struct cfg80211_wowlan_tcp *tcp)
8447{
8448 struct nlattr *nl_tcp;
8449
8450 if (!tcp)
8451 return 0;
8452
8453 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8454 if (!nl_tcp)
8455 return -ENOBUFS;
8456
8457 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8458 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8459 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8460 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8461 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8462 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8463 tcp->payload_len, tcp->payload) ||
8464 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8465 tcp->data_interval) ||
8466 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8467 tcp->wake_len, tcp->wake_data) ||
8468 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8469 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8470 return -ENOBUFS;
8471
8472 if (tcp->payload_seq.len &&
8473 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8474 sizeof(tcp->payload_seq), &tcp->payload_seq))
8475 return -ENOBUFS;
8476
8477 if (tcp->payload_tok.len &&
8478 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8479 sizeof(tcp->payload_tok) + tcp->tokens_size,
8480 &tcp->payload_tok))
8481 return -ENOBUFS;
8482
Johannes Berge248ad32013-05-16 10:24:28 +02008483 nla_nest_end(msg, nl_tcp);
8484
Johannes Berg2a0e0472013-01-23 22:57:40 +01008485 return 0;
8486}
8487
Johannes Bergff1b6e62011-05-04 15:37:28 +02008488static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8489{
8490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8491 struct sk_buff *msg;
8492 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008493 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008494
Johannes Berg964dc9e2013-06-03 17:25:34 +02008495 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008496 return -EOPNOTSUPP;
8497
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008498 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008499 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008500 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8501 rdev->wiphy.wowlan_config->tcp->payload_len +
8502 rdev->wiphy.wowlan_config->tcp->wake_len +
8503 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008504 }
8505
8506 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008507 if (!msg)
8508 return -ENOMEM;
8509
Eric W. Biederman15e47302012-09-07 20:12:54 +00008510 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008511 NL80211_CMD_GET_WOWLAN);
8512 if (!hdr)
8513 goto nla_put_failure;
8514
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008515 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008516 struct nlattr *nl_wowlan;
8517
8518 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8519 if (!nl_wowlan)
8520 goto nla_put_failure;
8521
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008522 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008523 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008524 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008525 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008526 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008527 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008528 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008529 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008530 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008531 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008532 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008533 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008534 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008535 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8536 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008537
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008538 if (nl80211_send_wowlan_patterns(msg, rdev))
8539 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008540
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008541 if (nl80211_send_wowlan_tcp(msg,
8542 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008543 goto nla_put_failure;
8544
Johannes Bergff1b6e62011-05-04 15:37:28 +02008545 nla_nest_end(msg, nl_wowlan);
8546 }
8547
8548 genlmsg_end(msg, hdr);
8549 return genlmsg_reply(msg, info);
8550
8551nla_put_failure:
8552 nlmsg_free(msg);
8553 return -ENOBUFS;
8554}
8555
Johannes Berg2a0e0472013-01-23 22:57:40 +01008556static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8557 struct nlattr *attr,
8558 struct cfg80211_wowlan *trig)
8559{
8560 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8561 struct cfg80211_wowlan_tcp *cfg;
8562 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8563 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8564 u32 size;
8565 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8566 int err, port;
8567
Johannes Berg964dc9e2013-06-03 17:25:34 +02008568 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008569 return -EINVAL;
8570
8571 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8572 nla_data(attr), nla_len(attr),
8573 nl80211_wowlan_tcp_policy);
8574 if (err)
8575 return err;
8576
8577 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8578 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8579 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8580 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8581 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8582 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8583 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8584 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8585 return -EINVAL;
8586
8587 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008588 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008589 return -EINVAL;
8590
8591 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008592 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008593 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008594 return -EINVAL;
8595
8596 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008597 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008598 return -EINVAL;
8599
8600 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8601 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8602 return -EINVAL;
8603
8604 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8605 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8606
8607 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8608 tokens_size = tokln - sizeof(*tok);
8609
8610 if (!tok->len || tokens_size % tok->len)
8611 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008612 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008613 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008614 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008615 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008616 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008617 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008618 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008619 return -EINVAL;
8620 if (tok->offset + tok->len > data_size)
8621 return -EINVAL;
8622 }
8623
8624 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8625 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008626 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008627 return -EINVAL;
8628 if (seq->len == 0 || seq->len > 4)
8629 return -EINVAL;
8630 if (seq->len + seq->offset > data_size)
8631 return -EINVAL;
8632 }
8633
8634 size = sizeof(*cfg);
8635 size += data_size;
8636 size += wake_size + wake_mask_size;
8637 size += tokens_size;
8638
8639 cfg = kzalloc(size, GFP_KERNEL);
8640 if (!cfg)
8641 return -ENOMEM;
8642 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8643 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8644 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8645 ETH_ALEN);
8646 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8647 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8648 else
8649 port = 0;
8650#ifdef CONFIG_INET
8651 /* allocate a socket and port for it and use it */
8652 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8653 IPPROTO_TCP, &cfg->sock, 1);
8654 if (err) {
8655 kfree(cfg);
8656 return err;
8657 }
8658 if (inet_csk_get_port(cfg->sock->sk, port)) {
8659 sock_release(cfg->sock);
8660 kfree(cfg);
8661 return -EADDRINUSE;
8662 }
8663 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8664#else
8665 if (!port) {
8666 kfree(cfg);
8667 return -EINVAL;
8668 }
8669 cfg->src_port = port;
8670#endif
8671
8672 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8673 cfg->payload_len = data_size;
8674 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8675 memcpy((void *)cfg->payload,
8676 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8677 data_size);
8678 if (seq)
8679 cfg->payload_seq = *seq;
8680 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8681 cfg->wake_len = wake_size;
8682 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8683 memcpy((void *)cfg->wake_data,
8684 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8685 wake_size);
8686 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8687 data_size + wake_size;
8688 memcpy((void *)cfg->wake_mask,
8689 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8690 wake_mask_size);
8691 if (tok) {
8692 cfg->tokens_size = tokens_size;
8693 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8694 }
8695
8696 trig->tcp = cfg;
8697
8698 return 0;
8699}
8700
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008701static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
8702 const struct wiphy_wowlan_support *wowlan,
8703 struct nlattr *attr,
8704 struct cfg80211_wowlan *trig)
8705{
8706 struct nlattr **tb;
8707 int err;
8708
8709 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
8710 if (!tb)
8711 return -ENOMEM;
8712
8713 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
8714 err = -EOPNOTSUPP;
8715 goto out;
8716 }
8717
8718 err = nla_parse(tb, NL80211_ATTR_MAX,
8719 nla_data(attr), nla_len(attr),
8720 nl80211_policy);
8721 if (err)
8722 goto out;
8723
8724 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, tb);
8725 err = PTR_ERR_OR_ZERO(trig->nd_config);
8726 if (err)
8727 trig->nd_config = NULL;
8728
8729out:
8730 kfree(tb);
8731 return err;
8732}
8733
Johannes Bergff1b6e62011-05-04 15:37:28 +02008734static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8735{
8736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8737 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008738 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008739 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008740 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008741 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008742 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008743
Johannes Berg964dc9e2013-06-03 17:25:34 +02008744 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008745 return -EOPNOTSUPP;
8746
Johannes Bergae33bd82012-07-12 16:25:02 +02008747 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8748 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008749 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008750 goto set_wakeup;
8751 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008752
8753 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8754 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8755 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8756 nl80211_wowlan_policy);
8757 if (err)
8758 return err;
8759
8760 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8761 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8762 return -EINVAL;
8763 new_triggers.any = true;
8764 }
8765
8766 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8767 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8768 return -EINVAL;
8769 new_triggers.disconnect = true;
8770 }
8771
8772 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8773 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8774 return -EINVAL;
8775 new_triggers.magic_pkt = true;
8776 }
8777
Johannes Berg77dbbb12011-07-13 10:48:55 +02008778 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8779 return -EINVAL;
8780
8781 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8782 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8783 return -EINVAL;
8784 new_triggers.gtk_rekey_failure = true;
8785 }
8786
8787 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8788 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8789 return -EINVAL;
8790 new_triggers.eap_identity_req = true;
8791 }
8792
8793 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8794 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8795 return -EINVAL;
8796 new_triggers.four_way_handshake = true;
8797 }
8798
8799 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8800 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8801 return -EINVAL;
8802 new_triggers.rfkill_release = true;
8803 }
8804
Johannes Bergff1b6e62011-05-04 15:37:28 +02008805 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8806 struct nlattr *pat;
8807 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008808 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008809 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008810
8811 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8812 rem)
8813 n_patterns++;
8814 if (n_patterns > wowlan->n_patterns)
8815 return -EINVAL;
8816
8817 new_triggers.patterns = kcalloc(n_patterns,
8818 sizeof(new_triggers.patterns[0]),
8819 GFP_KERNEL);
8820 if (!new_triggers.patterns)
8821 return -ENOMEM;
8822
8823 new_triggers.n_patterns = n_patterns;
8824 i = 0;
8825
8826 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8827 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008828 u8 *mask_pat;
8829
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008830 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8831 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008832 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008833 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8834 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008835 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008836 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008837 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008838 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008839 goto error;
8840 if (pat_len > wowlan->pattern_max_len ||
8841 pat_len < wowlan->pattern_min_len)
8842 goto error;
8843
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008844 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008845 pkt_offset = 0;
8846 else
8847 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008848 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008849 if (pkt_offset > wowlan->max_pkt_offset)
8850 goto error;
8851 new_triggers.patterns[i].pkt_offset = pkt_offset;
8852
Johannes Berg922bd802014-05-19 17:59:50 +02008853 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8854 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008855 err = -ENOMEM;
8856 goto error;
8857 }
Johannes Berg922bd802014-05-19 17:59:50 +02008858 new_triggers.patterns[i].mask = mask_pat;
8859 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008860 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008861 mask_pat += mask_len;
8862 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008863 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008864 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008865 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008866 pat_len);
8867 i++;
8868 }
8869 }
8870
Johannes Berg2a0e0472013-01-23 22:57:40 +01008871 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8872 err = nl80211_parse_wowlan_tcp(
8873 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8874 &new_triggers);
8875 if (err)
8876 goto error;
8877 }
8878
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008879 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
8880 err = nl80211_parse_wowlan_nd(
8881 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
8882 &new_triggers);
8883 if (err)
8884 goto error;
8885 }
8886
Johannes Bergae33bd82012-07-12 16:25:02 +02008887 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8888 if (!ntrig) {
8889 err = -ENOMEM;
8890 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008891 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008892 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008893 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008894
Johannes Bergae33bd82012-07-12 16:25:02 +02008895 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008896 if (rdev->ops->set_wakeup &&
8897 prev_enabled != !!rdev->wiphy.wowlan_config)
8898 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008899
Johannes Bergff1b6e62011-05-04 15:37:28 +02008900 return 0;
8901 error:
8902 for (i = 0; i < new_triggers.n_patterns; i++)
8903 kfree(new_triggers.patterns[i].mask);
8904 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008905 if (new_triggers.tcp && new_triggers.tcp->sock)
8906 sock_release(new_triggers.tcp->sock);
8907 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008908 return err;
8909}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008910#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008911
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008912static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8913 struct cfg80211_registered_device *rdev)
8914{
8915 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8916 int i, j, pat_len;
8917 struct cfg80211_coalesce_rules *rule;
8918
8919 if (!rdev->coalesce->n_rules)
8920 return 0;
8921
8922 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8923 if (!nl_rules)
8924 return -ENOBUFS;
8925
8926 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8927 nl_rule = nla_nest_start(msg, i + 1);
8928 if (!nl_rule)
8929 return -ENOBUFS;
8930
8931 rule = &rdev->coalesce->rules[i];
8932 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8933 rule->delay))
8934 return -ENOBUFS;
8935
8936 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8937 rule->condition))
8938 return -ENOBUFS;
8939
8940 nl_pats = nla_nest_start(msg,
8941 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8942 if (!nl_pats)
8943 return -ENOBUFS;
8944
8945 for (j = 0; j < rule->n_patterns; j++) {
8946 nl_pat = nla_nest_start(msg, j + 1);
8947 if (!nl_pat)
8948 return -ENOBUFS;
8949 pat_len = rule->patterns[j].pattern_len;
8950 if (nla_put(msg, NL80211_PKTPAT_MASK,
8951 DIV_ROUND_UP(pat_len, 8),
8952 rule->patterns[j].mask) ||
8953 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8954 rule->patterns[j].pattern) ||
8955 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8956 rule->patterns[j].pkt_offset))
8957 return -ENOBUFS;
8958 nla_nest_end(msg, nl_pat);
8959 }
8960 nla_nest_end(msg, nl_pats);
8961 nla_nest_end(msg, nl_rule);
8962 }
8963 nla_nest_end(msg, nl_rules);
8964
8965 return 0;
8966}
8967
8968static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8969{
8970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8971 struct sk_buff *msg;
8972 void *hdr;
8973
8974 if (!rdev->wiphy.coalesce)
8975 return -EOPNOTSUPP;
8976
8977 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8978 if (!msg)
8979 return -ENOMEM;
8980
8981 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8982 NL80211_CMD_GET_COALESCE);
8983 if (!hdr)
8984 goto nla_put_failure;
8985
8986 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8987 goto nla_put_failure;
8988
8989 genlmsg_end(msg, hdr);
8990 return genlmsg_reply(msg, info);
8991
8992nla_put_failure:
8993 nlmsg_free(msg);
8994 return -ENOBUFS;
8995}
8996
8997void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8998{
8999 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9000 int i, j;
9001 struct cfg80211_coalesce_rules *rule;
9002
9003 if (!coalesce)
9004 return;
9005
9006 for (i = 0; i < coalesce->n_rules; i++) {
9007 rule = &coalesce->rules[i];
9008 for (j = 0; j < rule->n_patterns; j++)
9009 kfree(rule->patterns[j].mask);
9010 kfree(rule->patterns);
9011 }
9012 kfree(coalesce->rules);
9013 kfree(coalesce);
9014 rdev->coalesce = NULL;
9015}
9016
9017static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9018 struct nlattr *rule,
9019 struct cfg80211_coalesce_rules *new_rule)
9020{
9021 int err, i;
9022 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9023 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9024 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9025 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9026
9027 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9028 nla_len(rule), nl80211_coalesce_policy);
9029 if (err)
9030 return err;
9031
9032 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9033 new_rule->delay =
9034 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9035 if (new_rule->delay > coalesce->max_delay)
9036 return -EINVAL;
9037
9038 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9039 new_rule->condition =
9040 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9041 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9042 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9043 return -EINVAL;
9044
9045 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9046 return -EINVAL;
9047
9048 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9049 rem)
9050 n_patterns++;
9051 if (n_patterns > coalesce->n_patterns)
9052 return -EINVAL;
9053
9054 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9055 GFP_KERNEL);
9056 if (!new_rule->patterns)
9057 return -ENOMEM;
9058
9059 new_rule->n_patterns = n_patterns;
9060 i = 0;
9061
9062 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9063 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009064 u8 *mask_pat;
9065
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009066 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9067 nla_len(pat), NULL);
9068 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9069 !pat_tb[NL80211_PKTPAT_PATTERN])
9070 return -EINVAL;
9071 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9072 mask_len = DIV_ROUND_UP(pat_len, 8);
9073 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9074 return -EINVAL;
9075 if (pat_len > coalesce->pattern_max_len ||
9076 pat_len < coalesce->pattern_min_len)
9077 return -EINVAL;
9078
9079 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9080 pkt_offset = 0;
9081 else
9082 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9083 if (pkt_offset > coalesce->max_pkt_offset)
9084 return -EINVAL;
9085 new_rule->patterns[i].pkt_offset = pkt_offset;
9086
Johannes Berg922bd802014-05-19 17:59:50 +02009087 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9088 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009089 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009090
9091 new_rule->patterns[i].mask = mask_pat;
9092 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9093 mask_len);
9094
9095 mask_pat += mask_len;
9096 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009097 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009098 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9099 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009100 i++;
9101 }
9102
9103 return 0;
9104}
9105
9106static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9107{
9108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9109 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9110 struct cfg80211_coalesce new_coalesce = {};
9111 struct cfg80211_coalesce *n_coalesce;
9112 int err, rem_rule, n_rules = 0, i, j;
9113 struct nlattr *rule;
9114 struct cfg80211_coalesce_rules *tmp_rule;
9115
9116 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9117 return -EOPNOTSUPP;
9118
9119 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9120 cfg80211_rdev_free_coalesce(rdev);
9121 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9122 return 0;
9123 }
9124
9125 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9126 rem_rule)
9127 n_rules++;
9128 if (n_rules > coalesce->n_rules)
9129 return -EINVAL;
9130
9131 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9132 GFP_KERNEL);
9133 if (!new_coalesce.rules)
9134 return -ENOMEM;
9135
9136 new_coalesce.n_rules = n_rules;
9137 i = 0;
9138
9139 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9140 rem_rule) {
9141 err = nl80211_parse_coalesce_rule(rdev, rule,
9142 &new_coalesce.rules[i]);
9143 if (err)
9144 goto error;
9145
9146 i++;
9147 }
9148
9149 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9150 if (err)
9151 goto error;
9152
9153 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9154 if (!n_coalesce) {
9155 err = -ENOMEM;
9156 goto error;
9157 }
9158 cfg80211_rdev_free_coalesce(rdev);
9159 rdev->coalesce = n_coalesce;
9160
9161 return 0;
9162error:
9163 for (i = 0; i < new_coalesce.n_rules; i++) {
9164 tmp_rule = &new_coalesce.rules[i];
9165 for (j = 0; j < tmp_rule->n_patterns; j++)
9166 kfree(tmp_rule->patterns[j].mask);
9167 kfree(tmp_rule->patterns);
9168 }
9169 kfree(new_coalesce.rules);
9170
9171 return err;
9172}
9173
Johannes Berge5497d72011-07-05 16:35:40 +02009174static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9175{
9176 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9177 struct net_device *dev = info->user_ptr[1];
9178 struct wireless_dev *wdev = dev->ieee80211_ptr;
9179 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9180 struct cfg80211_gtk_rekey_data rekey_data;
9181 int err;
9182
9183 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9184 return -EINVAL;
9185
9186 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9187 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9188 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9189 nl80211_rekey_policy);
9190 if (err)
9191 return err;
9192
9193 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9194 return -ERANGE;
9195 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9196 return -ERANGE;
9197 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9198 return -ERANGE;
9199
Johannes Berg78f686c2014-09-10 22:28:06 +03009200 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9201 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9202 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009203
9204 wdev_lock(wdev);
9205 if (!wdev->current_bss) {
9206 err = -ENOTCONN;
9207 goto out;
9208 }
9209
9210 if (!rdev->ops->set_rekey_data) {
9211 err = -EOPNOTSUPP;
9212 goto out;
9213 }
9214
Hila Gonene35e4d22012-06-27 17:19:42 +03009215 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009216 out:
9217 wdev_unlock(wdev);
9218 return err;
9219}
9220
Johannes Berg28946da2011-11-04 11:18:12 +01009221static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9222 struct genl_info *info)
9223{
9224 struct net_device *dev = info->user_ptr[1];
9225 struct wireless_dev *wdev = dev->ieee80211_ptr;
9226
9227 if (wdev->iftype != NL80211_IFTYPE_AP &&
9228 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9229 return -EINVAL;
9230
Eric W. Biederman15e47302012-09-07 20:12:54 +00009231 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009232 return -EBUSY;
9233
Eric W. Biederman15e47302012-09-07 20:12:54 +00009234 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009235 return 0;
9236}
9237
Johannes Berg7f6cf312011-11-04 11:18:15 +01009238static int nl80211_probe_client(struct sk_buff *skb,
9239 struct genl_info *info)
9240{
9241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9242 struct net_device *dev = info->user_ptr[1];
9243 struct wireless_dev *wdev = dev->ieee80211_ptr;
9244 struct sk_buff *msg;
9245 void *hdr;
9246 const u8 *addr;
9247 u64 cookie;
9248 int err;
9249
9250 if (wdev->iftype != NL80211_IFTYPE_AP &&
9251 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9252 return -EOPNOTSUPP;
9253
9254 if (!info->attrs[NL80211_ATTR_MAC])
9255 return -EINVAL;
9256
9257 if (!rdev->ops->probe_client)
9258 return -EOPNOTSUPP;
9259
9260 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9261 if (!msg)
9262 return -ENOMEM;
9263
Eric W. Biederman15e47302012-09-07 20:12:54 +00009264 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009265 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009266 if (!hdr) {
9267 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009268 goto free_msg;
9269 }
9270
9271 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9272
Hila Gonene35e4d22012-06-27 17:19:42 +03009273 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009274 if (err)
9275 goto free_msg;
9276
David S. Miller9360ffd2012-03-29 04:41:26 -04009277 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9278 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009279
9280 genlmsg_end(msg, hdr);
9281
9282 return genlmsg_reply(msg, info);
9283
9284 nla_put_failure:
9285 err = -ENOBUFS;
9286 free_msg:
9287 nlmsg_free(msg);
9288 return err;
9289}
9290
Johannes Berg5e760232011-11-04 11:18:17 +01009291static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9292{
9293 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009294 struct cfg80211_beacon_registration *reg, *nreg;
9295 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009296
9297 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9298 return -EOPNOTSUPP;
9299
Ben Greear37c73b52012-10-26 14:49:25 -07009300 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9301 if (!nreg)
9302 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009303
Ben Greear37c73b52012-10-26 14:49:25 -07009304 /* First, check if already registered. */
9305 spin_lock_bh(&rdev->beacon_registrations_lock);
9306 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9307 if (reg->nlportid == info->snd_portid) {
9308 rv = -EALREADY;
9309 goto out_err;
9310 }
9311 }
9312 /* Add it to the list */
9313 nreg->nlportid = info->snd_portid;
9314 list_add(&nreg->list, &rdev->beacon_registrations);
9315
9316 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009317
9318 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009319out_err:
9320 spin_unlock_bh(&rdev->beacon_registrations_lock);
9321 kfree(nreg);
9322 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009323}
9324
Johannes Berg98104fde2012-06-16 00:19:54 +02009325static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9326{
9327 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9328 struct wireless_dev *wdev = info->user_ptr[1];
9329 int err;
9330
9331 if (!rdev->ops->start_p2p_device)
9332 return -EOPNOTSUPP;
9333
9334 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9335 return -EOPNOTSUPP;
9336
9337 if (wdev->p2p_started)
9338 return 0;
9339
Luciano Coelhob6a55012014-02-27 11:07:21 +02009340 if (rfkill_blocked(rdev->rfkill))
9341 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009342
Johannes Bergeeb126e2012-10-23 15:16:50 +02009343 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009344 if (err)
9345 return err;
9346
9347 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009348 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009349
9350 return 0;
9351}
9352
9353static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9354{
9355 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9356 struct wireless_dev *wdev = info->user_ptr[1];
9357
9358 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9359 return -EOPNOTSUPP;
9360
9361 if (!rdev->ops->stop_p2p_device)
9362 return -EOPNOTSUPP;
9363
Johannes Bergf9f47522013-03-19 15:04:07 +01009364 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009365
9366 return 0;
9367}
9368
Johannes Berg3713b4e2013-02-14 16:19:38 +01009369static int nl80211_get_protocol_features(struct sk_buff *skb,
9370 struct genl_info *info)
9371{
9372 void *hdr;
9373 struct sk_buff *msg;
9374
9375 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9376 if (!msg)
9377 return -ENOMEM;
9378
9379 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9380 NL80211_CMD_GET_PROTOCOL_FEATURES);
9381 if (!hdr)
9382 goto nla_put_failure;
9383
9384 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9385 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9386 goto nla_put_failure;
9387
9388 genlmsg_end(msg, hdr);
9389 return genlmsg_reply(msg, info);
9390
9391 nla_put_failure:
9392 kfree_skb(msg);
9393 return -ENOBUFS;
9394}
9395
Jouni Malinen355199e2013-02-27 17:14:27 +02009396static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9397{
9398 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9399 struct cfg80211_update_ft_ies_params ft_params;
9400 struct net_device *dev = info->user_ptr[1];
9401
9402 if (!rdev->ops->update_ft_ies)
9403 return -EOPNOTSUPP;
9404
9405 if (!info->attrs[NL80211_ATTR_MDID] ||
9406 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9407 return -EINVAL;
9408
9409 memset(&ft_params, 0, sizeof(ft_params));
9410 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9411 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9412 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9413
9414 return rdev_update_ft_ies(rdev, dev, &ft_params);
9415}
9416
Arend van Spriel5de17982013-04-18 15:49:00 +02009417static int nl80211_crit_protocol_start(struct sk_buff *skb,
9418 struct genl_info *info)
9419{
9420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9421 struct wireless_dev *wdev = info->user_ptr[1];
9422 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9423 u16 duration;
9424 int ret;
9425
9426 if (!rdev->ops->crit_proto_start)
9427 return -EOPNOTSUPP;
9428
9429 if (WARN_ON(!rdev->ops->crit_proto_stop))
9430 return -EINVAL;
9431
9432 if (rdev->crit_proto_nlportid)
9433 return -EBUSY;
9434
9435 /* determine protocol if provided */
9436 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9437 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9438
9439 if (proto >= NUM_NL80211_CRIT_PROTO)
9440 return -EINVAL;
9441
9442 /* timeout must be provided */
9443 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9444 return -EINVAL;
9445
9446 duration =
9447 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9448
9449 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9450 return -ERANGE;
9451
9452 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9453 if (!ret)
9454 rdev->crit_proto_nlportid = info->snd_portid;
9455
9456 return ret;
9457}
9458
9459static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9460 struct genl_info *info)
9461{
9462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9463 struct wireless_dev *wdev = info->user_ptr[1];
9464
9465 if (!rdev->ops->crit_proto_stop)
9466 return -EOPNOTSUPP;
9467
9468 if (rdev->crit_proto_nlportid) {
9469 rdev->crit_proto_nlportid = 0;
9470 rdev_crit_proto_stop(rdev, wdev);
9471 }
9472 return 0;
9473}
9474
Johannes Bergad7e7182013-11-13 13:37:47 +01009475static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9476{
9477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9478 struct wireless_dev *wdev =
9479 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9480 int i, err;
9481 u32 vid, subcmd;
9482
9483 if (!rdev->wiphy.vendor_commands)
9484 return -EOPNOTSUPP;
9485
9486 if (IS_ERR(wdev)) {
9487 err = PTR_ERR(wdev);
9488 if (err != -EINVAL)
9489 return err;
9490 wdev = NULL;
9491 } else if (wdev->wiphy != &rdev->wiphy) {
9492 return -EINVAL;
9493 }
9494
9495 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9496 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9497 return -EINVAL;
9498
9499 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9500 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9501 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9502 const struct wiphy_vendor_command *vcmd;
9503 void *data = NULL;
9504 int len = 0;
9505
9506 vcmd = &rdev->wiphy.vendor_commands[i];
9507
9508 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9509 continue;
9510
9511 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9512 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9513 if (!wdev)
9514 return -EINVAL;
9515 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9516 !wdev->netdev)
9517 return -EINVAL;
9518
9519 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9520 if (wdev->netdev &&
9521 !netif_running(wdev->netdev))
9522 return -ENETDOWN;
9523 if (!wdev->netdev && !wdev->p2p_started)
9524 return -ENETDOWN;
9525 }
9526 } else {
9527 wdev = NULL;
9528 }
9529
9530 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9531 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9532 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9533 }
9534
9535 rdev->cur_cmd_info = info;
9536 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9537 data, len);
9538 rdev->cur_cmd_info = NULL;
9539 return err;
9540 }
9541
9542 return -EOPNOTSUPP;
9543}
9544
9545struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9546 enum nl80211_commands cmd,
9547 enum nl80211_attrs attr,
9548 int approxlen)
9549{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009550 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009551
9552 if (WARN_ON(!rdev->cur_cmd_info))
9553 return NULL;
9554
9555 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9556 rdev->cur_cmd_info->snd_portid,
9557 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009558 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009559}
9560EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9561
9562int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9563{
9564 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9565 void *hdr = ((void **)skb->cb)[1];
9566 struct nlattr *data = ((void **)skb->cb)[2];
9567
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009568 /* clear CB data for netlink core to own from now on */
9569 memset(skb->cb, 0, sizeof(skb->cb));
9570
Johannes Bergad7e7182013-11-13 13:37:47 +01009571 if (WARN_ON(!rdev->cur_cmd_info)) {
9572 kfree_skb(skb);
9573 return -EINVAL;
9574 }
9575
9576 nla_nest_end(skb, data);
9577 genlmsg_end(skb, hdr);
9578 return genlmsg_reply(skb, rdev->cur_cmd_info);
9579}
9580EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9581
9582
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009583static int nl80211_set_qos_map(struct sk_buff *skb,
9584 struct genl_info *info)
9585{
9586 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9587 struct cfg80211_qos_map *qos_map = NULL;
9588 struct net_device *dev = info->user_ptr[1];
9589 u8 *pos, len, num_des, des_len, des;
9590 int ret;
9591
9592 if (!rdev->ops->set_qos_map)
9593 return -EOPNOTSUPP;
9594
9595 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9596 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9597 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9598
9599 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9600 len > IEEE80211_QOS_MAP_LEN_MAX)
9601 return -EINVAL;
9602
9603 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9604 if (!qos_map)
9605 return -ENOMEM;
9606
9607 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9608 if (num_des) {
9609 des_len = num_des *
9610 sizeof(struct cfg80211_dscp_exception);
9611 memcpy(qos_map->dscp_exception, pos, des_len);
9612 qos_map->num_des = num_des;
9613 for (des = 0; des < num_des; des++) {
9614 if (qos_map->dscp_exception[des].up > 7) {
9615 kfree(qos_map);
9616 return -EINVAL;
9617 }
9618 }
9619 pos += des_len;
9620 }
9621 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9622 }
9623
9624 wdev_lock(dev->ieee80211_ptr);
9625 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9626 if (!ret)
9627 ret = rdev_set_qos_map(rdev, dev, qos_map);
9628 wdev_unlock(dev->ieee80211_ptr);
9629
9630 kfree(qos_map);
9631 return ret;
9632}
9633
Johannes Berg960d01a2014-09-09 22:55:35 +03009634static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9635{
9636 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9637 struct net_device *dev = info->user_ptr[1];
9638 struct wireless_dev *wdev = dev->ieee80211_ptr;
9639 const u8 *peer;
9640 u8 tsid, up;
9641 u16 admitted_time = 0;
9642 int err;
9643
Johannes Berg723e73a2014-10-22 09:25:06 +02009644 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009645 return -EOPNOTSUPP;
9646
9647 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9648 !info->attrs[NL80211_ATTR_USER_PRIO])
9649 return -EINVAL;
9650
9651 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9652 if (tsid >= IEEE80211_NUM_TIDS)
9653 return -EINVAL;
9654
9655 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9656 if (up >= IEEE80211_NUM_UPS)
9657 return -EINVAL;
9658
9659 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009660 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009661 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009662 * need more attributes for that (e.g. BA session requirement);
9663 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009664 */
9665 return -EINVAL;
9666 }
9667
9668 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9669
9670 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9671 admitted_time =
9672 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9673 if (!admitted_time)
9674 return -EINVAL;
9675 }
9676
9677 wdev_lock(wdev);
9678 switch (wdev->iftype) {
9679 case NL80211_IFTYPE_STATION:
9680 case NL80211_IFTYPE_P2P_CLIENT:
9681 if (wdev->current_bss)
9682 break;
9683 err = -ENOTCONN;
9684 goto out;
9685 default:
9686 err = -EOPNOTSUPP;
9687 goto out;
9688 }
9689
9690 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9691
9692 out:
9693 wdev_unlock(wdev);
9694 return err;
9695}
9696
9697static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9698{
9699 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9700 struct net_device *dev = info->user_ptr[1];
9701 struct wireless_dev *wdev = dev->ieee80211_ptr;
9702 const u8 *peer;
9703 u8 tsid;
9704 int err;
9705
9706 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9707 return -EINVAL;
9708
9709 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9710 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9711
9712 wdev_lock(wdev);
9713 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9714 wdev_unlock(wdev);
9715
9716 return err;
9717}
9718
Arik Nemtsov1057d352014-11-19 12:54:26 +02009719static int nl80211_tdls_channel_switch(struct sk_buff *skb,
9720 struct genl_info *info)
9721{
9722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9723 struct net_device *dev = info->user_ptr[1];
9724 struct wireless_dev *wdev = dev->ieee80211_ptr;
9725 struct cfg80211_chan_def chandef = {};
9726 const u8 *addr;
9727 u8 oper_class;
9728 int err;
9729
9730 if (!rdev->ops->tdls_channel_switch ||
9731 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9732 return -EOPNOTSUPP;
9733
9734 switch (dev->ieee80211_ptr->iftype) {
9735 case NL80211_IFTYPE_STATION:
9736 case NL80211_IFTYPE_P2P_CLIENT:
9737 break;
9738 default:
9739 return -EOPNOTSUPP;
9740 }
9741
9742 if (!info->attrs[NL80211_ATTR_MAC] ||
9743 !info->attrs[NL80211_ATTR_OPER_CLASS])
9744 return -EINVAL;
9745
9746 err = nl80211_parse_chandef(rdev, info, &chandef);
9747 if (err)
9748 return err;
9749
9750 /*
9751 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
9752 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
9753 * specification is not defined for them.
9754 */
9755 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
9756 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
9757 chandef.width != NL80211_CHAN_WIDTH_20)
9758 return -EINVAL;
9759
9760 /* we will be active on the TDLS link */
9761 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
9762 return -EINVAL;
9763
9764 /* don't allow switching to DFS channels */
9765 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
9766 return -EINVAL;
9767
9768 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9769 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
9770
9771 wdev_lock(wdev);
9772 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
9773 wdev_unlock(wdev);
9774
9775 return err;
9776}
9777
9778static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
9779 struct genl_info *info)
9780{
9781 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9782 struct net_device *dev = info->user_ptr[1];
9783 struct wireless_dev *wdev = dev->ieee80211_ptr;
9784 const u8 *addr;
9785
9786 if (!rdev->ops->tdls_channel_switch ||
9787 !rdev->ops->tdls_cancel_channel_switch ||
9788 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9789 return -EOPNOTSUPP;
9790
9791 switch (dev->ieee80211_ptr->iftype) {
9792 case NL80211_IFTYPE_STATION:
9793 case NL80211_IFTYPE_P2P_CLIENT:
9794 break;
9795 default:
9796 return -EOPNOTSUPP;
9797 }
9798
9799 if (!info->attrs[NL80211_ATTR_MAC])
9800 return -EINVAL;
9801
9802 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9803
9804 wdev_lock(wdev);
9805 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
9806 wdev_unlock(wdev);
9807
9808 return 0;
9809}
9810
Johannes Berg4c476992010-10-04 21:36:35 +02009811#define NL80211_FLAG_NEED_WIPHY 0x01
9812#define NL80211_FLAG_NEED_NETDEV 0x02
9813#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009814#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9815#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9816 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009817#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009818/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009819#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9820 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +03009821#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +02009822
Johannes Bergf84f7712013-11-14 17:14:45 +01009823static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009824 struct genl_info *info)
9825{
9826 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009827 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009828 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009829 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9830
9831 if (rtnl)
9832 rtnl_lock();
9833
9834 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009835 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009836 if (IS_ERR(rdev)) {
9837 if (rtnl)
9838 rtnl_unlock();
9839 return PTR_ERR(rdev);
9840 }
9841 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009842 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9843 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009844 ASSERT_RTNL();
9845
Johannes Berg89a54e42012-06-15 14:33:17 +02009846 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9847 info->attrs);
9848 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009849 if (rtnl)
9850 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009851 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009852 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009853
Johannes Berg89a54e42012-06-15 14:33:17 +02009854 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009855 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009856
Johannes Berg1bf614e2012-06-15 15:23:36 +02009857 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9858 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009859 if (rtnl)
9860 rtnl_unlock();
9861 return -EINVAL;
9862 }
9863
9864 info->user_ptr[1] = dev;
9865 } else {
9866 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009867 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009868
Johannes Berg1bf614e2012-06-15 15:23:36 +02009869 if (dev) {
9870 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9871 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009872 if (rtnl)
9873 rtnl_unlock();
9874 return -ENETDOWN;
9875 }
9876
9877 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009878 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9879 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009880 if (rtnl)
9881 rtnl_unlock();
9882 return -ENETDOWN;
9883 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009884 }
9885
Johannes Berg4c476992010-10-04 21:36:35 +02009886 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009887 }
9888
9889 return 0;
9890}
9891
Johannes Bergf84f7712013-11-14 17:14:45 +01009892static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009893 struct genl_info *info)
9894{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009895 if (info->user_ptr[1]) {
9896 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9897 struct wireless_dev *wdev = info->user_ptr[1];
9898
9899 if (wdev->netdev)
9900 dev_put(wdev->netdev);
9901 } else {
9902 dev_put(info->user_ptr[1]);
9903 }
9904 }
Johannes Berg5393b912014-09-10 15:00:16 +03009905
Johannes Berg4c476992010-10-04 21:36:35 +02009906 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9907 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +03009908
9909 /* If needed, clear the netlink message payload from the SKB
9910 * as it might contain key data that shouldn't stick around on
9911 * the heap after the SKB is freed. The netlink message header
9912 * is still needed for further processing, so leave it intact.
9913 */
9914 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
9915 struct nlmsghdr *nlh = nlmsg_hdr(skb);
9916
9917 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
9918 }
Johannes Berg4c476992010-10-04 21:36:35 +02009919}
9920
Johannes Berg4534de82013-11-14 17:14:46 +01009921static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009922 {
9923 .cmd = NL80211_CMD_GET_WIPHY,
9924 .doit = nl80211_get_wiphy,
9925 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009926 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009927 .policy = nl80211_policy,
9928 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009929 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9930 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009931 },
9932 {
9933 .cmd = NL80211_CMD_SET_WIPHY,
9934 .doit = nl80211_set_wiphy,
9935 .policy = nl80211_policy,
9936 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009937 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009938 },
9939 {
9940 .cmd = NL80211_CMD_GET_INTERFACE,
9941 .doit = nl80211_get_interface,
9942 .dumpit = nl80211_dump_interface,
9943 .policy = nl80211_policy,
9944 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009945 .internal_flags = NL80211_FLAG_NEED_WDEV |
9946 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009947 },
9948 {
9949 .cmd = NL80211_CMD_SET_INTERFACE,
9950 .doit = nl80211_set_interface,
9951 .policy = nl80211_policy,
9952 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009953 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9954 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009955 },
9956 {
9957 .cmd = NL80211_CMD_NEW_INTERFACE,
9958 .doit = nl80211_new_interface,
9959 .policy = nl80211_policy,
9960 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009961 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9962 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009963 },
9964 {
9965 .cmd = NL80211_CMD_DEL_INTERFACE,
9966 .doit = nl80211_del_interface,
9967 .policy = nl80211_policy,
9968 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009969 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009970 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009971 },
Johannes Berg41ade002007-12-19 02:03:29 +01009972 {
9973 .cmd = NL80211_CMD_GET_KEY,
9974 .doit = nl80211_get_key,
9975 .policy = nl80211_policy,
9976 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009977 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009978 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009979 },
9980 {
9981 .cmd = NL80211_CMD_SET_KEY,
9982 .doit = nl80211_set_key,
9983 .policy = nl80211_policy,
9984 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009985 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009986 NL80211_FLAG_NEED_RTNL |
9987 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009988 },
9989 {
9990 .cmd = NL80211_CMD_NEW_KEY,
9991 .doit = nl80211_new_key,
9992 .policy = nl80211_policy,
9993 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009994 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009995 NL80211_FLAG_NEED_RTNL |
9996 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009997 },
9998 {
9999 .cmd = NL80211_CMD_DEL_KEY,
10000 .doit = nl80211_del_key,
10001 .policy = nl80211_policy,
10002 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010003 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010004 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010005 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010006 {
10007 .cmd = NL80211_CMD_SET_BEACON,
10008 .policy = nl80211_policy,
10009 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010010 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010012 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010013 },
10014 {
Johannes Berg88600202012-02-13 15:17:18 +010010015 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010016 .policy = nl80211_policy,
10017 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010018 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010019 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010020 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010021 },
10022 {
Johannes Berg88600202012-02-13 15:17:18 +010010023 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010024 .policy = nl80211_policy,
10025 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010026 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010027 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010028 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010029 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010030 {
10031 .cmd = NL80211_CMD_GET_STATION,
10032 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010033 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010034 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010035 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10036 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010037 },
10038 {
10039 .cmd = NL80211_CMD_SET_STATION,
10040 .doit = nl80211_set_station,
10041 .policy = nl80211_policy,
10042 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010043 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010044 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010045 },
10046 {
10047 .cmd = NL80211_CMD_NEW_STATION,
10048 .doit = nl80211_new_station,
10049 .policy = nl80211_policy,
10050 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010051 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010052 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010053 },
10054 {
10055 .cmd = NL80211_CMD_DEL_STATION,
10056 .doit = nl80211_del_station,
10057 .policy = nl80211_policy,
10058 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010060 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010061 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010062 {
10063 .cmd = NL80211_CMD_GET_MPATH,
10064 .doit = nl80211_get_mpath,
10065 .dumpit = nl80211_dump_mpath,
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 Berg4c476992010-10-04 21:36:35 +020010069 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010070 },
10071 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010072 .cmd = NL80211_CMD_GET_MPP,
10073 .doit = nl80211_get_mpp,
10074 .dumpit = nl80211_dump_mpp,
10075 .policy = nl80211_policy,
10076 .flags = GENL_ADMIN_PERM,
10077 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10078 NL80211_FLAG_NEED_RTNL,
10079 },
10080 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010081 .cmd = NL80211_CMD_SET_MPATH,
10082 .doit = nl80211_set_mpath,
10083 .policy = nl80211_policy,
10084 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010085 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010086 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010087 },
10088 {
10089 .cmd = NL80211_CMD_NEW_MPATH,
10090 .doit = nl80211_new_mpath,
10091 .policy = nl80211_policy,
10092 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010093 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010094 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010095 },
10096 {
10097 .cmd = NL80211_CMD_DEL_MPATH,
10098 .doit = nl80211_del_mpath,
10099 .policy = nl80211_policy,
10100 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010101 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010102 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010103 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010104 {
10105 .cmd = NL80211_CMD_SET_BSS,
10106 .doit = nl80211_set_bss,
10107 .policy = nl80211_policy,
10108 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010109 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010110 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010111 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010112 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010113 .cmd = NL80211_CMD_GET_REG,
10114 .doit = nl80211_get_reg,
10115 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010116 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010117 /* can be retrieved by unprivileged users */
10118 },
10119 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010120 .cmd = NL80211_CMD_SET_REG,
10121 .doit = nl80211_set_reg,
10122 .policy = nl80211_policy,
10123 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010124 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010125 },
10126 {
10127 .cmd = NL80211_CMD_REQ_SET_REG,
10128 .doit = nl80211_req_set_reg,
10129 .policy = nl80211_policy,
10130 .flags = GENL_ADMIN_PERM,
10131 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010132 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010133 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10134 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010135 .policy = nl80211_policy,
10136 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010137 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010138 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010139 },
10140 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010141 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10142 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010143 .policy = nl80211_policy,
10144 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010145 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010146 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010147 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010148 {
Johannes Berg2a519312009-02-10 21:25:55 +010010149 .cmd = NL80211_CMD_TRIGGER_SCAN,
10150 .doit = nl80211_trigger_scan,
10151 .policy = nl80211_policy,
10152 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010153 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010154 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010155 },
10156 {
10157 .cmd = NL80211_CMD_GET_SCAN,
10158 .policy = nl80211_policy,
10159 .dumpit = nl80211_dump_scan,
10160 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010161 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010162 .cmd = NL80211_CMD_START_SCHED_SCAN,
10163 .doit = nl80211_start_sched_scan,
10164 .policy = nl80211_policy,
10165 .flags = GENL_ADMIN_PERM,
10166 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10167 NL80211_FLAG_NEED_RTNL,
10168 },
10169 {
10170 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10171 .doit = nl80211_stop_sched_scan,
10172 .policy = nl80211_policy,
10173 .flags = GENL_ADMIN_PERM,
10174 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10175 NL80211_FLAG_NEED_RTNL,
10176 },
10177 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010178 .cmd = NL80211_CMD_AUTHENTICATE,
10179 .doit = nl80211_authenticate,
10180 .policy = nl80211_policy,
10181 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010182 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010183 NL80211_FLAG_NEED_RTNL |
10184 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010185 },
10186 {
10187 .cmd = NL80211_CMD_ASSOCIATE,
10188 .doit = nl80211_associate,
10189 .policy = nl80211_policy,
10190 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010191 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010192 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010193 },
10194 {
10195 .cmd = NL80211_CMD_DEAUTHENTICATE,
10196 .doit = nl80211_deauthenticate,
10197 .policy = nl80211_policy,
10198 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010199 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010200 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010201 },
10202 {
10203 .cmd = NL80211_CMD_DISASSOCIATE,
10204 .doit = nl80211_disassociate,
10205 .policy = nl80211_policy,
10206 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010207 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010208 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010209 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010210 {
10211 .cmd = NL80211_CMD_JOIN_IBSS,
10212 .doit = nl80211_join_ibss,
10213 .policy = nl80211_policy,
10214 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010216 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010217 },
10218 {
10219 .cmd = NL80211_CMD_LEAVE_IBSS,
10220 .doit = nl80211_leave_ibss,
10221 .policy = nl80211_policy,
10222 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010223 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010224 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010225 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010226#ifdef CONFIG_NL80211_TESTMODE
10227 {
10228 .cmd = NL80211_CMD_TESTMODE,
10229 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010230 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010231 .policy = nl80211_policy,
10232 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010233 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10234 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010235 },
10236#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010237 {
10238 .cmd = NL80211_CMD_CONNECT,
10239 .doit = nl80211_connect,
10240 .policy = nl80211_policy,
10241 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010242 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010243 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010244 },
10245 {
10246 .cmd = NL80211_CMD_DISCONNECT,
10247 .doit = nl80211_disconnect,
10248 .policy = nl80211_policy,
10249 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010250 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010251 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010252 },
Johannes Berg463d0182009-07-14 00:33:35 +020010253 {
10254 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10255 .doit = nl80211_wiphy_netns,
10256 .policy = nl80211_policy,
10257 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010258 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10259 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010260 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010261 {
10262 .cmd = NL80211_CMD_GET_SURVEY,
10263 .policy = nl80211_policy,
10264 .dumpit = nl80211_dump_survey,
10265 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010266 {
10267 .cmd = NL80211_CMD_SET_PMKSA,
10268 .doit = nl80211_setdel_pmksa,
10269 .policy = nl80211_policy,
10270 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010271 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010272 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010273 },
10274 {
10275 .cmd = NL80211_CMD_DEL_PMKSA,
10276 .doit = nl80211_setdel_pmksa,
10277 .policy = nl80211_policy,
10278 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010280 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010281 },
10282 {
10283 .cmd = NL80211_CMD_FLUSH_PMKSA,
10284 .doit = nl80211_flush_pmksa,
10285 .policy = nl80211_policy,
10286 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010287 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010288 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010289 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010290 {
10291 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10292 .doit = nl80211_remain_on_channel,
10293 .policy = nl80211_policy,
10294 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010295 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010296 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010297 },
10298 {
10299 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10300 .doit = nl80211_cancel_remain_on_channel,
10301 .policy = nl80211_policy,
10302 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010303 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010304 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010305 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010306 {
10307 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10308 .doit = nl80211_set_tx_bitrate_mask,
10309 .policy = nl80211_policy,
10310 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010311 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10312 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010313 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010314 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010315 .cmd = NL80211_CMD_REGISTER_FRAME,
10316 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010317 .policy = nl80211_policy,
10318 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010319 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010320 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010321 },
10322 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010323 .cmd = NL80211_CMD_FRAME,
10324 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010325 .policy = nl80211_policy,
10326 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010327 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010328 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010329 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010330 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010331 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10332 .doit = nl80211_tx_mgmt_cancel_wait,
10333 .policy = nl80211_policy,
10334 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010335 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010336 NL80211_FLAG_NEED_RTNL,
10337 },
10338 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010339 .cmd = NL80211_CMD_SET_POWER_SAVE,
10340 .doit = nl80211_set_power_save,
10341 .policy = nl80211_policy,
10342 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010343 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10344 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010345 },
10346 {
10347 .cmd = NL80211_CMD_GET_POWER_SAVE,
10348 .doit = nl80211_get_power_save,
10349 .policy = nl80211_policy,
10350 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010351 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10352 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010353 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010354 {
10355 .cmd = NL80211_CMD_SET_CQM,
10356 .doit = nl80211_set_cqm,
10357 .policy = nl80211_policy,
10358 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010359 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10360 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010361 },
Johannes Bergf444de02010-05-05 15:25:02 +020010362 {
10363 .cmd = NL80211_CMD_SET_CHANNEL,
10364 .doit = nl80211_set_channel,
10365 .policy = nl80211_policy,
10366 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010367 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10368 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010369 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010370 {
10371 .cmd = NL80211_CMD_SET_WDS_PEER,
10372 .doit = nl80211_set_wds_peer,
10373 .policy = nl80211_policy,
10374 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010375 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10376 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010377 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010378 {
10379 .cmd = NL80211_CMD_JOIN_MESH,
10380 .doit = nl80211_join_mesh,
10381 .policy = nl80211_policy,
10382 .flags = GENL_ADMIN_PERM,
10383 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10384 NL80211_FLAG_NEED_RTNL,
10385 },
10386 {
10387 .cmd = NL80211_CMD_LEAVE_MESH,
10388 .doit = nl80211_leave_mesh,
10389 .policy = nl80211_policy,
10390 .flags = GENL_ADMIN_PERM,
10391 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10392 NL80211_FLAG_NEED_RTNL,
10393 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010394 {
10395 .cmd = NL80211_CMD_JOIN_OCB,
10396 .doit = nl80211_join_ocb,
10397 .policy = nl80211_policy,
10398 .flags = GENL_ADMIN_PERM,
10399 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10400 NL80211_FLAG_NEED_RTNL,
10401 },
10402 {
10403 .cmd = NL80211_CMD_LEAVE_OCB,
10404 .doit = nl80211_leave_ocb,
10405 .policy = nl80211_policy,
10406 .flags = GENL_ADMIN_PERM,
10407 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10408 NL80211_FLAG_NEED_RTNL,
10409 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010410#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010411 {
10412 .cmd = NL80211_CMD_GET_WOWLAN,
10413 .doit = nl80211_get_wowlan,
10414 .policy = nl80211_policy,
10415 /* can be retrieved by unprivileged users */
10416 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10417 NL80211_FLAG_NEED_RTNL,
10418 },
10419 {
10420 .cmd = NL80211_CMD_SET_WOWLAN,
10421 .doit = nl80211_set_wowlan,
10422 .policy = nl80211_policy,
10423 .flags = GENL_ADMIN_PERM,
10424 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10425 NL80211_FLAG_NEED_RTNL,
10426 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010427#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010428 {
10429 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10430 .doit = nl80211_set_rekey_data,
10431 .policy = nl80211_policy,
10432 .flags = GENL_ADMIN_PERM,
10433 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010434 NL80211_FLAG_NEED_RTNL |
10435 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010436 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010437 {
10438 .cmd = NL80211_CMD_TDLS_MGMT,
10439 .doit = nl80211_tdls_mgmt,
10440 .policy = nl80211_policy,
10441 .flags = GENL_ADMIN_PERM,
10442 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10443 NL80211_FLAG_NEED_RTNL,
10444 },
10445 {
10446 .cmd = NL80211_CMD_TDLS_OPER,
10447 .doit = nl80211_tdls_oper,
10448 .policy = nl80211_policy,
10449 .flags = GENL_ADMIN_PERM,
10450 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10451 NL80211_FLAG_NEED_RTNL,
10452 },
Johannes Berg28946da2011-11-04 11:18:12 +010010453 {
10454 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10455 .doit = nl80211_register_unexpected_frame,
10456 .policy = nl80211_policy,
10457 .flags = GENL_ADMIN_PERM,
10458 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10459 NL80211_FLAG_NEED_RTNL,
10460 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010461 {
10462 .cmd = NL80211_CMD_PROBE_CLIENT,
10463 .doit = nl80211_probe_client,
10464 .policy = nl80211_policy,
10465 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010466 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010467 NL80211_FLAG_NEED_RTNL,
10468 },
Johannes Berg5e760232011-11-04 11:18:17 +010010469 {
10470 .cmd = NL80211_CMD_REGISTER_BEACONS,
10471 .doit = nl80211_register_beacons,
10472 .policy = nl80211_policy,
10473 .flags = GENL_ADMIN_PERM,
10474 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10475 NL80211_FLAG_NEED_RTNL,
10476 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010477 {
10478 .cmd = NL80211_CMD_SET_NOACK_MAP,
10479 .doit = nl80211_set_noack_map,
10480 .policy = nl80211_policy,
10481 .flags = GENL_ADMIN_PERM,
10482 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10483 NL80211_FLAG_NEED_RTNL,
10484 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010485 {
10486 .cmd = NL80211_CMD_START_P2P_DEVICE,
10487 .doit = nl80211_start_p2p_device,
10488 .policy = nl80211_policy,
10489 .flags = GENL_ADMIN_PERM,
10490 .internal_flags = NL80211_FLAG_NEED_WDEV |
10491 NL80211_FLAG_NEED_RTNL,
10492 },
10493 {
10494 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10495 .doit = nl80211_stop_p2p_device,
10496 .policy = nl80211_policy,
10497 .flags = GENL_ADMIN_PERM,
10498 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10499 NL80211_FLAG_NEED_RTNL,
10500 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010501 {
10502 .cmd = NL80211_CMD_SET_MCAST_RATE,
10503 .doit = nl80211_set_mcast_rate,
10504 .policy = nl80211_policy,
10505 .flags = GENL_ADMIN_PERM,
10506 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10507 NL80211_FLAG_NEED_RTNL,
10508 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010509 {
10510 .cmd = NL80211_CMD_SET_MAC_ACL,
10511 .doit = nl80211_set_mac_acl,
10512 .policy = nl80211_policy,
10513 .flags = GENL_ADMIN_PERM,
10514 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10515 NL80211_FLAG_NEED_RTNL,
10516 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010517 {
10518 .cmd = NL80211_CMD_RADAR_DETECT,
10519 .doit = nl80211_start_radar_detection,
10520 .policy = nl80211_policy,
10521 .flags = GENL_ADMIN_PERM,
10522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10523 NL80211_FLAG_NEED_RTNL,
10524 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010525 {
10526 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10527 .doit = nl80211_get_protocol_features,
10528 .policy = nl80211_policy,
10529 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010530 {
10531 .cmd = NL80211_CMD_UPDATE_FT_IES,
10532 .doit = nl80211_update_ft_ies,
10533 .policy = nl80211_policy,
10534 .flags = GENL_ADMIN_PERM,
10535 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10536 NL80211_FLAG_NEED_RTNL,
10537 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010538 {
10539 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10540 .doit = nl80211_crit_protocol_start,
10541 .policy = nl80211_policy,
10542 .flags = GENL_ADMIN_PERM,
10543 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10544 NL80211_FLAG_NEED_RTNL,
10545 },
10546 {
10547 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10548 .doit = nl80211_crit_protocol_stop,
10549 .policy = nl80211_policy,
10550 .flags = GENL_ADMIN_PERM,
10551 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10552 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010553 },
10554 {
10555 .cmd = NL80211_CMD_GET_COALESCE,
10556 .doit = nl80211_get_coalesce,
10557 .policy = nl80211_policy,
10558 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10559 NL80211_FLAG_NEED_RTNL,
10560 },
10561 {
10562 .cmd = NL80211_CMD_SET_COALESCE,
10563 .doit = nl80211_set_coalesce,
10564 .policy = nl80211_policy,
10565 .flags = GENL_ADMIN_PERM,
10566 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10567 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010568 },
10569 {
10570 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10571 .doit = nl80211_channel_switch,
10572 .policy = nl80211_policy,
10573 .flags = GENL_ADMIN_PERM,
10574 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10575 NL80211_FLAG_NEED_RTNL,
10576 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010577 {
10578 .cmd = NL80211_CMD_VENDOR,
10579 .doit = nl80211_vendor_cmd,
10580 .policy = nl80211_policy,
10581 .flags = GENL_ADMIN_PERM,
10582 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10583 NL80211_FLAG_NEED_RTNL,
10584 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010585 {
10586 .cmd = NL80211_CMD_SET_QOS_MAP,
10587 .doit = nl80211_set_qos_map,
10588 .policy = nl80211_policy,
10589 .flags = GENL_ADMIN_PERM,
10590 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10591 NL80211_FLAG_NEED_RTNL,
10592 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010593 {
10594 .cmd = NL80211_CMD_ADD_TX_TS,
10595 .doit = nl80211_add_tx_ts,
10596 .policy = nl80211_policy,
10597 .flags = GENL_ADMIN_PERM,
10598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10599 NL80211_FLAG_NEED_RTNL,
10600 },
10601 {
10602 .cmd = NL80211_CMD_DEL_TX_TS,
10603 .doit = nl80211_del_tx_ts,
10604 .policy = nl80211_policy,
10605 .flags = GENL_ADMIN_PERM,
10606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10607 NL80211_FLAG_NEED_RTNL,
10608 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020010609 {
10610 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
10611 .doit = nl80211_tdls_channel_switch,
10612 .policy = nl80211_policy,
10613 .flags = GENL_ADMIN_PERM,
10614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10615 NL80211_FLAG_NEED_RTNL,
10616 },
10617 {
10618 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
10619 .doit = nl80211_tdls_cancel_channel_switch,
10620 .policy = nl80211_policy,
10621 .flags = GENL_ADMIN_PERM,
10622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10623 NL80211_FLAG_NEED_RTNL,
10624 },
Johannes Berg55682962007-09-20 13:09:35 -040010625};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010626
Johannes Berg55682962007-09-20 13:09:35 -040010627/* notification functions */
10628
Johannes Berg3bb20552014-05-26 13:52:25 +020010629void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10630 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010631{
10632 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010633 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010634
Johannes Berg3bb20552014-05-26 13:52:25 +020010635 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10636 cmd != NL80211_CMD_DEL_WIPHY);
10637
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010638 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010639 if (!msg)
10640 return;
10641
Johannes Berg3bb20552014-05-26 13:52:25 +020010642 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010643 nlmsg_free(msg);
10644 return;
10645 }
10646
Johannes Berg68eb5502013-11-19 15:19:38 +010010647 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010648 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010649}
10650
Johannes Berg362a4152009-05-24 16:43:15 +020010651static int nl80211_add_scan_req(struct sk_buff *msg,
10652 struct cfg80211_registered_device *rdev)
10653{
10654 struct cfg80211_scan_request *req = rdev->scan_req;
10655 struct nlattr *nest;
10656 int i;
10657
10658 if (WARN_ON(!req))
10659 return 0;
10660
10661 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10662 if (!nest)
10663 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010664 for (i = 0; i < req->n_ssids; i++) {
10665 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10666 goto nla_put_failure;
10667 }
Johannes Berg362a4152009-05-24 16:43:15 +020010668 nla_nest_end(msg, nest);
10669
10670 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10671 if (!nest)
10672 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010673 for (i = 0; i < req->n_channels; i++) {
10674 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10675 goto nla_put_failure;
10676 }
Johannes Berg362a4152009-05-24 16:43:15 +020010677 nla_nest_end(msg, nest);
10678
David S. Miller9360ffd2012-03-29 04:41:26 -040010679 if (req->ie &&
10680 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10681 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010682
Johannes Bergae917c92013-10-25 11:05:22 +020010683 if (req->flags &&
10684 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10685 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010686
Johannes Berg362a4152009-05-24 16:43:15 +020010687 return 0;
10688 nla_put_failure:
10689 return -ENOBUFS;
10690}
10691
Johannes Berga538e2d2009-06-16 19:56:42 +020010692static int nl80211_send_scan_msg(struct sk_buff *msg,
10693 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010694 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010695 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010696 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010697{
10698 void *hdr;
10699
Eric W. Biederman15e47302012-09-07 20:12:54 +000010700 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010701 if (!hdr)
10702 return -1;
10703
David S. Miller9360ffd2012-03-29 04:41:26 -040010704 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010705 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10706 wdev->netdev->ifindex)) ||
10707 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010708 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010709
Johannes Berg362a4152009-05-24 16:43:15 +020010710 /* ignore errors and send incomplete event anyway */
10711 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010712
10713 return genlmsg_end(msg, hdr);
10714
10715 nla_put_failure:
10716 genlmsg_cancel(msg, hdr);
10717 return -EMSGSIZE;
10718}
10719
Luciano Coelho807f8a82011-05-11 17:09:35 +030010720static int
10721nl80211_send_sched_scan_msg(struct sk_buff *msg,
10722 struct cfg80211_registered_device *rdev,
10723 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010724 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010725{
10726 void *hdr;
10727
Eric W. Biederman15e47302012-09-07 20:12:54 +000010728 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010729 if (!hdr)
10730 return -1;
10731
David S. Miller9360ffd2012-03-29 04:41:26 -040010732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10733 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10734 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010735
10736 return genlmsg_end(msg, hdr);
10737
10738 nla_put_failure:
10739 genlmsg_cancel(msg, hdr);
10740 return -EMSGSIZE;
10741}
10742
Johannes Berga538e2d2009-06-16 19:56:42 +020010743void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010744 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010745{
10746 struct sk_buff *msg;
10747
Thomas Graf58050fc2012-06-28 03:57:45 +000010748 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010749 if (!msg)
10750 return;
10751
Johannes Bergfd014282012-06-18 19:17:03 +020010752 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010753 NL80211_CMD_TRIGGER_SCAN) < 0) {
10754 nlmsg_free(msg);
10755 return;
10756 }
10757
Johannes Berg68eb5502013-11-19 15:19:38 +010010758 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010759 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010760}
10761
Johannes Bergf9d15d12014-01-22 11:14:19 +020010762struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10763 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010764{
10765 struct sk_buff *msg;
10766
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010768 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010769 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010770
Johannes Bergfd014282012-06-18 19:17:03 +020010771 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010772 aborted ? NL80211_CMD_SCAN_ABORTED :
10773 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010774 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010775 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010776 }
10777
Johannes Bergf9d15d12014-01-22 11:14:19 +020010778 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010779}
10780
Johannes Bergf9d15d12014-01-22 11:14:19 +020010781void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10782 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010783{
Johannes Berg2a519312009-02-10 21:25:55 +010010784 if (!msg)
10785 return;
10786
Johannes Berg68eb5502013-11-19 15:19:38 +010010787 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010788 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010789}
10790
Luciano Coelho807f8a82011-05-11 17:09:35 +030010791void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10792 struct net_device *netdev)
10793{
10794 struct sk_buff *msg;
10795
10796 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10797 if (!msg)
10798 return;
10799
10800 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10801 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10802 nlmsg_free(msg);
10803 return;
10804 }
10805
Johannes Berg68eb5502013-11-19 15:19:38 +010010806 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010807 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010808}
10809
10810void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10811 struct net_device *netdev, u32 cmd)
10812{
10813 struct sk_buff *msg;
10814
Thomas Graf58050fc2012-06-28 03:57:45 +000010815 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010816 if (!msg)
10817 return;
10818
10819 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10820 nlmsg_free(msg);
10821 return;
10822 }
10823
Johannes Berg68eb5502013-11-19 15:19:38 +010010824 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010825 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010826}
10827
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010828/*
10829 * This can happen on global regulatory changes or device specific settings
10830 * based on custom world regulatory domains.
10831 */
10832void nl80211_send_reg_change_event(struct regulatory_request *request)
10833{
10834 struct sk_buff *msg;
10835 void *hdr;
10836
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010837 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010838 if (!msg)
10839 return;
10840
10841 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10842 if (!hdr) {
10843 nlmsg_free(msg);
10844 return;
10845 }
10846
10847 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010848 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10849 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010850
David S. Miller9360ffd2012-03-29 04:41:26 -040010851 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10852 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10853 NL80211_REGDOM_TYPE_WORLD))
10854 goto nla_put_failure;
10855 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10856 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10857 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10858 goto nla_put_failure;
10859 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10860 request->intersect) {
10861 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10862 NL80211_REGDOM_TYPE_INTERSECTION))
10863 goto nla_put_failure;
10864 } else {
10865 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10866 NL80211_REGDOM_TYPE_COUNTRY) ||
10867 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10868 request->alpha2))
10869 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010870 }
10871
Johannes Bergf4173762012-12-03 18:23:37 +010010872 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010873 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10874 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010875
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010876 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010877
Johannes Bergbc43b282009-07-25 10:54:13 +020010878 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010879 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010880 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010881 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010882
10883 return;
10884
10885nla_put_failure:
10886 genlmsg_cancel(msg, hdr);
10887 nlmsg_free(msg);
10888}
10889
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010890static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10891 struct net_device *netdev,
10892 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010893 enum nl80211_commands cmd, gfp_t gfp,
10894 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010895{
10896 struct sk_buff *msg;
10897 void *hdr;
10898
Johannes Berge6d6e342009-07-01 21:26:47 +020010899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010900 if (!msg)
10901 return;
10902
10903 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10904 if (!hdr) {
10905 nlmsg_free(msg);
10906 return;
10907 }
10908
David S. Miller9360ffd2012-03-29 04:41:26 -040010909 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10910 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10911 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10912 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010913
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010914 if (uapsd_queues >= 0) {
10915 struct nlattr *nla_wmm =
10916 nla_nest_start(msg, NL80211_ATTR_STA_WME);
10917 if (!nla_wmm)
10918 goto nla_put_failure;
10919
10920 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
10921 uapsd_queues))
10922 goto nla_put_failure;
10923
10924 nla_nest_end(msg, nla_wmm);
10925 }
10926
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010927 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010928
Johannes Berg68eb5502013-11-19 15:19:38 +010010929 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010930 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010931 return;
10932
10933 nla_put_failure:
10934 genlmsg_cancel(msg, hdr);
10935 nlmsg_free(msg);
10936}
10937
10938void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010939 struct net_device *netdev, const u8 *buf,
10940 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010941{
10942 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010943 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010944}
10945
10946void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10947 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010948 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010949{
Johannes Berge6d6e342009-07-01 21:26:47 +020010950 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010951 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010952}
10953
Jouni Malinen53b46b82009-03-27 20:53:56 +020010954void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010955 struct net_device *netdev, const u8 *buf,
10956 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010957{
10958 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010959 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010960}
10961
Jouni Malinen53b46b82009-03-27 20:53:56 +020010962void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10963 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010964 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010965{
10966 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010967 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010968}
10969
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010970void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10971 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010972{
Johannes Berg947add32013-02-22 22:05:20 +010010973 struct wireless_dev *wdev = dev->ieee80211_ptr;
10974 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010975 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010976 const struct ieee80211_mgmt *mgmt = (void *)buf;
10977 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010978
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010979 if (WARN_ON(len < 2))
10980 return;
10981
10982 if (ieee80211_is_deauth(mgmt->frame_control))
10983 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10984 else
10985 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10986
10987 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010988 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010989}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010990EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010991
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010992static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10993 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010994 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010995{
10996 struct sk_buff *msg;
10997 void *hdr;
10998
Johannes Berge6d6e342009-07-01 21:26:47 +020010999 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011000 if (!msg)
11001 return;
11002
11003 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11004 if (!hdr) {
11005 nlmsg_free(msg);
11006 return;
11007 }
11008
David S. Miller9360ffd2012-03-29 04:41:26 -040011009 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11010 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11011 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11012 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11013 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011014
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011015 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011016
Johannes Berg68eb5502013-11-19 15:19:38 +010011017 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011018 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011019 return;
11020
11021 nla_put_failure:
11022 genlmsg_cancel(msg, hdr);
11023 nlmsg_free(msg);
11024}
11025
11026void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011027 struct net_device *netdev, const u8 *addr,
11028 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011029{
11030 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011031 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011032}
11033
11034void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011035 struct net_device *netdev, const u8 *addr,
11036 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011037{
Johannes Berge6d6e342009-07-01 21:26:47 +020011038 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11039 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011040}
11041
Samuel Ortizb23aa672009-07-01 21:26:54 +020011042void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11043 struct net_device *netdev, const u8 *bssid,
11044 const u8 *req_ie, size_t req_ie_len,
11045 const u8 *resp_ie, size_t resp_ie_len,
11046 u16 status, gfp_t gfp)
11047{
11048 struct sk_buff *msg;
11049 void *hdr;
11050
Thomas Graf58050fc2012-06-28 03:57:45 +000011051 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011052 if (!msg)
11053 return;
11054
11055 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11056 if (!hdr) {
11057 nlmsg_free(msg);
11058 return;
11059 }
11060
David S. Miller9360ffd2012-03-29 04:41:26 -040011061 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11062 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11063 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11064 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11065 (req_ie &&
11066 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11067 (resp_ie &&
11068 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11069 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011070
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011071 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011072
Johannes Berg68eb5502013-11-19 15:19:38 +010011073 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011074 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011075 return;
11076
11077 nla_put_failure:
11078 genlmsg_cancel(msg, hdr);
11079 nlmsg_free(msg);
11080
11081}
11082
11083void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11084 struct net_device *netdev, const u8 *bssid,
11085 const u8 *req_ie, size_t req_ie_len,
11086 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11087{
11088 struct sk_buff *msg;
11089 void *hdr;
11090
Thomas Graf58050fc2012-06-28 03:57:45 +000011091 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011092 if (!msg)
11093 return;
11094
11095 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11096 if (!hdr) {
11097 nlmsg_free(msg);
11098 return;
11099 }
11100
David S. Miller9360ffd2012-03-29 04:41:26 -040011101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11102 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11103 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11104 (req_ie &&
11105 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11106 (resp_ie &&
11107 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11108 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011109
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011110 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011111
Johannes Berg68eb5502013-11-19 15:19:38 +010011112 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011113 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011114 return;
11115
11116 nla_put_failure:
11117 genlmsg_cancel(msg, hdr);
11118 nlmsg_free(msg);
11119
11120}
11121
11122void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11123 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020011124 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011125{
11126 struct sk_buff *msg;
11127 void *hdr;
11128
Thomas Graf58050fc2012-06-28 03:57:45 +000011129 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011130 if (!msg)
11131 return;
11132
11133 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11134 if (!hdr) {
11135 nlmsg_free(msg);
11136 return;
11137 }
11138
David S. Miller9360ffd2012-03-29 04:41:26 -040011139 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11140 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11141 (from_ap && reason &&
11142 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11143 (from_ap &&
11144 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11145 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11146 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011147
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011148 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011149
Johannes Berg68eb5502013-11-19 15:19:38 +010011150 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011151 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011152 return;
11153
11154 nla_put_failure:
11155 genlmsg_cancel(msg, hdr);
11156 nlmsg_free(msg);
11157
11158}
11159
Johannes Berg04a773a2009-04-19 21:24:32 +020011160void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11161 struct net_device *netdev, const u8 *bssid,
11162 gfp_t gfp)
11163{
11164 struct sk_buff *msg;
11165 void *hdr;
11166
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011167 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011168 if (!msg)
11169 return;
11170
11171 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11172 if (!hdr) {
11173 nlmsg_free(msg);
11174 return;
11175 }
11176
David S. Miller9360ffd2012-03-29 04:41:26 -040011177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11178 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11179 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11180 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011181
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011182 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011183
Johannes Berg68eb5502013-11-19 15:19:38 +010011184 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011185 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011186 return;
11187
11188 nla_put_failure:
11189 genlmsg_cancel(msg, hdr);
11190 nlmsg_free(msg);
11191}
11192
Johannes Berg947add32013-02-22 22:05:20 +010011193void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11194 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011195{
Johannes Berg947add32013-02-22 22:05:20 +010011196 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011197 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011198 struct sk_buff *msg;
11199 void *hdr;
11200
Johannes Berg947add32013-02-22 22:05:20 +010011201 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11202 return;
11203
11204 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11205
Javier Cardonac93b5e72011-04-07 15:08:34 -070011206 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11207 if (!msg)
11208 return;
11209
11210 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11211 if (!hdr) {
11212 nlmsg_free(msg);
11213 return;
11214 }
11215
David S. Miller9360ffd2012-03-29 04:41:26 -040011216 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011217 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11218 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011219 (ie_len && ie &&
11220 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11221 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011222
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011223 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011224
Johannes Berg68eb5502013-11-19 15:19:38 +010011225 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011226 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011227 return;
11228
11229 nla_put_failure:
11230 genlmsg_cancel(msg, hdr);
11231 nlmsg_free(msg);
11232}
Johannes Berg947add32013-02-22 22:05:20 +010011233EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011234
Jouni Malinena3b8b052009-03-27 21:59:49 +020011235void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11236 struct net_device *netdev, const u8 *addr,
11237 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011238 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011239{
11240 struct sk_buff *msg;
11241 void *hdr;
11242
Johannes Berge6d6e342009-07-01 21:26:47 +020011243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011244 if (!msg)
11245 return;
11246
11247 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11248 if (!hdr) {
11249 nlmsg_free(msg);
11250 return;
11251 }
11252
David S. Miller9360ffd2012-03-29 04:41:26 -040011253 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11254 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11255 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11256 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11257 (key_id != -1 &&
11258 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11259 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11260 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011261
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011262 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011263
Johannes Berg68eb5502013-11-19 15:19:38 +010011264 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011265 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011266 return;
11267
11268 nla_put_failure:
11269 genlmsg_cancel(msg, hdr);
11270 nlmsg_free(msg);
11271}
11272
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011273void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11274 struct ieee80211_channel *channel_before,
11275 struct ieee80211_channel *channel_after)
11276{
11277 struct sk_buff *msg;
11278 void *hdr;
11279 struct nlattr *nl_freq;
11280
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011281 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011282 if (!msg)
11283 return;
11284
11285 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11286 if (!hdr) {
11287 nlmsg_free(msg);
11288 return;
11289 }
11290
11291 /*
11292 * Since we are applying the beacon hint to a wiphy we know its
11293 * wiphy_idx is valid
11294 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011295 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11296 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011297
11298 /* Before */
11299 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11300 if (!nl_freq)
11301 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011302 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011303 goto nla_put_failure;
11304 nla_nest_end(msg, nl_freq);
11305
11306 /* After */
11307 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11308 if (!nl_freq)
11309 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011310 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011311 goto nla_put_failure;
11312 nla_nest_end(msg, nl_freq);
11313
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011314 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011315
Johannes Berg463d0182009-07-14 00:33:35 +020011316 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011317 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011318 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011319 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011320
11321 return;
11322
11323nla_put_failure:
11324 genlmsg_cancel(msg, hdr);
11325 nlmsg_free(msg);
11326}
11327
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011328static void nl80211_send_remain_on_chan_event(
11329 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011330 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011331 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011332 unsigned int duration, gfp_t gfp)
11333{
11334 struct sk_buff *msg;
11335 void *hdr;
11336
11337 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11338 if (!msg)
11339 return;
11340
11341 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11342 if (!hdr) {
11343 nlmsg_free(msg);
11344 return;
11345 }
11346
David S. Miller9360ffd2012-03-29 04:41:26 -040011347 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011348 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11349 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011350 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011351 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011352 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11353 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011354 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11355 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011356
David S. Miller9360ffd2012-03-29 04:41:26 -040011357 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11358 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11359 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011360
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011361 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011362
Johannes Berg68eb5502013-11-19 15:19:38 +010011363 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011364 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011365 return;
11366
11367 nla_put_failure:
11368 genlmsg_cancel(msg, hdr);
11369 nlmsg_free(msg);
11370}
11371
Johannes Berg947add32013-02-22 22:05:20 +010011372void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11373 struct ieee80211_channel *chan,
11374 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011375{
Johannes Berg947add32013-02-22 22:05:20 +010011376 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011377 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011378
11379 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011380 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011381 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011382 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011383}
Johannes Berg947add32013-02-22 22:05:20 +010011384EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011385
Johannes Berg947add32013-02-22 22:05:20 +010011386void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11387 struct ieee80211_channel *chan,
11388 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011389{
Johannes Berg947add32013-02-22 22:05:20 +010011390 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011391 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011392
11393 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011394 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011395 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011396}
Johannes Berg947add32013-02-22 22:05:20 +010011397EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011398
Johannes Berg947add32013-02-22 22:05:20 +010011399void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11400 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011401{
Johannes Berg947add32013-02-22 22:05:20 +010011402 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011403 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011404 struct sk_buff *msg;
11405
Johannes Berg947add32013-02-22 22:05:20 +010011406 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11407
Thomas Graf58050fc2012-06-28 03:57:45 +000011408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011409 if (!msg)
11410 return;
11411
John W. Linville66266b32012-03-15 13:25:41 -040011412 if (nl80211_send_station(msg, 0, 0, 0,
11413 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011414 nlmsg_free(msg);
11415 return;
11416 }
11417
Johannes Berg68eb5502013-11-19 15:19:38 +010011418 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011419 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011420}
Johannes Berg947add32013-02-22 22:05:20 +010011421EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011422
Johannes Berg947add32013-02-22 22:05:20 +010011423void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011424{
Johannes Berg947add32013-02-22 22:05:20 +010011425 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011426 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011427 struct sk_buff *msg;
11428 void *hdr;
11429
Johannes Berg947add32013-02-22 22:05:20 +010011430 trace_cfg80211_del_sta(dev, mac_addr);
11431
Thomas Graf58050fc2012-06-28 03:57:45 +000011432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011433 if (!msg)
11434 return;
11435
11436 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11437 if (!hdr) {
11438 nlmsg_free(msg);
11439 return;
11440 }
11441
David S. Miller9360ffd2012-03-29 04:41:26 -040011442 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11443 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11444 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011445
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011446 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011447
Johannes Berg68eb5502013-11-19 15:19:38 +010011448 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011449 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011450 return;
11451
11452 nla_put_failure:
11453 genlmsg_cancel(msg, hdr);
11454 nlmsg_free(msg);
11455}
Johannes Berg947add32013-02-22 22:05:20 +010011456EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011457
Johannes Berg947add32013-02-22 22:05:20 +010011458void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11459 enum nl80211_connect_failed_reason reason,
11460 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011461{
Johannes Berg947add32013-02-22 22:05:20 +010011462 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011463 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011464 struct sk_buff *msg;
11465 void *hdr;
11466
11467 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11468 if (!msg)
11469 return;
11470
11471 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11472 if (!hdr) {
11473 nlmsg_free(msg);
11474 return;
11475 }
11476
11477 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11478 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11479 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11480 goto nla_put_failure;
11481
11482 genlmsg_end(msg, hdr);
11483
Johannes Berg68eb5502013-11-19 15:19:38 +010011484 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011485 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011486 return;
11487
11488 nla_put_failure:
11489 genlmsg_cancel(msg, hdr);
11490 nlmsg_free(msg);
11491}
Johannes Berg947add32013-02-22 22:05:20 +010011492EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011493
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011494static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11495 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011496{
11497 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011498 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011499 struct sk_buff *msg;
11500 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011501 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011502
Eric W. Biederman15e47302012-09-07 20:12:54 +000011503 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011504 return false;
11505
11506 msg = nlmsg_new(100, gfp);
11507 if (!msg)
11508 return true;
11509
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011510 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011511 if (!hdr) {
11512 nlmsg_free(msg);
11513 return true;
11514 }
11515
David S. Miller9360ffd2012-03-29 04:41:26 -040011516 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11517 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11518 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11519 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011520
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011521 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011522 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011523 return true;
11524
11525 nla_put_failure:
11526 genlmsg_cancel(msg, hdr);
11527 nlmsg_free(msg);
11528 return true;
11529}
11530
Johannes Berg947add32013-02-22 22:05:20 +010011531bool cfg80211_rx_spurious_frame(struct net_device *dev,
11532 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011533{
Johannes Berg947add32013-02-22 22:05:20 +010011534 struct wireless_dev *wdev = dev->ieee80211_ptr;
11535 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011536
Johannes Berg947add32013-02-22 22:05:20 +010011537 trace_cfg80211_rx_spurious_frame(dev, addr);
11538
11539 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11540 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11541 trace_cfg80211_return_bool(false);
11542 return false;
11543 }
11544 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11545 addr, gfp);
11546 trace_cfg80211_return_bool(ret);
11547 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011548}
Johannes Berg947add32013-02-22 22:05:20 +010011549EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11550
11551bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11552 const u8 *addr, gfp_t gfp)
11553{
11554 struct wireless_dev *wdev = dev->ieee80211_ptr;
11555 bool ret;
11556
11557 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11558
11559 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11560 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11561 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11562 trace_cfg80211_return_bool(false);
11563 return false;
11564 }
11565 ret = __nl80211_unexpected_frame(dev,
11566 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11567 addr, gfp);
11568 trace_cfg80211_return_bool(ret);
11569 return ret;
11570}
11571EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011572
Johannes Berg2e161f72010-08-12 15:38:38 +020011573int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011574 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011575 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011576 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011577{
Johannes Berg71bbc992012-06-15 15:30:18 +020011578 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011579 struct sk_buff *msg;
11580 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011581
11582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11583 if (!msg)
11584 return -ENOMEM;
11585
Johannes Berg2e161f72010-08-12 15:38:38 +020011586 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011587 if (!hdr) {
11588 nlmsg_free(msg);
11589 return -ENOMEM;
11590 }
11591
David S. Miller9360ffd2012-03-29 04:41:26 -040011592 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011593 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11594 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011595 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011596 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11597 (sig_dbm &&
11598 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011599 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11600 (flags &&
11601 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011602 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011603
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011604 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011605
Eric W. Biederman15e47302012-09-07 20:12:54 +000011606 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011607
11608 nla_put_failure:
11609 genlmsg_cancel(msg, hdr);
11610 nlmsg_free(msg);
11611 return -ENOBUFS;
11612}
11613
Johannes Berg947add32013-02-22 22:05:20 +010011614void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11615 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011616{
Johannes Berg947add32013-02-22 22:05:20 +010011617 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011618 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011619 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011620 struct sk_buff *msg;
11621 void *hdr;
11622
Johannes Berg947add32013-02-22 22:05:20 +010011623 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11624
Jouni Malinen026331c2010-02-15 12:53:10 +020011625 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11626 if (!msg)
11627 return;
11628
Johannes Berg2e161f72010-08-12 15:38:38 +020011629 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011630 if (!hdr) {
11631 nlmsg_free(msg);
11632 return;
11633 }
11634
David S. Miller9360ffd2012-03-29 04:41:26 -040011635 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011636 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11637 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011638 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011639 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11640 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11641 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11642 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011643
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011644 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011645
Johannes Berg68eb5502013-11-19 15:19:38 +010011646 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011647 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011648 return;
11649
11650 nla_put_failure:
11651 genlmsg_cancel(msg, hdr);
11652 nlmsg_free(msg);
11653}
Johannes Berg947add32013-02-22 22:05:20 +010011654EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011655
Johannes Berg947add32013-02-22 22:05:20 +010011656void cfg80211_cqm_rssi_notify(struct net_device *dev,
11657 enum nl80211_cqm_rssi_threshold_event rssi_event,
11658 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011659{
Johannes Berg947add32013-02-22 22:05:20 +010011660 struct wireless_dev *wdev = dev->ieee80211_ptr;
11661 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011662 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011663 struct sk_buff *msg;
11664 struct nlattr *pinfoattr;
11665 void *hdr;
11666
Johannes Berg947add32013-02-22 22:05:20 +010011667 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11668
Thomas Graf58050fc2012-06-28 03:57:45 +000011669 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011670 if (!msg)
11671 return;
11672
11673 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11674 if (!hdr) {
11675 nlmsg_free(msg);
11676 return;
11677 }
11678
David S. Miller9360ffd2012-03-29 04:41:26 -040011679 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011680 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011681 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011682
11683 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11684 if (!pinfoattr)
11685 goto nla_put_failure;
11686
David S. Miller9360ffd2012-03-29 04:41:26 -040011687 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11688 rssi_event))
11689 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011690
11691 nla_nest_end(msg, pinfoattr);
11692
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011693 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011694
Johannes Berg68eb5502013-11-19 15:19:38 +010011695 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011696 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011697 return;
11698
11699 nla_put_failure:
11700 genlmsg_cancel(msg, hdr);
11701 nlmsg_free(msg);
11702}
Johannes Berg947add32013-02-22 22:05:20 +010011703EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011704
Johannes Berg947add32013-02-22 22:05:20 +010011705static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11706 struct net_device *netdev, const u8 *bssid,
11707 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011708{
11709 struct sk_buff *msg;
11710 struct nlattr *rekey_attr;
11711 void *hdr;
11712
Thomas Graf58050fc2012-06-28 03:57:45 +000011713 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011714 if (!msg)
11715 return;
11716
11717 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11718 if (!hdr) {
11719 nlmsg_free(msg);
11720 return;
11721 }
11722
David S. Miller9360ffd2012-03-29 04:41:26 -040011723 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11724 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11725 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11726 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011727
11728 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11729 if (!rekey_attr)
11730 goto nla_put_failure;
11731
David S. Miller9360ffd2012-03-29 04:41:26 -040011732 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11733 NL80211_REPLAY_CTR_LEN, replay_ctr))
11734 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011735
11736 nla_nest_end(msg, rekey_attr);
11737
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011738 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011739
Johannes Berg68eb5502013-11-19 15:19:38 +010011740 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011741 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011742 return;
11743
11744 nla_put_failure:
11745 genlmsg_cancel(msg, hdr);
11746 nlmsg_free(msg);
11747}
11748
Johannes Berg947add32013-02-22 22:05:20 +010011749void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11750 const u8 *replay_ctr, gfp_t gfp)
11751{
11752 struct wireless_dev *wdev = dev->ieee80211_ptr;
11753 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011754 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011755
11756 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11757 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11758}
11759EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11760
11761static void
11762nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11763 struct net_device *netdev, int index,
11764 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011765{
11766 struct sk_buff *msg;
11767 struct nlattr *attr;
11768 void *hdr;
11769
Thomas Graf58050fc2012-06-28 03:57:45 +000011770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011771 if (!msg)
11772 return;
11773
11774 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11775 if (!hdr) {
11776 nlmsg_free(msg);
11777 return;
11778 }
11779
David S. Miller9360ffd2012-03-29 04:41:26 -040011780 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11781 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11782 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011783
11784 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11785 if (!attr)
11786 goto nla_put_failure;
11787
David S. Miller9360ffd2012-03-29 04:41:26 -040011788 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11789 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11790 (preauth &&
11791 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11792 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011793
11794 nla_nest_end(msg, attr);
11795
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011796 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011797
Johannes Berg68eb5502013-11-19 15:19:38 +010011798 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011799 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011800 return;
11801
11802 nla_put_failure:
11803 genlmsg_cancel(msg, hdr);
11804 nlmsg_free(msg);
11805}
11806
Johannes Berg947add32013-02-22 22:05:20 +010011807void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11808 const u8 *bssid, bool preauth, gfp_t gfp)
11809{
11810 struct wireless_dev *wdev = dev->ieee80211_ptr;
11811 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011812 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011813
11814 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11815 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11816}
11817EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11818
11819static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11820 struct net_device *netdev,
11821 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020011822 gfp_t gfp,
11823 enum nl80211_commands notif,
11824 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070011825{
11826 struct sk_buff *msg;
11827 void *hdr;
11828
Thomas Graf58050fc2012-06-28 03:57:45 +000011829 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011830 if (!msg)
11831 return;
11832
Luciano Coelhof8d75522014-11-07 14:31:35 +020011833 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070011834 if (!hdr) {
11835 nlmsg_free(msg);
11836 return;
11837 }
11838
Johannes Berg683b6d32012-11-08 21:25:48 +010011839 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11840 goto nla_put_failure;
11841
11842 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011843 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011844
Luciano Coelhof8d75522014-11-07 14:31:35 +020011845 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
11846 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
11847 goto nla_put_failure;
11848
Thomas Pedersen53145262012-04-06 13:35:47 -070011849 genlmsg_end(msg, hdr);
11850
Johannes Berg68eb5502013-11-19 15:19:38 +010011851 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011852 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011853 return;
11854
11855 nla_put_failure:
11856 genlmsg_cancel(msg, hdr);
11857 nlmsg_free(msg);
11858}
11859
Johannes Berg947add32013-02-22 22:05:20 +010011860void cfg80211_ch_switch_notify(struct net_device *dev,
11861 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011862{
Johannes Berg947add32013-02-22 22:05:20 +010011863 struct wireless_dev *wdev = dev->ieee80211_ptr;
11864 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011865 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011866
Simon Wunderliche487eae2013-11-21 18:19:51 +010011867 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011868
Simon Wunderliche487eae2013-11-21 18:19:51 +010011869 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011870
Michal Kazior9e0e2962014-01-29 14:22:27 +010011871 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011872 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020011873 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
11874 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010011875}
11876EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11877
Luciano Coelhof8d75522014-11-07 14:31:35 +020011878void cfg80211_ch_switch_started_notify(struct net_device *dev,
11879 struct cfg80211_chan_def *chandef,
11880 u8 count)
11881{
11882 struct wireless_dev *wdev = dev->ieee80211_ptr;
11883 struct wiphy *wiphy = wdev->wiphy;
11884 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
11885
11886 trace_cfg80211_ch_switch_started_notify(dev, chandef);
11887
11888 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
11889 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
11890}
11891EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
11892
Johannes Berg947add32013-02-22 22:05:20 +010011893void cfg80211_cqm_txe_notify(struct net_device *dev,
11894 const u8 *peer, u32 num_packets,
11895 u32 rate, u32 intvl, gfp_t gfp)
11896{
11897 struct wireless_dev *wdev = dev->ieee80211_ptr;
11898 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011899 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011900 struct sk_buff *msg;
11901 struct nlattr *pinfoattr;
11902 void *hdr;
11903
11904 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11905 if (!msg)
11906 return;
11907
11908 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11909 if (!hdr) {
11910 nlmsg_free(msg);
11911 return;
11912 }
11913
11914 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011915 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011916 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11917 goto nla_put_failure;
11918
11919 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11920 if (!pinfoattr)
11921 goto nla_put_failure;
11922
11923 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11924 goto nla_put_failure;
11925
11926 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11927 goto nla_put_failure;
11928
11929 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11930 goto nla_put_failure;
11931
11932 nla_nest_end(msg, pinfoattr);
11933
11934 genlmsg_end(msg, hdr);
11935
Johannes Berg68eb5502013-11-19 15:19:38 +010011936 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011937 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011938 return;
11939
11940 nla_put_failure:
11941 genlmsg_cancel(msg, hdr);
11942 nlmsg_free(msg);
11943}
Johannes Berg947add32013-02-22 22:05:20 +010011944EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011945
11946void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011947nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011948 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011949 enum nl80211_radar_event event,
11950 struct net_device *netdev, gfp_t gfp)
11951{
11952 struct sk_buff *msg;
11953 void *hdr;
11954
11955 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11956 if (!msg)
11957 return;
11958
11959 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11960 if (!hdr) {
11961 nlmsg_free(msg);
11962 return;
11963 }
11964
11965 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11966 goto nla_put_failure;
11967
11968 /* NOP and radar events don't need a netdev parameter */
11969 if (netdev) {
11970 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11971
11972 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11973 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11974 goto nla_put_failure;
11975 }
11976
11977 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11978 goto nla_put_failure;
11979
11980 if (nl80211_send_chandef(msg, chandef))
11981 goto nla_put_failure;
11982
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011983 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011984
Johannes Berg68eb5502013-11-19 15:19:38 +010011985 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011986 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011987 return;
11988
11989 nla_put_failure:
11990 genlmsg_cancel(msg, hdr);
11991 nlmsg_free(msg);
11992}
11993
Johannes Berg947add32013-02-22 22:05:20 +010011994void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11995 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011996{
Johannes Berg947add32013-02-22 22:05:20 +010011997 struct wireless_dev *wdev = dev->ieee80211_ptr;
11998 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011999 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012000 struct sk_buff *msg;
12001 struct nlattr *pinfoattr;
12002 void *hdr;
12003
Johannes Berg947add32013-02-22 22:05:20 +010012004 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12005
Thomas Graf58050fc2012-06-28 03:57:45 +000012006 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012007 if (!msg)
12008 return;
12009
12010 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12011 if (!hdr) {
12012 nlmsg_free(msg);
12013 return;
12014 }
12015
David S. Miller9360ffd2012-03-29 04:41:26 -040012016 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012017 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012018 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
12019 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010012020
12021 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
12022 if (!pinfoattr)
12023 goto nla_put_failure;
12024
David S. Miller9360ffd2012-03-29 04:41:26 -040012025 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12026 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010012027
12028 nla_nest_end(msg, pinfoattr);
12029
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012030 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012031
Johannes Berg68eb5502013-11-19 15:19:38 +010012032 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012033 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012034 return;
12035
12036 nla_put_failure:
12037 genlmsg_cancel(msg, hdr);
12038 nlmsg_free(msg);
12039}
Johannes Berg947add32013-02-22 22:05:20 +010012040EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010012041
Johannes Berg7f6cf312011-11-04 11:18:15 +010012042void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12043 u64 cookie, bool acked, gfp_t gfp)
12044{
12045 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012046 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012047 struct sk_buff *msg;
12048 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012049
Beni Lev4ee3e062012-08-27 12:49:39 +030012050 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12051
Thomas Graf58050fc2012-06-28 03:57:45 +000012052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012053
Johannes Berg7f6cf312011-11-04 11:18:15 +010012054 if (!msg)
12055 return;
12056
12057 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12058 if (!hdr) {
12059 nlmsg_free(msg);
12060 return;
12061 }
12062
David S. Miller9360ffd2012-03-29 04:41:26 -040012063 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12064 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12065 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12066 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12067 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12068 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012069
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012070 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012071
Johannes Berg68eb5502013-11-19 15:19:38 +010012072 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012073 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012074 return;
12075
12076 nla_put_failure:
12077 genlmsg_cancel(msg, hdr);
12078 nlmsg_free(msg);
12079}
12080EXPORT_SYMBOL(cfg80211_probe_status);
12081
Johannes Berg5e760232011-11-04 11:18:17 +010012082void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12083 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012084 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012085{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012086 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012087 struct sk_buff *msg;
12088 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012089 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012090
Beni Lev4ee3e062012-08-27 12:49:39 +030012091 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12092
Ben Greear37c73b52012-10-26 14:49:25 -070012093 spin_lock_bh(&rdev->beacon_registrations_lock);
12094 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12095 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12096 if (!msg) {
12097 spin_unlock_bh(&rdev->beacon_registrations_lock);
12098 return;
12099 }
Johannes Berg5e760232011-11-04 11:18:17 +010012100
Ben Greear37c73b52012-10-26 14:49:25 -070012101 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12102 if (!hdr)
12103 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012104
Ben Greear37c73b52012-10-26 14:49:25 -070012105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12106 (freq &&
12107 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12108 (sig_dbm &&
12109 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12110 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12111 goto nla_put_failure;
12112
12113 genlmsg_end(msg, hdr);
12114
12115 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012116 }
Ben Greear37c73b52012-10-26 14:49:25 -070012117 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012118 return;
12119
12120 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012121 spin_unlock_bh(&rdev->beacon_registrations_lock);
12122 if (hdr)
12123 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012124 nlmsg_free(msg);
12125}
12126EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12127
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012128#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012129static int cfg80211_net_detect_results(struct sk_buff *msg,
12130 struct cfg80211_wowlan_wakeup *wakeup)
12131{
12132 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12133 struct nlattr *nl_results, *nl_match, *nl_freqs;
12134 int i, j;
12135
12136 nl_results = nla_nest_start(
12137 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12138 if (!nl_results)
12139 return -EMSGSIZE;
12140
12141 for (i = 0; i < nd->n_matches; i++) {
12142 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12143
12144 nl_match = nla_nest_start(msg, i);
12145 if (!nl_match)
12146 break;
12147
12148 /* The SSID attribute is optional in nl80211, but for
12149 * simplicity reasons it's always present in the
12150 * cfg80211 structure. If a driver can't pass the
12151 * SSID, that needs to be changed. A zero length SSID
12152 * is still a valid SSID (wildcard), so it cannot be
12153 * used for this purpose.
12154 */
12155 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12156 match->ssid.ssid)) {
12157 nla_nest_cancel(msg, nl_match);
12158 goto out;
12159 }
12160
12161 if (match->n_channels) {
12162 nl_freqs = nla_nest_start(
12163 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12164 if (!nl_freqs) {
12165 nla_nest_cancel(msg, nl_match);
12166 goto out;
12167 }
12168
12169 for (j = 0; j < match->n_channels; j++) {
12170 if (nla_put_u32(msg,
12171 NL80211_ATTR_WIPHY_FREQ,
12172 match->channels[j])) {
12173 nla_nest_cancel(msg, nl_freqs);
12174 nla_nest_cancel(msg, nl_match);
12175 goto out;
12176 }
12177 }
12178
12179 nla_nest_end(msg, nl_freqs);
12180 }
12181
12182 nla_nest_end(msg, nl_match);
12183 }
12184
12185out:
12186 nla_nest_end(msg, nl_results);
12187 return 0;
12188}
12189
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012190void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12191 struct cfg80211_wowlan_wakeup *wakeup,
12192 gfp_t gfp)
12193{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012194 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012195 struct sk_buff *msg;
12196 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012197 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012198
12199 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12200
12201 if (wakeup)
12202 size += wakeup->packet_present_len;
12203
12204 msg = nlmsg_new(size, gfp);
12205 if (!msg)
12206 return;
12207
12208 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12209 if (!hdr)
12210 goto free_msg;
12211
12212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12213 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12214 goto free_msg;
12215
12216 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12217 wdev->netdev->ifindex))
12218 goto free_msg;
12219
12220 if (wakeup) {
12221 struct nlattr *reasons;
12222
12223 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012224 if (!reasons)
12225 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012226
12227 if (wakeup->disconnect &&
12228 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12229 goto free_msg;
12230 if (wakeup->magic_pkt &&
12231 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12232 goto free_msg;
12233 if (wakeup->gtk_rekey_failure &&
12234 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12235 goto free_msg;
12236 if (wakeup->eap_identity_req &&
12237 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12238 goto free_msg;
12239 if (wakeup->four_way_handshake &&
12240 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12241 goto free_msg;
12242 if (wakeup->rfkill_release &&
12243 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12244 goto free_msg;
12245
12246 if (wakeup->pattern_idx >= 0 &&
12247 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12248 wakeup->pattern_idx))
12249 goto free_msg;
12250
Johannes Bergae917c92013-10-25 11:05:22 +020012251 if (wakeup->tcp_match &&
12252 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12253 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012254
Johannes Bergae917c92013-10-25 11:05:22 +020012255 if (wakeup->tcp_connlost &&
12256 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12257 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012258
Johannes Bergae917c92013-10-25 11:05:22 +020012259 if (wakeup->tcp_nomoretokens &&
12260 nla_put_flag(msg,
12261 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12262 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012263
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012264 if (wakeup->packet) {
12265 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12266 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12267
12268 if (!wakeup->packet_80211) {
12269 pkt_attr =
12270 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12271 len_attr =
12272 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12273 }
12274
12275 if (wakeup->packet_len &&
12276 nla_put_u32(msg, len_attr, wakeup->packet_len))
12277 goto free_msg;
12278
12279 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12280 wakeup->packet))
12281 goto free_msg;
12282 }
12283
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012284 if (wakeup->net_detect &&
12285 cfg80211_net_detect_results(msg, wakeup))
12286 goto free_msg;
12287
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012288 nla_nest_end(msg, reasons);
12289 }
12290
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012291 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012292
Johannes Berg68eb5502013-11-19 15:19:38 +010012293 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012294 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012295 return;
12296
12297 free_msg:
12298 nlmsg_free(msg);
12299}
12300EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12301#endif
12302
Jouni Malinen3475b092012-11-16 22:49:57 +020012303void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12304 enum nl80211_tdls_operation oper,
12305 u16 reason_code, gfp_t gfp)
12306{
12307 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012308 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012309 struct sk_buff *msg;
12310 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012311
12312 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12313 reason_code);
12314
12315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12316 if (!msg)
12317 return;
12318
12319 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12320 if (!hdr) {
12321 nlmsg_free(msg);
12322 return;
12323 }
12324
12325 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12326 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12327 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12328 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12329 (reason_code > 0 &&
12330 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12331 goto nla_put_failure;
12332
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012333 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012334
Johannes Berg68eb5502013-11-19 15:19:38 +010012335 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012336 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012337 return;
12338
12339 nla_put_failure:
12340 genlmsg_cancel(msg, hdr);
12341 nlmsg_free(msg);
12342}
12343EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12344
Jouni Malinen026331c2010-02-15 12:53:10 +020012345static int nl80211_netlink_notify(struct notifier_block * nb,
12346 unsigned long state,
12347 void *_notify)
12348{
12349 struct netlink_notify *notify = _notify;
12350 struct cfg80211_registered_device *rdev;
12351 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012352 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012353
12354 if (state != NETLINK_URELEASE)
12355 return NOTIFY_DONE;
12356
12357 rcu_read_lock();
12358
Johannes Berg5e760232011-11-04 11:18:17 +010012359 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012360 bool schedule_destroy_work = false;
12361
12362 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012363 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012364
Johannes Berg78f22b62014-03-24 17:57:27 +010012365 if (wdev->owner_nlportid == notify->portid)
12366 schedule_destroy_work = true;
12367 }
12368
Ben Greear37c73b52012-10-26 14:49:25 -070012369 spin_lock_bh(&rdev->beacon_registrations_lock);
12370 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12371 list) {
12372 if (reg->nlportid == notify->portid) {
12373 list_del(&reg->list);
12374 kfree(reg);
12375 break;
12376 }
12377 }
12378 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012379
12380 if (schedule_destroy_work) {
12381 struct cfg80211_iface_destroy *destroy;
12382
12383 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12384 if (destroy) {
12385 destroy->nlportid = notify->portid;
12386 spin_lock(&rdev->destroy_list_lock);
12387 list_add(&destroy->list, &rdev->destroy_list);
12388 spin_unlock(&rdev->destroy_list_lock);
12389 schedule_work(&rdev->destroy_work);
12390 }
12391 }
Johannes Berg5e760232011-11-04 11:18:17 +010012392 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012393
12394 rcu_read_unlock();
12395
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012396 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012397}
12398
12399static struct notifier_block nl80211_netlink_notifier = {
12400 .notifier_call = nl80211_netlink_notify,
12401};
12402
Jouni Malinen355199e2013-02-27 17:14:27 +020012403void cfg80211_ft_event(struct net_device *netdev,
12404 struct cfg80211_ft_event_params *ft_event)
12405{
12406 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012407 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012408 struct sk_buff *msg;
12409 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012410
12411 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12412
12413 if (!ft_event->target_ap)
12414 return;
12415
12416 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12417 if (!msg)
12418 return;
12419
12420 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012421 if (!hdr)
12422 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012423
Johannes Bergae917c92013-10-25 11:05:22 +020012424 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12425 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12426 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12427 goto out;
12428
12429 if (ft_event->ies &&
12430 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12431 goto out;
12432 if (ft_event->ric_ies &&
12433 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12434 ft_event->ric_ies))
12435 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012436
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012437 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012438
Johannes Berg68eb5502013-11-19 15:19:38 +010012439 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012440 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012441 return;
12442 out:
12443 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012444}
12445EXPORT_SYMBOL(cfg80211_ft_event);
12446
Arend van Spriel5de17982013-04-18 15:49:00 +020012447void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12448{
12449 struct cfg80211_registered_device *rdev;
12450 struct sk_buff *msg;
12451 void *hdr;
12452 u32 nlportid;
12453
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012454 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012455 if (!rdev->crit_proto_nlportid)
12456 return;
12457
12458 nlportid = rdev->crit_proto_nlportid;
12459 rdev->crit_proto_nlportid = 0;
12460
12461 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12462 if (!msg)
12463 return;
12464
12465 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12466 if (!hdr)
12467 goto nla_put_failure;
12468
12469 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12470 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12471 goto nla_put_failure;
12472
12473 genlmsg_end(msg, hdr);
12474
12475 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12476 return;
12477
12478 nla_put_failure:
12479 if (hdr)
12480 genlmsg_cancel(msg, hdr);
12481 nlmsg_free(msg);
12482
12483}
12484EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12485
Johannes Berg348baf02014-01-24 14:06:29 +010012486void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12487{
12488 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012489 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012490 struct sk_buff *msg;
12491 void *hdr;
12492
12493 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12494 if (!msg)
12495 return;
12496
12497 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12498 if (!hdr)
12499 goto out;
12500
12501 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12502 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12503 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12504 goto out;
12505
12506 genlmsg_end(msg, hdr);
12507
12508 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12509 NL80211_MCGRP_MLME, GFP_KERNEL);
12510 return;
12511 out:
12512 nlmsg_free(msg);
12513}
12514
Johannes Berg55682962007-09-20 13:09:35 -040012515/* initialisation/exit functions */
12516
12517int nl80211_init(void)
12518{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012519 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012520
Johannes Berg2a94fe42013-11-19 15:19:39 +010012521 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12522 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012523 if (err)
12524 return err;
12525
Jouni Malinen026331c2010-02-15 12:53:10 +020012526 err = netlink_register_notifier(&nl80211_netlink_notifier);
12527 if (err)
12528 goto err_out;
12529
Johannes Berg55682962007-09-20 13:09:35 -040012530 return 0;
12531 err_out:
12532 genl_unregister_family(&nl80211_fam);
12533 return err;
12534}
12535
12536void nl80211_exit(void)
12537{
Jouni Malinen026331c2010-02-15 12:53:10 +020012538 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012539 genl_unregister_family(&nl80211_fam);
12540}