blob: 5b1907f4c181046658e236502a65441a2e4efaf9 [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 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200391 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200398 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200399 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400400};
401
Johannes Berge31b8212010-10-05 19:39:30 +0200402/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000403static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200404 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200405 [NL80211_KEY_IDX] = { .type = NLA_U8 },
406 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200407 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
409 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200410 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100411 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
412};
413
414/* policy for the key default flags */
415static const struct nla_policy
416nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
417 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
418 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200419};
420
Johannes Bergff1b6e62011-05-04 15:37:28 +0200421/* policy for WoWLAN attributes */
422static const struct nla_policy
423nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
424 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
426 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
427 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200428 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
431 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100432 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300433 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100434};
435
436static const struct nla_policy
437nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
438 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
439 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
440 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
441 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
442 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
443 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
444 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
445 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
446 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
448 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
449 },
450 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
451 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
452 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200453};
454
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700455/* policy for coalesce rule attributes */
456static const struct nla_policy
457nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
458 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
459 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
460 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
461};
462
Johannes Berge5497d72011-07-05 16:35:40 +0200463/* policy for GTK rekey offload attributes */
464static const struct nla_policy
465nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
466 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
467 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
468 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
469};
470
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300471static const struct nla_policy
472nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200473 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700475 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300476};
477
Johannes Berg97990a02013-04-19 01:02:55 +0200478static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
479 struct netlink_callback *cb,
480 struct cfg80211_registered_device **rdev,
481 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100482{
Johannes Berg67748892010-10-04 21:14:06 +0200483 int err;
484
Johannes Berg67748892010-10-04 21:14:06 +0200485 rtnl_lock();
486
Johannes Berg97990a02013-04-19 01:02:55 +0200487 if (!cb->args[0]) {
488 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
489 nl80211_fam.attrbuf, nl80211_fam.maxattr,
490 nl80211_policy);
491 if (err)
492 goto out_unlock;
493
494 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
495 nl80211_fam.attrbuf);
496 if (IS_ERR(*wdev)) {
497 err = PTR_ERR(*wdev);
498 goto out_unlock;
499 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800500 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200501 /* 0 is the first index - add 1 to parse only once */
502 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200503 cb->args[1] = (*wdev)->identifier;
504 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200505 /* subtract the 1 again here */
506 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200507 struct wireless_dev *tmp;
508
509 if (!wiphy) {
510 err = -ENODEV;
511 goto out_unlock;
512 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800513 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200514 *wdev = NULL;
515
Johannes Berg97990a02013-04-19 01:02:55 +0200516 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
517 if (tmp->identifier == cb->args[1]) {
518 *wdev = tmp;
519 break;
520 }
521 }
Johannes Berg97990a02013-04-19 01:02:55 +0200522
523 if (!*wdev) {
524 err = -ENODEV;
525 goto out_unlock;
526 }
Johannes Berg67748892010-10-04 21:14:06 +0200527 }
528
Johannes Berg67748892010-10-04 21:14:06 +0200529 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200530 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200531 rtnl_unlock();
532 return err;
533}
534
Johannes Berg97990a02013-04-19 01:02:55 +0200535static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200536{
Johannes Berg67748892010-10-04 21:14:06 +0200537 rtnl_unlock();
538}
539
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100540/* IE validation */
541static bool is_valid_ie_attr(const struct nlattr *attr)
542{
543 const u8 *pos;
544 int len;
545
546 if (!attr)
547 return true;
548
549 pos = nla_data(attr);
550 len = nla_len(attr);
551
552 while (len) {
553 u8 elemlen;
554
555 if (len < 2)
556 return false;
557 len -= 2;
558
559 elemlen = pos[1];
560 if (elemlen > len)
561 return false;
562
563 len -= elemlen;
564 pos += 2 + elemlen;
565 }
566
567 return true;
568}
569
Johannes Berg55682962007-09-20 13:09:35 -0400570/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000571static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400572 int flags, u8 cmd)
573{
574 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000575 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400576}
577
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400578static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100579 struct ieee80211_channel *chan,
580 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200582 /* Some channels must be completely excluded from the
583 * list to protect old user-space tools from breaking
584 */
585 if (!large && chan->flags &
586 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
587 return 0;
588
David S. Miller9360ffd2012-03-29 04:41:26 -0400589 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
590 chan->center_freq))
591 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400592
David S. Miller9360ffd2012-03-29 04:41:26 -0400593 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
594 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
595 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200596 if (chan->flags & IEEE80211_CHAN_NO_IR) {
597 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
598 goto nla_put_failure;
599 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
600 goto nla_put_failure;
601 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100602 if (chan->flags & IEEE80211_CHAN_RADAR) {
603 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
604 goto nla_put_failure;
605 if (large) {
606 u32 time;
607
608 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
609
610 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
611 chan->dfs_state))
612 goto nla_put_failure;
613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
614 time))
615 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100616 if (nla_put_u32(msg,
617 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
618 chan->dfs_cac_ms))
619 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100620 }
621 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400622
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100623 if (large) {
624 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
625 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
626 goto nla_put_failure;
627 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
635 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200636 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
638 goto nla_put_failure;
639 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
641 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200642 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
644 goto nla_put_failure;
645 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
646 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
647 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100648 }
649
David S. Miller9360ffd2012-03-29 04:41:26 -0400650 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
651 DBM_TO_MBM(chan->max_power)))
652 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400653
654 return 0;
655
656 nla_put_failure:
657 return -ENOBUFS;
658}
659
Johannes Berg55682962007-09-20 13:09:35 -0400660/* netlink command implementations */
661
Johannes Bergb9454e82009-07-08 13:29:08 +0200662struct key_parse {
663 struct key_params p;
664 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200665 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200666 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100667 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200668};
669
670static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
671{
672 struct nlattr *tb[NL80211_KEY_MAX + 1];
673 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
674 nl80211_key_policy);
675 if (err)
676 return err;
677
678 k->def = !!tb[NL80211_KEY_DEFAULT];
679 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
680
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100681 if (k->def) {
682 k->def_uni = true;
683 k->def_multi = true;
684 }
685 if (k->defmgmt)
686 k->def_multi = true;
687
Johannes Bergb9454e82009-07-08 13:29:08 +0200688 if (tb[NL80211_KEY_IDX])
689 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
690
691 if (tb[NL80211_KEY_DATA]) {
692 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
693 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
694 }
695
696 if (tb[NL80211_KEY_SEQ]) {
697 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
698 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
699 }
700
701 if (tb[NL80211_KEY_CIPHER])
702 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
703
Johannes Berge31b8212010-10-05 19:39:30 +0200704 if (tb[NL80211_KEY_TYPE]) {
705 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
706 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
707 return -EINVAL;
708 }
709
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100710 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
711 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100712 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
713 tb[NL80211_KEY_DEFAULT_TYPES],
714 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100715 if (err)
716 return err;
717
718 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
719 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
720 }
721
Johannes Bergb9454e82009-07-08 13:29:08 +0200722 return 0;
723}
724
725static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
726{
727 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
728 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
729 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
730 }
731
732 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
733 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
734 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
735 }
736
737 if (info->attrs[NL80211_ATTR_KEY_IDX])
738 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
739
740 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
741 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
742
743 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
744 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
745
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100746 if (k->def) {
747 k->def_uni = true;
748 k->def_multi = true;
749 }
750 if (k->defmgmt)
751 k->def_multi = true;
752
Johannes Berge31b8212010-10-05 19:39:30 +0200753 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
754 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
755 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
756 return -EINVAL;
757 }
758
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100759 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
760 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
761 int err = nla_parse_nested(
762 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
763 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
764 nl80211_key_default_policy);
765 if (err)
766 return err;
767
768 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
769 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
770 }
771
Johannes Bergb9454e82009-07-08 13:29:08 +0200772 return 0;
773}
774
775static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
776{
777 int err;
778
779 memset(k, 0, sizeof(*k));
780 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200781 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200782
783 if (info->attrs[NL80211_ATTR_KEY])
784 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
785 else
786 err = nl80211_parse_key_old(info, k);
787
788 if (err)
789 return err;
790
791 if (k->def && k->defmgmt)
792 return -EINVAL;
793
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100794 if (k->defmgmt) {
795 if (k->def_uni || !k->def_multi)
796 return -EINVAL;
797 }
798
Johannes Bergb9454e82009-07-08 13:29:08 +0200799 if (k->idx != -1) {
800 if (k->defmgmt) {
801 if (k->idx < 4 || k->idx > 5)
802 return -EINVAL;
803 } else if (k->def) {
804 if (k->idx < 0 || k->idx > 3)
805 return -EINVAL;
806 } else {
807 if (k->idx < 0 || k->idx > 5)
808 return -EINVAL;
809 }
810 }
811
812 return 0;
813}
814
Johannes Bergfffd0932009-07-08 14:22:54 +0200815static struct cfg80211_cached_keys *
816nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530817 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200818{
819 struct key_parse parse;
820 struct nlattr *key;
821 struct cfg80211_cached_keys *result;
822 int rem, err, def = 0;
823
824 result = kzalloc(sizeof(*result), GFP_KERNEL);
825 if (!result)
826 return ERR_PTR(-ENOMEM);
827
828 result->def = -1;
829 result->defmgmt = -1;
830
831 nla_for_each_nested(key, keys, rem) {
832 memset(&parse, 0, sizeof(parse));
833 parse.idx = -1;
834
835 err = nl80211_parse_key_new(key, &parse);
836 if (err)
837 goto error;
838 err = -EINVAL;
839 if (!parse.p.key)
840 goto error;
841 if (parse.idx < 0 || parse.idx > 4)
842 goto error;
843 if (parse.def) {
844 if (def)
845 goto error;
846 def = 1;
847 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100848 if (!parse.def_uni || !parse.def_multi)
849 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200850 } else if (parse.defmgmt)
851 goto error;
852 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200853 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200854 if (err)
855 goto error;
856 result->params[parse.idx].cipher = parse.p.cipher;
857 result->params[parse.idx].key_len = parse.p.key_len;
858 result->params[parse.idx].key = result->data[parse.idx];
859 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530860
861 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
862 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
863 if (no_ht)
864 *no_ht = true;
865 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200866 }
867
868 return result;
869 error:
870 kfree(result);
871 return ERR_PTR(err);
872}
873
874static int nl80211_key_allowed(struct wireless_dev *wdev)
875{
876 ASSERT_WDEV_LOCK(wdev);
877
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 switch (wdev->iftype) {
879 case NL80211_IFTYPE_AP:
880 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200881 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700882 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200883 break;
884 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200885 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200886 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200887 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 return -ENOLINK;
889 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100890 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100891 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100892 case NL80211_IFTYPE_MONITOR:
893 case NL80211_IFTYPE_P2P_DEVICE:
894 case NL80211_IFTYPE_WDS:
895 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200896 return -EINVAL;
897 }
898
899 return 0;
900}
901
Jouni Malinen664834d2014-01-15 00:01:44 +0200902static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
903 struct nlattr *tb)
904{
905 struct ieee80211_channel *chan;
906
907 if (tb == NULL)
908 return NULL;
909 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
910 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
911 return NULL;
912 return chan;
913}
914
Johannes Berg7527a782011-05-13 10:58:57 +0200915static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
916{
917 struct nlattr *nl_modes = nla_nest_start(msg, attr);
918 int i;
919
920 if (!nl_modes)
921 goto nla_put_failure;
922
923 i = 0;
924 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400925 if ((ifmodes & 1) && nla_put_flag(msg, i))
926 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200927 ifmodes >>= 1;
928 i++;
929 }
930
931 nla_nest_end(msg, nl_modes);
932 return 0;
933
934nla_put_failure:
935 return -ENOBUFS;
936}
937
938static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100939 struct sk_buff *msg,
940 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200941{
942 struct nlattr *nl_combis;
943 int i, j;
944
945 nl_combis = nla_nest_start(msg,
946 NL80211_ATTR_INTERFACE_COMBINATIONS);
947 if (!nl_combis)
948 goto nla_put_failure;
949
950 for (i = 0; i < wiphy->n_iface_combinations; i++) {
951 const struct ieee80211_iface_combination *c;
952 struct nlattr *nl_combi, *nl_limits;
953
954 c = &wiphy->iface_combinations[i];
955
956 nl_combi = nla_nest_start(msg, i + 1);
957 if (!nl_combi)
958 goto nla_put_failure;
959
960 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
961 if (!nl_limits)
962 goto nla_put_failure;
963
964 for (j = 0; j < c->n_limits; j++) {
965 struct nlattr *nl_limit;
966
967 nl_limit = nla_nest_start(msg, j + 1);
968 if (!nl_limit)
969 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400970 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
971 c->limits[j].max))
972 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200973 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
974 c->limits[j].types))
975 goto nla_put_failure;
976 nla_nest_end(msg, nl_limit);
977 }
978
979 nla_nest_end(msg, nl_limits);
980
David S. Miller9360ffd2012-03-29 04:41:26 -0400981 if (c->beacon_int_infra_match &&
982 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
983 goto nla_put_failure;
984 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
985 c->num_different_channels) ||
986 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
987 c->max_interfaces))
988 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100989 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200990 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
991 c->radar_detect_widths) ||
992 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
993 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100994 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200995
996 nla_nest_end(msg, nl_combi);
997 }
998
999 nla_nest_end(msg, nl_combis);
1000
1001 return 0;
1002nla_put_failure:
1003 return -ENOBUFS;
1004}
1005
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001007static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1008 struct sk_buff *msg)
1009{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001010 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001011 struct nlattr *nl_tcp;
1012
1013 if (!tcp)
1014 return 0;
1015
1016 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1017 if (!nl_tcp)
1018 return -ENOBUFS;
1019
1020 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1021 tcp->data_payload_max))
1022 return -ENOBUFS;
1023
1024 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1025 tcp->data_payload_max))
1026 return -ENOBUFS;
1027
1028 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1029 return -ENOBUFS;
1030
1031 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1032 sizeof(*tcp->tok), tcp->tok))
1033 return -ENOBUFS;
1034
1035 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1036 tcp->data_interval_max))
1037 return -ENOBUFS;
1038
1039 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1040 tcp->wake_payload_max))
1041 return -ENOBUFS;
1042
1043 nla_nest_end(msg, nl_tcp);
1044 return 0;
1045}
1046
Johannes Berg3713b4e2013-02-14 16:19:38 +01001047static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001048 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001049 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050{
1051 struct nlattr *nl_wowlan;
1052
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001053 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054 return 0;
1055
1056 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1057 if (!nl_wowlan)
1058 return -ENOBUFS;
1059
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001060 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001067 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001068 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001073 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001074 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1076 return -ENOBUFS;
1077
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001078 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001079 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001080 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1081 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1082 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1083 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001084 };
1085
1086 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1087 sizeof(pat), &pat))
1088 return -ENOBUFS;
1089 }
1090
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001091 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001092 return -ENOBUFS;
1093
Luciano Coelho8cd4d452014-09-17 11:55:28 +03001094 /* TODO: send wowlan net detect */
1095
Johannes Berg3713b4e2013-02-14 16:19:38 +01001096 nla_nest_end(msg, nl_wowlan);
1097
1098 return 0;
1099}
1100#endif
1101
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001102static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001103 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001104{
1105 struct nl80211_coalesce_rule_support rule;
1106
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001107 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001108 return 0;
1109
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001110 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1111 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1112 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1113 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1114 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1115 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001116
1117 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1118 return -ENOBUFS;
1119
1120 return 0;
1121}
1122
Johannes Berg3713b4e2013-02-14 16:19:38 +01001123static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1124 struct ieee80211_supported_band *sband)
1125{
1126 struct nlattr *nl_rates, *nl_rate;
1127 struct ieee80211_rate *rate;
1128 int i;
1129
1130 /* add HT info */
1131 if (sband->ht_cap.ht_supported &&
1132 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1133 sizeof(sband->ht_cap.mcs),
1134 &sband->ht_cap.mcs) ||
1135 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1136 sband->ht_cap.cap) ||
1137 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1138 sband->ht_cap.ampdu_factor) ||
1139 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1140 sband->ht_cap.ampdu_density)))
1141 return -ENOBUFS;
1142
1143 /* add VHT info */
1144 if (sband->vht_cap.vht_supported &&
1145 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1146 sizeof(sband->vht_cap.vht_mcs),
1147 &sband->vht_cap.vht_mcs) ||
1148 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1149 sband->vht_cap.cap)))
1150 return -ENOBUFS;
1151
1152 /* add bitrates */
1153 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1154 if (!nl_rates)
1155 return -ENOBUFS;
1156
1157 for (i = 0; i < sband->n_bitrates; i++) {
1158 nl_rate = nla_nest_start(msg, i);
1159 if (!nl_rate)
1160 return -ENOBUFS;
1161
1162 rate = &sband->bitrates[i];
1163 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1164 rate->bitrate))
1165 return -ENOBUFS;
1166 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1167 nla_put_flag(msg,
1168 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1169 return -ENOBUFS;
1170
1171 nla_nest_end(msg, nl_rate);
1172 }
1173
1174 nla_nest_end(msg, nl_rates);
1175
1176 return 0;
1177}
1178
1179static int
1180nl80211_send_mgmt_stypes(struct sk_buff *msg,
1181 const struct ieee80211_txrx_stypes *mgmt_stypes)
1182{
1183 u16 stypes;
1184 struct nlattr *nl_ftypes, *nl_ifs;
1185 enum nl80211_iftype ift;
1186 int i;
1187
1188 if (!mgmt_stypes)
1189 return 0;
1190
1191 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1192 if (!nl_ifs)
1193 return -ENOBUFS;
1194
1195 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1196 nl_ftypes = nla_nest_start(msg, ift);
1197 if (!nl_ftypes)
1198 return -ENOBUFS;
1199 i = 0;
1200 stypes = mgmt_stypes[ift].tx;
1201 while (stypes) {
1202 if ((stypes & 1) &&
1203 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1204 (i << 4) | IEEE80211_FTYPE_MGMT))
1205 return -ENOBUFS;
1206 stypes >>= 1;
1207 i++;
1208 }
1209 nla_nest_end(msg, nl_ftypes);
1210 }
1211
1212 nla_nest_end(msg, nl_ifs);
1213
1214 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1215 if (!nl_ifs)
1216 return -ENOBUFS;
1217
1218 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1219 nl_ftypes = nla_nest_start(msg, ift);
1220 if (!nl_ftypes)
1221 return -ENOBUFS;
1222 i = 0;
1223 stypes = mgmt_stypes[ift].rx;
1224 while (stypes) {
1225 if ((stypes & 1) &&
1226 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1227 (i << 4) | IEEE80211_FTYPE_MGMT))
1228 return -ENOBUFS;
1229 stypes >>= 1;
1230 i++;
1231 }
1232 nla_nest_end(msg, nl_ftypes);
1233 }
1234 nla_nest_end(msg, nl_ifs);
1235
1236 return 0;
1237}
1238
Johannes Berg86e8cf92013-06-19 10:57:22 +02001239struct nl80211_dump_wiphy_state {
1240 s64 filter_wiphy;
1241 long start;
1242 long split_start, band_start, chan_start;
1243 bool split;
1244};
1245
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001246static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001247 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001249 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001250{
1251 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001252 struct nlattr *nl_bands, *nl_band;
1253 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001254 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001255 enum ieee80211_band band;
1256 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001257 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001258 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001259 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001260 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001261
Johannes Berg3bb20552014-05-26 13:52:25 +02001262 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001263 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 return -ENOBUFS;
1265
Johannes Berg86e8cf92013-06-19 10:57:22 +02001266 if (WARN_ON(!state))
1267 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001268
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001272 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001274 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001275
Johannes Berg3bb20552014-05-26 13:52:25 +02001276 if (cmd != NL80211_CMD_NEW_WIPHY)
1277 goto finish;
1278
Johannes Berg86e8cf92013-06-19 10:57:22 +02001279 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 case 0:
1281 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001301 goto nla_put_failure;
1302
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001303 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1305 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001307 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1308 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1311 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001312 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1314 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1317 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001318 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001320 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001321 state->split_start++;
1322 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 break;
1324 case 1:
1325 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001326 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1327 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001328 goto nla_put_failure;
1329
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001332 goto nla_put_failure;
1333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1336 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001337
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001341 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001343
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001344 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001348
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.available_antennas_tx ||
1350 rdev->wiphy.available_antennas_rx) &&
1351 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001352 u32 tx_ant = 0, rx_ant = 0;
1353 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001354 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 if (!res) {
1356 if (nla_put_u32(msg,
1357 NL80211_ATTR_WIPHY_ANTENNA_TX,
1358 tx_ant) ||
1359 nla_put_u32(msg,
1360 NL80211_ATTR_WIPHY_ANTENNA_RX,
1361 rx_ant))
1362 goto nla_put_failure;
1363 }
Johannes Bergee688b002008-01-24 19:38:39 +01001364 }
1365
Johannes Berg86e8cf92013-06-19 10:57:22 +02001366 state->split_start++;
1367 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368 break;
1369 case 2:
1370 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001373 state->split_start++;
1374 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 break;
1376 case 3:
1377 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1378 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001379 goto nla_put_failure;
1380
Johannes Berg86e8cf92013-06-19 10:57:22 +02001381 for (band = state->band_start;
1382 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 struct ieee80211_supported_band *sband;
1384
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001385 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386
1387 if (!sband)
1388 continue;
1389
1390 nl_band = nla_nest_start(msg, band);
1391 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001392 goto nla_put_failure;
1393
Johannes Berg86e8cf92013-06-19 10:57:22 +02001394 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 case 0:
1396 if (nl80211_send_band_rateinfo(msg, sband))
1397 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001398 state->chan_start++;
1399 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001400 break;
1401 default:
1402 /* add frequencies */
1403 nl_freqs = nla_nest_start(
1404 msg, NL80211_BAND_ATTR_FREQS);
1405 if (!nl_freqs)
1406 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001407
Johannes Berg86e8cf92013-06-19 10:57:22 +02001408 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001409 i < sband->n_channels;
1410 i++) {
1411 nl_freq = nla_nest_start(msg, i);
1412 if (!nl_freq)
1413 goto nla_put_failure;
1414
1415 chan = &sband->channels[i];
1416
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 if (nl80211_msg_put_channel(
1418 msg, chan,
1419 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 goto nla_put_failure;
1421
1422 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001423 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424 break;
1425 }
1426 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 nla_nest_end(msg, nl_freqs);
1431 }
1432
1433 nla_nest_end(msg, nl_band);
1434
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001437 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 band--;
1439 break;
1440 }
Johannes Bergee688b002008-01-24 19:38:39 +01001441 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001443
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001445 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001447 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001448
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001450 if (state->band_start == 0 && state->chan_start == 0)
1451 state->split_start++;
1452 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 break;
1454 case 4:
1455 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1456 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001457 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458
1459 i = 0;
1460#define CMD(op, n) \
1461 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001462 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 i++; \
1464 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1465 goto nla_put_failure; \
1466 } \
1467 } while (0)
1468
1469 CMD(add_virtual_intf, NEW_INTERFACE);
1470 CMD(change_virtual_intf, SET_INTERFACE);
1471 CMD(add_key, NEW_KEY);
1472 CMD(start_ap, START_AP);
1473 CMD(add_station, NEW_STATION);
1474 CMD(add_mpath, NEW_MPATH);
1475 CMD(update_mesh_config, SET_MESH_CONFIG);
1476 CMD(change_bss, SET_BSS);
1477 CMD(auth, AUTHENTICATE);
1478 CMD(assoc, ASSOCIATE);
1479 CMD(deauth, DEAUTHENTICATE);
1480 CMD(disassoc, DISASSOCIATE);
1481 CMD(join_ibss, JOIN_IBSS);
1482 CMD(join_mesh, JOIN_MESH);
1483 CMD(set_pmksa, SET_PMKSA);
1484 CMD(del_pmksa, DEL_PMKSA);
1485 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1488 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1489 CMD(mgmt_tx, FRAME);
1490 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001491 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 i++;
1493 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1494 goto nla_put_failure;
1495 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1497 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 i++;
1499 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1500 goto nla_put_failure;
1501 }
1502 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001503 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 CMD(tdls_mgmt, TDLS_MGMT);
1505 CMD(tdls_oper, TDLS_OPER);
1506 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001507 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001508 CMD(sched_scan_start, START_SCHED_SCAN);
1509 CMD(probe_client, PROBE_CLIENT);
1510 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001511 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 i++;
1513 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1514 goto nla_put_failure;
1515 }
1516 CMD(start_p2p_device, START_P2P_DEVICE);
1517 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001518#ifdef CONFIG_NL80211_TESTMODE
1519 CMD(testmode_cmd, TESTMODE);
1520#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001521 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001522 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1523 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001525 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001526 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001527 if (rdev->wiphy.features &
1528 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001529 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001530 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001531 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001532#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001533
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 i++;
1536 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001537 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001538 }
1539
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 i++;
1542 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1543 goto nla_put_failure;
1544 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001545
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001547 state->split_start++;
1548 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 break;
1550 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001551 if (rdev->ops->remain_on_channel &&
1552 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 nla_put_u32(msg,
1554 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001556 goto nla_put_failure;
1557
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001558 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1560 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001561
Johannes Berg3713b4e2013-02-14 16:19:38 +01001562 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1563 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001564 state->split_start++;
1565 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 break;
1567 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001568#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001569 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001571 state->split_start++;
1572 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 break;
1574#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001575 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576#endif
1577 case 7:
1578 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001579 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001580 goto nla_put_failure;
1581
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001585
Johannes Berg86e8cf92013-06-19 10:57:22 +02001586 state->split_start++;
1587 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 break;
1589 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001590 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001592 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 goto nla_put_failure;
1594
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001595 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001596 /*
1597 * We can only add the per-channel limit information if the
1598 * dump is split, otherwise it makes it too big. Therefore
1599 * only advertise it in that case.
1600 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001601 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001602 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1603 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 goto nla_put_failure;
1605
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001606 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001608 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1609 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 goto nla_put_failure;
1611
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1613 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001614 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 goto nla_put_failure;
1617
1618 /*
1619 * Any information below this point is only available to
1620 * applications that can deal with it being split. This
1621 * helps ensure that newly added capabilities don't break
1622 * older tools by overrunning their buffers.
1623 *
1624 * We still increment split_start so that in the split
1625 * case we'll continue with more data in the next round,
1626 * but break unconditionally so unsplit data stops here.
1627 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 break;
1630 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001632 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 rdev->wiphy.extended_capabilities_len,
1634 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001635 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001636 rdev->wiphy.extended_capabilities_len,
1637 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001638 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001639
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001641 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1643 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001644 goto nla_put_failure;
1645
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001646 state->split_start++;
1647 break;
1648 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001650 goto nla_put_failure;
1651
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001652 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001653 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1654 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1655 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001656
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001657 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001658 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001659 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001660 goto nla_put_failure;
1661
Johannes Bergad7e7182013-11-13 13:37:47 +01001662 state->split_start++;
1663 break;
1664 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001666 const struct nl80211_vendor_cmd_info *info;
1667 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001668
Johannes Berg567ffc32013-12-18 14:43:31 +01001669 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1670 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001671 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001672
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1674 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001675 if (nla_put(msg, i + 1, sizeof(*info), info))
1676 goto nla_put_failure;
1677 }
1678 nla_nest_end(msg, nested);
1679 }
1680
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001681 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001682 const struct nl80211_vendor_cmd_info *info;
1683 struct nlattr *nested;
1684
1685 nested = nla_nest_start(msg,
1686 NL80211_ATTR_VENDOR_EVENTS);
1687 if (!nested)
1688 goto nla_put_failure;
1689
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1691 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001692 if (nla_put(msg, i + 1, sizeof(*info), info))
1693 goto nla_put_failure;
1694 }
1695 nla_nest_end(msg, nested);
1696 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001697 state->split_start++;
1698 break;
1699 case 12:
1700 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1701 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1702 rdev->wiphy.max_num_csa_counters))
1703 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001704
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001705 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1706 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1707 goto nla_put_failure;
1708
Johannes Berg3713b4e2013-02-14 16:19:38 +01001709 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001710 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001711 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001712 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001713 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001714 return genlmsg_end(msg, hdr);
1715
1716 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001717 genlmsg_cancel(msg, hdr);
1718 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001719}
1720
Johannes Berg86e8cf92013-06-19 10:57:22 +02001721static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1722 struct netlink_callback *cb,
1723 struct nl80211_dump_wiphy_state *state)
1724{
1725 struct nlattr **tb = nl80211_fam.attrbuf;
1726 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1727 tb, nl80211_fam.maxattr, nl80211_policy);
1728 /* ignore parse errors for backward compatibility */
1729 if (ret)
1730 return 0;
1731
1732 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1733 if (tb[NL80211_ATTR_WIPHY])
1734 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1735 if (tb[NL80211_ATTR_WDEV])
1736 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1737 if (tb[NL80211_ATTR_IFINDEX]) {
1738 struct net_device *netdev;
1739 struct cfg80211_registered_device *rdev;
1740 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1741
Ying Xue7f2b8562014-01-15 10:23:45 +08001742 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001743 if (!netdev)
1744 return -ENODEV;
1745 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001746 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001747 netdev->ieee80211_ptr->wiphy);
1748 state->filter_wiphy = rdev->wiphy_idx;
1749 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001750 }
1751
1752 return 0;
1753}
1754
Johannes Berg55682962007-09-20 13:09:35 -04001755static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1756{
Johannes Berg645e77d2013-03-01 14:03:49 +01001757 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001758 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001759 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001760
Johannes Berg5fe231e2013-05-08 21:45:15 +02001761 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762 if (!state) {
1763 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001764 if (!state) {
1765 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001766 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001767 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001768 state->filter_wiphy = -1;
1769 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1770 if (ret) {
1771 kfree(state);
1772 rtnl_unlock();
1773 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001774 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001775 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001776 }
1777
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001778 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1779 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001780 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001781 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001782 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001783 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001784 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001785 continue;
1786 /* attempt to fit multiple wiphy data chunks into the skb */
1787 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001788 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1789 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001790 NETLINK_CB(cb->skb).portid,
1791 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001792 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001793 if (ret < 0) {
1794 /*
1795 * If sending the wiphy data didn't fit (ENOBUFS
1796 * or EMSGSIZE returned), this SKB is still
1797 * empty (so it's not too big because another
1798 * wiphy dataset is already in the skb) and
1799 * we've not tried to adjust the dump allocation
1800 * yet ... then adjust the alloc size to be
1801 * bigger, and return 1 but with the empty skb.
1802 * This results in an empty message being RX'ed
1803 * in userspace, but that is ignored.
1804 *
1805 * We can then retry with the larger buffer.
1806 */
1807 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001808 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001809 cb->min_dump_alloc < 4096) {
1810 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001811 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001812 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001813 return 1;
1814 }
1815 idx--;
1816 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001817 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001819 break;
Johannes Berg55682962007-09-20 13:09:35 -04001820 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001821 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001822
Johannes Berg86e8cf92013-06-19 10:57:22 +02001823 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001824
1825 return skb->len;
1826}
1827
Johannes Berg86e8cf92013-06-19 10:57:22 +02001828static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1829{
1830 kfree((void *)cb->args[0]);
1831 return 0;
1832}
1833
Johannes Berg55682962007-09-20 13:09:35 -04001834static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1835{
1836 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001837 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001838 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001839
Johannes Berg645e77d2013-03-01 14:03:49 +01001840 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001841 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001842 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001843
Johannes Berg3bb20552014-05-26 13:52:25 +02001844 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1845 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001846 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001847 nlmsg_free(msg);
1848 return -ENOBUFS;
1849 }
Johannes Berg55682962007-09-20 13:09:35 -04001850
Johannes Berg134e6372009-07-10 09:51:34 +00001851 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001852}
1853
Jouni Malinen31888482008-10-30 16:59:24 +02001854static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1855 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1856 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1857 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1858 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1859 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1860};
1861
1862static int parse_txq_params(struct nlattr *tb[],
1863 struct ieee80211_txq_params *txq_params)
1864{
Johannes Berga3304b02012-03-28 11:04:24 +02001865 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001866 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1867 !tb[NL80211_TXQ_ATTR_AIFS])
1868 return -EINVAL;
1869
Johannes Berga3304b02012-03-28 11:04:24 +02001870 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001871 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1872 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1873 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1874 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1875
Johannes Berga3304b02012-03-28 11:04:24 +02001876 if (txq_params->ac >= NL80211_NUM_ACS)
1877 return -EINVAL;
1878
Jouni Malinen31888482008-10-30 16:59:24 +02001879 return 0;
1880}
1881
Johannes Bergf444de02010-05-05 15:25:02 +02001882static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1883{
1884 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001885 * You can only set the channel explicitly for WDS interfaces,
1886 * all others have their channel managed via their respective
1887 * "establish a connection" command (connect, join, ...)
1888 *
1889 * For AP/GO and mesh mode, the channel can be set with the
1890 * channel userspace API, but is only stored and passed to the
1891 * low-level driver when the AP starts or the mesh is joined.
1892 * This is for backward compatibility, userspace can also give
1893 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001894 *
1895 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001896 * whatever else is going on, so they have their own special
1897 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001898 */
1899 return !wdev ||
1900 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001901 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001902 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1903 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001904}
1905
Johannes Berg683b6d32012-11-08 21:25:48 +01001906static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1907 struct genl_info *info,
1908 struct cfg80211_chan_def *chandef)
1909{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301910 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001911
1912 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1913 return -EINVAL;
1914
1915 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1916
1917 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001918 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1919 chandef->center_freq1 = control_freq;
1920 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001921
1922 /* Primary channel not allowed */
1923 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1924 return -EINVAL;
1925
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001926 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1927 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001928
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001929 chantype = nla_get_u32(
1930 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1931
1932 switch (chantype) {
1933 case NL80211_CHAN_NO_HT:
1934 case NL80211_CHAN_HT20:
1935 case NL80211_CHAN_HT40PLUS:
1936 case NL80211_CHAN_HT40MINUS:
1937 cfg80211_chandef_create(chandef, chandef->chan,
1938 chantype);
1939 break;
1940 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001941 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001942 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001943 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1944 chandef->width =
1945 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1946 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1947 chandef->center_freq1 =
1948 nla_get_u32(
1949 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1950 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1951 chandef->center_freq2 =
1952 nla_get_u32(
1953 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1954 }
1955
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001956 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001957 return -EINVAL;
1958
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001959 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1960 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001961 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001962
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001963 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1964 chandef->width == NL80211_CHAN_WIDTH_10) &&
1965 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1966 return -EINVAL;
1967
Johannes Berg683b6d32012-11-08 21:25:48 +01001968 return 0;
1969}
1970
Johannes Bergf444de02010-05-05 15:25:02 +02001971static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001972 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001973 struct genl_info *info)
1974{
Johannes Berg683b6d32012-11-08 21:25:48 +01001975 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001976 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001977 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001978 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001979
Jouni Malinene16821b2014-04-28 11:22:08 +03001980 if (dev)
1981 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001982 if (!nl80211_can_set_dev_channel(wdev))
1983 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001984 if (wdev)
1985 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001986
Johannes Berg683b6d32012-11-08 21:25:48 +01001987 result = nl80211_parse_chandef(rdev, info, &chandef);
1988 if (result)
1989 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001990
Johannes Berge8c9bd52012-06-06 08:18:22 +02001991 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001992 case NL80211_IFTYPE_AP:
1993 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001994 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001995 result = -EINVAL;
1996 break;
1997 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001998 if (wdev->beacon_interval) {
1999 if (!dev || !rdev->ops->set_ap_chanwidth ||
2000 !(rdev->wiphy.features &
2001 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2002 result = -EBUSY;
2003 break;
2004 }
2005
2006 /* Only allow dynamic channel width changes */
2007 if (chandef.chan != wdev->preset_chandef.chan) {
2008 result = -EBUSY;
2009 break;
2010 }
2011 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2012 if (result)
2013 break;
2014 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002015 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002016 result = 0;
2017 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002018 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002019 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002020 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002021 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002022 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002023 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002024 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002025 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002026 }
Johannes Bergf444de02010-05-05 15:25:02 +02002027
2028 return result;
2029}
2030
2031static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2032{
Johannes Berg4c476992010-10-04 21:36:35 +02002033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2034 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002035
Jouni Malinene16821b2014-04-28 11:22:08 +03002036 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002037}
2038
Bill Jordane8347eb2010-10-01 13:54:28 -04002039static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2040{
Johannes Berg43b19952010-10-07 13:10:30 +02002041 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2042 struct net_device *dev = info->user_ptr[1];
2043 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002044 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002045
2046 if (!info->attrs[NL80211_ATTR_MAC])
2047 return -EINVAL;
2048
Johannes Berg43b19952010-10-07 13:10:30 +02002049 if (netif_running(dev))
2050 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002051
Johannes Berg43b19952010-10-07 13:10:30 +02002052 if (!rdev->ops->set_wds_peer)
2053 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002054
Johannes Berg43b19952010-10-07 13:10:30 +02002055 if (wdev->iftype != NL80211_IFTYPE_WDS)
2056 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002057
2058 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002059 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002060}
2061
2062
Johannes Berg55682962007-09-20 13:09:35 -04002063static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2064{
2065 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002066 struct net_device *netdev = NULL;
2067 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002068 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002069 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002070 u32 changed;
2071 u8 retry_short = 0, retry_long = 0;
2072 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002073 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002074
Johannes Berg5fe231e2013-05-08 21:45:15 +02002075 ASSERT_RTNL();
2076
Johannes Bergf444de02010-05-05 15:25:02 +02002077 /*
2078 * Try to find the wiphy and netdev. Normally this
2079 * function shouldn't need the netdev, but this is
2080 * done for backward compatibility -- previously
2081 * setting the channel was done per wiphy, but now
2082 * it is per netdev. Previous userland like hostapd
2083 * also passed a netdev to set_wiphy, so that it is
2084 * possible to let that go to the right netdev!
2085 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002086
Johannes Bergf444de02010-05-05 15:25:02 +02002087 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2088 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2089
Ying Xue7f2b8562014-01-15 10:23:45 +08002090 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002091 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002092 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002093 else
Johannes Bergf444de02010-05-05 15:25:02 +02002094 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002095 }
2096
Johannes Bergf444de02010-05-05 15:25:02 +02002097 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002098 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2099 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002100 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002101 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002102 wdev = NULL;
2103 netdev = NULL;
2104 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002105 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002106 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002107
2108 /*
2109 * end workaround code, by now the rdev is available
2110 * and locked, and wdev may or may not be NULL.
2111 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002112
2113 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002114 result = cfg80211_dev_rename(
2115 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002116
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002117 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002118 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002119
Jouni Malinen31888482008-10-30 16:59:24 +02002120 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2121 struct ieee80211_txq_params txq_params;
2122 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2123
Ying Xue7f2b8562014-01-15 10:23:45 +08002124 if (!rdev->ops->set_txq_params)
2125 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002126
Ying Xue7f2b8562014-01-15 10:23:45 +08002127 if (!netdev)
2128 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002129
Johannes Berg133a3ff2011-11-03 14:50:13 +01002130 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002131 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2132 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002133
Ying Xue7f2b8562014-01-15 10:23:45 +08002134 if (!netif_running(netdev))
2135 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002136
Jouni Malinen31888482008-10-30 16:59:24 +02002137 nla_for_each_nested(nl_txq_params,
2138 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2139 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002140 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2141 nla_data(nl_txq_params),
2142 nla_len(nl_txq_params),
2143 txq_params_policy);
2144 if (result)
2145 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002146 result = parse_txq_params(tb, &txq_params);
2147 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002148 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002149
Hila Gonene35e4d22012-06-27 17:19:42 +03002150 result = rdev_set_txq_params(rdev, netdev,
2151 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002152 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002153 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002154 }
2155 }
2156
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002157 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002158 result = __nl80211_set_channel(
2159 rdev,
2160 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2161 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002162 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002163 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002164 }
2165
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002166 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002167 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002168 enum nl80211_tx_power_setting type;
2169 int idx, mbm = 0;
2170
Johannes Bergc8442112012-10-24 10:17:18 +02002171 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2172 txp_wdev = NULL;
2173
Ying Xue7f2b8562014-01-15 10:23:45 +08002174 if (!rdev->ops->set_tx_power)
2175 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002176
2177 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2178 type = nla_get_u32(info->attrs[idx]);
2179
2180 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002181 (type != NL80211_TX_POWER_AUTOMATIC))
2182 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002183
2184 if (type != NL80211_TX_POWER_AUTOMATIC) {
2185 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2186 mbm = nla_get_u32(info->attrs[idx]);
2187 }
2188
Johannes Bergc8442112012-10-24 10:17:18 +02002189 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002190 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002191 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002192 }
2193
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002194 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2195 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2196 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002197 if ((!rdev->wiphy.available_antennas_tx &&
2198 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002199 !rdev->ops->set_antenna)
2200 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002201
2202 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2203 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2204
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002205 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002206 * available antenna masks, except for the "all" mask */
2207 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002208 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2209 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002210
Bruno Randolf7f531e02010-12-16 11:30:22 +09002211 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2212 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002213
Hila Gonene35e4d22012-06-27 17:19:42 +03002214 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002215 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002216 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002217 }
2218
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002219 changed = 0;
2220
2221 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2222 retry_short = nla_get_u8(
2223 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002224 if (retry_short == 0)
2225 return -EINVAL;
2226
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002227 changed |= WIPHY_PARAM_RETRY_SHORT;
2228 }
2229
2230 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2231 retry_long = nla_get_u8(
2232 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002233 if (retry_long == 0)
2234 return -EINVAL;
2235
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002236 changed |= WIPHY_PARAM_RETRY_LONG;
2237 }
2238
2239 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2240 frag_threshold = nla_get_u32(
2241 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002242 if (frag_threshold < 256)
2243 return -EINVAL;
2244
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002245 if (frag_threshold != (u32) -1) {
2246 /*
2247 * Fragments (apart from the last one) are required to
2248 * have even length. Make the fragmentation code
2249 * simpler by stripping LSB should someone try to use
2250 * odd threshold value.
2251 */
2252 frag_threshold &= ~0x1;
2253 }
2254 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2255 }
2256
2257 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2258 rts_threshold = nla_get_u32(
2259 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2260 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2261 }
2262
Lukáš Turek81077e82009-12-21 22:50:47 +01002263 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002264 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2265 return -EINVAL;
2266
Lukáš Turek81077e82009-12-21 22:50:47 +01002267 coverage_class = nla_get_u8(
2268 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2269 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2270 }
2271
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002272 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2273 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2274 return -EOPNOTSUPP;
2275
2276 changed |= WIPHY_PARAM_DYN_ACK;
2277 }
2278
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002279 if (changed) {
2280 u8 old_retry_short, old_retry_long;
2281 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002282 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002283
Ying Xue7f2b8562014-01-15 10:23:45 +08002284 if (!rdev->ops->set_wiphy_params)
2285 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002286
2287 old_retry_short = rdev->wiphy.retry_short;
2288 old_retry_long = rdev->wiphy.retry_long;
2289 old_frag_threshold = rdev->wiphy.frag_threshold;
2290 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002291 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002292
2293 if (changed & WIPHY_PARAM_RETRY_SHORT)
2294 rdev->wiphy.retry_short = retry_short;
2295 if (changed & WIPHY_PARAM_RETRY_LONG)
2296 rdev->wiphy.retry_long = retry_long;
2297 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2298 rdev->wiphy.frag_threshold = frag_threshold;
2299 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2300 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002301 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2302 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002303
Hila Gonene35e4d22012-06-27 17:19:42 +03002304 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002305 if (result) {
2306 rdev->wiphy.retry_short = old_retry_short;
2307 rdev->wiphy.retry_long = old_retry_long;
2308 rdev->wiphy.frag_threshold = old_frag_threshold;
2309 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002310 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002311 }
2312 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002313 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002314}
2315
Johannes Berg71bbc992012-06-15 15:30:18 +02002316static inline u64 wdev_id(struct wireless_dev *wdev)
2317{
2318 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002319 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002320}
Johannes Berg55682962007-09-20 13:09:35 -04002321
Johannes Berg683b6d32012-11-08 21:25:48 +01002322static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002323 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002324{
Johannes Berg601555c2014-11-27 17:26:56 +01002325 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2326 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002327
Johannes Berg683b6d32012-11-08 21:25:48 +01002328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2329 chandef->chan->center_freq))
2330 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002331 switch (chandef->width) {
2332 case NL80211_CHAN_WIDTH_20_NOHT:
2333 case NL80211_CHAN_WIDTH_20:
2334 case NL80211_CHAN_WIDTH_40:
2335 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2336 cfg80211_get_chandef_type(chandef)))
2337 return -ENOBUFS;
2338 break;
2339 default:
2340 break;
2341 }
2342 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2343 return -ENOBUFS;
2344 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2345 return -ENOBUFS;
2346 if (chandef->center_freq2 &&
2347 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002348 return -ENOBUFS;
2349 return 0;
2350}
2351
Eric W. Biederman15e47302012-09-07 20:12:54 +00002352static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002353 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002354 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002355{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002356 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002357 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002358 void *hdr;
2359
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002360 if (removal)
2361 cmd = NL80211_CMD_DEL_INTERFACE;
2362
2363 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002364 if (!hdr)
2365 return -1;
2366
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002367 if (dev &&
2368 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002369 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002370 goto nla_put_failure;
2371
2372 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2373 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002374 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002375 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002376 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2377 rdev->devlist_generation ^
2378 (cfg80211_rdev_list_generation << 2)))
2379 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002380
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002381 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002382 int ret;
2383 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002384
Johannes Berg683b6d32012-11-08 21:25:48 +01002385 ret = rdev_get_channel(rdev, wdev, &chandef);
2386 if (ret == 0) {
2387 if (nl80211_send_chandef(msg, &chandef))
2388 goto nla_put_failure;
2389 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002390 }
2391
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002392 if (wdev->ssid_len) {
2393 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2394 goto nla_put_failure;
2395 }
2396
Johannes Berg55682962007-09-20 13:09:35 -04002397 return genlmsg_end(msg, hdr);
2398
2399 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002400 genlmsg_cancel(msg, hdr);
2401 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002402}
2403
2404static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2405{
2406 int wp_idx = 0;
2407 int if_idx = 0;
2408 int wp_start = cb->args[0];
2409 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002410 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002411 struct wireless_dev *wdev;
2412
Johannes Berg5fe231e2013-05-08 21:45:15 +02002413 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002414 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2415 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002416 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002417 if (wp_idx < wp_start) {
2418 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002419 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002420 }
Johannes Berg55682962007-09-20 13:09:35 -04002421 if_idx = 0;
2422
Johannes Berg89a54e42012-06-15 14:33:17 +02002423 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002424 if (if_idx < if_start) {
2425 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002426 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002427 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002428 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002429 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002430 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002431 goto out;
2432 }
2433 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002434 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002435
2436 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002437 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002438 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002439 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002440
2441 cb->args[0] = wp_idx;
2442 cb->args[1] = if_idx;
2443
2444 return skb->len;
2445}
2446
2447static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2448{
2449 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002450 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002451 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002452
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002453 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002454 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002455 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002456
Eric W. Biederman15e47302012-09-07 20:12:54 +00002457 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002458 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002459 nlmsg_free(msg);
2460 return -ENOBUFS;
2461 }
Johannes Berg55682962007-09-20 13:09:35 -04002462
Johannes Berg134e6372009-07-10 09:51:34 +00002463 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002464}
2465
Michael Wu66f7ac52008-01-31 19:48:22 +01002466static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2467 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2468 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2469 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2470 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2471 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002472 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002473};
2474
2475static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2476{
2477 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2478 int flag;
2479
2480 *mntrflags = 0;
2481
2482 if (!nla)
2483 return -EINVAL;
2484
2485 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2486 nla, mntr_flags_policy))
2487 return -EINVAL;
2488
2489 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2490 if (flags[flag])
2491 *mntrflags |= (1<<flag);
2492
2493 return 0;
2494}
2495
Johannes Berg9bc383d2009-11-19 11:55:19 +01002496static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002497 struct net_device *netdev, u8 use_4addr,
2498 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002499{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002500 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002501 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002502 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002503 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002504 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002505
2506 switch (iftype) {
2507 case NL80211_IFTYPE_AP_VLAN:
2508 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2509 return 0;
2510 break;
2511 case NL80211_IFTYPE_STATION:
2512 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2513 return 0;
2514 break;
2515 default:
2516 break;
2517 }
2518
2519 return -EOPNOTSUPP;
2520}
2521
Johannes Berg55682962007-09-20 13:09:35 -04002522static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2523{
Johannes Berg4c476992010-10-04 21:36:35 +02002524 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002525 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002526 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002527 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002528 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002529 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002530 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002531
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002532 memset(&params, 0, sizeof(params));
2533
Johannes Berg04a773a2009-04-19 21:24:32 +02002534 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002535
Johannes Berg723b0382008-09-16 20:22:09 +02002536 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002537 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002538 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002539 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002540 if (ntype > NL80211_IFTYPE_MAX)
2541 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002542 }
2543
Johannes Berg92ffe052008-09-16 20:39:36 +02002544 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002545 struct wireless_dev *wdev = dev->ieee80211_ptr;
2546
Johannes Berg4c476992010-10-04 21:36:35 +02002547 if (ntype != NL80211_IFTYPE_MESH_POINT)
2548 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002549 if (netif_running(dev))
2550 return -EBUSY;
2551
2552 wdev_lock(wdev);
2553 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2554 IEEE80211_MAX_MESH_ID_LEN);
2555 wdev->mesh_id_up_len =
2556 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2557 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2558 wdev->mesh_id_up_len);
2559 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002560 }
2561
Felix Fietkau8b787642009-11-10 18:53:10 +01002562 if (info->attrs[NL80211_ATTR_4ADDR]) {
2563 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2564 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002565 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002566 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002567 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002568 } else {
2569 params.use_4addr = -1;
2570 }
2571
Johannes Berg92ffe052008-09-16 20:39:36 +02002572 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002573 if (ntype != NL80211_IFTYPE_MONITOR)
2574 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002575 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2576 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002577 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002578 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002579
2580 flags = &_flags;
2581 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002582 }
Johannes Berg3b858752009-03-12 09:55:09 +01002583
Luciano Coelho18003292013-08-29 13:26:57 +03002584 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002585 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2586 return -EOPNOTSUPP;
2587
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002588 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002589 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002590 else
2591 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002592
Johannes Berg9bc383d2009-11-19 11:55:19 +01002593 if (!err && params.use_4addr != -1)
2594 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2595
Johannes Berg55682962007-09-20 13:09:35 -04002596 return err;
2597}
2598
2599static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2600{
Johannes Berg4c476992010-10-04 21:36:35 +02002601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002602 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002603 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002604 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002605 int err;
2606 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002607 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002608
Johannes Berg78f22b62014-03-24 17:57:27 +01002609 /* to avoid failing a new interface creation due to pending removal */
2610 cfg80211_destroy_ifaces(rdev);
2611
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002612 memset(&params, 0, sizeof(params));
2613
Johannes Berg55682962007-09-20 13:09:35 -04002614 if (!info->attrs[NL80211_ATTR_IFNAME])
2615 return -EINVAL;
2616
2617 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2618 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2619 if (type > NL80211_IFTYPE_MAX)
2620 return -EINVAL;
2621 }
2622
Johannes Berg79c97e92009-07-07 03:56:12 +02002623 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002624 !(rdev->wiphy.interface_modes & (1 << type)))
2625 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002626
Ben Greeare8f479b2014-10-22 12:23:05 -07002627 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2628 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2629 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002630 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2631 ETH_ALEN);
2632 if (!is_valid_ether_addr(params.macaddr))
2633 return -EADDRNOTAVAIL;
2634 }
2635
Johannes Berg9bc383d2009-11-19 11:55:19 +01002636 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002637 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002638 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002639 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002640 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002641 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002642
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002643 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2644 if (!msg)
2645 return -ENOMEM;
2646
Michael Wu66f7ac52008-01-31 19:48:22 +01002647 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2648 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2649 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002650
Luciano Coelho18003292013-08-29 13:26:57 +03002651 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002652 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2653 return -EOPNOTSUPP;
2654
Hila Gonene35e4d22012-06-27 17:19:42 +03002655 wdev = rdev_add_virtual_intf(rdev,
2656 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2657 type, err ? NULL : &flags, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002658 if (WARN_ON(!wdev)) {
2659 nlmsg_free(msg);
2660 return -EPROTO;
2661 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002662 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002663 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002664 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002665
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002666 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002667 wdev->owner_nlportid = info->snd_portid;
2668
Johannes Berg98104fde2012-06-16 00:19:54 +02002669 switch (type) {
2670 case NL80211_IFTYPE_MESH_POINT:
2671 if (!info->attrs[NL80211_ATTR_MESH_ID])
2672 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002673 wdev_lock(wdev);
2674 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2675 IEEE80211_MAX_MESH_ID_LEN);
2676 wdev->mesh_id_up_len =
2677 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2678 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2679 wdev->mesh_id_up_len);
2680 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002681 break;
2682 case NL80211_IFTYPE_P2P_DEVICE:
2683 /*
2684 * P2P Device doesn't have a netdev, so doesn't go
2685 * through the netdev notifier and must be added here
2686 */
2687 mutex_init(&wdev->mtx);
2688 INIT_LIST_HEAD(&wdev->event_list);
2689 spin_lock_init(&wdev->event_lock);
2690 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2691 spin_lock_init(&wdev->mgmt_registrations_lock);
2692
Johannes Berg98104fde2012-06-16 00:19:54 +02002693 wdev->identifier = ++rdev->wdev_id;
2694 list_add_rcu(&wdev->list, &rdev->wdev_list);
2695 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002696 break;
2697 default:
2698 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002699 }
2700
Eric W. Biederman15e47302012-09-07 20:12:54 +00002701 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002702 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002703 nlmsg_free(msg);
2704 return -ENOBUFS;
2705 }
2706
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002707 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2708 if (event) {
2709 if (nl80211_send_iface(event, 0, 0, 0,
2710 rdev, wdev, false) < 0) {
2711 nlmsg_free(event);
2712 goto out;
2713 }
2714
2715 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2716 event, 0, NL80211_MCGRP_CONFIG,
2717 GFP_KERNEL);
2718 }
2719
2720out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002721 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002722}
2723
2724static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2725{
Johannes Berg4c476992010-10-04 21:36:35 +02002726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002727 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002728 struct sk_buff *msg;
2729 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002730
Johannes Berg4c476992010-10-04 21:36:35 +02002731 if (!rdev->ops->del_virtual_intf)
2732 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002733
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002734 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2735 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2736 nlmsg_free(msg);
2737 msg = NULL;
2738 }
2739
Johannes Berg84efbb82012-06-16 00:00:26 +02002740 /*
2741 * If we remove a wireless device without a netdev then clear
2742 * user_ptr[1] so that nl80211_post_doit won't dereference it
2743 * to check if it needs to do dev_put(). Otherwise it crashes
2744 * since the wdev has been freed, unlike with a netdev where
2745 * we need the dev_put() for the netdev to really be freed.
2746 */
2747 if (!wdev->netdev)
2748 info->user_ptr[1] = NULL;
2749
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002750 status = rdev_del_virtual_intf(rdev, wdev);
2751 if (status >= 0 && msg)
2752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2753 msg, 0, NL80211_MCGRP_CONFIG,
2754 GFP_KERNEL);
2755 else
2756 nlmsg_free(msg);
2757
2758 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002759}
2760
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002761static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2762{
2763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2764 struct net_device *dev = info->user_ptr[1];
2765 u16 noack_map;
2766
2767 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2768 return -EINVAL;
2769
2770 if (!rdev->ops->set_noack_map)
2771 return -EOPNOTSUPP;
2772
2773 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2774
Hila Gonene35e4d22012-06-27 17:19:42 +03002775 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002776}
2777
Johannes Berg41ade002007-12-19 02:03:29 +01002778struct get_key_cookie {
2779 struct sk_buff *msg;
2780 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002781 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002782};
2783
2784static void get_key_callback(void *c, struct key_params *params)
2785{
Johannes Bergb9454e82009-07-08 13:29:08 +02002786 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002787 struct get_key_cookie *cookie = c;
2788
David S. Miller9360ffd2012-03-29 04:41:26 -04002789 if ((params->key &&
2790 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2791 params->key_len, params->key)) ||
2792 (params->seq &&
2793 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2794 params->seq_len, params->seq)) ||
2795 (params->cipher &&
2796 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2797 params->cipher)))
2798 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002799
Johannes Bergb9454e82009-07-08 13:29:08 +02002800 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2801 if (!key)
2802 goto nla_put_failure;
2803
David S. Miller9360ffd2012-03-29 04:41:26 -04002804 if ((params->key &&
2805 nla_put(cookie->msg, NL80211_KEY_DATA,
2806 params->key_len, params->key)) ||
2807 (params->seq &&
2808 nla_put(cookie->msg, NL80211_KEY_SEQ,
2809 params->seq_len, params->seq)) ||
2810 (params->cipher &&
2811 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2812 params->cipher)))
2813 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002814
David S. Miller9360ffd2012-03-29 04:41:26 -04002815 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2816 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002817
2818 nla_nest_end(cookie->msg, key);
2819
Johannes Berg41ade002007-12-19 02:03:29 +01002820 return;
2821 nla_put_failure:
2822 cookie->error = 1;
2823}
2824
2825static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2826{
Johannes Berg4c476992010-10-04 21:36:35 +02002827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002828 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002829 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002830 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002831 const u8 *mac_addr = NULL;
2832 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002833 struct get_key_cookie cookie = {
2834 .error = 0,
2835 };
2836 void *hdr;
2837 struct sk_buff *msg;
2838
2839 if (info->attrs[NL80211_ATTR_KEY_IDX])
2840 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2841
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002842 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002843 return -EINVAL;
2844
2845 if (info->attrs[NL80211_ATTR_MAC])
2846 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2847
Johannes Berge31b8212010-10-05 19:39:30 +02002848 pairwise = !!mac_addr;
2849 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2850 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2851 if (kt >= NUM_NL80211_KEYTYPES)
2852 return -EINVAL;
2853 if (kt != NL80211_KEYTYPE_GROUP &&
2854 kt != NL80211_KEYTYPE_PAIRWISE)
2855 return -EINVAL;
2856 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2857 }
2858
Johannes Berg4c476992010-10-04 21:36:35 +02002859 if (!rdev->ops->get_key)
2860 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002861
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002862 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002863 if (!msg)
2864 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002865
Eric W. Biederman15e47302012-09-07 20:12:54 +00002866 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002867 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002868 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002869 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002870
2871 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002872 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002873
David S. Miller9360ffd2012-03-29 04:41:26 -04002874 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2875 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2876 goto nla_put_failure;
2877 if (mac_addr &&
2878 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2879 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002880
Johannes Berge31b8212010-10-05 19:39:30 +02002881 if (pairwise && mac_addr &&
2882 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2883 return -ENOENT;
2884
Hila Gonene35e4d22012-06-27 17:19:42 +03002885 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2886 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002887
2888 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002889 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002890
2891 if (cookie.error)
2892 goto nla_put_failure;
2893
2894 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002895 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002896
2897 nla_put_failure:
2898 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002899 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002900 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002901 return err;
2902}
2903
2904static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2905{
Johannes Berg4c476992010-10-04 21:36:35 +02002906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002907 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002908 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002909 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002910
Johannes Bergb9454e82009-07-08 13:29:08 +02002911 err = nl80211_parse_key(info, &key);
2912 if (err)
2913 return err;
2914
2915 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002916 return -EINVAL;
2917
Johannes Bergb9454e82009-07-08 13:29:08 +02002918 /* only support setting default key */
2919 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002920 return -EINVAL;
2921
Johannes Bergfffd0932009-07-08 14:22:54 +02002922 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002923
2924 if (key.def) {
2925 if (!rdev->ops->set_default_key) {
2926 err = -EOPNOTSUPP;
2927 goto out;
2928 }
2929
2930 err = nl80211_key_allowed(dev->ieee80211_ptr);
2931 if (err)
2932 goto out;
2933
Hila Gonene35e4d22012-06-27 17:19:42 +03002934 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002935 key.def_uni, key.def_multi);
2936
2937 if (err)
2938 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002939
Johannes Berg3d23e342009-09-29 23:27:28 +02002940#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002941 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002942#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002943 } else {
2944 if (key.def_uni || !key.def_multi) {
2945 err = -EINVAL;
2946 goto out;
2947 }
2948
2949 if (!rdev->ops->set_default_mgmt_key) {
2950 err = -EOPNOTSUPP;
2951 goto out;
2952 }
2953
2954 err = nl80211_key_allowed(dev->ieee80211_ptr);
2955 if (err)
2956 goto out;
2957
Hila Gonene35e4d22012-06-27 17:19:42 +03002958 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002959 if (err)
2960 goto out;
2961
2962#ifdef CONFIG_CFG80211_WEXT
2963 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2964#endif
2965 }
2966
2967 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002968 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002969
Johannes Berg41ade002007-12-19 02:03:29 +01002970 return err;
2971}
2972
2973static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2974{
Johannes Berg4c476992010-10-04 21:36:35 +02002975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002976 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002977 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002978 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002979 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002980
Johannes Bergb9454e82009-07-08 13:29:08 +02002981 err = nl80211_parse_key(info, &key);
2982 if (err)
2983 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002984
Johannes Bergb9454e82009-07-08 13:29:08 +02002985 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002986 return -EINVAL;
2987
Johannes Berg41ade002007-12-19 02:03:29 +01002988 if (info->attrs[NL80211_ATTR_MAC])
2989 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2990
Johannes Berge31b8212010-10-05 19:39:30 +02002991 if (key.type == -1) {
2992 if (mac_addr)
2993 key.type = NL80211_KEYTYPE_PAIRWISE;
2994 else
2995 key.type = NL80211_KEYTYPE_GROUP;
2996 }
2997
2998 /* for now */
2999 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3000 key.type != NL80211_KEYTYPE_GROUP)
3001 return -EINVAL;
3002
Johannes Berg4c476992010-10-04 21:36:35 +02003003 if (!rdev->ops->add_key)
3004 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003005
Johannes Berge31b8212010-10-05 19:39:30 +02003006 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3007 key.type == NL80211_KEYTYPE_PAIRWISE,
3008 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003009 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003010
3011 wdev_lock(dev->ieee80211_ptr);
3012 err = nl80211_key_allowed(dev->ieee80211_ptr);
3013 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003014 err = rdev_add_key(rdev, dev, key.idx,
3015 key.type == NL80211_KEYTYPE_PAIRWISE,
3016 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003017 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003018
Johannes Berg41ade002007-12-19 02:03:29 +01003019 return err;
3020}
3021
3022static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3023{
Johannes Berg4c476992010-10-04 21:36:35 +02003024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003025 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003026 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003027 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003028 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003029
Johannes Bergb9454e82009-07-08 13:29:08 +02003030 err = nl80211_parse_key(info, &key);
3031 if (err)
3032 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003033
3034 if (info->attrs[NL80211_ATTR_MAC])
3035 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3036
Johannes Berge31b8212010-10-05 19:39:30 +02003037 if (key.type == -1) {
3038 if (mac_addr)
3039 key.type = NL80211_KEYTYPE_PAIRWISE;
3040 else
3041 key.type = NL80211_KEYTYPE_GROUP;
3042 }
3043
3044 /* for now */
3045 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3046 key.type != NL80211_KEYTYPE_GROUP)
3047 return -EINVAL;
3048
Johannes Berg4c476992010-10-04 21:36:35 +02003049 if (!rdev->ops->del_key)
3050 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003051
Johannes Bergfffd0932009-07-08 14:22:54 +02003052 wdev_lock(dev->ieee80211_ptr);
3053 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003054
3055 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3056 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3057 err = -ENOENT;
3058
Johannes Bergfffd0932009-07-08 14:22:54 +02003059 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003060 err = rdev_del_key(rdev, dev, key.idx,
3061 key.type == NL80211_KEYTYPE_PAIRWISE,
3062 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003063
Johannes Berg3d23e342009-09-29 23:27:28 +02003064#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003065 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003066 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003067 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003068 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003069 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3070 }
3071#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003072 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003073
Johannes Berg41ade002007-12-19 02:03:29 +01003074 return err;
3075}
3076
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303077/* This function returns an error or the number of nested attributes */
3078static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3079{
3080 struct nlattr *attr;
3081 int n_entries = 0, tmp;
3082
3083 nla_for_each_nested(attr, nl_attr, tmp) {
3084 if (nla_len(attr) != ETH_ALEN)
3085 return -EINVAL;
3086
3087 n_entries++;
3088 }
3089
3090 return n_entries;
3091}
3092
3093/*
3094 * This function parses ACL information and allocates memory for ACL data.
3095 * On successful return, the calling function is responsible to free the
3096 * ACL buffer returned by this function.
3097 */
3098static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3099 struct genl_info *info)
3100{
3101 enum nl80211_acl_policy acl_policy;
3102 struct nlattr *attr;
3103 struct cfg80211_acl_data *acl;
3104 int i = 0, n_entries, tmp;
3105
3106 if (!wiphy->max_acl_mac_addrs)
3107 return ERR_PTR(-EOPNOTSUPP);
3108
3109 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3110 return ERR_PTR(-EINVAL);
3111
3112 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3113 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3114 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3115 return ERR_PTR(-EINVAL);
3116
3117 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3118 return ERR_PTR(-EINVAL);
3119
3120 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3121 if (n_entries < 0)
3122 return ERR_PTR(n_entries);
3123
3124 if (n_entries > wiphy->max_acl_mac_addrs)
3125 return ERR_PTR(-ENOTSUPP);
3126
3127 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3128 GFP_KERNEL);
3129 if (!acl)
3130 return ERR_PTR(-ENOMEM);
3131
3132 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3133 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3134 i++;
3135 }
3136
3137 acl->n_acl_entries = n_entries;
3138 acl->acl_policy = acl_policy;
3139
3140 return acl;
3141}
3142
3143static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3144{
3145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3146 struct net_device *dev = info->user_ptr[1];
3147 struct cfg80211_acl_data *acl;
3148 int err;
3149
3150 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3151 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3152 return -EOPNOTSUPP;
3153
3154 if (!dev->ieee80211_ptr->beacon_interval)
3155 return -EINVAL;
3156
3157 acl = parse_acl_data(&rdev->wiphy, info);
3158 if (IS_ERR(acl))
3159 return PTR_ERR(acl);
3160
3161 err = rdev_set_mac_acl(rdev, dev, acl);
3162
3163 kfree(acl);
3164
3165 return err;
3166}
3167
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003168static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003169 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003170{
Johannes Berg88600202012-02-13 15:17:18 +01003171 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003172
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003173 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3174 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3175 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3176 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003177 return -EINVAL;
3178
Johannes Berg88600202012-02-13 15:17:18 +01003179 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003180
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003181 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3182 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3183 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003184 if (!bcn->head_len)
3185 return -EINVAL;
3186 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003187 }
3188
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003189 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3190 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3191 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003192 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003193 }
3194
Johannes Berg4c476992010-10-04 21:36:35 +02003195 if (!haveinfo)
3196 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003197
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003198 if (attrs[NL80211_ATTR_IE]) {
3199 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3200 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003201 }
3202
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003203 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003204 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003205 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003206 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003207 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003208 }
3209
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003210 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003211 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003212 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003213 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003214 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003215 }
3216
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003217 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3218 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3219 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003220 }
3221
Johannes Berg88600202012-02-13 15:17:18 +01003222 return 0;
3223}
3224
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003225static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3226 struct cfg80211_ap_settings *params)
3227{
3228 struct wireless_dev *wdev;
3229 bool ret = false;
3230
Johannes Berg89a54e42012-06-15 14:33:17 +02003231 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003232 if (wdev->iftype != NL80211_IFTYPE_AP &&
3233 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3234 continue;
3235
Johannes Berg683b6d32012-11-08 21:25:48 +01003236 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003237 continue;
3238
Johannes Berg683b6d32012-11-08 21:25:48 +01003239 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003240 ret = true;
3241 break;
3242 }
3243
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003244 return ret;
3245}
3246
Jouni Malinene39e5b52012-09-30 19:29:39 +03003247static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3248 enum nl80211_auth_type auth_type,
3249 enum nl80211_commands cmd)
3250{
3251 if (auth_type > NL80211_AUTHTYPE_MAX)
3252 return false;
3253
3254 switch (cmd) {
3255 case NL80211_CMD_AUTHENTICATE:
3256 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3257 auth_type == NL80211_AUTHTYPE_SAE)
3258 return false;
3259 return true;
3260 case NL80211_CMD_CONNECT:
3261 case NL80211_CMD_START_AP:
3262 /* SAE not supported yet */
3263 if (auth_type == NL80211_AUTHTYPE_SAE)
3264 return false;
3265 return true;
3266 default:
3267 return false;
3268 }
3269}
3270
Johannes Berg88600202012-02-13 15:17:18 +01003271static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3272{
3273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3274 struct net_device *dev = info->user_ptr[1];
3275 struct wireless_dev *wdev = dev->ieee80211_ptr;
3276 struct cfg80211_ap_settings params;
3277 int err;
3278
3279 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3280 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3281 return -EOPNOTSUPP;
3282
3283 if (!rdev->ops->start_ap)
3284 return -EOPNOTSUPP;
3285
3286 if (wdev->beacon_interval)
3287 return -EALREADY;
3288
3289 memset(&params, 0, sizeof(params));
3290
3291 /* these are required for START_AP */
3292 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3293 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3294 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3295 return -EINVAL;
3296
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003297 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003298 if (err)
3299 return err;
3300
3301 params.beacon_interval =
3302 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3303 params.dtim_period =
3304 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3305
3306 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3307 if (err)
3308 return err;
3309
3310 /*
3311 * In theory, some of these attributes should be required here
3312 * but since they were not used when the command was originally
3313 * added, keep them optional for old user space programs to let
3314 * them continue to work with drivers that do not need the
3315 * additional information -- drivers must check!
3316 */
3317 if (info->attrs[NL80211_ATTR_SSID]) {
3318 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3319 params.ssid_len =
3320 nla_len(info->attrs[NL80211_ATTR_SSID]);
3321 if (params.ssid_len == 0 ||
3322 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3323 return -EINVAL;
3324 }
3325
3326 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3327 params.hidden_ssid = nla_get_u32(
3328 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3329 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3330 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3331 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3332 return -EINVAL;
3333 }
3334
3335 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3336
3337 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3338 params.auth_type = nla_get_u32(
3339 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003340 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3341 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003342 return -EINVAL;
3343 } else
3344 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3345
3346 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3347 NL80211_MAX_NR_CIPHER_SUITES);
3348 if (err)
3349 return err;
3350
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303351 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3352 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3353 return -EOPNOTSUPP;
3354 params.inactivity_timeout = nla_get_u16(
3355 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3356 }
3357
Johannes Berg53cabad2012-11-14 15:17:28 +01003358 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3359 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3360 return -EINVAL;
3361 params.p2p_ctwindow =
3362 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3363 if (params.p2p_ctwindow > 127)
3364 return -EINVAL;
3365 if (params.p2p_ctwindow != 0 &&
3366 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3367 return -EINVAL;
3368 }
3369
3370 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3371 u8 tmp;
3372
3373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3374 return -EINVAL;
3375 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3376 if (tmp > 1)
3377 return -EINVAL;
3378 params.p2p_opp_ps = tmp;
3379 if (params.p2p_opp_ps != 0 &&
3380 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3381 return -EINVAL;
3382 }
3383
Johannes Bergaa430da2012-05-16 23:50:18 +02003384 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003385 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3386 if (err)
3387 return err;
3388 } else if (wdev->preset_chandef.chan) {
3389 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003390 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003391 return -EINVAL;
3392
Ilan Peer174e0cd2014-02-23 09:13:01 +02003393 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3394 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003395 return -EINVAL;
3396
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303397 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3398 params.acl = parse_acl_data(&rdev->wiphy, info);
3399 if (IS_ERR(params.acl))
3400 return PTR_ERR(params.acl);
3401 }
3402
Eliad Peller18998c32014-09-10 14:07:34 +03003403 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3404 params.smps_mode =
3405 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3406 switch (params.smps_mode) {
3407 case NL80211_SMPS_OFF:
3408 break;
3409 case NL80211_SMPS_STATIC:
3410 if (!(rdev->wiphy.features &
3411 NL80211_FEATURE_STATIC_SMPS))
3412 return -EINVAL;
3413 break;
3414 case NL80211_SMPS_DYNAMIC:
3415 if (!(rdev->wiphy.features &
3416 NL80211_FEATURE_DYNAMIC_SMPS))
3417 return -EINVAL;
3418 break;
3419 default:
3420 return -EINVAL;
3421 }
3422 } else {
3423 params.smps_mode = NL80211_SMPS_OFF;
3424 }
3425
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003426 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003427 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003428 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003429 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003430 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003431 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003432 wdev->ssid_len = params.ssid_len;
3433 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003434 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003435 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303436
3437 kfree(params.acl);
3438
Johannes Berg56d18932011-05-09 18:41:15 +02003439 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003440}
3441
Johannes Berg88600202012-02-13 15:17:18 +01003442static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3443{
3444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3445 struct net_device *dev = info->user_ptr[1];
3446 struct wireless_dev *wdev = dev->ieee80211_ptr;
3447 struct cfg80211_beacon_data params;
3448 int err;
3449
3450 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3451 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3452 return -EOPNOTSUPP;
3453
3454 if (!rdev->ops->change_beacon)
3455 return -EOPNOTSUPP;
3456
3457 if (!wdev->beacon_interval)
3458 return -EINVAL;
3459
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003460 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003461 if (err)
3462 return err;
3463
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003464 wdev_lock(wdev);
3465 err = rdev_change_beacon(rdev, dev, &params);
3466 wdev_unlock(wdev);
3467
3468 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003469}
3470
3471static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003472{
Johannes Berg4c476992010-10-04 21:36:35 +02003473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3474 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003475
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003476 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003477}
3478
Johannes Berg5727ef12007-12-19 02:03:34 +01003479static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3480 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3481 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3482 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003483 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003484 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003485 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003486};
3487
Johannes Bergeccb8e82009-05-11 21:57:56 +03003488static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003489 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003490 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003491{
3492 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003493 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003494 int flag;
3495
Johannes Bergeccb8e82009-05-11 21:57:56 +03003496 /*
3497 * Try parsing the new attribute first so userspace
3498 * can specify both for older kernels.
3499 */
3500 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3501 if (nla) {
3502 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003503
Johannes Bergeccb8e82009-05-11 21:57:56 +03003504 sta_flags = nla_data(nla);
3505 params->sta_flags_mask = sta_flags->mask;
3506 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003507 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003508 if ((params->sta_flags_mask |
3509 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3510 return -EINVAL;
3511 return 0;
3512 }
3513
3514 /* if present, parse the old attribute */
3515
3516 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003517 if (!nla)
3518 return 0;
3519
3520 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3521 nla, sta_flags_policy))
3522 return -EINVAL;
3523
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003524 /*
3525 * Only allow certain flags for interface types so that
3526 * other attributes are silently ignored. Remember that
3527 * this is backward compatibility code with old userspace
3528 * and shouldn't be hit in other cases anyway.
3529 */
3530 switch (iftype) {
3531 case NL80211_IFTYPE_AP:
3532 case NL80211_IFTYPE_AP_VLAN:
3533 case NL80211_IFTYPE_P2P_GO:
3534 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3535 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3536 BIT(NL80211_STA_FLAG_WME) |
3537 BIT(NL80211_STA_FLAG_MFP);
3538 break;
3539 case NL80211_IFTYPE_P2P_CLIENT:
3540 case NL80211_IFTYPE_STATION:
3541 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3542 BIT(NL80211_STA_FLAG_TDLS_PEER);
3543 break;
3544 case NL80211_IFTYPE_MESH_POINT:
3545 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3546 BIT(NL80211_STA_FLAG_MFP) |
3547 BIT(NL80211_STA_FLAG_AUTHORIZED);
3548 default:
3549 return -EINVAL;
3550 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003551
Johannes Berg3383b5a2012-05-10 20:14:43 +02003552 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3553 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003554 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003555
Johannes Berg3383b5a2012-05-10 20:14:43 +02003556 /* no longer support new API additions in old API */
3557 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3558 return -EINVAL;
3559 }
3560 }
3561
Johannes Berg5727ef12007-12-19 02:03:34 +01003562 return 0;
3563}
3564
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003565static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3566 int attr)
3567{
3568 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003569 u32 bitrate;
3570 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003571
3572 rate = nla_nest_start(msg, attr);
3573 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003574 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003575
3576 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3577 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003578 /* report 16-bit bitrate only if we can */
3579 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003580 if (bitrate > 0 &&
3581 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3582 return false;
3583 if (bitrate_compat > 0 &&
3584 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3585 return false;
3586
3587 if (info->flags & RATE_INFO_FLAGS_MCS) {
3588 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3589 return false;
3590 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3591 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3592 return false;
3593 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3594 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3595 return false;
3596 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3597 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3598 return false;
3599 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3600 return false;
3601 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3602 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3603 return false;
3604 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3605 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3606 return false;
3607 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3608 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3609 return false;
3610 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3611 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3612 return false;
3613 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3614 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3615 return false;
3616 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003617
3618 nla_nest_end(msg, rate);
3619 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003620}
3621
Felix Fietkau119363c2013-04-22 16:29:30 +02003622static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3623 int id)
3624{
3625 void *attr;
3626 int i = 0;
3627
3628 if (!mask)
3629 return true;
3630
3631 attr = nla_nest_start(msg, id);
3632 if (!attr)
3633 return false;
3634
3635 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3636 if (!(mask & BIT(i)))
3637 continue;
3638
3639 if (nla_put_u8(msg, i, signal[i]))
3640 return false;
3641 }
3642
3643 nla_nest_end(msg, attr);
3644
3645 return true;
3646}
3647
Eric W. Biederman15e47302012-09-07 20:12:54 +00003648static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003649 int flags,
3650 struct cfg80211_registered_device *rdev,
3651 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003652 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003653{
3654 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003655 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003656
Eric W. Biederman15e47302012-09-07 20:12:54 +00003657 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003658 if (!hdr)
3659 return -1;
3660
David S. Miller9360ffd2012-03-29 04:41:26 -04003661 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3662 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3663 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3664 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003665
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003666 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3667 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003668 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003669 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3670 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3671 sinfo->connected_time))
3672 goto nla_put_failure;
3673 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3674 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3675 sinfo->inactive_time))
3676 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003677 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3678 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003679 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003680 (u32)sinfo->rx_bytes))
3681 goto nla_put_failure;
3682 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003683 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003684 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3685 (u32)sinfo->tx_bytes))
3686 goto nla_put_failure;
3687 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3688 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003689 sinfo->rx_bytes))
3690 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003691 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3692 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003693 sinfo->tx_bytes))
3694 goto nla_put_failure;
3695 if ((sinfo->filled & STATION_INFO_LLID) &&
3696 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3697 goto nla_put_failure;
3698 if ((sinfo->filled & STATION_INFO_PLID) &&
3699 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3700 goto nla_put_failure;
3701 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3702 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3703 sinfo->plink_state))
3704 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003705 switch (rdev->wiphy.signal_type) {
3706 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003707 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3708 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3709 sinfo->signal))
3710 goto nla_put_failure;
3711 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3712 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3713 sinfo->signal_avg))
3714 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003715 break;
3716 default:
3717 break;
3718 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003719 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3720 if (!nl80211_put_signal(msg, sinfo->chains,
3721 sinfo->chain_signal,
3722 NL80211_STA_INFO_CHAIN_SIGNAL))
3723 goto nla_put_failure;
3724 }
3725 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3726 if (!nl80211_put_signal(msg, sinfo->chains,
3727 sinfo->chain_signal_avg,
3728 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3729 goto nla_put_failure;
3730 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003731 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003732 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3733 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003734 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003735 }
3736 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3737 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3738 NL80211_STA_INFO_RX_BITRATE))
3739 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003740 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003741 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3742 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3743 sinfo->rx_packets))
3744 goto nla_put_failure;
3745 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3746 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3747 sinfo->tx_packets))
3748 goto nla_put_failure;
3749 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3750 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3751 sinfo->tx_retries))
3752 goto nla_put_failure;
3753 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3754 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3755 sinfo->tx_failed))
3756 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003757 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3758 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3759 sinfo->expected_throughput))
3760 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003761 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3762 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3763 sinfo->beacon_loss_count))
3764 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003765 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3766 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3767 sinfo->local_pm))
3768 goto nla_put_failure;
3769 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3770 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3771 sinfo->peer_pm))
3772 goto nla_put_failure;
3773 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3774 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3775 sinfo->nonpeer_pm))
3776 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003777 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3778 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3779 if (!bss_param)
3780 goto nla_put_failure;
3781
David S. Miller9360ffd2012-03-29 04:41:26 -04003782 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3783 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3784 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3785 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3786 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3787 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3788 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3789 sinfo->bss_param.dtim_period) ||
3790 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3791 sinfo->bss_param.beacon_interval))
3792 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003793
3794 nla_nest_end(msg, bss_param);
3795 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003796 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3797 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3798 sizeof(struct nl80211_sta_flag_update),
3799 &sinfo->sta_flags))
3800 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003801 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3802 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3803 sinfo->t_offset))
3804 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003805 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003806
David S. Miller9360ffd2012-03-29 04:41:26 -04003807 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3808 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3809 sinfo->assoc_req_ies))
3810 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003811
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003812 return genlmsg_end(msg, hdr);
3813
3814 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003815 genlmsg_cancel(msg, hdr);
3816 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003817}
3818
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003819static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003820 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003821{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003822 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003823 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003824 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003825 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003826 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003827 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003828
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003829 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003830 if (err)
3831 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003832
Johannes Berg97990a02013-04-19 01:02:55 +02003833 if (!wdev->netdev) {
3834 err = -EINVAL;
3835 goto out_err;
3836 }
3837
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003838 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003839 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003840 goto out_err;
3841 }
3842
Johannes Bergbba95fe2008-07-29 13:22:51 +02003843 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003844 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003845 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003846 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003847 if (err == -ENOENT)
3848 break;
3849 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003850 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003851
3852 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003853 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003854 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003855 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003856 &sinfo) < 0)
3857 goto out;
3858
3859 sta_idx++;
3860 }
3861
3862
3863 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003864 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003865 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003866 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003867 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003868
3869 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003870}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003871
Johannes Berg5727ef12007-12-19 02:03:34 +01003872static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3873{
Johannes Berg4c476992010-10-04 21:36:35 +02003874 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3875 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003876 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003877 struct sk_buff *msg;
3878 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003879 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003880
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003881 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003882
3883 if (!info->attrs[NL80211_ATTR_MAC])
3884 return -EINVAL;
3885
3886 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3887
Johannes Berg4c476992010-10-04 21:36:35 +02003888 if (!rdev->ops->get_station)
3889 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003890
Hila Gonene35e4d22012-06-27 17:19:42 +03003891 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003892 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003893 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003894
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003896 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003897 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003898
Eric W. Biederman15e47302012-09-07 20:12:54 +00003899 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003900 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003901 nlmsg_free(msg);
3902 return -ENOBUFS;
3903 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003904
Johannes Berg4c476992010-10-04 21:36:35 +02003905 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003906}
3907
Johannes Berg77ee7c82013-02-15 00:48:33 +01003908int cfg80211_check_station_change(struct wiphy *wiphy,
3909 struct station_parameters *params,
3910 enum cfg80211_station_type statype)
3911{
3912 if (params->listen_interval != -1)
3913 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003914 if (params->aid &&
3915 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003916 return -EINVAL;
3917
3918 /* When you run into this, adjust the code below for the new flag */
3919 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3920
3921 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003922 case CFG80211_STA_MESH_PEER_KERNEL:
3923 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003924 /*
3925 * No ignoring the TDLS flag here -- the userspace mesh
3926 * code doesn't have the bug of including TDLS in the
3927 * mask everywhere.
3928 */
3929 if (params->sta_flags_mask &
3930 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3931 BIT(NL80211_STA_FLAG_MFP) |
3932 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3933 return -EINVAL;
3934 break;
3935 case CFG80211_STA_TDLS_PEER_SETUP:
3936 case CFG80211_STA_TDLS_PEER_ACTIVE:
3937 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3938 return -EINVAL;
3939 /* ignore since it can't change */
3940 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3941 break;
3942 default:
3943 /* disallow mesh-specific things */
3944 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3945 return -EINVAL;
3946 if (params->local_pm)
3947 return -EINVAL;
3948 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3949 return -EINVAL;
3950 }
3951
3952 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3953 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3954 /* TDLS can't be set, ... */
3955 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3956 return -EINVAL;
3957 /*
3958 * ... but don't bother the driver with it. This works around
3959 * a hostapd/wpa_supplicant issue -- it always includes the
3960 * TLDS_PEER flag in the mask even for AP mode.
3961 */
3962 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3963 }
3964
3965 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3966 /* reject other things that can't change */
3967 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3968 return -EINVAL;
3969 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3970 return -EINVAL;
3971 if (params->supported_rates)
3972 return -EINVAL;
3973 if (params->ext_capab || params->ht_capa || params->vht_capa)
3974 return -EINVAL;
3975 }
3976
3977 if (statype != CFG80211_STA_AP_CLIENT) {
3978 if (params->vlan)
3979 return -EINVAL;
3980 }
3981
3982 switch (statype) {
3983 case CFG80211_STA_AP_MLME_CLIENT:
3984 /* Use this only for authorizing/unauthorizing a station */
3985 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3986 return -EOPNOTSUPP;
3987 break;
3988 case CFG80211_STA_AP_CLIENT:
3989 /* accept only the listed bits */
3990 if (params->sta_flags_mask &
3991 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3992 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3993 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3994 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3995 BIT(NL80211_STA_FLAG_WME) |
3996 BIT(NL80211_STA_FLAG_MFP)))
3997 return -EINVAL;
3998
3999 /* but authenticated/associated only if driver handles it */
4000 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4001 params->sta_flags_mask &
4002 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4003 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4004 return -EINVAL;
4005 break;
4006 case CFG80211_STA_IBSS:
4007 case CFG80211_STA_AP_STA:
4008 /* reject any changes other than AUTHORIZED */
4009 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4010 return -EINVAL;
4011 break;
4012 case CFG80211_STA_TDLS_PEER_SETUP:
4013 /* reject any changes other than AUTHORIZED or WME */
4014 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4015 BIT(NL80211_STA_FLAG_WME)))
4016 return -EINVAL;
4017 /* force (at least) rates when authorizing */
4018 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4019 !params->supported_rates)
4020 return -EINVAL;
4021 break;
4022 case CFG80211_STA_TDLS_PEER_ACTIVE:
4023 /* reject any changes */
4024 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004025 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004026 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4027 return -EINVAL;
4028 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004029 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004030 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4031 return -EINVAL;
4032 break;
4033 }
4034
4035 return 0;
4036}
4037EXPORT_SYMBOL(cfg80211_check_station_change);
4038
Johannes Berg5727ef12007-12-19 02:03:34 +01004039/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004040 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004041 */
Johannes Berg80b99892011-11-18 16:23:01 +01004042static struct net_device *get_vlan(struct genl_info *info,
4043 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004044{
Johannes Berg463d0182009-07-14 00:33:35 +02004045 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004046 struct net_device *v;
4047 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004048
Johannes Berg80b99892011-11-18 16:23:01 +01004049 if (!vlanattr)
4050 return NULL;
4051
4052 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4053 if (!v)
4054 return ERR_PTR(-ENODEV);
4055
4056 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4057 ret = -EINVAL;
4058 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004059 }
Johannes Berg80b99892011-11-18 16:23:01 +01004060
Johannes Berg77ee7c82013-02-15 00:48:33 +01004061 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4062 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4063 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4064 ret = -EINVAL;
4065 goto error;
4066 }
4067
Johannes Berg80b99892011-11-18 16:23:01 +01004068 if (!netif_running(v)) {
4069 ret = -ENETDOWN;
4070 goto error;
4071 }
4072
4073 return v;
4074 error:
4075 dev_put(v);
4076 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004077}
4078
Johannes Berg94e860f2014-01-20 23:58:15 +01004079static const struct nla_policy
4080nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004081 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4082 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4083};
4084
Johannes Bergff276692013-02-15 00:09:01 +01004085static int nl80211_parse_sta_wme(struct genl_info *info,
4086 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004087{
Jouni Malinendf881292013-02-14 21:10:54 +02004088 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4089 struct nlattr *nla;
4090 int err;
4091
Jouni Malinendf881292013-02-14 21:10:54 +02004092 /* parse WME attributes if present */
4093 if (!info->attrs[NL80211_ATTR_STA_WME])
4094 return 0;
4095
4096 nla = info->attrs[NL80211_ATTR_STA_WME];
4097 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4098 nl80211_sta_wme_policy);
4099 if (err)
4100 return err;
4101
4102 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4103 params->uapsd_queues = nla_get_u8(
4104 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4105 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4106 return -EINVAL;
4107
4108 if (tb[NL80211_STA_WME_MAX_SP])
4109 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4110
4111 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4112 return -EINVAL;
4113
4114 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4115
4116 return 0;
4117}
4118
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304119static int nl80211_parse_sta_channel_info(struct genl_info *info,
4120 struct station_parameters *params)
4121{
4122 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4123 params->supported_channels =
4124 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4125 params->supported_channels_len =
4126 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4127 /*
4128 * Need to include at least one (first channel, number of
4129 * channels) tuple for each subband, and must have proper
4130 * tuples for the rest of the data as well.
4131 */
4132 if (params->supported_channels_len < 2)
4133 return -EINVAL;
4134 if (params->supported_channels_len % 2)
4135 return -EINVAL;
4136 }
4137
4138 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4139 params->supported_oper_classes =
4140 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4141 params->supported_oper_classes_len =
4142 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4143 /*
4144 * The value of the Length field of the Supported Operating
4145 * Classes element is between 2 and 253.
4146 */
4147 if (params->supported_oper_classes_len < 2 ||
4148 params->supported_oper_classes_len > 253)
4149 return -EINVAL;
4150 }
4151 return 0;
4152}
4153
Johannes Bergff276692013-02-15 00:09:01 +01004154static int nl80211_set_station_tdls(struct genl_info *info,
4155 struct station_parameters *params)
4156{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304157 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004158 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004159 if (info->attrs[NL80211_ATTR_PEER_AID])
4160 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004161 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4162 params->ht_capa =
4163 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4164 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4165 params->vht_capa =
4166 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4167
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304168 err = nl80211_parse_sta_channel_info(info, params);
4169 if (err)
4170 return err;
4171
Johannes Bergff276692013-02-15 00:09:01 +01004172 return nl80211_parse_sta_wme(info, params);
4173}
4174
Johannes Berg5727ef12007-12-19 02:03:34 +01004175static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4176{
Johannes Berg4c476992010-10-04 21:36:35 +02004177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004178 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004179 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004180 u8 *mac_addr;
4181 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004182
4183 memset(&params, 0, sizeof(params));
4184
4185 params.listen_interval = -1;
4186
Johannes Berg77ee7c82013-02-15 00:48:33 +01004187 if (!rdev->ops->change_station)
4188 return -EOPNOTSUPP;
4189
Johannes Berg5727ef12007-12-19 02:03:34 +01004190 if (info->attrs[NL80211_ATTR_STA_AID])
4191 return -EINVAL;
4192
4193 if (!info->attrs[NL80211_ATTR_MAC])
4194 return -EINVAL;
4195
4196 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4197
4198 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4199 params.supported_rates =
4200 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4201 params.supported_rates_len =
4202 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4203 }
4204
Jouni Malinen9d62a982013-02-14 21:10:13 +02004205 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4206 params.capability =
4207 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4208 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4209 }
4210
4211 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4212 params.ext_capab =
4213 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4214 params.ext_capab_len =
4215 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4216 }
4217
Jouni Malinendf881292013-02-14 21:10:54 +02004218 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004219 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004220
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004221 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004222 return -EINVAL;
4223
Johannes Bergf8bacc22013-02-14 23:27:01 +01004224 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004225 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004226 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4227 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4228 return -EINVAL;
4229 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004230
Johannes Bergf8bacc22013-02-14 23:27:01 +01004231 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004232 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004233 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4234 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4235 return -EINVAL;
4236 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4237 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004238
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004239 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4240 enum nl80211_mesh_power_mode pm = nla_get_u32(
4241 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4242
4243 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4244 pm > NL80211_MESH_POWER_MAX)
4245 return -EINVAL;
4246
4247 params.local_pm = pm;
4248 }
4249
Johannes Berg77ee7c82013-02-15 00:48:33 +01004250 /* Include parameters for TDLS peer (will check later) */
4251 err = nl80211_set_station_tdls(info, &params);
4252 if (err)
4253 return err;
4254
4255 params.vlan = get_vlan(info, rdev);
4256 if (IS_ERR(params.vlan))
4257 return PTR_ERR(params.vlan);
4258
Johannes Berga97f4422009-06-18 17:23:43 +02004259 switch (dev->ieee80211_ptr->iftype) {
4260 case NL80211_IFTYPE_AP:
4261 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004262 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004263 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004264 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004265 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004266 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004267 break;
4268 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004269 err = -EOPNOTSUPP;
4270 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004271 }
4272
Johannes Berg77ee7c82013-02-15 00:48:33 +01004273 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004274 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004275
Johannes Berg77ee7c82013-02-15 00:48:33 +01004276 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004277 if (params.vlan)
4278 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004279
Johannes Berg5727ef12007-12-19 02:03:34 +01004280 return err;
4281}
4282
4283static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4284{
Johannes Berg4c476992010-10-04 21:36:35 +02004285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004286 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004287 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004288 struct station_parameters params;
4289 u8 *mac_addr = NULL;
4290
4291 memset(&params, 0, sizeof(params));
4292
Johannes Berg984c3112013-02-14 23:43:25 +01004293 if (!rdev->ops->add_station)
4294 return -EOPNOTSUPP;
4295
Johannes Berg5727ef12007-12-19 02:03:34 +01004296 if (!info->attrs[NL80211_ATTR_MAC])
4297 return -EINVAL;
4298
Johannes Berg5727ef12007-12-19 02:03:34 +01004299 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4300 return -EINVAL;
4301
4302 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4303 return -EINVAL;
4304
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004305 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4306 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004307 return -EINVAL;
4308
Johannes Berg5727ef12007-12-19 02:03:34 +01004309 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4310 params.supported_rates =
4311 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4312 params.supported_rates_len =
4313 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4314 params.listen_interval =
4315 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004316
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004317 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004318 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004319 else
4320 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004321 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4322 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004323
Jouni Malinen9d62a982013-02-14 21:10:13 +02004324 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4325 params.capability =
4326 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4327 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4328 }
4329
4330 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4331 params.ext_capab =
4332 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4333 params.ext_capab_len =
4334 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4335 }
4336
Jouni Malinen36aedc92008-08-25 11:58:58 +03004337 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4338 params.ht_capa =
4339 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004340
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004341 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4342 params.vht_capa =
4343 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4344
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004345 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4346 params.opmode_notif_used = true;
4347 params.opmode_notif =
4348 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4349 }
4350
Johannes Bergf8bacc22013-02-14 23:27:01 +01004351 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004352 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004353 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4354 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4355 return -EINVAL;
4356 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004357
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304358 err = nl80211_parse_sta_channel_info(info, &params);
4359 if (err)
4360 return err;
4361
Johannes Bergff276692013-02-15 00:09:01 +01004362 err = nl80211_parse_sta_wme(info, &params);
4363 if (err)
4364 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004365
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004366 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004367 return -EINVAL;
4368
Johannes Berg77ee7c82013-02-15 00:48:33 +01004369 /* When you run into this, adjust the code below for the new flag */
4370 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4371
Johannes Bergbdd90d52011-12-14 12:20:27 +01004372 switch (dev->ieee80211_ptr->iftype) {
4373 case NL80211_IFTYPE_AP:
4374 case NL80211_IFTYPE_AP_VLAN:
4375 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004376 /* ignore WME attributes if iface/sta is not capable */
4377 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4378 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4379 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004380
Johannes Bergbdd90d52011-12-14 12:20:27 +01004381 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004382 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4383 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004384 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004385 /* but don't bother the driver with it */
4386 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004387
Johannes Bergd582cff2012-10-26 17:53:44 +02004388 /* allow authenticated/associated only if driver handles it */
4389 if (!(rdev->wiphy.features &
4390 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4391 params.sta_flags_mask &
4392 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4393 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4394 return -EINVAL;
4395
Johannes Bergbdd90d52011-12-14 12:20:27 +01004396 /* must be last in here for error handling */
4397 params.vlan = get_vlan(info, rdev);
4398 if (IS_ERR(params.vlan))
4399 return PTR_ERR(params.vlan);
4400 break;
4401 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004402 /* ignore uAPSD data */
4403 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4404
Johannes Bergd582cff2012-10-26 17:53:44 +02004405 /* associated is disallowed */
4406 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4407 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004408 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004409 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4410 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004411 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004412 break;
4413 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004414 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004415 /* ignore uAPSD data */
4416 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4417
Johannes Berg77ee7c82013-02-15 00:48:33 +01004418 /* these are disallowed */
4419 if (params.sta_flags_mask &
4420 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4421 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004422 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004423 /* Only TDLS peers can be added */
4424 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4425 return -EINVAL;
4426 /* Can only add if TDLS ... */
4427 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4428 return -EOPNOTSUPP;
4429 /* ... with external setup is supported */
4430 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4431 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004432 /*
4433 * Older wpa_supplicant versions always mark the TDLS peer
4434 * as authorized, but it shouldn't yet be.
4435 */
4436 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004437 break;
4438 default:
4439 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004440 }
4441
Johannes Bergbdd90d52011-12-14 12:20:27 +01004442 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004443
Hila Gonene35e4d22012-06-27 17:19:42 +03004444 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004445
Johannes Berg5727ef12007-12-19 02:03:34 +01004446 if (params.vlan)
4447 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004448 return err;
4449}
4450
4451static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4452{
Johannes Berg4c476992010-10-04 21:36:35 +02004453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4454 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004455 struct station_del_parameters params;
4456
4457 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004458
4459 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004460 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004461
Johannes Berge80cf852009-05-11 14:43:13 +02004462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004463 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004464 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004465 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4466 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004467
Johannes Berg4c476992010-10-04 21:36:35 +02004468 if (!rdev->ops->del_station)
4469 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004470
Jouni Malinen98856862014-10-20 13:20:45 +03004471 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4472 params.subtype =
4473 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4474 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4475 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4476 return -EINVAL;
4477 } else {
4478 /* Default to Deauthentication frame */
4479 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4480 }
4481
4482 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4483 params.reason_code =
4484 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4485 if (params.reason_code == 0)
4486 return -EINVAL; /* 0 is reserved */
4487 } else {
4488 /* Default to reason code 2 */
4489 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4490 }
4491
Jouni Malinen89c771e2014-10-10 20:52:40 +03004492 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004493}
4494
Eric W. Biederman15e47302012-09-07 20:12:54 +00004495static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004496 int flags, struct net_device *dev,
4497 u8 *dst, u8 *next_hop,
4498 struct mpath_info *pinfo)
4499{
4500 void *hdr;
4501 struct nlattr *pinfoattr;
4502
Henning Rogge1ef4c852014-11-04 16:14:58 +01004503 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504 if (!hdr)
4505 return -1;
4506
David S. Miller9360ffd2012-03-29 04:41:26 -04004507 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4508 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4509 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4510 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4511 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004512
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004513 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4514 if (!pinfoattr)
4515 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004516 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4517 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4518 pinfo->frame_qlen))
4519 goto nla_put_failure;
4520 if (((pinfo->filled & MPATH_INFO_SN) &&
4521 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4522 ((pinfo->filled & MPATH_INFO_METRIC) &&
4523 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4524 pinfo->metric)) ||
4525 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4526 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4527 pinfo->exptime)) ||
4528 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4529 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4530 pinfo->flags)) ||
4531 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4532 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4533 pinfo->discovery_timeout)) ||
4534 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4535 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4536 pinfo->discovery_retries)))
4537 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004538
4539 nla_nest_end(msg, pinfoattr);
4540
4541 return genlmsg_end(msg, hdr);
4542
4543 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004544 genlmsg_cancel(msg, hdr);
4545 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004546}
4547
4548static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004549 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004550{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004551 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004552 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004553 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004554 u8 dst[ETH_ALEN];
4555 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004556 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004557 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004558
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004559 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004560 if (err)
4561 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004562
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004563 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004564 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004565 goto out_err;
4566 }
4567
Johannes Berg97990a02013-04-19 01:02:55 +02004568 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004569 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004570 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004571 }
4572
Johannes Bergbba95fe2008-07-29 13:22:51 +02004573 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004574 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004575 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004576 if (err == -ENOENT)
4577 break;
4578 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004579 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004580
Eric W. Biederman15e47302012-09-07 20:12:54 +00004581 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004582 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004583 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004584 &pinfo) < 0)
4585 goto out;
4586
4587 path_idx++;
4588 }
4589
4590
4591 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004592 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004593 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004594 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004595 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004596 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004597}
4598
4599static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4600{
Johannes Berg4c476992010-10-04 21:36:35 +02004601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004602 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004603 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004604 struct mpath_info pinfo;
4605 struct sk_buff *msg;
4606 u8 *dst = NULL;
4607 u8 next_hop[ETH_ALEN];
4608
4609 memset(&pinfo, 0, sizeof(pinfo));
4610
4611 if (!info->attrs[NL80211_ATTR_MAC])
4612 return -EINVAL;
4613
4614 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4615
Johannes Berg4c476992010-10-04 21:36:35 +02004616 if (!rdev->ops->get_mpath)
4617 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004618
Johannes Berg4c476992010-10-04 21:36:35 +02004619 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4620 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004621
Hila Gonene35e4d22012-06-27 17:19:42 +03004622 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004623 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004624 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004625
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004626 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004627 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004628 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004629
Eric W. Biederman15e47302012-09-07 20:12:54 +00004630 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004631 dev, dst, next_hop, &pinfo) < 0) {
4632 nlmsg_free(msg);
4633 return -ENOBUFS;
4634 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004635
Johannes Berg4c476992010-10-04 21:36:35 +02004636 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004637}
4638
4639static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4640{
Johannes Berg4c476992010-10-04 21:36:35 +02004641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4642 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004643 u8 *dst = NULL;
4644 u8 *next_hop = NULL;
4645
4646 if (!info->attrs[NL80211_ATTR_MAC])
4647 return -EINVAL;
4648
4649 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4650 return -EINVAL;
4651
4652 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4653 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4654
Johannes Berg4c476992010-10-04 21:36:35 +02004655 if (!rdev->ops->change_mpath)
4656 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004657
Johannes Berg4c476992010-10-04 21:36:35 +02004658 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4659 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004660
Hila Gonene35e4d22012-06-27 17:19:42 +03004661 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004662}
Johannes Berg4c476992010-10-04 21:36:35 +02004663
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004664static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4665{
Johannes Berg4c476992010-10-04 21:36:35 +02004666 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4667 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004668 u8 *dst = NULL;
4669 u8 *next_hop = NULL;
4670
4671 if (!info->attrs[NL80211_ATTR_MAC])
4672 return -EINVAL;
4673
4674 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4675 return -EINVAL;
4676
4677 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4678 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4679
Johannes Berg4c476992010-10-04 21:36:35 +02004680 if (!rdev->ops->add_mpath)
4681 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004682
Johannes Berg4c476992010-10-04 21:36:35 +02004683 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4684 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004685
Hila Gonene35e4d22012-06-27 17:19:42 +03004686 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004687}
4688
4689static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4690{
Johannes Berg4c476992010-10-04 21:36:35 +02004691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4692 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004693 u8 *dst = NULL;
4694
4695 if (info->attrs[NL80211_ATTR_MAC])
4696 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4697
Johannes Berg4c476992010-10-04 21:36:35 +02004698 if (!rdev->ops->del_mpath)
4699 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004700
Hila Gonene35e4d22012-06-27 17:19:42 +03004701 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004702}
4703
Henning Rogge66be7d22014-09-12 08:58:49 +02004704static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4705{
4706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4707 int err;
4708 struct net_device *dev = info->user_ptr[1];
4709 struct mpath_info pinfo;
4710 struct sk_buff *msg;
4711 u8 *dst = NULL;
4712 u8 mpp[ETH_ALEN];
4713
4714 memset(&pinfo, 0, sizeof(pinfo));
4715
4716 if (!info->attrs[NL80211_ATTR_MAC])
4717 return -EINVAL;
4718
4719 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4720
4721 if (!rdev->ops->get_mpp)
4722 return -EOPNOTSUPP;
4723
4724 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4725 return -EOPNOTSUPP;
4726
4727 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4728 if (err)
4729 return err;
4730
4731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4732 if (!msg)
4733 return -ENOMEM;
4734
4735 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4736 dev, dst, mpp, &pinfo) < 0) {
4737 nlmsg_free(msg);
4738 return -ENOBUFS;
4739 }
4740
4741 return genlmsg_reply(msg, info);
4742}
4743
4744static int nl80211_dump_mpp(struct sk_buff *skb,
4745 struct netlink_callback *cb)
4746{
4747 struct mpath_info pinfo;
4748 struct cfg80211_registered_device *rdev;
4749 struct wireless_dev *wdev;
4750 u8 dst[ETH_ALEN];
4751 u8 mpp[ETH_ALEN];
4752 int path_idx = cb->args[2];
4753 int err;
4754
4755 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4756 if (err)
4757 return err;
4758
4759 if (!rdev->ops->dump_mpp) {
4760 err = -EOPNOTSUPP;
4761 goto out_err;
4762 }
4763
4764 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4765 err = -EOPNOTSUPP;
4766 goto out_err;
4767 }
4768
4769 while (1) {
4770 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4771 mpp, &pinfo);
4772 if (err == -ENOENT)
4773 break;
4774 if (err)
4775 goto out_err;
4776
4777 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4778 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4779 wdev->netdev, dst, mpp,
4780 &pinfo) < 0)
4781 goto out;
4782
4783 path_idx++;
4784 }
4785
4786 out:
4787 cb->args[2] = path_idx;
4788 err = skb->len;
4789 out_err:
4790 nl80211_finish_wdev_dump(rdev);
4791 return err;
4792}
4793
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004794static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4795{
Johannes Berg4c476992010-10-04 21:36:35 +02004796 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4797 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004798 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004799 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004800 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004801
4802 memset(&params, 0, sizeof(params));
4803 /* default to not changing parameters */
4804 params.use_cts_prot = -1;
4805 params.use_short_preamble = -1;
4806 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004807 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004808 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004809 params.p2p_ctwindow = -1;
4810 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004811
4812 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4813 params.use_cts_prot =
4814 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4815 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4816 params.use_short_preamble =
4817 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4818 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4819 params.use_short_slot_time =
4820 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004821 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4822 params.basic_rates =
4823 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4824 params.basic_rates_len =
4825 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4826 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004827 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4828 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004829 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4830 params.ht_opmode =
4831 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004832
Johannes Berg53cabad2012-11-14 15:17:28 +01004833 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4834 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4835 return -EINVAL;
4836 params.p2p_ctwindow =
4837 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4838 if (params.p2p_ctwindow < 0)
4839 return -EINVAL;
4840 if (params.p2p_ctwindow != 0 &&
4841 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4842 return -EINVAL;
4843 }
4844
4845 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4846 u8 tmp;
4847
4848 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4849 return -EINVAL;
4850 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4851 if (tmp > 1)
4852 return -EINVAL;
4853 params.p2p_opp_ps = tmp;
4854 if (params.p2p_opp_ps &&
4855 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4856 return -EINVAL;
4857 }
4858
Johannes Berg4c476992010-10-04 21:36:35 +02004859 if (!rdev->ops->change_bss)
4860 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004861
Johannes Berg074ac8d2010-09-16 14:58:22 +02004862 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004863 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4864 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004865
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004866 wdev_lock(wdev);
4867 err = rdev_change_bss(rdev, dev, &params);
4868 wdev_unlock(wdev);
4869
4870 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004871}
4872
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004873static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004874 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4875 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4876 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4877 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4878 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4879 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004880 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004881};
4882
4883static int parse_reg_rule(struct nlattr *tb[],
4884 struct ieee80211_reg_rule *reg_rule)
4885{
4886 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4887 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4888
4889 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4890 return -EINVAL;
4891 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4892 return -EINVAL;
4893 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4894 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004895 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4896 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004897 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4898 return -EINVAL;
4899
4900 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4901
4902 freq_range->start_freq_khz =
4903 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4904 freq_range->end_freq_khz =
4905 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004906 freq_range->max_bandwidth_khz =
4907 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004908
4909 power_rule->max_eirp =
4910 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4911
4912 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4913 power_rule->max_antenna_gain =
4914 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4915
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004916 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4917 reg_rule->dfs_cac_ms =
4918 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4919
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004920 return 0;
4921}
4922
4923static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4924{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004925 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004926 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004927
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004928 /*
4929 * You should only get this when cfg80211 hasn't yet initialized
4930 * completely when built-in to the kernel right between the time
4931 * window between nl80211_init() and regulatory_init(), if that is
4932 * even possible.
4933 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004934 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004935 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004936
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004937 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4938 user_reg_hint_type =
4939 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4940 else
4941 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4942
4943 switch (user_reg_hint_type) {
4944 case NL80211_USER_REG_HINT_USER:
4945 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004946 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4947 return -EINVAL;
4948
4949 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4950 return regulatory_hint_user(data, user_reg_hint_type);
4951 case NL80211_USER_REG_HINT_INDOOR:
4952 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004953 default:
4954 return -EINVAL;
4955 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004956}
4957
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004958static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004959 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004960{
Johannes Berg4c476992010-10-04 21:36:35 +02004961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004962 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004963 struct wireless_dev *wdev = dev->ieee80211_ptr;
4964 struct mesh_config cur_params;
4965 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004966 void *hdr;
4967 struct nlattr *pinfoattr;
4968 struct sk_buff *msg;
4969
Johannes Berg29cbe682010-12-03 09:20:44 +01004970 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4971 return -EOPNOTSUPP;
4972
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004973 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004974 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004975
Johannes Berg29cbe682010-12-03 09:20:44 +01004976 wdev_lock(wdev);
4977 /* If not connected, get default parameters */
4978 if (!wdev->mesh_id_len)
4979 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4980 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004981 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004982 wdev_unlock(wdev);
4983
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004984 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004985 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004986
4987 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004989 if (!msg)
4990 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004991 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004992 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004993 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004994 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004995 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004996 if (!pinfoattr)
4997 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004998 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4999 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5000 cur_params.dot11MeshRetryTimeout) ||
5001 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5002 cur_params.dot11MeshConfirmTimeout) ||
5003 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5004 cur_params.dot11MeshHoldingTimeout) ||
5005 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5006 cur_params.dot11MeshMaxPeerLinks) ||
5007 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5008 cur_params.dot11MeshMaxRetries) ||
5009 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5010 cur_params.dot11MeshTTL) ||
5011 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5012 cur_params.element_ttl) ||
5013 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5014 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005015 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5016 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005017 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5018 cur_params.dot11MeshHWMPmaxPREQretries) ||
5019 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5020 cur_params.path_refresh_time) ||
5021 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5022 cur_params.min_discovery_timeout) ||
5023 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5024 cur_params.dot11MeshHWMPactivePathTimeout) ||
5025 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5026 cur_params.dot11MeshHWMPpreqMinInterval) ||
5027 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5028 cur_params.dot11MeshHWMPperrMinInterval) ||
5029 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5030 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5031 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5032 cur_params.dot11MeshHWMPRootMode) ||
5033 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5034 cur_params.dot11MeshHWMPRannInterval) ||
5035 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5036 cur_params.dot11MeshGateAnnouncementProtocol) ||
5037 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5038 cur_params.dot11MeshForwarding) ||
5039 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005040 cur_params.rssi_threshold) ||
5041 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005042 cur_params.ht_opmode) ||
5043 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5044 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5045 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005046 cur_params.dot11MeshHWMProotInterval) ||
5047 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005048 cur_params.dot11MeshHWMPconfirmationInterval) ||
5049 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5050 cur_params.power_mode) ||
5051 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005052 cur_params.dot11MeshAwakeWindowDuration) ||
5053 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5054 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005055 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005056 nla_nest_end(msg, pinfoattr);
5057 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005058 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005059
Johannes Berg3b858752009-03-12 09:55:09 +01005060 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005061 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005062 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005063 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005064 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005065}
5066
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005067static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005068 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5069 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5070 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5071 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5072 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5073 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005074 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005075 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005076 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005077 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5078 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5079 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5080 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5081 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005082 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005083 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005084 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005085 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005086 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005087 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005088 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5089 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005090 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5091 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005092 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005093 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5094 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005095 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005096};
5097
Javier Cardonac80d5452010-12-16 17:37:49 -08005098static const struct nla_policy
5099 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005100 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005101 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5102 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005103 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005104 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005105 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005106 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005107 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005108 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005109};
5110
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005111static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005112 struct mesh_config *cfg,
5113 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005114{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005115 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005116 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005117
Marco Porschea54fba2013-01-07 16:04:48 +01005118#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5119do { \
5120 if (tb[attr]) { \
5121 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5122 return -EINVAL; \
5123 cfg->param = fn(tb[attr]); \
5124 mask |= (1 << (attr - 1)); \
5125 } \
5126} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005127
5128
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005129 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005130 return -EINVAL;
5131 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005132 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005133 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005134 return -EINVAL;
5135
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005136 /* This makes sure that there aren't more than 32 mesh config
5137 * parameters (otherwise our bitfield scheme would not work.) */
5138 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5139
5140 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005141 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005142 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5143 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005144 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005145 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5146 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005147 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005148 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5149 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005150 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005151 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5152 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005153 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005154 mask, NL80211_MESHCONF_MAX_RETRIES,
5155 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005156 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005157 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005158 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005159 mask, NL80211_MESHCONF_ELEMENT_TTL,
5160 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005161 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005162 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5163 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005164 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5165 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005166 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5167 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005168 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005169 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5170 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005171 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005172 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5173 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005174 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005175 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5176 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005177 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5178 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005179 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5180 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005181 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005182 1, 65535, mask,
5183 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005184 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005185 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005186 1, 65535, mask,
5187 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005188 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005189 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005190 dot11MeshHWMPnetDiameterTraversalTime,
5191 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005192 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5193 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005194 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5195 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5196 nla_get_u8);
5197 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5198 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005199 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005200 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005201 dot11MeshGateAnnouncementProtocol, 0, 1,
5202 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005203 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005204 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005205 mask, NL80211_MESHCONF_FORWARDING,
5206 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005207 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005208 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005209 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005210 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005211 mask, NL80211_MESHCONF_HT_OPMODE,
5212 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005213 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005214 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005215 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5216 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005217 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005218 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5219 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005220 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005221 dot11MeshHWMPconfirmationInterval,
5222 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005223 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5224 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005225 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5226 NL80211_MESH_POWER_ACTIVE,
5227 NL80211_MESH_POWER_MAX,
5228 mask, NL80211_MESHCONF_POWER_MODE,
5229 nla_get_u32);
5230 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5231 0, 65535, mask,
5232 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005233 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5234 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5235 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005236 if (mask_out)
5237 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005238
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005239 return 0;
5240
5241#undef FILL_IN_MESH_PARAM_IF_SET
5242}
5243
Javier Cardonac80d5452010-12-16 17:37:49 -08005244static int nl80211_parse_mesh_setup(struct genl_info *info,
5245 struct mesh_setup *setup)
5246{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005247 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005248 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5249
5250 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5251 return -EINVAL;
5252 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5253 info->attrs[NL80211_ATTR_MESH_SETUP],
5254 nl80211_mesh_setup_params_policy))
5255 return -EINVAL;
5256
Javier Cardonad299a1f2012-03-31 11:31:33 -07005257 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5258 setup->sync_method =
5259 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5260 IEEE80211_SYNC_METHOD_VENDOR :
5261 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5262
Javier Cardonac80d5452010-12-16 17:37:49 -08005263 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5264 setup->path_sel_proto =
5265 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5266 IEEE80211_PATH_PROTOCOL_VENDOR :
5267 IEEE80211_PATH_PROTOCOL_HWMP;
5268
5269 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5270 setup->path_metric =
5271 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5272 IEEE80211_PATH_METRIC_VENDOR :
5273 IEEE80211_PATH_METRIC_AIRTIME;
5274
Javier Cardona581a8b02011-04-07 15:08:27 -07005275
5276 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005277 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005278 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005279 if (!is_valid_ie_attr(ieattr))
5280 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005281 setup->ie = nla_data(ieattr);
5282 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005283 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005284 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5285 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5286 return -EINVAL;
5287 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005288 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5289 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005290 if (setup->is_secure)
5291 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005292
Colleen Twitty6e16d902013-05-08 11:45:59 -07005293 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5294 if (!setup->user_mpm)
5295 return -EINVAL;
5296 setup->auth_id =
5297 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5298 }
5299
Javier Cardonac80d5452010-12-16 17:37:49 -08005300 return 0;
5301}
5302
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005303static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005304 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005305{
5306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5307 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005308 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005309 struct mesh_config cfg;
5310 u32 mask;
5311 int err;
5312
Johannes Berg29cbe682010-12-03 09:20:44 +01005313 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5314 return -EOPNOTSUPP;
5315
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005316 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005317 return -EOPNOTSUPP;
5318
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005319 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005320 if (err)
5321 return err;
5322
Johannes Berg29cbe682010-12-03 09:20:44 +01005323 wdev_lock(wdev);
5324 if (!wdev->mesh_id_len)
5325 err = -ENOLINK;
5326
5327 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005328 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005329
5330 wdev_unlock(wdev);
5331
5332 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005333}
5334
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005335static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5336 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005337{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005338 struct nlattr *nl_reg_rules;
5339 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005340
Johannes Berg458f4f92012-12-06 15:47:38 +01005341 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5342 (regdom->dfs_region &&
5343 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005344 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005345
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005346 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5347 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005348 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005349
Johannes Berg458f4f92012-12-06 15:47:38 +01005350 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005351 struct nlattr *nl_reg_rule;
5352 const struct ieee80211_reg_rule *reg_rule;
5353 const struct ieee80211_freq_range *freq_range;
5354 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005355 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005356
Johannes Berg458f4f92012-12-06 15:47:38 +01005357 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005358 freq_range = &reg_rule->freq_range;
5359 power_rule = &reg_rule->power_rule;
5360
5361 nl_reg_rule = nla_nest_start(msg, i);
5362 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005363 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005364
Janusz Dziedzic97524822014-01-30 09:52:20 +01005365 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5366 if (!max_bandwidth_khz)
5367 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5368 reg_rule);
5369
David S. Miller9360ffd2012-03-29 04:41:26 -04005370 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5371 reg_rule->flags) ||
5372 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5373 freq_range->start_freq_khz) ||
5374 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5375 freq_range->end_freq_khz) ||
5376 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005377 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005378 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5379 power_rule->max_antenna_gain) ||
5380 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005381 power_rule->max_eirp) ||
5382 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5383 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005384 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005385
5386 nla_nest_end(msg, nl_reg_rule);
5387 }
5388
5389 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005390 return 0;
5391
5392nla_put_failure:
5393 return -EMSGSIZE;
5394}
5395
5396static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5397{
5398 const struct ieee80211_regdomain *regdom = NULL;
5399 struct cfg80211_registered_device *rdev;
5400 struct wiphy *wiphy = NULL;
5401 struct sk_buff *msg;
5402 void *hdr;
5403
5404 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5405 if (!msg)
5406 return -ENOBUFS;
5407
5408 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5409 NL80211_CMD_GET_REG);
5410 if (!hdr)
5411 goto put_failure;
5412
5413 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005414 bool self_managed;
5415
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005416 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5417 if (IS_ERR(rdev)) {
5418 nlmsg_free(msg);
5419 return PTR_ERR(rdev);
5420 }
5421
5422 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005423 self_managed = wiphy->regulatory_flags &
5424 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005425 regdom = get_wiphy_regdom(wiphy);
5426
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005427 /* a self-managed-reg device must have a private regdom */
5428 if (WARN_ON(!regdom && self_managed)) {
5429 nlmsg_free(msg);
5430 return -EINVAL;
5431 }
5432
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005433 if (regdom &&
5434 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5435 goto nla_put_failure;
5436 }
5437
5438 if (!wiphy && reg_last_request_cell_base() &&
5439 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5440 NL80211_USER_REG_HINT_CELL_BASE))
5441 goto nla_put_failure;
5442
5443 rcu_read_lock();
5444
5445 if (!regdom)
5446 regdom = rcu_dereference(cfg80211_regdomain);
5447
5448 if (nl80211_put_regdom(regdom, msg))
5449 goto nla_put_failure_rcu;
5450
5451 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005452
5453 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005454 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005455
Johannes Berg458f4f92012-12-06 15:47:38 +01005456nla_put_failure_rcu:
5457 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005458nla_put_failure:
5459 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005460put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005461 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005462 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005463}
5464
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005465static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5466 u32 seq, int flags, struct wiphy *wiphy,
5467 const struct ieee80211_regdomain *regdom)
5468{
5469 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5470 NL80211_CMD_GET_REG);
5471
5472 if (!hdr)
5473 return -1;
5474
5475 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5476
5477 if (nl80211_put_regdom(regdom, msg))
5478 goto nla_put_failure;
5479
5480 if (!wiphy && reg_last_request_cell_base() &&
5481 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5482 NL80211_USER_REG_HINT_CELL_BASE))
5483 goto nla_put_failure;
5484
5485 if (wiphy &&
5486 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5487 goto nla_put_failure;
5488
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005489 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5490 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5491 goto nla_put_failure;
5492
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005493 return genlmsg_end(msg, hdr);
5494
5495nla_put_failure:
5496 genlmsg_cancel(msg, hdr);
5497 return -EMSGSIZE;
5498}
5499
5500static int nl80211_get_reg_dump(struct sk_buff *skb,
5501 struct netlink_callback *cb)
5502{
5503 const struct ieee80211_regdomain *regdom = NULL;
5504 struct cfg80211_registered_device *rdev;
5505 int err, reg_idx, start = cb->args[2];
5506
5507 rtnl_lock();
5508
5509 if (cfg80211_regdomain && start == 0) {
5510 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5511 NLM_F_MULTI, NULL,
5512 rtnl_dereference(cfg80211_regdomain));
5513 if (err < 0)
5514 goto out_err;
5515 }
5516
5517 /* the global regdom is idx 0 */
5518 reg_idx = 1;
5519 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5520 regdom = get_wiphy_regdom(&rdev->wiphy);
5521 if (!regdom)
5522 continue;
5523
5524 if (++reg_idx <= start)
5525 continue;
5526
5527 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5528 NLM_F_MULTI, &rdev->wiphy, regdom);
5529 if (err < 0) {
5530 reg_idx--;
5531 break;
5532 }
5533 }
5534
5535 cb->args[2] = reg_idx;
5536 err = skb->len;
5537out_err:
5538 rtnl_unlock();
5539 return err;
5540}
5541
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005542static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5543{
5544 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5545 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005546 char *alpha2;
5547 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005548 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005549 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005550 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005551
5552 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5553 return -EINVAL;
5554
5555 if (!info->attrs[NL80211_ATTR_REG_RULES])
5556 return -EINVAL;
5557
5558 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5559
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005560 if (info->attrs[NL80211_ATTR_DFS_REGION])
5561 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5562
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005563 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005564 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005565 num_rules++;
5566 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005567 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005568 }
5569
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005570 if (!reg_is_valid_request(alpha2))
5571 return -EINVAL;
5572
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005573 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005574 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005575
5576 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005577 if (!rd)
5578 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005579
5580 rd->n_reg_rules = num_rules;
5581 rd->alpha2[0] = alpha2[0];
5582 rd->alpha2[1] = alpha2[1];
5583
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005584 /*
5585 * Disable DFS master mode if the DFS region was
5586 * not supported or known on this kernel.
5587 */
5588 if (reg_supported_dfs_region(dfs_region))
5589 rd->dfs_region = dfs_region;
5590
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005591 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005592 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005593 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5594 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5595 reg_rule_policy);
5596 if (r)
5597 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005598 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5599 if (r)
5600 goto bad_reg;
5601
5602 rule_idx++;
5603
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005604 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5605 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005606 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005607 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005608 }
5609
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005610 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005611 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005612 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005613
Johannes Bergd2372b32008-10-24 20:32:20 +02005614 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005615 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005616 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005617}
5618
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005619static int validate_scan_freqs(struct nlattr *freqs)
5620{
5621 struct nlattr *attr1, *attr2;
5622 int n_channels = 0, tmp1, tmp2;
5623
5624 nla_for_each_nested(attr1, freqs, tmp1) {
5625 n_channels++;
5626 /*
5627 * Some hardware has a limited channel list for
5628 * scanning, and it is pretty much nonsensical
5629 * to scan for a channel twice, so disallow that
5630 * and don't require drivers to check that the
5631 * channel list they get isn't longer than what
5632 * they can scan, as long as they can scan all
5633 * the channels they registered at once.
5634 */
5635 nla_for_each_nested(attr2, freqs, tmp2)
5636 if (attr1 != attr2 &&
5637 nla_get_u32(attr1) == nla_get_u32(attr2))
5638 return 0;
5639 }
5640
5641 return n_channels;
5642}
5643
Johannes Bergad2b26a2014-06-12 21:39:05 +02005644static int nl80211_parse_random_mac(struct nlattr **attrs,
5645 u8 *mac_addr, u8 *mac_addr_mask)
5646{
5647 int i;
5648
5649 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5650 memset(mac_addr, 0, ETH_ALEN);
5651 memset(mac_addr_mask, 0, ETH_ALEN);
5652 mac_addr[0] = 0x2;
5653 mac_addr_mask[0] = 0x3;
5654
5655 return 0;
5656 }
5657
5658 /* need both or none */
5659 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5660 return -EINVAL;
5661
5662 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5663 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5664
5665 /* don't allow or configure an mcast address */
5666 if (!is_multicast_ether_addr(mac_addr_mask) ||
5667 is_multicast_ether_addr(mac_addr))
5668 return -EINVAL;
5669
5670 /*
5671 * allow users to pass a MAC address that has bits set outside
5672 * of the mask, but don't bother drivers with having to deal
5673 * with such bits
5674 */
5675 for (i = 0; i < ETH_ALEN; i++)
5676 mac_addr[i] &= mac_addr_mask[i];
5677
5678 return 0;
5679}
5680
Johannes Berg2a519312009-02-10 21:25:55 +01005681static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5682{
Johannes Berg4c476992010-10-04 21:36:35 +02005683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005684 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005685 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005686 struct nlattr *attr;
5687 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005688 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005689 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005690
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005691 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5692 return -EINVAL;
5693
Johannes Berg79c97e92009-07-07 03:56:12 +02005694 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005695
Johannes Berg4c476992010-10-04 21:36:35 +02005696 if (!rdev->ops->scan)
5697 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005698
Johannes Bergf9d15d12014-01-22 11:14:19 +02005699 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005700 err = -EBUSY;
5701 goto unlock;
5702 }
Johannes Berg2a519312009-02-10 21:25:55 +01005703
5704 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005705 n_channels = validate_scan_freqs(
5706 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005707 if (!n_channels) {
5708 err = -EINVAL;
5709 goto unlock;
5710 }
Johannes Berg2a519312009-02-10 21:25:55 +01005711 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005712 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005713 }
5714
5715 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5716 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5717 n_ssids++;
5718
Johannes Bergf9f47522013-03-19 15:04:07 +01005719 if (n_ssids > wiphy->max_scan_ssids) {
5720 err = -EINVAL;
5721 goto unlock;
5722 }
Johannes Berg2a519312009-02-10 21:25:55 +01005723
Jouni Malinen70692ad2009-02-16 19:39:13 +02005724 if (info->attrs[NL80211_ATTR_IE])
5725 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5726 else
5727 ie_len = 0;
5728
Johannes Bergf9f47522013-03-19 15:04:07 +01005729 if (ie_len > wiphy->max_scan_ie_len) {
5730 err = -EINVAL;
5731 goto unlock;
5732 }
Johannes Berg18a83652009-03-31 12:12:05 +02005733
Johannes Berg2a519312009-02-10 21:25:55 +01005734 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005735 + sizeof(*request->ssids) * n_ssids
5736 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005737 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005738 if (!request) {
5739 err = -ENOMEM;
5740 goto unlock;
5741 }
Johannes Berg2a519312009-02-10 21:25:55 +01005742
Johannes Berg2a519312009-02-10 21:25:55 +01005743 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005744 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005745 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005746 if (ie_len) {
5747 if (request->ssids)
5748 request->ie = (void *)(request->ssids + n_ssids);
5749 else
5750 request->ie = (void *)(request->channels + n_channels);
5751 }
Johannes Berg2a519312009-02-10 21:25:55 +01005752
Johannes Berg584991d2009-11-02 13:32:03 +01005753 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005754 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5755 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005756 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005757 struct ieee80211_channel *chan;
5758
5759 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5760
5761 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005762 err = -EINVAL;
5763 goto out_free;
5764 }
Johannes Berg584991d2009-11-02 13:32:03 +01005765
5766 /* ignore disabled channels */
5767 if (chan->flags & IEEE80211_CHAN_DISABLED)
5768 continue;
5769
5770 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005771 i++;
5772 }
5773 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005774 enum ieee80211_band band;
5775
Johannes Berg2a519312009-02-10 21:25:55 +01005776 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005777 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5778 int j;
5779 if (!wiphy->bands[band])
5780 continue;
5781 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005782 struct ieee80211_channel *chan;
5783
5784 chan = &wiphy->bands[band]->channels[j];
5785
5786 if (chan->flags & IEEE80211_CHAN_DISABLED)
5787 continue;
5788
5789 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005790 i++;
5791 }
5792 }
5793 }
5794
Johannes Berg584991d2009-11-02 13:32:03 +01005795 if (!i) {
5796 err = -EINVAL;
5797 goto out_free;
5798 }
5799
5800 request->n_channels = i;
5801
Johannes Berg2a519312009-02-10 21:25:55 +01005802 i = 0;
5803 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5804 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005805 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005806 err = -EINVAL;
5807 goto out_free;
5808 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005809 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005810 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005811 i++;
5812 }
5813 }
5814
Jouni Malinen70692ad2009-02-16 19:39:13 +02005815 if (info->attrs[NL80211_ATTR_IE]) {
5816 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005817 memcpy((void *)request->ie,
5818 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005819 request->ie_len);
5820 }
5821
Johannes Berg34850ab2011-07-18 18:08:35 +02005822 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005823 if (wiphy->bands[i])
5824 request->rates[i] =
5825 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005826
5827 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5828 nla_for_each_nested(attr,
5829 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5830 tmp) {
5831 enum ieee80211_band band = nla_type(attr);
5832
Dan Carpenter84404622011-07-29 11:52:18 +03005833 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005834 err = -EINVAL;
5835 goto out_free;
5836 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005837
5838 if (!wiphy->bands[band])
5839 continue;
5840
Johannes Berg34850ab2011-07-18 18:08:35 +02005841 err = ieee80211_get_ratemask(wiphy->bands[band],
5842 nla_data(attr),
5843 nla_len(attr),
5844 &request->rates[band]);
5845 if (err)
5846 goto out_free;
5847 }
5848 }
5849
Sam Leffler46856bb2012-10-11 21:03:32 -07005850 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005851 request->flags = nla_get_u32(
5852 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005853 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5854 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005855 err = -EOPNOTSUPP;
5856 goto out_free;
5857 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005858
5859 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5860 if (!(wiphy->features &
5861 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5862 err = -EOPNOTSUPP;
5863 goto out_free;
5864 }
5865
5866 if (wdev->current_bss) {
5867 err = -EOPNOTSUPP;
5868 goto out_free;
5869 }
5870
5871 err = nl80211_parse_random_mac(info->attrs,
5872 request->mac_addr,
5873 request->mac_addr_mask);
5874 if (err)
5875 goto out_free;
5876 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005877 }
Sam Lefflered4737712012-10-11 21:03:31 -07005878
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305879 request->no_cck =
5880 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5881
Johannes Bergfd014282012-06-18 19:17:03 +02005882 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005883 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005884 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005885
Johannes Berg79c97e92009-07-07 03:56:12 +02005886 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005887 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005888
Johannes Berg463d0182009-07-14 00:33:35 +02005889 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005890 nl80211_send_scan_start(rdev, wdev);
5891 if (wdev->netdev)
5892 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005893 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005894 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005895 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005896 kfree(request);
5897 }
Johannes Berg3b858752009-03-12 09:55:09 +01005898
Johannes Bergf9f47522013-03-19 15:04:07 +01005899 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005900 return err;
5901}
5902
Luciano Coelho256da022014-11-10 16:13:46 +02005903static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005904nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005905 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005906{
5907 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005908 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005909 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005910 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005911 enum ieee80211_band band;
5912 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005913 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005914 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005915
Luciano Coelho256da022014-11-10 16:13:46 +02005916 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5917 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005918
Luciano Coelho256da022014-11-10 16:13:46 +02005919 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5920 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005921
Luciano Coelho256da022014-11-10 16:13:46 +02005922 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005923 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005924 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005925
Luciano Coelho256da022014-11-10 16:13:46 +02005926 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005927 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005928 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005929 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005930 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005931 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005932 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005933 }
5934
Luciano Coelho256da022014-11-10 16:13:46 +02005935 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5936 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005937 tmp)
5938 n_ssids++;
5939
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005940 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005941 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005942
Johannes Bergea73cbc2014-01-24 10:53:53 +01005943 /*
5944 * First, count the number of 'real' matchsets. Due to an issue with
5945 * the old implementation, matchsets containing only the RSSI attribute
5946 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5947 * RSSI for all matchsets, rather than their own matchset for reporting
5948 * all APs with a strong RSSI. This is needed to be compatible with
5949 * older userspace that treated a matchset with only the RSSI as the
5950 * global RSSI for all other matchsets - if there are other matchsets.
5951 */
Luciano Coelho256da022014-11-10 16:13:46 +02005952 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005953 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005954 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005955 tmp) {
5956 struct nlattr *rssi;
5957
5958 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5959 nla_data(attr), nla_len(attr),
5960 nl80211_match_policy);
5961 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02005962 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005963 /* add other standalone attributes here */
5964 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5965 n_match_sets++;
5966 continue;
5967 }
5968 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5969 if (rssi)
5970 default_match_rssi = nla_get_s32(rssi);
5971 }
5972 }
5973
5974 /* However, if there's no other matchset, add the RSSI one */
5975 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5976 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005977
5978 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02005979 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005980
Luciano Coelho256da022014-11-10 16:13:46 +02005981 if (attrs[NL80211_ATTR_IE])
5982 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005983 else
5984 ie_len = 0;
5985
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005986 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02005987 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005988
Luciano Coelho807f8a82011-05-11 17:09:35 +03005989 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005990 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005991 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005992 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005993 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02005994 if (!request)
5995 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005996
5997 if (n_ssids)
5998 request->ssids = (void *)&request->channels[n_channels];
5999 request->n_ssids = n_ssids;
6000 if (ie_len) {
6001 if (request->ssids)
6002 request->ie = (void *)(request->ssids + n_ssids);
6003 else
6004 request->ie = (void *)(request->channels + n_channels);
6005 }
6006
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006007 if (n_match_sets) {
6008 if (request->ie)
6009 request->match_sets = (void *)(request->ie + ie_len);
6010 else if (request->ssids)
6011 request->match_sets =
6012 (void *)(request->ssids + n_ssids);
6013 else
6014 request->match_sets =
6015 (void *)(request->channels + n_channels);
6016 }
6017 request->n_match_sets = n_match_sets;
6018
Luciano Coelho807f8a82011-05-11 17:09:35 +03006019 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006020 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006021 /* user specified, bail out if channel not found */
6022 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006023 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006024 tmp) {
6025 struct ieee80211_channel *chan;
6026
6027 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6028
6029 if (!chan) {
6030 err = -EINVAL;
6031 goto out_free;
6032 }
6033
6034 /* ignore disabled channels */
6035 if (chan->flags & IEEE80211_CHAN_DISABLED)
6036 continue;
6037
6038 request->channels[i] = chan;
6039 i++;
6040 }
6041 } else {
6042 /* all channels */
6043 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6044 int j;
6045 if (!wiphy->bands[band])
6046 continue;
6047 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6048 struct ieee80211_channel *chan;
6049
6050 chan = &wiphy->bands[band]->channels[j];
6051
6052 if (chan->flags & IEEE80211_CHAN_DISABLED)
6053 continue;
6054
6055 request->channels[i] = chan;
6056 i++;
6057 }
6058 }
6059 }
6060
6061 if (!i) {
6062 err = -EINVAL;
6063 goto out_free;
6064 }
6065
6066 request->n_channels = i;
6067
6068 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006069 if (attrs[NL80211_ATTR_SCAN_SSIDS]) {
6070 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006071 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006072 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006073 err = -EINVAL;
6074 goto out_free;
6075 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006076 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006077 memcpy(request->ssids[i].ssid, nla_data(attr),
6078 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006079 i++;
6080 }
6081 }
6082
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006083 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006084 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006085 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006086 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006087 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006088 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006089
Johannes Bergae811e22014-01-24 10:17:47 +01006090 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6091 nla_data(attr), nla_len(attr),
6092 nl80211_match_policy);
6093 if (err)
6094 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006095 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006096 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006097 if (WARN_ON(i >= n_match_sets)) {
6098 /* this indicates a programming error,
6099 * the loop above should have verified
6100 * things properly
6101 */
6102 err = -EINVAL;
6103 goto out_free;
6104 }
6105
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006106 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6107 err = -EINVAL;
6108 goto out_free;
6109 }
6110 memcpy(request->match_sets[i].ssid.ssid,
6111 nla_data(ssid), nla_len(ssid));
6112 request->match_sets[i].ssid.ssid_len =
6113 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006114 /* special attribute - old implemenation w/a */
6115 request->match_sets[i].rssi_thold =
6116 default_match_rssi;
6117 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6118 if (rssi)
6119 request->match_sets[i].rssi_thold =
6120 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006121 }
6122 i++;
6123 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006124
6125 /* there was no other matchset, so the RSSI one is alone */
6126 if (i == 0)
6127 request->match_sets[0].rssi_thold = default_match_rssi;
6128
6129 request->min_rssi_thold = INT_MAX;
6130 for (i = 0; i < n_match_sets; i++)
6131 request->min_rssi_thold =
6132 min(request->match_sets[i].rssi_thold,
6133 request->min_rssi_thold);
6134 } else {
6135 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006136 }
6137
Johannes Berg9900e482014-02-04 21:01:25 +01006138 if (ie_len) {
6139 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006140 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006141 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006142 request->ie_len);
6143 }
6144
Luciano Coelho256da022014-11-10 16:13:46 +02006145 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006146 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006147 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006148 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6149 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006150 err = -EOPNOTSUPP;
6151 goto out_free;
6152 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006153
6154 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6155 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6156
6157 if (!wdev) /* must be net-detect */
6158 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6159
6160 if (!(wiphy->features & flg)) {
6161 err = -EOPNOTSUPP;
6162 goto out_free;
6163 }
6164
6165 if (wdev && wdev->current_bss) {
6166 err = -EOPNOTSUPP;
6167 goto out_free;
6168 }
6169
6170 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6171 request->mac_addr_mask);
6172 if (err)
6173 goto out_free;
6174 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006175 }
Sam Lefflered4737712012-10-11 21:03:31 -07006176
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006177 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006178 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006179
Luciano Coelho256da022014-11-10 16:13:46 +02006180 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006181
6182out_free:
6183 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006184 return ERR_PTR(err);
6185}
6186
6187static int nl80211_start_sched_scan(struct sk_buff *skb,
6188 struct genl_info *info)
6189{
6190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6191 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006192 struct wireless_dev *wdev = dev->ieee80211_ptr;
Luciano Coelho256da022014-11-10 16:13:46 +02006193 int err;
6194
6195 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6196 !rdev->ops->sched_scan_start)
6197 return -EOPNOTSUPP;
6198
6199 if (rdev->sched_scan_req)
6200 return -EINPROGRESS;
6201
Johannes Bergad2b26a2014-06-12 21:39:05 +02006202 rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006203 info->attrs);
6204 err = PTR_ERR_OR_ZERO(rdev->sched_scan_req);
6205 if (err)
6206 goto out_err;
6207
6208 err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req);
6209 if (err)
6210 goto out_free;
6211
6212 rdev->sched_scan_req->dev = dev;
6213 rdev->sched_scan_req->wiphy = &rdev->wiphy;
6214
6215 nl80211_send_sched_scan(rdev, dev,
6216 NL80211_CMD_START_SCHED_SCAN);
6217 return 0;
6218
6219out_free:
6220 kfree(rdev->sched_scan_req);
6221out_err:
6222 rdev->sched_scan_req = NULL;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006223 return err;
6224}
6225
6226static int nl80211_stop_sched_scan(struct sk_buff *skb,
6227 struct genl_info *info)
6228{
6229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6230
6231 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6232 !rdev->ops->sched_scan_stop)
6233 return -EOPNOTSUPP;
6234
Johannes Berg5fe231e2013-05-08 21:45:15 +02006235 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006236}
6237
Simon Wunderlich04f39042013-02-08 18:16:19 +01006238static int nl80211_start_radar_detection(struct sk_buff *skb,
6239 struct genl_info *info)
6240{
6241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6242 struct net_device *dev = info->user_ptr[1];
6243 struct wireless_dev *wdev = dev->ieee80211_ptr;
6244 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006245 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006246 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006247 int err;
6248
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006249 dfs_region = reg_get_dfs_region(wdev->wiphy);
6250 if (dfs_region == NL80211_DFS_UNSET)
6251 return -EINVAL;
6252
Simon Wunderlich04f39042013-02-08 18:16:19 +01006253 err = nl80211_parse_chandef(rdev, info, &chandef);
6254 if (err)
6255 return err;
6256
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006257 if (netif_carrier_ok(dev))
6258 return -EBUSY;
6259
Simon Wunderlich04f39042013-02-08 18:16:19 +01006260 if (wdev->cac_started)
6261 return -EBUSY;
6262
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006263 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006264 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006265 if (err < 0)
6266 return err;
6267
6268 if (err == 0)
6269 return -EINVAL;
6270
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006271 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006272 return -EINVAL;
6273
6274 if (!rdev->ops->start_radar_detection)
6275 return -EOPNOTSUPP;
6276
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006277 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6278 if (WARN_ON(!cac_time_ms))
6279 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6280
6281 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6282 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006283 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006284 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006285 wdev->cac_started = true;
6286 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006287 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006288 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006289 return err;
6290}
6291
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006292static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6293{
6294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6295 struct net_device *dev = info->user_ptr[1];
6296 struct wireless_dev *wdev = dev->ieee80211_ptr;
6297 struct cfg80211_csa_settings params;
6298 /* csa_attrs is defined static to avoid waste of stack size - this
6299 * function is called under RTNL lock, so this should not be a problem.
6300 */
6301 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006302 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006303 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006304 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006305 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006306
6307 if (!rdev->ops->channel_switch ||
6308 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6309 return -EOPNOTSUPP;
6310
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006311 switch (dev->ieee80211_ptr->iftype) {
6312 case NL80211_IFTYPE_AP:
6313 case NL80211_IFTYPE_P2P_GO:
6314 need_new_beacon = true;
6315
6316 /* useless if AP is not running */
6317 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006318 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006319 break;
6320 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006321 if (!wdev->ssid_len)
6322 return -ENOTCONN;
6323 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006324 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006325 if (!wdev->mesh_id_len)
6326 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006327 break;
6328 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006329 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006330 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006331
6332 memset(&params, 0, sizeof(params));
6333
6334 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6335 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6336 return -EINVAL;
6337
6338 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006339 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006340 return -EINVAL;
6341
Luciano Coelho252e07c2014-10-08 09:48:34 +03006342 /* Even though the attribute is u32, the specification says
6343 * u8, so let's make sure we don't overflow.
6344 */
6345 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6346 if (cs_count > 255)
6347 return -EINVAL;
6348
6349 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006350
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006351 if (!need_new_beacon)
6352 goto skip_beacons;
6353
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006354 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6355 if (err)
6356 return err;
6357
6358 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6359 info->attrs[NL80211_ATTR_CSA_IES],
6360 nl80211_policy);
6361 if (err)
6362 return err;
6363
6364 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6365 if (err)
6366 return err;
6367
6368 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6369 return -EINVAL;
6370
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006371 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6372 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006373 return -EINVAL;
6374
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006375 params.n_counter_offsets_beacon = len / sizeof(u16);
6376 if (rdev->wiphy.max_num_csa_counters &&
6377 (params.n_counter_offsets_beacon >
6378 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006379 return -EINVAL;
6380
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006381 params.counter_offsets_beacon =
6382 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6383
6384 /* sanity checks - counters should fit and be the same */
6385 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6386 u16 offset = params.counter_offsets_beacon[i];
6387
6388 if (offset >= params.beacon_csa.tail_len)
6389 return -EINVAL;
6390
6391 if (params.beacon_csa.tail[offset] != params.count)
6392 return -EINVAL;
6393 }
6394
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006395 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006396 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6397 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006398 return -EINVAL;
6399
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006400 params.n_counter_offsets_presp = len / sizeof(u16);
6401 if (rdev->wiphy.max_num_csa_counters &&
6402 (params.n_counter_offsets_beacon >
6403 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006404 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006405
6406 params.counter_offsets_presp =
6407 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6408
6409 /* sanity checks - counters should fit and be the same */
6410 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6411 u16 offset = params.counter_offsets_presp[i];
6412
6413 if (offset >= params.beacon_csa.probe_resp_len)
6414 return -EINVAL;
6415
6416 if (params.beacon_csa.probe_resp[offset] !=
6417 params.count)
6418 return -EINVAL;
6419 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006420 }
6421
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006422skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006423 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6424 if (err)
6425 return err;
6426
Ilan Peer174e0cd2014-02-23 09:13:01 +02006427 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6428 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006429 return -EINVAL;
6430
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006431 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6432 &params.chandef,
6433 wdev->iftype);
6434 if (err < 0)
6435 return err;
6436
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006437 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006438 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006439
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006440 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6441 params.block_tx = true;
6442
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006443 wdev_lock(wdev);
6444 err = rdev_channel_switch(rdev, dev, &params);
6445 wdev_unlock(wdev);
6446
6447 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006448}
6449
Johannes Berg9720bb32011-06-21 09:45:33 +02006450static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6451 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006452 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006453 struct wireless_dev *wdev,
6454 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006455{
Johannes Berg48ab9052009-07-10 18:42:31 +02006456 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006457 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006458 void *hdr;
6459 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006460
6461 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006462
Eric W. Biederman15e47302012-09-07 20:12:54 +00006463 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006464 NL80211_CMD_NEW_SCAN_RESULTS);
6465 if (!hdr)
6466 return -1;
6467
Johannes Berg9720bb32011-06-21 09:45:33 +02006468 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6469
Johannes Berg97990a02013-04-19 01:02:55 +02006470 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6471 goto nla_put_failure;
6472 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006473 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6474 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006475 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6476 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006477
6478 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6479 if (!bss)
6480 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006481 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006482 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006483 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006484
6485 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006486 /* indicate whether we have probe response data or not */
6487 if (rcu_access_pointer(res->proberesp_ies) &&
6488 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6489 goto fail_unlock_rcu;
6490
6491 /* this pointer prefers to be pointed to probe response data
6492 * but is always valid
6493 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006494 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006495 if (ies) {
6496 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6497 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006498 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6499 ies->len, ies->data))
6500 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006501 }
Johannes Berg0e227082014-08-12 20:34:30 +02006502
6503 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006504 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006505 if (ies && ies->from_beacon) {
6506 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006507 goto fail_unlock_rcu;
6508 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6509 ies->len, ies->data))
6510 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006511 }
6512 rcu_read_unlock();
6513
David S. Miller9360ffd2012-03-29 04:41:26 -04006514 if (res->beacon_interval &&
6515 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6516 goto nla_put_failure;
6517 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6518 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006519 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006520 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6521 jiffies_to_msecs(jiffies - intbss->ts)))
6522 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006523
Johannes Berg77965c92009-02-18 18:45:06 +01006524 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006525 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006526 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6527 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006528 break;
6529 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006530 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6531 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006532 break;
6533 default:
6534 break;
6535 }
6536
Johannes Berg48ab9052009-07-10 18:42:31 +02006537 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006538 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006539 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006540 if (intbss == wdev->current_bss &&
6541 nla_put_u32(msg, NL80211_BSS_STATUS,
6542 NL80211_BSS_STATUS_ASSOCIATED))
6543 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006544 break;
6545 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006546 if (intbss == wdev->current_bss &&
6547 nla_put_u32(msg, NL80211_BSS_STATUS,
6548 NL80211_BSS_STATUS_IBSS_JOINED))
6549 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006550 break;
6551 default:
6552 break;
6553 }
6554
Johannes Berg2a519312009-02-10 21:25:55 +01006555 nla_nest_end(msg, bss);
6556
6557 return genlmsg_end(msg, hdr);
6558
Johannes Berg8cef2c92013-02-05 16:54:31 +01006559 fail_unlock_rcu:
6560 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006561 nla_put_failure:
6562 genlmsg_cancel(msg, hdr);
6563 return -EMSGSIZE;
6564}
6565
Johannes Berg97990a02013-04-19 01:02:55 +02006566static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006567{
Johannes Berg48ab9052009-07-10 18:42:31 +02006568 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006569 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006570 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006571 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006572 int err;
6573
Johannes Berg97990a02013-04-19 01:02:55 +02006574 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006575 if (err)
6576 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006577
Johannes Berg48ab9052009-07-10 18:42:31 +02006578 wdev_lock(wdev);
6579 spin_lock_bh(&rdev->bss_lock);
6580 cfg80211_bss_expire(rdev);
6581
Johannes Berg9720bb32011-06-21 09:45:33 +02006582 cb->seq = rdev->bss_generation;
6583
Johannes Berg48ab9052009-07-10 18:42:31 +02006584 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006585 if (++idx <= start)
6586 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006587 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006588 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006589 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006590 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006591 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006592 }
6593 }
6594
Johannes Berg48ab9052009-07-10 18:42:31 +02006595 spin_unlock_bh(&rdev->bss_lock);
6596 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006597
Johannes Berg97990a02013-04-19 01:02:55 +02006598 cb->args[2] = idx;
6599 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006600
Johannes Berg67748892010-10-04 21:14:06 +02006601 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006602}
6603
Eric W. Biederman15e47302012-09-07 20:12:54 +00006604static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006605 int flags, struct net_device *dev,
6606 struct survey_info *survey)
6607{
6608 void *hdr;
6609 struct nlattr *infoattr;
6610
Eric W. Biederman15e47302012-09-07 20:12:54 +00006611 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006612 NL80211_CMD_NEW_SURVEY_RESULTS);
6613 if (!hdr)
6614 return -ENOMEM;
6615
David S. Miller9360ffd2012-03-29 04:41:26 -04006616 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6617 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006618
6619 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6620 if (!infoattr)
6621 goto nla_put_failure;
6622
David S. Miller9360ffd2012-03-29 04:41:26 -04006623 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6624 survey->channel->center_freq))
6625 goto nla_put_failure;
6626
6627 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6628 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6629 goto nla_put_failure;
6630 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6631 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6632 goto nla_put_failure;
6633 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6634 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6635 survey->channel_time))
6636 goto nla_put_failure;
6637 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6638 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6639 survey->channel_time_busy))
6640 goto nla_put_failure;
6641 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6642 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6643 survey->channel_time_ext_busy))
6644 goto nla_put_failure;
6645 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6646 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6647 survey->channel_time_rx))
6648 goto nla_put_failure;
6649 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6650 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6651 survey->channel_time_tx))
6652 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006653
6654 nla_nest_end(msg, infoattr);
6655
6656 return genlmsg_end(msg, hdr);
6657
6658 nla_put_failure:
6659 genlmsg_cancel(msg, hdr);
6660 return -EMSGSIZE;
6661}
6662
6663static int nl80211_dump_survey(struct sk_buff *skb,
6664 struct netlink_callback *cb)
6665{
6666 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006667 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006668 struct wireless_dev *wdev;
6669 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006670 int res;
6671
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006672 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006673 if (res)
6674 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006675
Johannes Berg97990a02013-04-19 01:02:55 +02006676 if (!wdev->netdev) {
6677 res = -EINVAL;
6678 goto out_err;
6679 }
6680
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006681 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006682 res = -EOPNOTSUPP;
6683 goto out_err;
6684 }
6685
6686 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006687 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006688 if (res == -ENOENT)
6689 break;
6690 if (res)
6691 goto out_err;
6692
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006693 /* Survey without a channel doesn't make sense */
6694 if (!survey.channel) {
6695 res = -EINVAL;
6696 goto out;
6697 }
6698
Johannes Bergea9eba62014-11-21 15:24:31 +01006699 if (survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006700 survey_idx++;
6701 continue;
6702 }
6703
Holger Schurig61fa7132009-11-11 12:25:40 +01006704 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006705 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006706 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006707 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006708 goto out;
6709 survey_idx++;
6710 }
6711
6712 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006713 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006714 res = skb->len;
6715 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006716 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006717 return res;
6718}
6719
Samuel Ortizb23aa672009-07-01 21:26:54 +02006720static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6721{
6722 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6723 NL80211_WPA_VERSION_2));
6724}
6725
Jouni Malinen636a5d32009-03-19 13:39:22 +02006726static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6727{
Johannes Berg4c476992010-10-04 21:36:35 +02006728 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6729 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006730 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006731 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6732 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006733 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006734 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006735 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006736
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006737 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6738 return -EINVAL;
6739
6740 if (!info->attrs[NL80211_ATTR_MAC])
6741 return -EINVAL;
6742
Jouni Malinen17780922009-03-27 20:52:47 +02006743 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6744 return -EINVAL;
6745
Johannes Berg19957bb2009-07-02 17:20:43 +02006746 if (!info->attrs[NL80211_ATTR_SSID])
6747 return -EINVAL;
6748
6749 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6750 return -EINVAL;
6751
Johannes Bergfffd0932009-07-08 14:22:54 +02006752 err = nl80211_parse_key(info, &key);
6753 if (err)
6754 return err;
6755
6756 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006757 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6758 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006759 if (!key.p.key || !key.p.key_len)
6760 return -EINVAL;
6761 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6762 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6763 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6764 key.p.key_len != WLAN_KEY_LEN_WEP104))
6765 return -EINVAL;
6766 if (key.idx > 4)
6767 return -EINVAL;
6768 } else {
6769 key.p.key_len = 0;
6770 key.p.key = NULL;
6771 }
6772
Johannes Bergafea0b72010-08-10 09:46:42 +02006773 if (key.idx >= 0) {
6774 int i;
6775 bool ok = false;
6776 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6777 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6778 ok = true;
6779 break;
6780 }
6781 }
Johannes Berg4c476992010-10-04 21:36:35 +02006782 if (!ok)
6783 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006784 }
6785
Johannes Berg4c476992010-10-04 21:36:35 +02006786 if (!rdev->ops->auth)
6787 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006788
Johannes Berg074ac8d2010-09-16 14:58:22 +02006789 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006790 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6791 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006792
Johannes Berg19957bb2009-07-02 17:20:43 +02006793 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006794 chan = nl80211_get_valid_chan(&rdev->wiphy,
6795 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6796 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006797 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006798
Johannes Berg19957bb2009-07-02 17:20:43 +02006799 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6800 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6801
6802 if (info->attrs[NL80211_ATTR_IE]) {
6803 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6804 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6805 }
6806
6807 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006808 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006809 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006810
Jouni Malinene39e5b52012-09-30 19:29:39 +03006811 if (auth_type == NL80211_AUTHTYPE_SAE &&
6812 !info->attrs[NL80211_ATTR_SAE_DATA])
6813 return -EINVAL;
6814
6815 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6816 if (auth_type != NL80211_AUTHTYPE_SAE)
6817 return -EINVAL;
6818 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6819 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6820 /* need to include at least Auth Transaction and Status Code */
6821 if (sae_data_len < 4)
6822 return -EINVAL;
6823 }
6824
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006825 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6826
Johannes Berg95de8172012-01-20 13:55:25 +01006827 /*
6828 * Since we no longer track auth state, ignore
6829 * requests to only change local state.
6830 */
6831 if (local_state_change)
6832 return 0;
6833
Johannes Berg91bf9b22013-05-15 17:44:01 +02006834 wdev_lock(dev->ieee80211_ptr);
6835 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6836 ssid, ssid_len, ie, ie_len,
6837 key.p.key, key.p.key_len, key.idx,
6838 sae_data, sae_data_len);
6839 wdev_unlock(dev->ieee80211_ptr);
6840 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006841}
6842
Johannes Bergc0692b82010-08-27 14:26:53 +03006843static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6844 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006845 struct cfg80211_crypto_settings *settings,
6846 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006847{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006848 memset(settings, 0, sizeof(*settings));
6849
Samuel Ortizb23aa672009-07-01 21:26:54 +02006850 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6851
Johannes Bergc0692b82010-08-27 14:26:53 +03006852 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6853 u16 proto;
6854 proto = nla_get_u16(
6855 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6856 settings->control_port_ethertype = cpu_to_be16(proto);
6857 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6858 proto != ETH_P_PAE)
6859 return -EINVAL;
6860 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6861 settings->control_port_no_encrypt = true;
6862 } else
6863 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6864
Samuel Ortizb23aa672009-07-01 21:26:54 +02006865 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6866 void *data;
6867 int len, i;
6868
6869 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6870 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6871 settings->n_ciphers_pairwise = len / sizeof(u32);
6872
6873 if (len % sizeof(u32))
6874 return -EINVAL;
6875
Johannes Berg3dc27d22009-07-02 21:36:37 +02006876 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006877 return -EINVAL;
6878
6879 memcpy(settings->ciphers_pairwise, data, len);
6880
6881 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006882 if (!cfg80211_supported_cipher_suite(
6883 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006884 settings->ciphers_pairwise[i]))
6885 return -EINVAL;
6886 }
6887
6888 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6889 settings->cipher_group =
6890 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006891 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6892 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006893 return -EINVAL;
6894 }
6895
6896 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6897 settings->wpa_versions =
6898 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6899 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6900 return -EINVAL;
6901 }
6902
6903 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6904 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006905 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006906
6907 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6908 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6909 settings->n_akm_suites = len / sizeof(u32);
6910
6911 if (len % sizeof(u32))
6912 return -EINVAL;
6913
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006914 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6915 return -EINVAL;
6916
Samuel Ortizb23aa672009-07-01 21:26:54 +02006917 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006918 }
6919
6920 return 0;
6921}
6922
Jouni Malinen636a5d32009-03-19 13:39:22 +02006923static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6924{
Johannes Berg4c476992010-10-04 21:36:35 +02006925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6926 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006927 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006928 struct cfg80211_assoc_request req = {};
6929 const u8 *bssid, *ssid;
6930 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006931
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006932 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6933 return -EINVAL;
6934
6935 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006936 !info->attrs[NL80211_ATTR_SSID] ||
6937 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006938 return -EINVAL;
6939
Johannes Berg4c476992010-10-04 21:36:35 +02006940 if (!rdev->ops->assoc)
6941 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006942
Johannes Berg074ac8d2010-09-16 14:58:22 +02006943 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006944 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6945 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006946
Johannes Berg19957bb2009-07-02 17:20:43 +02006947 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006948
Jouni Malinen664834d2014-01-15 00:01:44 +02006949 chan = nl80211_get_valid_chan(&rdev->wiphy,
6950 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6951 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006952 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006953
Johannes Berg19957bb2009-07-02 17:20:43 +02006954 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6955 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006956
6957 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006958 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6959 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006960 }
6961
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006962 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006963 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006964 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006965 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006966 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006967 else if (mfp != NL80211_MFP_NO)
6968 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006969 }
6970
Johannes Berg3e5d7642009-07-07 14:37:26 +02006971 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006972 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006973
Ben Greear7e7c8922011-11-18 11:31:59 -08006974 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006975 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006976
6977 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006978 memcpy(&req.ht_capa_mask,
6979 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6980 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006981
6982 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006983 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006984 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006985 memcpy(&req.ht_capa,
6986 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6987 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006988 }
6989
Johannes Bergee2aca32013-02-21 17:36:01 +01006990 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006991 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006992
6993 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006994 memcpy(&req.vht_capa_mask,
6995 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6996 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006997
6998 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006999 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007000 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007001 memcpy(&req.vht_capa,
7002 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7003 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007004 }
7005
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007006 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7007 if (!(rdev->wiphy.features &
7008 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7009 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7010 return -EINVAL;
7011 req.flags |= ASSOC_REQ_USE_RRM;
7012 }
7013
Johannes Bergf62fab72013-02-21 20:09:09 +01007014 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007015 if (!err) {
7016 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007017 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7018 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007019 wdev_unlock(dev->ieee80211_ptr);
7020 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007021
Jouni Malinen636a5d32009-03-19 13:39:22 +02007022 return err;
7023}
7024
7025static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7026{
Johannes Berg4c476992010-10-04 21:36:35 +02007027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7028 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007029 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007030 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007031 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007032 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007033
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007034 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7035 return -EINVAL;
7036
7037 if (!info->attrs[NL80211_ATTR_MAC])
7038 return -EINVAL;
7039
7040 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7041 return -EINVAL;
7042
Johannes Berg4c476992010-10-04 21:36:35 +02007043 if (!rdev->ops->deauth)
7044 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007045
Johannes Berg074ac8d2010-09-16 14:58:22 +02007046 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007047 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7048 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007049
Johannes Berg19957bb2009-07-02 17:20:43 +02007050 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007051
Johannes Berg19957bb2009-07-02 17:20:43 +02007052 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7053 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007054 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007055 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007056 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007057
7058 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007059 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7060 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007061 }
7062
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007063 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7064
Johannes Berg91bf9b22013-05-15 17:44:01 +02007065 wdev_lock(dev->ieee80211_ptr);
7066 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7067 local_state_change);
7068 wdev_unlock(dev->ieee80211_ptr);
7069 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007070}
7071
7072static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7073{
Johannes Berg4c476992010-10-04 21:36:35 +02007074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7075 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007076 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007077 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007078 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007079 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007080
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007081 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7082 return -EINVAL;
7083
7084 if (!info->attrs[NL80211_ATTR_MAC])
7085 return -EINVAL;
7086
7087 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7088 return -EINVAL;
7089
Johannes Berg4c476992010-10-04 21:36:35 +02007090 if (!rdev->ops->disassoc)
7091 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007092
Johannes Berg074ac8d2010-09-16 14:58:22 +02007093 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007094 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7095 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007096
Johannes Berg19957bb2009-07-02 17:20:43 +02007097 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007098
Johannes Berg19957bb2009-07-02 17:20:43 +02007099 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7100 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007101 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007102 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007103 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007104
7105 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007106 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7107 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007108 }
7109
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007110 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7111
Johannes Berg91bf9b22013-05-15 17:44:01 +02007112 wdev_lock(dev->ieee80211_ptr);
7113 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7114 local_state_change);
7115 wdev_unlock(dev->ieee80211_ptr);
7116 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007117}
7118
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007119static bool
7120nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7121 int mcast_rate[IEEE80211_NUM_BANDS],
7122 int rateval)
7123{
7124 struct wiphy *wiphy = &rdev->wiphy;
7125 bool found = false;
7126 int band, i;
7127
7128 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7129 struct ieee80211_supported_band *sband;
7130
7131 sband = wiphy->bands[band];
7132 if (!sband)
7133 continue;
7134
7135 for (i = 0; i < sband->n_bitrates; i++) {
7136 if (sband->bitrates[i].bitrate == rateval) {
7137 mcast_rate[band] = i + 1;
7138 found = true;
7139 break;
7140 }
7141 }
7142 }
7143
7144 return found;
7145}
7146
Johannes Berg04a773a2009-04-19 21:24:32 +02007147static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7148{
Johannes Berg4c476992010-10-04 21:36:35 +02007149 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7150 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007151 struct cfg80211_ibss_params ibss;
7152 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007153 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007154 int err;
7155
Johannes Berg8e30bc52009-04-22 17:45:38 +02007156 memset(&ibss, 0, sizeof(ibss));
7157
Johannes Berg04a773a2009-04-19 21:24:32 +02007158 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7159 return -EINVAL;
7160
Johannes Berg683b6d32012-11-08 21:25:48 +01007161 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007162 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7163 return -EINVAL;
7164
Johannes Berg8e30bc52009-04-22 17:45:38 +02007165 ibss.beacon_interval = 100;
7166
7167 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7168 ibss.beacon_interval =
7169 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7170 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7171 return -EINVAL;
7172 }
7173
Johannes Berg4c476992010-10-04 21:36:35 +02007174 if (!rdev->ops->join_ibss)
7175 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007176
Johannes Berg4c476992010-10-04 21:36:35 +02007177 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7178 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007179
Johannes Berg79c97e92009-07-07 03:56:12 +02007180 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007181
Johannes Berg39193492011-09-16 13:45:25 +02007182 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007183 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007184
7185 if (!is_valid_ether_addr(ibss.bssid))
7186 return -EINVAL;
7187 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007188 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7189 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7190
7191 if (info->attrs[NL80211_ATTR_IE]) {
7192 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7193 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7194 }
7195
Johannes Berg683b6d32012-11-08 21:25:48 +01007196 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7197 if (err)
7198 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007199
Ilan Peer174e0cd2014-02-23 09:13:01 +02007200 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7201 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007202 return -EINVAL;
7203
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007204 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007205 case NL80211_CHAN_WIDTH_5:
7206 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007207 case NL80211_CHAN_WIDTH_20_NOHT:
7208 break;
7209 case NL80211_CHAN_WIDTH_20:
7210 case NL80211_CHAN_WIDTH_40:
7211 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
7212 break;
7213 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007214 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007215 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007216
Johannes Berg04a773a2009-04-19 21:24:32 +02007217 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007218 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007219
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007220 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7221 u8 *rates =
7222 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7223 int n_rates =
7224 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7225 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007226 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007227
Johannes Berg34850ab2011-07-18 18:08:35 +02007228 err = ieee80211_get_ratemask(sband, rates, n_rates,
7229 &ibss.basic_rates);
7230 if (err)
7231 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007232 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007233
Simon Wunderlich803768f2013-06-28 10:39:58 +02007234 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7235 memcpy(&ibss.ht_capa_mask,
7236 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7237 sizeof(ibss.ht_capa_mask));
7238
7239 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7240 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7241 return -EINVAL;
7242 memcpy(&ibss.ht_capa,
7243 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7244 sizeof(ibss.ht_capa));
7245 }
7246
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007247 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7248 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7249 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7250 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007251
Johannes Berg4c476992010-10-04 21:36:35 +02007252 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307253 bool no_ht = false;
7254
Johannes Berg4c476992010-10-04 21:36:35 +02007255 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307256 info->attrs[NL80211_ATTR_KEYS],
7257 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007258 if (IS_ERR(connkeys))
7259 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307260
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007261 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7262 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307263 kfree(connkeys);
7264 return -EINVAL;
7265 }
Johannes Berg4c476992010-10-04 21:36:35 +02007266 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007267
Antonio Quartulli267335d2012-01-31 20:25:47 +01007268 ibss.control_port =
7269 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7270
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007271 ibss.userspace_handles_dfs =
7272 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7273
Johannes Berg4c476992010-10-04 21:36:35 +02007274 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007275 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007276 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007277 return err;
7278}
7279
7280static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7281{
Johannes Berg4c476992010-10-04 21:36:35 +02007282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7283 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007284
Johannes Berg4c476992010-10-04 21:36:35 +02007285 if (!rdev->ops->leave_ibss)
7286 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007287
Johannes Berg4c476992010-10-04 21:36:35 +02007288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7289 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007290
Johannes Berg4c476992010-10-04 21:36:35 +02007291 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007292}
7293
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007294static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7295{
7296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7297 struct net_device *dev = info->user_ptr[1];
7298 int mcast_rate[IEEE80211_NUM_BANDS];
7299 u32 nla_rate;
7300 int err;
7301
7302 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7303 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7304 return -EOPNOTSUPP;
7305
7306 if (!rdev->ops->set_mcast_rate)
7307 return -EOPNOTSUPP;
7308
7309 memset(mcast_rate, 0, sizeof(mcast_rate));
7310
7311 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7312 return -EINVAL;
7313
7314 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7315 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7316 return -EINVAL;
7317
7318 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7319
7320 return err;
7321}
7322
Johannes Bergad7e7182013-11-13 13:37:47 +01007323static struct sk_buff *
7324__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7325 int approxlen, u32 portid, u32 seq,
7326 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007327 enum nl80211_attrs attr,
7328 const struct nl80211_vendor_cmd_info *info,
7329 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007330{
7331 struct sk_buff *skb;
7332 void *hdr;
7333 struct nlattr *data;
7334
7335 skb = nlmsg_new(approxlen + 100, gfp);
7336 if (!skb)
7337 return NULL;
7338
7339 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7340 if (!hdr) {
7341 kfree_skb(skb);
7342 return NULL;
7343 }
7344
7345 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7346 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007347
7348 if (info) {
7349 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7350 info->vendor_id))
7351 goto nla_put_failure;
7352 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7353 info->subcmd))
7354 goto nla_put_failure;
7355 }
7356
Johannes Bergad7e7182013-11-13 13:37:47 +01007357 data = nla_nest_start(skb, attr);
7358
7359 ((void **)skb->cb)[0] = rdev;
7360 ((void **)skb->cb)[1] = hdr;
7361 ((void **)skb->cb)[2] = data;
7362
7363 return skb;
7364
7365 nla_put_failure:
7366 kfree_skb(skb);
7367 return NULL;
7368}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007369
Johannes Berge03ad6e2014-01-01 17:22:30 +01007370struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7371 enum nl80211_commands cmd,
7372 enum nl80211_attrs attr,
7373 int vendor_event_idx,
7374 int approxlen, gfp_t gfp)
7375{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007376 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007377 const struct nl80211_vendor_cmd_info *info;
7378
7379 switch (cmd) {
7380 case NL80211_CMD_TESTMODE:
7381 if (WARN_ON(vendor_event_idx != -1))
7382 return NULL;
7383 info = NULL;
7384 break;
7385 case NL80211_CMD_VENDOR:
7386 if (WARN_ON(vendor_event_idx < 0 ||
7387 vendor_event_idx >= wiphy->n_vendor_events))
7388 return NULL;
7389 info = &wiphy->vendor_events[vendor_event_idx];
7390 break;
7391 default:
7392 WARN_ON(1);
7393 return NULL;
7394 }
7395
7396 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7397 cmd, attr, info, gfp);
7398}
7399EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7400
7401void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7402{
7403 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7404 void *hdr = ((void **)skb->cb)[1];
7405 struct nlattr *data = ((void **)skb->cb)[2];
7406 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7407
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007408 /* clear CB data for netlink core to own from now on */
7409 memset(skb->cb, 0, sizeof(skb->cb));
7410
Johannes Berge03ad6e2014-01-01 17:22:30 +01007411 nla_nest_end(skb, data);
7412 genlmsg_end(skb, hdr);
7413
7414 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7415 mcgrp = NL80211_MCGRP_VENDOR;
7416
7417 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7418 mcgrp, gfp);
7419}
7420EXPORT_SYMBOL(__cfg80211_send_event_skb);
7421
Johannes Bergaff89a92009-07-01 21:26:51 +02007422#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007423static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7424{
Johannes Berg4c476992010-10-04 21:36:35 +02007425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007426 struct wireless_dev *wdev =
7427 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007428 int err;
7429
David Spinadelfc73f112013-07-31 18:04:15 +03007430 if (!rdev->ops->testmode_cmd)
7431 return -EOPNOTSUPP;
7432
7433 if (IS_ERR(wdev)) {
7434 err = PTR_ERR(wdev);
7435 if (err != -EINVAL)
7436 return err;
7437 wdev = NULL;
7438 } else if (wdev->wiphy != &rdev->wiphy) {
7439 return -EINVAL;
7440 }
7441
Johannes Bergaff89a92009-07-01 21:26:51 +02007442 if (!info->attrs[NL80211_ATTR_TESTDATA])
7443 return -EINVAL;
7444
Johannes Bergad7e7182013-11-13 13:37:47 +01007445 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007446 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007447 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7448 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007449 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007450
Johannes Bergaff89a92009-07-01 21:26:51 +02007451 return err;
7452}
7453
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007454static int nl80211_testmode_dump(struct sk_buff *skb,
7455 struct netlink_callback *cb)
7456{
Johannes Berg00918d32011-12-13 17:22:05 +01007457 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007458 int err;
7459 long phy_idx;
7460 void *data = NULL;
7461 int data_len = 0;
7462
Johannes Berg5fe231e2013-05-08 21:45:15 +02007463 rtnl_lock();
7464
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007465 if (cb->args[0]) {
7466 /*
7467 * 0 is a valid index, but not valid for args[0],
7468 * so we need to offset by 1.
7469 */
7470 phy_idx = cb->args[0] - 1;
7471 } else {
7472 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7473 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7474 nl80211_policy);
7475 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007476 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007477
Johannes Berg2bd7e352012-06-15 14:23:16 +02007478 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7479 nl80211_fam.attrbuf);
7480 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007481 err = PTR_ERR(rdev);
7482 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007483 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007484 phy_idx = rdev->wiphy_idx;
7485 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007486
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007487 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7488 cb->args[1] =
7489 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7490 }
7491
7492 if (cb->args[1]) {
7493 data = nla_data((void *)cb->args[1]);
7494 data_len = nla_len((void *)cb->args[1]);
7495 }
7496
Johannes Berg00918d32011-12-13 17:22:05 +01007497 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7498 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007499 err = -ENOENT;
7500 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007501 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007502
Johannes Berg00918d32011-12-13 17:22:05 +01007503 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007504 err = -EOPNOTSUPP;
7505 goto out_err;
7506 }
7507
7508 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007509 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007510 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7511 NL80211_CMD_TESTMODE);
7512 struct nlattr *tmdata;
7513
Dan Carpentercb35fba2013-08-14 14:50:01 +03007514 if (!hdr)
7515 break;
7516
David S. Miller9360ffd2012-03-29 04:41:26 -04007517 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007518 genlmsg_cancel(skb, hdr);
7519 break;
7520 }
7521
7522 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7523 if (!tmdata) {
7524 genlmsg_cancel(skb, hdr);
7525 break;
7526 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007527 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007528 nla_nest_end(skb, tmdata);
7529
7530 if (err == -ENOBUFS || err == -ENOENT) {
7531 genlmsg_cancel(skb, hdr);
7532 break;
7533 } else if (err) {
7534 genlmsg_cancel(skb, hdr);
7535 goto out_err;
7536 }
7537
7538 genlmsg_end(skb, hdr);
7539 }
7540
7541 err = skb->len;
7542 /* see above */
7543 cb->args[0] = phy_idx + 1;
7544 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007545 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007546 return err;
7547}
Johannes Bergaff89a92009-07-01 21:26:51 +02007548#endif
7549
Samuel Ortizb23aa672009-07-01 21:26:54 +02007550static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7551{
Johannes Berg4c476992010-10-04 21:36:35 +02007552 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7553 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007554 struct cfg80211_connect_params connect;
7555 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007556 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007557 int err;
7558
7559 memset(&connect, 0, sizeof(connect));
7560
7561 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7562 return -EINVAL;
7563
7564 if (!info->attrs[NL80211_ATTR_SSID] ||
7565 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7566 return -EINVAL;
7567
7568 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7569 connect.auth_type =
7570 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007571 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7572 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007573 return -EINVAL;
7574 } else
7575 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7576
7577 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7578
Johannes Bergc0692b82010-08-27 14:26:53 +03007579 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007580 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007581 if (err)
7582 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007583
Johannes Berg074ac8d2010-09-16 14:58:22 +02007584 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007585 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7586 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007587
Johannes Berg79c97e92009-07-07 03:56:12 +02007588 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007589
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307590 connect.bg_scan_period = -1;
7591 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7592 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7593 connect.bg_scan_period =
7594 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7595 }
7596
Samuel Ortizb23aa672009-07-01 21:26:54 +02007597 if (info->attrs[NL80211_ATTR_MAC])
7598 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007599 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7600 connect.bssid_hint =
7601 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007602 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7603 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7604
7605 if (info->attrs[NL80211_ATTR_IE]) {
7606 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7607 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7608 }
7609
Jouni Malinencee00a92013-01-15 17:15:57 +02007610 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7611 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7612 if (connect.mfp != NL80211_MFP_REQUIRED &&
7613 connect.mfp != NL80211_MFP_NO)
7614 return -EINVAL;
7615 } else {
7616 connect.mfp = NL80211_MFP_NO;
7617 }
7618
Samuel Ortizb23aa672009-07-01 21:26:54 +02007619 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007620 connect.channel = nl80211_get_valid_chan(
7621 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7622 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007623 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007624 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007625 connect.channel_hint = nl80211_get_valid_chan(
7626 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7627 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007628 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007629 }
7630
Johannes Bergfffd0932009-07-08 14:22:54 +02007631 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7632 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307633 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007634 if (IS_ERR(connkeys))
7635 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007636 }
7637
Ben Greear7e7c8922011-11-18 11:31:59 -08007638 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7639 connect.flags |= ASSOC_REQ_DISABLE_HT;
7640
7641 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7642 memcpy(&connect.ht_capa_mask,
7643 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7644 sizeof(connect.ht_capa_mask));
7645
7646 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007647 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007648 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007649 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007650 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007651 memcpy(&connect.ht_capa,
7652 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7653 sizeof(connect.ht_capa));
7654 }
7655
Johannes Bergee2aca32013-02-21 17:36:01 +01007656 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7657 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7658
7659 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7660 memcpy(&connect.vht_capa_mask,
7661 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7662 sizeof(connect.vht_capa_mask));
7663
7664 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7665 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007666 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007667 return -EINVAL;
7668 }
7669 memcpy(&connect.vht_capa,
7670 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7671 sizeof(connect.vht_capa));
7672 }
7673
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007674 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7675 if (!(rdev->wiphy.features &
7676 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7677 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7678 return -EINVAL;
7679 connect.flags |= ASSOC_REQ_USE_RRM;
7680 }
7681
Johannes Berg83739b02013-05-15 17:44:01 +02007682 wdev_lock(dev->ieee80211_ptr);
7683 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7684 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007685 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007686 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007687 return err;
7688}
7689
7690static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7691{
Johannes Berg4c476992010-10-04 21:36:35 +02007692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7693 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007694 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007695 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007696
7697 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7698 reason = WLAN_REASON_DEAUTH_LEAVING;
7699 else
7700 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7701
7702 if (reason == 0)
7703 return -EINVAL;
7704
Johannes Berg074ac8d2010-09-16 14:58:22 +02007705 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007706 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7707 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007708
Johannes Berg83739b02013-05-15 17:44:01 +02007709 wdev_lock(dev->ieee80211_ptr);
7710 ret = cfg80211_disconnect(rdev, dev, reason, true);
7711 wdev_unlock(dev->ieee80211_ptr);
7712 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007713}
7714
Johannes Berg463d0182009-07-14 00:33:35 +02007715static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7716{
Johannes Berg4c476992010-10-04 21:36:35 +02007717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007718 struct net *net;
7719 int err;
7720 u32 pid;
7721
7722 if (!info->attrs[NL80211_ATTR_PID])
7723 return -EINVAL;
7724
7725 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7726
Johannes Berg463d0182009-07-14 00:33:35 +02007727 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007728 if (IS_ERR(net))
7729 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007730
7731 err = 0;
7732
7733 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007734 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7735 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007736
Johannes Berg463d0182009-07-14 00:33:35 +02007737 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007738 return err;
7739}
7740
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007741static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7742{
Johannes Berg4c476992010-10-04 21:36:35 +02007743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007744 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7745 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007746 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007747 struct cfg80211_pmksa pmksa;
7748
7749 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7750
7751 if (!info->attrs[NL80211_ATTR_MAC])
7752 return -EINVAL;
7753
7754 if (!info->attrs[NL80211_ATTR_PMKID])
7755 return -EINVAL;
7756
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007757 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7758 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7759
Johannes Berg074ac8d2010-09-16 14:58:22 +02007760 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007761 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7762 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007763
7764 switch (info->genlhdr->cmd) {
7765 case NL80211_CMD_SET_PMKSA:
7766 rdev_ops = rdev->ops->set_pmksa;
7767 break;
7768 case NL80211_CMD_DEL_PMKSA:
7769 rdev_ops = rdev->ops->del_pmksa;
7770 break;
7771 default:
7772 WARN_ON(1);
7773 break;
7774 }
7775
Johannes Berg4c476992010-10-04 21:36:35 +02007776 if (!rdev_ops)
7777 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007778
Johannes Berg4c476992010-10-04 21:36:35 +02007779 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007780}
7781
7782static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7783{
Johannes Berg4c476992010-10-04 21:36:35 +02007784 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7785 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007786
Johannes Berg074ac8d2010-09-16 14:58:22 +02007787 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007788 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7789 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007790
Johannes Berg4c476992010-10-04 21:36:35 +02007791 if (!rdev->ops->flush_pmksa)
7792 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007793
Hila Gonene35e4d22012-06-27 17:19:42 +03007794 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007795}
7796
Arik Nemtsov109086c2011-09-28 14:12:50 +03007797static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7798{
7799 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7800 struct net_device *dev = info->user_ptr[1];
7801 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307802 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007803 u16 status_code;
7804 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007805 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007806
7807 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7808 !rdev->ops->tdls_mgmt)
7809 return -EOPNOTSUPP;
7810
7811 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7812 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7813 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7814 !info->attrs[NL80211_ATTR_IE] ||
7815 !info->attrs[NL80211_ATTR_MAC])
7816 return -EINVAL;
7817
7818 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7819 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7820 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7821 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007822 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307823 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7824 peer_capability =
7825 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007826
Hila Gonene35e4d22012-06-27 17:19:42 +03007827 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307828 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007829 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007830 nla_data(info->attrs[NL80211_ATTR_IE]),
7831 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007832}
7833
7834static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7835{
7836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7837 struct net_device *dev = info->user_ptr[1];
7838 enum nl80211_tdls_operation operation;
7839 u8 *peer;
7840
7841 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7842 !rdev->ops->tdls_oper)
7843 return -EOPNOTSUPP;
7844
7845 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7846 !info->attrs[NL80211_ATTR_MAC])
7847 return -EINVAL;
7848
7849 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7850 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7851
Hila Gonene35e4d22012-06-27 17:19:42 +03007852 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007853}
7854
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007855static int nl80211_remain_on_channel(struct sk_buff *skb,
7856 struct genl_info *info)
7857{
Johannes Berg4c476992010-10-04 21:36:35 +02007858 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007859 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007860 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007861 struct sk_buff *msg;
7862 void *hdr;
7863 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007864 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007865 int err;
7866
7867 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7868 !info->attrs[NL80211_ATTR_DURATION])
7869 return -EINVAL;
7870
7871 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7872
Johannes Berg7c4ef712011-11-18 15:33:48 +01007873 if (!rdev->ops->remain_on_channel ||
7874 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007875 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007876
Johannes Bergebf348f2012-06-01 12:50:54 +02007877 /*
7878 * We should be on that channel for at least a minimum amount of
7879 * time (10ms) but no longer than the driver supports.
7880 */
7881 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7882 duration > rdev->wiphy.max_remain_on_channel_duration)
7883 return -EINVAL;
7884
Johannes Berg683b6d32012-11-08 21:25:48 +01007885 err = nl80211_parse_chandef(rdev, info, &chandef);
7886 if (err)
7887 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007888
7889 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007890 if (!msg)
7891 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007892
Eric W. Biederman15e47302012-09-07 20:12:54 +00007893 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007894 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007895 if (!hdr) {
7896 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007897 goto free_msg;
7898 }
7899
Johannes Berg683b6d32012-11-08 21:25:48 +01007900 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7901 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007902
7903 if (err)
7904 goto free_msg;
7905
David S. Miller9360ffd2012-03-29 04:41:26 -04007906 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7907 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007908
7909 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007910
7911 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007912
7913 nla_put_failure:
7914 err = -ENOBUFS;
7915 free_msg:
7916 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007917 return err;
7918}
7919
7920static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7921 struct genl_info *info)
7922{
Johannes Berg4c476992010-10-04 21:36:35 +02007923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007924 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007925 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007926
7927 if (!info->attrs[NL80211_ATTR_COOKIE])
7928 return -EINVAL;
7929
Johannes Berg4c476992010-10-04 21:36:35 +02007930 if (!rdev->ops->cancel_remain_on_channel)
7931 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007932
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007933 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7934
Hila Gonene35e4d22012-06-27 17:19:42 +03007935 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007936}
7937
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007938static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7939 u8 *rates, u8 rates_len)
7940{
7941 u8 i;
7942 u32 mask = 0;
7943
7944 for (i = 0; i < rates_len; i++) {
7945 int rate = (rates[i] & 0x7f) * 5;
7946 int ridx;
7947 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7948 struct ieee80211_rate *srate =
7949 &sband->bitrates[ridx];
7950 if (rate == srate->bitrate) {
7951 mask |= 1 << ridx;
7952 break;
7953 }
7954 }
7955 if (ridx == sband->n_bitrates)
7956 return 0; /* rate not found */
7957 }
7958
7959 return mask;
7960}
7961
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007962static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7963 u8 *rates, u8 rates_len,
7964 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7965{
7966 u8 i;
7967
7968 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7969
7970 for (i = 0; i < rates_len; i++) {
7971 int ridx, rbit;
7972
7973 ridx = rates[i] / 8;
7974 rbit = BIT(rates[i] % 8);
7975
7976 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007977 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007978 return false;
7979
7980 /* check availability */
7981 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7982 mcs[ridx] |= rbit;
7983 else
7984 return false;
7985 }
7986
7987 return true;
7988}
7989
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007990static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7991{
7992 u16 mcs_mask = 0;
7993
7994 switch (vht_mcs_map) {
7995 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7996 break;
7997 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7998 mcs_mask = 0x00FF;
7999 break;
8000 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8001 mcs_mask = 0x01FF;
8002 break;
8003 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8004 mcs_mask = 0x03FF;
8005 break;
8006 default:
8007 break;
8008 }
8009
8010 return mcs_mask;
8011}
8012
8013static void vht_build_mcs_mask(u16 vht_mcs_map,
8014 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8015{
8016 u8 nss;
8017
8018 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8019 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8020 vht_mcs_map >>= 2;
8021 }
8022}
8023
8024static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8025 struct nl80211_txrate_vht *txrate,
8026 u16 mcs[NL80211_VHT_NSS_MAX])
8027{
8028 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8029 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8030 u8 i;
8031
8032 if (!sband->vht_cap.vht_supported)
8033 return false;
8034
8035 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8036
8037 /* Build vht_mcs_mask from VHT capabilities */
8038 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8039
8040 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8041 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8042 mcs[i] = txrate->mcs[i];
8043 else
8044 return false;
8045 }
8046
8047 return true;
8048}
8049
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008050static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008051 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8052 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008053 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8054 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008055 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008056 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008057};
8058
8059static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8060 struct genl_info *info)
8061{
8062 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008064 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008065 int rem, i;
8066 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008067 struct nlattr *tx_rates;
8068 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008069 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008070
Johannes Berg4c476992010-10-04 21:36:35 +02008071 if (!rdev->ops->set_bitrate_mask)
8072 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008073
8074 memset(&mask, 0, sizeof(mask));
8075 /* Default to all rates enabled */
8076 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8077 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008078
8079 if (!sband)
8080 continue;
8081
8082 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008083 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008084 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008085 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008086
8087 if (!sband->vht_cap.vht_supported)
8088 continue;
8089
8090 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8091 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008092 }
8093
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008094 /* if no rates are given set it back to the defaults */
8095 if (!info->attrs[NL80211_ATTR_TX_RATES])
8096 goto out;
8097
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008098 /*
8099 * The nested attribute uses enum nl80211_band as the index. This maps
8100 * directly to the enum ieee80211_band values used in cfg80211.
8101 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008102 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008103 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008104 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008105 int err;
8106
Johannes Berg4c476992010-10-04 21:36:35 +02008107 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8108 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008109 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008110 if (sband == NULL)
8111 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008112 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8113 nla_len(tx_rates), nl80211_txattr_policy);
8114 if (err)
8115 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008116 if (tb[NL80211_TXRATE_LEGACY]) {
8117 mask.control[band].legacy = rateset_to_mask(
8118 sband,
8119 nla_data(tb[NL80211_TXRATE_LEGACY]),
8120 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308121 if ((mask.control[band].legacy == 0) &&
8122 nla_len(tb[NL80211_TXRATE_LEGACY]))
8123 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008124 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008125 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008126 if (!ht_rateset_to_mask(
8127 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008128 nla_data(tb[NL80211_TXRATE_HT]),
8129 nla_len(tb[NL80211_TXRATE_HT]),
8130 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008131 return -EINVAL;
8132 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008133 if (tb[NL80211_TXRATE_VHT]) {
8134 if (!vht_set_mcs_mask(
8135 sband,
8136 nla_data(tb[NL80211_TXRATE_VHT]),
8137 mask.control[band].vht_mcs))
8138 return -EINVAL;
8139 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008140 if (tb[NL80211_TXRATE_GI]) {
8141 mask.control[band].gi =
8142 nla_get_u8(tb[NL80211_TXRATE_GI]);
8143 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8144 return -EINVAL;
8145 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008146
8147 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008148 /* don't allow empty legacy rates if HT or VHT
8149 * are not even supported.
8150 */
8151 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8152 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008153 return -EINVAL;
8154
8155 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008156 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008157 goto out;
8158
8159 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8160 if (mask.control[band].vht_mcs[i])
8161 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008162
8163 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008164 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008165 }
8166 }
8167
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008168out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008169 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008170}
8171
Johannes Berg2e161f72010-08-12 15:38:38 +02008172static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008173{
Johannes Berg4c476992010-10-04 21:36:35 +02008174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008175 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008176 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008177
8178 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8179 return -EINVAL;
8180
Johannes Berg2e161f72010-08-12 15:38:38 +02008181 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8182 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008183
Johannes Berg71bbc992012-06-15 15:30:18 +02008184 switch (wdev->iftype) {
8185 case NL80211_IFTYPE_STATION:
8186 case NL80211_IFTYPE_ADHOC:
8187 case NL80211_IFTYPE_P2P_CLIENT:
8188 case NL80211_IFTYPE_AP:
8189 case NL80211_IFTYPE_AP_VLAN:
8190 case NL80211_IFTYPE_MESH_POINT:
8191 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008192 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008193 break;
8194 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008195 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008196 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008197
8198 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008199 if (!rdev->ops->mgmt_tx)
8200 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008201
Eric W. Biederman15e47302012-09-07 20:12:54 +00008202 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008203 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8204 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008205}
8206
Johannes Berg2e161f72010-08-12 15:38:38 +02008207static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008208{
Johannes Berg4c476992010-10-04 21:36:35 +02008209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008210 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008211 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008212 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008213 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008214 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008215 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008216 struct cfg80211_mgmt_tx_params params = {
8217 .dont_wait_for_ack =
8218 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8219 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008220
Johannes Berg683b6d32012-11-08 21:25:48 +01008221 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008222 return -EINVAL;
8223
Johannes Berg4c476992010-10-04 21:36:35 +02008224 if (!rdev->ops->mgmt_tx)
8225 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008226
Johannes Berg71bbc992012-06-15 15:30:18 +02008227 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008228 case NL80211_IFTYPE_P2P_DEVICE:
8229 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8230 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008231 case NL80211_IFTYPE_STATION:
8232 case NL80211_IFTYPE_ADHOC:
8233 case NL80211_IFTYPE_P2P_CLIENT:
8234 case NL80211_IFTYPE_AP:
8235 case NL80211_IFTYPE_AP_VLAN:
8236 case NL80211_IFTYPE_MESH_POINT:
8237 case NL80211_IFTYPE_P2P_GO:
8238 break;
8239 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008240 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008241 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008242
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008243 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008244 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008245 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008246 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008247
8248 /*
8249 * We should wait on the channel for at least a minimum amount
8250 * of time (10ms) but no longer than the driver supports.
8251 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008252 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8253 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008254 return -EINVAL;
8255
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008256 }
8257
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008258 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008259
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008260 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008261 return -EINVAL;
8262
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008263 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308264
Antonio Quartulliea141b752013-06-11 14:20:03 +02008265 /* get the channel if any has been specified, otherwise pass NULL to
8266 * the driver. The latter will use the current one
8267 */
8268 chandef.chan = NULL;
8269 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8270 err = nl80211_parse_chandef(rdev, info, &chandef);
8271 if (err)
8272 return err;
8273 }
8274
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008275 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008276 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008277
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008278 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8279 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8280
8281 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8282 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8283 int i;
8284
8285 if (len % sizeof(u16))
8286 return -EINVAL;
8287
8288 params.n_csa_offsets = len / sizeof(u16);
8289 params.csa_offsets =
8290 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8291
8292 /* check that all the offsets fit the frame */
8293 for (i = 0; i < params.n_csa_offsets; i++) {
8294 if (params.csa_offsets[i] >= params.len)
8295 return -EINVAL;
8296 }
8297 }
8298
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008299 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008300 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8301 if (!msg)
8302 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008303
Eric W. Biederman15e47302012-09-07 20:12:54 +00008304 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008305 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008306 if (!hdr) {
8307 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008308 goto free_msg;
8309 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008310 }
Johannes Berge247bd902011-11-04 11:18:21 +01008311
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008312 params.chan = chandef.chan;
8313 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008314 if (err)
8315 goto free_msg;
8316
Johannes Berge247bd902011-11-04 11:18:21 +01008317 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008318 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8319 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008320
Johannes Berge247bd902011-11-04 11:18:21 +01008321 genlmsg_end(msg, hdr);
8322 return genlmsg_reply(msg, info);
8323 }
8324
8325 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008326
8327 nla_put_failure:
8328 err = -ENOBUFS;
8329 free_msg:
8330 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008331 return err;
8332}
8333
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008334static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8335{
8336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008337 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008338 u64 cookie;
8339
8340 if (!info->attrs[NL80211_ATTR_COOKIE])
8341 return -EINVAL;
8342
8343 if (!rdev->ops->mgmt_tx_cancel_wait)
8344 return -EOPNOTSUPP;
8345
Johannes Berg71bbc992012-06-15 15:30:18 +02008346 switch (wdev->iftype) {
8347 case NL80211_IFTYPE_STATION:
8348 case NL80211_IFTYPE_ADHOC:
8349 case NL80211_IFTYPE_P2P_CLIENT:
8350 case NL80211_IFTYPE_AP:
8351 case NL80211_IFTYPE_AP_VLAN:
8352 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008353 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008354 break;
8355 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008356 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008357 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008358
8359 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8360
Hila Gonene35e4d22012-06-27 17:19:42 +03008361 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008362}
8363
Kalle Valoffb9eb32010-02-17 17:58:10 +02008364static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8365{
Johannes Berg4c476992010-10-04 21:36:35 +02008366 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008367 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008368 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008369 u8 ps_state;
8370 bool state;
8371 int err;
8372
Johannes Berg4c476992010-10-04 21:36:35 +02008373 if (!info->attrs[NL80211_ATTR_PS_STATE])
8374 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008375
8376 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8377
Johannes Berg4c476992010-10-04 21:36:35 +02008378 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8379 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008380
8381 wdev = dev->ieee80211_ptr;
8382
Johannes Berg4c476992010-10-04 21:36:35 +02008383 if (!rdev->ops->set_power_mgmt)
8384 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008385
8386 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8387
8388 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008389 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008390
Hila Gonene35e4d22012-06-27 17:19:42 +03008391 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008392 if (!err)
8393 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008394 return err;
8395}
8396
8397static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8398{
Johannes Berg4c476992010-10-04 21:36:35 +02008399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008400 enum nl80211_ps_state ps_state;
8401 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008402 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008403 struct sk_buff *msg;
8404 void *hdr;
8405 int err;
8406
Kalle Valoffb9eb32010-02-17 17:58:10 +02008407 wdev = dev->ieee80211_ptr;
8408
Johannes Berg4c476992010-10-04 21:36:35 +02008409 if (!rdev->ops->set_power_mgmt)
8410 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008411
8412 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008413 if (!msg)
8414 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008415
Eric W. Biederman15e47302012-09-07 20:12:54 +00008416 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008417 NL80211_CMD_GET_POWER_SAVE);
8418 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008419 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008420 goto free_msg;
8421 }
8422
8423 if (wdev->ps)
8424 ps_state = NL80211_PS_ENABLED;
8425 else
8426 ps_state = NL80211_PS_DISABLED;
8427
David S. Miller9360ffd2012-03-29 04:41:26 -04008428 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8429 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008430
8431 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008432 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008433
Johannes Berg4c476992010-10-04 21:36:35 +02008434 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008435 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008436 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008437 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008438 return err;
8439}
8440
Johannes Berg94e860f2014-01-20 23:58:15 +01008441static const struct nla_policy
8442nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008443 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8444 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8445 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008446 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8447 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8448 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008449};
8450
Thomas Pedersen84f10702012-07-12 16:17:33 -07008451static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008452 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008453{
8454 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008455 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008456 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008457
Johannes Bergd9d8b012012-11-26 12:51:52 +01008458 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008459 return -EINVAL;
8460
Thomas Pedersen84f10702012-07-12 16:17:33 -07008461 if (!rdev->ops->set_cqm_txe_config)
8462 return -EOPNOTSUPP;
8463
8464 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8465 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8466 return -EOPNOTSUPP;
8467
Hila Gonene35e4d22012-06-27 17:19:42 +03008468 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008469}
8470
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008471static int nl80211_set_cqm_rssi(struct genl_info *info,
8472 s32 threshold, u32 hysteresis)
8473{
Johannes Berg4c476992010-10-04 21:36:35 +02008474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008475 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008476 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008477
8478 if (threshold > 0)
8479 return -EINVAL;
8480
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008481 /* disabling - hysteresis should also be zero then */
8482 if (threshold == 0)
8483 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008484
Johannes Berg4c476992010-10-04 21:36:35 +02008485 if (!rdev->ops->set_cqm_rssi_config)
8486 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008487
Johannes Berg074ac8d2010-09-16 14:58:22 +02008488 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008489 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8490 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008491
Hila Gonene35e4d22012-06-27 17:19:42 +03008492 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008493}
8494
8495static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8496{
8497 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8498 struct nlattr *cqm;
8499 int err;
8500
8501 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008502 if (!cqm)
8503 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008504
8505 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8506 nl80211_attr_cqm_policy);
8507 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008508 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008509
8510 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8511 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008512 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8513 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008514
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008515 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8516 }
8517
8518 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8519 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8520 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8521 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8522 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8523 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8524
8525 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8526 }
8527
8528 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008529}
8530
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008531static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8532{
8533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8534 struct net_device *dev = info->user_ptr[1];
8535 struct ocb_setup setup = {};
8536 int err;
8537
8538 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8539 if (err)
8540 return err;
8541
8542 return cfg80211_join_ocb(rdev, dev, &setup);
8543}
8544
8545static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8546{
8547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8548 struct net_device *dev = info->user_ptr[1];
8549
8550 return cfg80211_leave_ocb(rdev, dev);
8551}
8552
Johannes Berg29cbe682010-12-03 09:20:44 +01008553static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8554{
8555 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8556 struct net_device *dev = info->user_ptr[1];
8557 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008558 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008559 int err;
8560
8561 /* start with default */
8562 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008563 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008564
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008565 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008566 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008567 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008568 if (err)
8569 return err;
8570 }
8571
8572 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8573 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8574 return -EINVAL;
8575
Javier Cardonac80d5452010-12-16 17:37:49 -08008576 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8577 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8578
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008579 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8580 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8581 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8582 return -EINVAL;
8583
Marco Porsch9bdbf042013-01-07 16:04:51 +01008584 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8585 setup.beacon_interval =
8586 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8587 if (setup.beacon_interval < 10 ||
8588 setup.beacon_interval > 10000)
8589 return -EINVAL;
8590 }
8591
8592 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8593 setup.dtim_period =
8594 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8595 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8596 return -EINVAL;
8597 }
8598
Javier Cardonac80d5452010-12-16 17:37:49 -08008599 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8600 /* parse additional setup parameters if given */
8601 err = nl80211_parse_mesh_setup(info, &setup);
8602 if (err)
8603 return err;
8604 }
8605
Thomas Pedersend37bb182013-03-04 13:06:13 -08008606 if (setup.user_mpm)
8607 cfg.auto_open_plinks = false;
8608
Johannes Bergcc1d2802012-05-16 23:50:20 +02008609 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008610 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8611 if (err)
8612 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008613 } else {
8614 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008615 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008616 }
8617
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008618 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8619 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8620 int n_rates =
8621 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8622 struct ieee80211_supported_band *sband;
8623
8624 if (!setup.chandef.chan)
8625 return -EINVAL;
8626
8627 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8628
8629 err = ieee80211_get_ratemask(sband, rates, n_rates,
8630 &setup.basic_rates);
8631 if (err)
8632 return err;
8633 }
8634
Javier Cardonac80d5452010-12-16 17:37:49 -08008635 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008636}
8637
8638static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8639{
8640 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8641 struct net_device *dev = info->user_ptr[1];
8642
8643 return cfg80211_leave_mesh(rdev, dev);
8644}
8645
Johannes Bergdfb89c52012-06-27 09:23:48 +02008646#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008647static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8648 struct cfg80211_registered_device *rdev)
8649{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008650 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008651 struct nlattr *nl_pats, *nl_pat;
8652 int i, pat_len;
8653
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008654 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008655 return 0;
8656
8657 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8658 if (!nl_pats)
8659 return -ENOBUFS;
8660
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008661 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008662 nl_pat = nla_nest_start(msg, i + 1);
8663 if (!nl_pat)
8664 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008665 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008666 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008667 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008668 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8669 wowlan->patterns[i].pattern) ||
8670 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008671 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008672 return -ENOBUFS;
8673 nla_nest_end(msg, nl_pat);
8674 }
8675 nla_nest_end(msg, nl_pats);
8676
8677 return 0;
8678}
8679
Johannes Berg2a0e0472013-01-23 22:57:40 +01008680static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8681 struct cfg80211_wowlan_tcp *tcp)
8682{
8683 struct nlattr *nl_tcp;
8684
8685 if (!tcp)
8686 return 0;
8687
8688 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8689 if (!nl_tcp)
8690 return -ENOBUFS;
8691
8692 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8693 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8694 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8695 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8696 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8697 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8698 tcp->payload_len, tcp->payload) ||
8699 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8700 tcp->data_interval) ||
8701 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8702 tcp->wake_len, tcp->wake_data) ||
8703 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8704 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8705 return -ENOBUFS;
8706
8707 if (tcp->payload_seq.len &&
8708 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8709 sizeof(tcp->payload_seq), &tcp->payload_seq))
8710 return -ENOBUFS;
8711
8712 if (tcp->payload_tok.len &&
8713 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8714 sizeof(tcp->payload_tok) + tcp->tokens_size,
8715 &tcp->payload_tok))
8716 return -ENOBUFS;
8717
Johannes Berge248ad32013-05-16 10:24:28 +02008718 nla_nest_end(msg, nl_tcp);
8719
Johannes Berg2a0e0472013-01-23 22:57:40 +01008720 return 0;
8721}
8722
Johannes Bergff1b6e62011-05-04 15:37:28 +02008723static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8724{
8725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8726 struct sk_buff *msg;
8727 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008728 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008729
Johannes Berg964dc9e2013-06-03 17:25:34 +02008730 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008731 return -EOPNOTSUPP;
8732
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008733 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008734 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008735 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8736 rdev->wiphy.wowlan_config->tcp->payload_len +
8737 rdev->wiphy.wowlan_config->tcp->wake_len +
8738 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008739 }
8740
8741 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008742 if (!msg)
8743 return -ENOMEM;
8744
Eric W. Biederman15e47302012-09-07 20:12:54 +00008745 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008746 NL80211_CMD_GET_WOWLAN);
8747 if (!hdr)
8748 goto nla_put_failure;
8749
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008750 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008751 struct nlattr *nl_wowlan;
8752
8753 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8754 if (!nl_wowlan)
8755 goto nla_put_failure;
8756
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008757 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008758 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008759 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008760 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008761 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008762 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008763 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008764 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008765 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008766 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008767 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008768 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008769 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008770 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8771 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008772
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008773 if (nl80211_send_wowlan_patterns(msg, rdev))
8774 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008775
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008776 if (nl80211_send_wowlan_tcp(msg,
8777 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008778 goto nla_put_failure;
8779
Johannes Bergff1b6e62011-05-04 15:37:28 +02008780 nla_nest_end(msg, nl_wowlan);
8781 }
8782
8783 genlmsg_end(msg, hdr);
8784 return genlmsg_reply(msg, info);
8785
8786nla_put_failure:
8787 nlmsg_free(msg);
8788 return -ENOBUFS;
8789}
8790
Johannes Berg2a0e0472013-01-23 22:57:40 +01008791static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8792 struct nlattr *attr,
8793 struct cfg80211_wowlan *trig)
8794{
8795 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8796 struct cfg80211_wowlan_tcp *cfg;
8797 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8798 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8799 u32 size;
8800 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8801 int err, port;
8802
Johannes Berg964dc9e2013-06-03 17:25:34 +02008803 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008804 return -EINVAL;
8805
8806 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8807 nla_data(attr), nla_len(attr),
8808 nl80211_wowlan_tcp_policy);
8809 if (err)
8810 return err;
8811
8812 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8813 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8814 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8815 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8816 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8817 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8818 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8819 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8820 return -EINVAL;
8821
8822 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008823 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008824 return -EINVAL;
8825
8826 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008827 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008828 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008829 return -EINVAL;
8830
8831 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008832 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008833 return -EINVAL;
8834
8835 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8836 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8837 return -EINVAL;
8838
8839 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8840 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8841
8842 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8843 tokens_size = tokln - sizeof(*tok);
8844
8845 if (!tok->len || tokens_size % tok->len)
8846 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008847 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008848 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008849 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008850 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008851 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008852 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008853 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008854 return -EINVAL;
8855 if (tok->offset + tok->len > data_size)
8856 return -EINVAL;
8857 }
8858
8859 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8860 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008861 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008862 return -EINVAL;
8863 if (seq->len == 0 || seq->len > 4)
8864 return -EINVAL;
8865 if (seq->len + seq->offset > data_size)
8866 return -EINVAL;
8867 }
8868
8869 size = sizeof(*cfg);
8870 size += data_size;
8871 size += wake_size + wake_mask_size;
8872 size += tokens_size;
8873
8874 cfg = kzalloc(size, GFP_KERNEL);
8875 if (!cfg)
8876 return -ENOMEM;
8877 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8878 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8879 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8880 ETH_ALEN);
8881 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8882 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8883 else
8884 port = 0;
8885#ifdef CONFIG_INET
8886 /* allocate a socket and port for it and use it */
8887 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8888 IPPROTO_TCP, &cfg->sock, 1);
8889 if (err) {
8890 kfree(cfg);
8891 return err;
8892 }
8893 if (inet_csk_get_port(cfg->sock->sk, port)) {
8894 sock_release(cfg->sock);
8895 kfree(cfg);
8896 return -EADDRINUSE;
8897 }
8898 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8899#else
8900 if (!port) {
8901 kfree(cfg);
8902 return -EINVAL;
8903 }
8904 cfg->src_port = port;
8905#endif
8906
8907 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8908 cfg->payload_len = data_size;
8909 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8910 memcpy((void *)cfg->payload,
8911 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8912 data_size);
8913 if (seq)
8914 cfg->payload_seq = *seq;
8915 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8916 cfg->wake_len = wake_size;
8917 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8918 memcpy((void *)cfg->wake_data,
8919 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8920 wake_size);
8921 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8922 data_size + wake_size;
8923 memcpy((void *)cfg->wake_mask,
8924 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8925 wake_mask_size);
8926 if (tok) {
8927 cfg->tokens_size = tokens_size;
8928 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8929 }
8930
8931 trig->tcp = cfg;
8932
8933 return 0;
8934}
8935
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008936static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
8937 const struct wiphy_wowlan_support *wowlan,
8938 struct nlattr *attr,
8939 struct cfg80211_wowlan *trig)
8940{
8941 struct nlattr **tb;
8942 int err;
8943
8944 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
8945 if (!tb)
8946 return -ENOMEM;
8947
8948 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
8949 err = -EOPNOTSUPP;
8950 goto out;
8951 }
8952
8953 err = nla_parse(tb, NL80211_ATTR_MAX,
8954 nla_data(attr), nla_len(attr),
8955 nl80211_policy);
8956 if (err)
8957 goto out;
8958
Johannes Bergad2b26a2014-06-12 21:39:05 +02008959 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008960 err = PTR_ERR_OR_ZERO(trig->nd_config);
8961 if (err)
8962 trig->nd_config = NULL;
8963
8964out:
8965 kfree(tb);
8966 return err;
8967}
8968
Johannes Bergff1b6e62011-05-04 15:37:28 +02008969static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8970{
8971 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8972 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008973 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008974 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008975 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008976 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008977 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008978
Johannes Berg964dc9e2013-06-03 17:25:34 +02008979 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008980 return -EOPNOTSUPP;
8981
Johannes Bergae33bd82012-07-12 16:25:02 +02008982 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8983 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008984 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008985 goto set_wakeup;
8986 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008987
8988 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8989 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8990 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8991 nl80211_wowlan_policy);
8992 if (err)
8993 return err;
8994
8995 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8996 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8997 return -EINVAL;
8998 new_triggers.any = true;
8999 }
9000
9001 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9002 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9003 return -EINVAL;
9004 new_triggers.disconnect = true;
9005 }
9006
9007 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9008 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9009 return -EINVAL;
9010 new_triggers.magic_pkt = true;
9011 }
9012
Johannes Berg77dbbb12011-07-13 10:48:55 +02009013 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9014 return -EINVAL;
9015
9016 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9017 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9018 return -EINVAL;
9019 new_triggers.gtk_rekey_failure = true;
9020 }
9021
9022 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9023 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9024 return -EINVAL;
9025 new_triggers.eap_identity_req = true;
9026 }
9027
9028 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9029 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9030 return -EINVAL;
9031 new_triggers.four_way_handshake = true;
9032 }
9033
9034 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9035 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9036 return -EINVAL;
9037 new_triggers.rfkill_release = true;
9038 }
9039
Johannes Bergff1b6e62011-05-04 15:37:28 +02009040 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9041 struct nlattr *pat;
9042 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009043 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009044 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009045
9046 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9047 rem)
9048 n_patterns++;
9049 if (n_patterns > wowlan->n_patterns)
9050 return -EINVAL;
9051
9052 new_triggers.patterns = kcalloc(n_patterns,
9053 sizeof(new_triggers.patterns[0]),
9054 GFP_KERNEL);
9055 if (!new_triggers.patterns)
9056 return -ENOMEM;
9057
9058 new_triggers.n_patterns = n_patterns;
9059 i = 0;
9060
9061 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9062 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009063 u8 *mask_pat;
9064
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009065 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9066 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009067 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009068 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9069 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009070 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009071 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009072 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009073 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009074 goto error;
9075 if (pat_len > wowlan->pattern_max_len ||
9076 pat_len < wowlan->pattern_min_len)
9077 goto error;
9078
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009079 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009080 pkt_offset = 0;
9081 else
9082 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009083 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009084 if (pkt_offset > wowlan->max_pkt_offset)
9085 goto error;
9086 new_triggers.patterns[i].pkt_offset = pkt_offset;
9087
Johannes Berg922bd802014-05-19 17:59:50 +02009088 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9089 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009090 err = -ENOMEM;
9091 goto error;
9092 }
Johannes Berg922bd802014-05-19 17:59:50 +02009093 new_triggers.patterns[i].mask = mask_pat;
9094 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009095 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009096 mask_pat += mask_len;
9097 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009098 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009099 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009100 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009101 pat_len);
9102 i++;
9103 }
9104 }
9105
Johannes Berg2a0e0472013-01-23 22:57:40 +01009106 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
9107 err = nl80211_parse_wowlan_tcp(
9108 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9109 &new_triggers);
9110 if (err)
9111 goto error;
9112 }
9113
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009114 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
9115 err = nl80211_parse_wowlan_nd(
9116 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9117 &new_triggers);
9118 if (err)
9119 goto error;
9120 }
9121
Johannes Bergae33bd82012-07-12 16:25:02 +02009122 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9123 if (!ntrig) {
9124 err = -ENOMEM;
9125 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009126 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009127 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009128 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009129
Johannes Bergae33bd82012-07-12 16:25:02 +02009130 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009131 if (rdev->ops->set_wakeup &&
9132 prev_enabled != !!rdev->wiphy.wowlan_config)
9133 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009134
Johannes Bergff1b6e62011-05-04 15:37:28 +02009135 return 0;
9136 error:
9137 for (i = 0; i < new_triggers.n_patterns; i++)
9138 kfree(new_triggers.patterns[i].mask);
9139 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009140 if (new_triggers.tcp && new_triggers.tcp->sock)
9141 sock_release(new_triggers.tcp->sock);
9142 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009143 return err;
9144}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009145#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009146
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009147static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9148 struct cfg80211_registered_device *rdev)
9149{
9150 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9151 int i, j, pat_len;
9152 struct cfg80211_coalesce_rules *rule;
9153
9154 if (!rdev->coalesce->n_rules)
9155 return 0;
9156
9157 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9158 if (!nl_rules)
9159 return -ENOBUFS;
9160
9161 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9162 nl_rule = nla_nest_start(msg, i + 1);
9163 if (!nl_rule)
9164 return -ENOBUFS;
9165
9166 rule = &rdev->coalesce->rules[i];
9167 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9168 rule->delay))
9169 return -ENOBUFS;
9170
9171 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9172 rule->condition))
9173 return -ENOBUFS;
9174
9175 nl_pats = nla_nest_start(msg,
9176 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9177 if (!nl_pats)
9178 return -ENOBUFS;
9179
9180 for (j = 0; j < rule->n_patterns; j++) {
9181 nl_pat = nla_nest_start(msg, j + 1);
9182 if (!nl_pat)
9183 return -ENOBUFS;
9184 pat_len = rule->patterns[j].pattern_len;
9185 if (nla_put(msg, NL80211_PKTPAT_MASK,
9186 DIV_ROUND_UP(pat_len, 8),
9187 rule->patterns[j].mask) ||
9188 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9189 rule->patterns[j].pattern) ||
9190 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9191 rule->patterns[j].pkt_offset))
9192 return -ENOBUFS;
9193 nla_nest_end(msg, nl_pat);
9194 }
9195 nla_nest_end(msg, nl_pats);
9196 nla_nest_end(msg, nl_rule);
9197 }
9198 nla_nest_end(msg, nl_rules);
9199
9200 return 0;
9201}
9202
9203static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9204{
9205 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9206 struct sk_buff *msg;
9207 void *hdr;
9208
9209 if (!rdev->wiphy.coalesce)
9210 return -EOPNOTSUPP;
9211
9212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9213 if (!msg)
9214 return -ENOMEM;
9215
9216 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9217 NL80211_CMD_GET_COALESCE);
9218 if (!hdr)
9219 goto nla_put_failure;
9220
9221 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9222 goto nla_put_failure;
9223
9224 genlmsg_end(msg, hdr);
9225 return genlmsg_reply(msg, info);
9226
9227nla_put_failure:
9228 nlmsg_free(msg);
9229 return -ENOBUFS;
9230}
9231
9232void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9233{
9234 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9235 int i, j;
9236 struct cfg80211_coalesce_rules *rule;
9237
9238 if (!coalesce)
9239 return;
9240
9241 for (i = 0; i < coalesce->n_rules; i++) {
9242 rule = &coalesce->rules[i];
9243 for (j = 0; j < rule->n_patterns; j++)
9244 kfree(rule->patterns[j].mask);
9245 kfree(rule->patterns);
9246 }
9247 kfree(coalesce->rules);
9248 kfree(coalesce);
9249 rdev->coalesce = NULL;
9250}
9251
9252static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9253 struct nlattr *rule,
9254 struct cfg80211_coalesce_rules *new_rule)
9255{
9256 int err, i;
9257 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9258 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9259 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9260 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9261
9262 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9263 nla_len(rule), nl80211_coalesce_policy);
9264 if (err)
9265 return err;
9266
9267 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9268 new_rule->delay =
9269 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9270 if (new_rule->delay > coalesce->max_delay)
9271 return -EINVAL;
9272
9273 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9274 new_rule->condition =
9275 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9276 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9277 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9278 return -EINVAL;
9279
9280 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9281 return -EINVAL;
9282
9283 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9284 rem)
9285 n_patterns++;
9286 if (n_patterns > coalesce->n_patterns)
9287 return -EINVAL;
9288
9289 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9290 GFP_KERNEL);
9291 if (!new_rule->patterns)
9292 return -ENOMEM;
9293
9294 new_rule->n_patterns = n_patterns;
9295 i = 0;
9296
9297 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9298 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009299 u8 *mask_pat;
9300
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009301 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9302 nla_len(pat), NULL);
9303 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9304 !pat_tb[NL80211_PKTPAT_PATTERN])
9305 return -EINVAL;
9306 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9307 mask_len = DIV_ROUND_UP(pat_len, 8);
9308 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9309 return -EINVAL;
9310 if (pat_len > coalesce->pattern_max_len ||
9311 pat_len < coalesce->pattern_min_len)
9312 return -EINVAL;
9313
9314 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9315 pkt_offset = 0;
9316 else
9317 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9318 if (pkt_offset > coalesce->max_pkt_offset)
9319 return -EINVAL;
9320 new_rule->patterns[i].pkt_offset = pkt_offset;
9321
Johannes Berg922bd802014-05-19 17:59:50 +02009322 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9323 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009324 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009325
9326 new_rule->patterns[i].mask = mask_pat;
9327 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9328 mask_len);
9329
9330 mask_pat += mask_len;
9331 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009332 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009333 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9334 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009335 i++;
9336 }
9337
9338 return 0;
9339}
9340
9341static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9342{
9343 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9344 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9345 struct cfg80211_coalesce new_coalesce = {};
9346 struct cfg80211_coalesce *n_coalesce;
9347 int err, rem_rule, n_rules = 0, i, j;
9348 struct nlattr *rule;
9349 struct cfg80211_coalesce_rules *tmp_rule;
9350
9351 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9352 return -EOPNOTSUPP;
9353
9354 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9355 cfg80211_rdev_free_coalesce(rdev);
9356 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9357 return 0;
9358 }
9359
9360 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9361 rem_rule)
9362 n_rules++;
9363 if (n_rules > coalesce->n_rules)
9364 return -EINVAL;
9365
9366 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9367 GFP_KERNEL);
9368 if (!new_coalesce.rules)
9369 return -ENOMEM;
9370
9371 new_coalesce.n_rules = n_rules;
9372 i = 0;
9373
9374 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9375 rem_rule) {
9376 err = nl80211_parse_coalesce_rule(rdev, rule,
9377 &new_coalesce.rules[i]);
9378 if (err)
9379 goto error;
9380
9381 i++;
9382 }
9383
9384 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9385 if (err)
9386 goto error;
9387
9388 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9389 if (!n_coalesce) {
9390 err = -ENOMEM;
9391 goto error;
9392 }
9393 cfg80211_rdev_free_coalesce(rdev);
9394 rdev->coalesce = n_coalesce;
9395
9396 return 0;
9397error:
9398 for (i = 0; i < new_coalesce.n_rules; i++) {
9399 tmp_rule = &new_coalesce.rules[i];
9400 for (j = 0; j < tmp_rule->n_patterns; j++)
9401 kfree(tmp_rule->patterns[j].mask);
9402 kfree(tmp_rule->patterns);
9403 }
9404 kfree(new_coalesce.rules);
9405
9406 return err;
9407}
9408
Johannes Berge5497d72011-07-05 16:35:40 +02009409static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9410{
9411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9412 struct net_device *dev = info->user_ptr[1];
9413 struct wireless_dev *wdev = dev->ieee80211_ptr;
9414 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9415 struct cfg80211_gtk_rekey_data rekey_data;
9416 int err;
9417
9418 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9419 return -EINVAL;
9420
9421 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9422 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9423 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9424 nl80211_rekey_policy);
9425 if (err)
9426 return err;
9427
9428 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9429 return -ERANGE;
9430 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9431 return -ERANGE;
9432 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9433 return -ERANGE;
9434
Johannes Berg78f686c2014-09-10 22:28:06 +03009435 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9436 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9437 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009438
9439 wdev_lock(wdev);
9440 if (!wdev->current_bss) {
9441 err = -ENOTCONN;
9442 goto out;
9443 }
9444
9445 if (!rdev->ops->set_rekey_data) {
9446 err = -EOPNOTSUPP;
9447 goto out;
9448 }
9449
Hila Gonene35e4d22012-06-27 17:19:42 +03009450 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009451 out:
9452 wdev_unlock(wdev);
9453 return err;
9454}
9455
Johannes Berg28946da2011-11-04 11:18:12 +01009456static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9457 struct genl_info *info)
9458{
9459 struct net_device *dev = info->user_ptr[1];
9460 struct wireless_dev *wdev = dev->ieee80211_ptr;
9461
9462 if (wdev->iftype != NL80211_IFTYPE_AP &&
9463 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9464 return -EINVAL;
9465
Eric W. Biederman15e47302012-09-07 20:12:54 +00009466 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009467 return -EBUSY;
9468
Eric W. Biederman15e47302012-09-07 20:12:54 +00009469 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009470 return 0;
9471}
9472
Johannes Berg7f6cf312011-11-04 11:18:15 +01009473static int nl80211_probe_client(struct sk_buff *skb,
9474 struct genl_info *info)
9475{
9476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9477 struct net_device *dev = info->user_ptr[1];
9478 struct wireless_dev *wdev = dev->ieee80211_ptr;
9479 struct sk_buff *msg;
9480 void *hdr;
9481 const u8 *addr;
9482 u64 cookie;
9483 int err;
9484
9485 if (wdev->iftype != NL80211_IFTYPE_AP &&
9486 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9487 return -EOPNOTSUPP;
9488
9489 if (!info->attrs[NL80211_ATTR_MAC])
9490 return -EINVAL;
9491
9492 if (!rdev->ops->probe_client)
9493 return -EOPNOTSUPP;
9494
9495 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9496 if (!msg)
9497 return -ENOMEM;
9498
Eric W. Biederman15e47302012-09-07 20:12:54 +00009499 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009500 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009501 if (!hdr) {
9502 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009503 goto free_msg;
9504 }
9505
9506 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9507
Hila Gonene35e4d22012-06-27 17:19:42 +03009508 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009509 if (err)
9510 goto free_msg;
9511
David S. Miller9360ffd2012-03-29 04:41:26 -04009512 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9513 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009514
9515 genlmsg_end(msg, hdr);
9516
9517 return genlmsg_reply(msg, info);
9518
9519 nla_put_failure:
9520 err = -ENOBUFS;
9521 free_msg:
9522 nlmsg_free(msg);
9523 return err;
9524}
9525
Johannes Berg5e760232011-11-04 11:18:17 +01009526static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9527{
9528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009529 struct cfg80211_beacon_registration *reg, *nreg;
9530 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009531
9532 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9533 return -EOPNOTSUPP;
9534
Ben Greear37c73b52012-10-26 14:49:25 -07009535 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9536 if (!nreg)
9537 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009538
Ben Greear37c73b52012-10-26 14:49:25 -07009539 /* First, check if already registered. */
9540 spin_lock_bh(&rdev->beacon_registrations_lock);
9541 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9542 if (reg->nlportid == info->snd_portid) {
9543 rv = -EALREADY;
9544 goto out_err;
9545 }
9546 }
9547 /* Add it to the list */
9548 nreg->nlportid = info->snd_portid;
9549 list_add(&nreg->list, &rdev->beacon_registrations);
9550
9551 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009552
9553 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009554out_err:
9555 spin_unlock_bh(&rdev->beacon_registrations_lock);
9556 kfree(nreg);
9557 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009558}
9559
Johannes Berg98104fde2012-06-16 00:19:54 +02009560static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9561{
9562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9563 struct wireless_dev *wdev = info->user_ptr[1];
9564 int err;
9565
9566 if (!rdev->ops->start_p2p_device)
9567 return -EOPNOTSUPP;
9568
9569 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9570 return -EOPNOTSUPP;
9571
9572 if (wdev->p2p_started)
9573 return 0;
9574
Luciano Coelhob6a55012014-02-27 11:07:21 +02009575 if (rfkill_blocked(rdev->rfkill))
9576 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009577
Johannes Bergeeb126e2012-10-23 15:16:50 +02009578 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009579 if (err)
9580 return err;
9581
9582 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009583 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009584
9585 return 0;
9586}
9587
9588static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9589{
9590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9591 struct wireless_dev *wdev = info->user_ptr[1];
9592
9593 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9594 return -EOPNOTSUPP;
9595
9596 if (!rdev->ops->stop_p2p_device)
9597 return -EOPNOTSUPP;
9598
Johannes Bergf9f47522013-03-19 15:04:07 +01009599 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009600
9601 return 0;
9602}
9603
Johannes Berg3713b4e2013-02-14 16:19:38 +01009604static int nl80211_get_protocol_features(struct sk_buff *skb,
9605 struct genl_info *info)
9606{
9607 void *hdr;
9608 struct sk_buff *msg;
9609
9610 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9611 if (!msg)
9612 return -ENOMEM;
9613
9614 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9615 NL80211_CMD_GET_PROTOCOL_FEATURES);
9616 if (!hdr)
9617 goto nla_put_failure;
9618
9619 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9620 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9621 goto nla_put_failure;
9622
9623 genlmsg_end(msg, hdr);
9624 return genlmsg_reply(msg, info);
9625
9626 nla_put_failure:
9627 kfree_skb(msg);
9628 return -ENOBUFS;
9629}
9630
Jouni Malinen355199e2013-02-27 17:14:27 +02009631static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9632{
9633 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9634 struct cfg80211_update_ft_ies_params ft_params;
9635 struct net_device *dev = info->user_ptr[1];
9636
9637 if (!rdev->ops->update_ft_ies)
9638 return -EOPNOTSUPP;
9639
9640 if (!info->attrs[NL80211_ATTR_MDID] ||
9641 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9642 return -EINVAL;
9643
9644 memset(&ft_params, 0, sizeof(ft_params));
9645 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9646 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9647 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9648
9649 return rdev_update_ft_ies(rdev, dev, &ft_params);
9650}
9651
Arend van Spriel5de17982013-04-18 15:49:00 +02009652static int nl80211_crit_protocol_start(struct sk_buff *skb,
9653 struct genl_info *info)
9654{
9655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9656 struct wireless_dev *wdev = info->user_ptr[1];
9657 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9658 u16 duration;
9659 int ret;
9660
9661 if (!rdev->ops->crit_proto_start)
9662 return -EOPNOTSUPP;
9663
9664 if (WARN_ON(!rdev->ops->crit_proto_stop))
9665 return -EINVAL;
9666
9667 if (rdev->crit_proto_nlportid)
9668 return -EBUSY;
9669
9670 /* determine protocol if provided */
9671 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9672 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9673
9674 if (proto >= NUM_NL80211_CRIT_PROTO)
9675 return -EINVAL;
9676
9677 /* timeout must be provided */
9678 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9679 return -EINVAL;
9680
9681 duration =
9682 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9683
9684 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9685 return -ERANGE;
9686
9687 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9688 if (!ret)
9689 rdev->crit_proto_nlportid = info->snd_portid;
9690
9691 return ret;
9692}
9693
9694static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9695 struct genl_info *info)
9696{
9697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9698 struct wireless_dev *wdev = info->user_ptr[1];
9699
9700 if (!rdev->ops->crit_proto_stop)
9701 return -EOPNOTSUPP;
9702
9703 if (rdev->crit_proto_nlportid) {
9704 rdev->crit_proto_nlportid = 0;
9705 rdev_crit_proto_stop(rdev, wdev);
9706 }
9707 return 0;
9708}
9709
Johannes Bergad7e7182013-11-13 13:37:47 +01009710static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9711{
9712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9713 struct wireless_dev *wdev =
9714 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9715 int i, err;
9716 u32 vid, subcmd;
9717
9718 if (!rdev->wiphy.vendor_commands)
9719 return -EOPNOTSUPP;
9720
9721 if (IS_ERR(wdev)) {
9722 err = PTR_ERR(wdev);
9723 if (err != -EINVAL)
9724 return err;
9725 wdev = NULL;
9726 } else if (wdev->wiphy != &rdev->wiphy) {
9727 return -EINVAL;
9728 }
9729
9730 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9731 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9732 return -EINVAL;
9733
9734 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9735 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9736 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9737 const struct wiphy_vendor_command *vcmd;
9738 void *data = NULL;
9739 int len = 0;
9740
9741 vcmd = &rdev->wiphy.vendor_commands[i];
9742
9743 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9744 continue;
9745
9746 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9747 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9748 if (!wdev)
9749 return -EINVAL;
9750 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9751 !wdev->netdev)
9752 return -EINVAL;
9753
9754 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9755 if (wdev->netdev &&
9756 !netif_running(wdev->netdev))
9757 return -ENETDOWN;
9758 if (!wdev->netdev && !wdev->p2p_started)
9759 return -ENETDOWN;
9760 }
9761 } else {
9762 wdev = NULL;
9763 }
9764
9765 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9766 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9767 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9768 }
9769
9770 rdev->cur_cmd_info = info;
9771 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9772 data, len);
9773 rdev->cur_cmd_info = NULL;
9774 return err;
9775 }
9776
9777 return -EOPNOTSUPP;
9778}
9779
9780struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9781 enum nl80211_commands cmd,
9782 enum nl80211_attrs attr,
9783 int approxlen)
9784{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009785 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009786
9787 if (WARN_ON(!rdev->cur_cmd_info))
9788 return NULL;
9789
9790 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9791 rdev->cur_cmd_info->snd_portid,
9792 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009793 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009794}
9795EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9796
9797int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9798{
9799 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9800 void *hdr = ((void **)skb->cb)[1];
9801 struct nlattr *data = ((void **)skb->cb)[2];
9802
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009803 /* clear CB data for netlink core to own from now on */
9804 memset(skb->cb, 0, sizeof(skb->cb));
9805
Johannes Bergad7e7182013-11-13 13:37:47 +01009806 if (WARN_ON(!rdev->cur_cmd_info)) {
9807 kfree_skb(skb);
9808 return -EINVAL;
9809 }
9810
9811 nla_nest_end(skb, data);
9812 genlmsg_end(skb, hdr);
9813 return genlmsg_reply(skb, rdev->cur_cmd_info);
9814}
9815EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9816
9817
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009818static int nl80211_set_qos_map(struct sk_buff *skb,
9819 struct genl_info *info)
9820{
9821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9822 struct cfg80211_qos_map *qos_map = NULL;
9823 struct net_device *dev = info->user_ptr[1];
9824 u8 *pos, len, num_des, des_len, des;
9825 int ret;
9826
9827 if (!rdev->ops->set_qos_map)
9828 return -EOPNOTSUPP;
9829
9830 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9831 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9832 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9833
9834 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9835 len > IEEE80211_QOS_MAP_LEN_MAX)
9836 return -EINVAL;
9837
9838 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9839 if (!qos_map)
9840 return -ENOMEM;
9841
9842 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9843 if (num_des) {
9844 des_len = num_des *
9845 sizeof(struct cfg80211_dscp_exception);
9846 memcpy(qos_map->dscp_exception, pos, des_len);
9847 qos_map->num_des = num_des;
9848 for (des = 0; des < num_des; des++) {
9849 if (qos_map->dscp_exception[des].up > 7) {
9850 kfree(qos_map);
9851 return -EINVAL;
9852 }
9853 }
9854 pos += des_len;
9855 }
9856 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9857 }
9858
9859 wdev_lock(dev->ieee80211_ptr);
9860 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9861 if (!ret)
9862 ret = rdev_set_qos_map(rdev, dev, qos_map);
9863 wdev_unlock(dev->ieee80211_ptr);
9864
9865 kfree(qos_map);
9866 return ret;
9867}
9868
Johannes Berg960d01a2014-09-09 22:55:35 +03009869static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9870{
9871 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9872 struct net_device *dev = info->user_ptr[1];
9873 struct wireless_dev *wdev = dev->ieee80211_ptr;
9874 const u8 *peer;
9875 u8 tsid, up;
9876 u16 admitted_time = 0;
9877 int err;
9878
Johannes Berg723e73a2014-10-22 09:25:06 +02009879 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009880 return -EOPNOTSUPP;
9881
9882 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9883 !info->attrs[NL80211_ATTR_USER_PRIO])
9884 return -EINVAL;
9885
9886 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9887 if (tsid >= IEEE80211_NUM_TIDS)
9888 return -EINVAL;
9889
9890 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9891 if (up >= IEEE80211_NUM_UPS)
9892 return -EINVAL;
9893
9894 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009895 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009896 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009897 * need more attributes for that (e.g. BA session requirement);
9898 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009899 */
9900 return -EINVAL;
9901 }
9902
9903 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9904
9905 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9906 admitted_time =
9907 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9908 if (!admitted_time)
9909 return -EINVAL;
9910 }
9911
9912 wdev_lock(wdev);
9913 switch (wdev->iftype) {
9914 case NL80211_IFTYPE_STATION:
9915 case NL80211_IFTYPE_P2P_CLIENT:
9916 if (wdev->current_bss)
9917 break;
9918 err = -ENOTCONN;
9919 goto out;
9920 default:
9921 err = -EOPNOTSUPP;
9922 goto out;
9923 }
9924
9925 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9926
9927 out:
9928 wdev_unlock(wdev);
9929 return err;
9930}
9931
9932static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9933{
9934 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9935 struct net_device *dev = info->user_ptr[1];
9936 struct wireless_dev *wdev = dev->ieee80211_ptr;
9937 const u8 *peer;
9938 u8 tsid;
9939 int err;
9940
9941 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9942 return -EINVAL;
9943
9944 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9945 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9946
9947 wdev_lock(wdev);
9948 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9949 wdev_unlock(wdev);
9950
9951 return err;
9952}
9953
Arik Nemtsov1057d352014-11-19 12:54:26 +02009954static int nl80211_tdls_channel_switch(struct sk_buff *skb,
9955 struct genl_info *info)
9956{
9957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9958 struct net_device *dev = info->user_ptr[1];
9959 struct wireless_dev *wdev = dev->ieee80211_ptr;
9960 struct cfg80211_chan_def chandef = {};
9961 const u8 *addr;
9962 u8 oper_class;
9963 int err;
9964
9965 if (!rdev->ops->tdls_channel_switch ||
9966 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9967 return -EOPNOTSUPP;
9968
9969 switch (dev->ieee80211_ptr->iftype) {
9970 case NL80211_IFTYPE_STATION:
9971 case NL80211_IFTYPE_P2P_CLIENT:
9972 break;
9973 default:
9974 return -EOPNOTSUPP;
9975 }
9976
9977 if (!info->attrs[NL80211_ATTR_MAC] ||
9978 !info->attrs[NL80211_ATTR_OPER_CLASS])
9979 return -EINVAL;
9980
9981 err = nl80211_parse_chandef(rdev, info, &chandef);
9982 if (err)
9983 return err;
9984
9985 /*
9986 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
9987 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
9988 * specification is not defined for them.
9989 */
9990 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
9991 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
9992 chandef.width != NL80211_CHAN_WIDTH_20)
9993 return -EINVAL;
9994
9995 /* we will be active on the TDLS link */
9996 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
9997 return -EINVAL;
9998
9999 /* don't allow switching to DFS channels */
10000 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10001 return -EINVAL;
10002
10003 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10004 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10005
10006 wdev_lock(wdev);
10007 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10008 wdev_unlock(wdev);
10009
10010 return err;
10011}
10012
10013static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10014 struct genl_info *info)
10015{
10016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10017 struct net_device *dev = info->user_ptr[1];
10018 struct wireless_dev *wdev = dev->ieee80211_ptr;
10019 const u8 *addr;
10020
10021 if (!rdev->ops->tdls_channel_switch ||
10022 !rdev->ops->tdls_cancel_channel_switch ||
10023 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10024 return -EOPNOTSUPP;
10025
10026 switch (dev->ieee80211_ptr->iftype) {
10027 case NL80211_IFTYPE_STATION:
10028 case NL80211_IFTYPE_P2P_CLIENT:
10029 break;
10030 default:
10031 return -EOPNOTSUPP;
10032 }
10033
10034 if (!info->attrs[NL80211_ATTR_MAC])
10035 return -EINVAL;
10036
10037 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10038
10039 wdev_lock(wdev);
10040 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10041 wdev_unlock(wdev);
10042
10043 return 0;
10044}
10045
Johannes Berg4c476992010-10-04 21:36:35 +020010046#define NL80211_FLAG_NEED_WIPHY 0x01
10047#define NL80211_FLAG_NEED_NETDEV 0x02
10048#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010049#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10050#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10051 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010052#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010053/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010054#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10055 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010056#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010057
Johannes Bergf84f7712013-11-14 17:14:45 +010010058static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010059 struct genl_info *info)
10060{
10061 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010062 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010063 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010064 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10065
10066 if (rtnl)
10067 rtnl_lock();
10068
10069 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010070 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010071 if (IS_ERR(rdev)) {
10072 if (rtnl)
10073 rtnl_unlock();
10074 return PTR_ERR(rdev);
10075 }
10076 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010077 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10078 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010079 ASSERT_RTNL();
10080
Johannes Berg89a54e42012-06-15 14:33:17 +020010081 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10082 info->attrs);
10083 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010084 if (rtnl)
10085 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010086 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010087 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010088
Johannes Berg89a54e42012-06-15 14:33:17 +020010089 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010090 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010091
Johannes Berg1bf614e2012-06-15 15:23:36 +020010092 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10093 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010094 if (rtnl)
10095 rtnl_unlock();
10096 return -EINVAL;
10097 }
10098
10099 info->user_ptr[1] = dev;
10100 } else {
10101 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010102 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010103
Johannes Berg1bf614e2012-06-15 15:23:36 +020010104 if (dev) {
10105 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10106 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010107 if (rtnl)
10108 rtnl_unlock();
10109 return -ENETDOWN;
10110 }
10111
10112 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010113 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10114 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010115 if (rtnl)
10116 rtnl_unlock();
10117 return -ENETDOWN;
10118 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010119 }
10120
Johannes Berg4c476992010-10-04 21:36:35 +020010121 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010122 }
10123
10124 return 0;
10125}
10126
Johannes Bergf84f7712013-11-14 17:14:45 +010010127static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010128 struct genl_info *info)
10129{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010130 if (info->user_ptr[1]) {
10131 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10132 struct wireless_dev *wdev = info->user_ptr[1];
10133
10134 if (wdev->netdev)
10135 dev_put(wdev->netdev);
10136 } else {
10137 dev_put(info->user_ptr[1]);
10138 }
10139 }
Johannes Berg5393b912014-09-10 15:00:16 +030010140
Johannes Berg4c476992010-10-04 21:36:35 +020010141 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10142 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010143
10144 /* If needed, clear the netlink message payload from the SKB
10145 * as it might contain key data that shouldn't stick around on
10146 * the heap after the SKB is freed. The netlink message header
10147 * is still needed for further processing, so leave it intact.
10148 */
10149 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10150 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10151
10152 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10153 }
Johannes Berg4c476992010-10-04 21:36:35 +020010154}
10155
Johannes Berg4534de82013-11-14 17:14:46 +010010156static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010157 {
10158 .cmd = NL80211_CMD_GET_WIPHY,
10159 .doit = nl80211_get_wiphy,
10160 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010161 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010162 .policy = nl80211_policy,
10163 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010164 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10165 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010166 },
10167 {
10168 .cmd = NL80211_CMD_SET_WIPHY,
10169 .doit = nl80211_set_wiphy,
10170 .policy = nl80211_policy,
10171 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010172 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010173 },
10174 {
10175 .cmd = NL80211_CMD_GET_INTERFACE,
10176 .doit = nl80211_get_interface,
10177 .dumpit = nl80211_dump_interface,
10178 .policy = nl80211_policy,
10179 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010180 .internal_flags = NL80211_FLAG_NEED_WDEV |
10181 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010182 },
10183 {
10184 .cmd = NL80211_CMD_SET_INTERFACE,
10185 .doit = nl80211_set_interface,
10186 .policy = nl80211_policy,
10187 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010188 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10189 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010190 },
10191 {
10192 .cmd = NL80211_CMD_NEW_INTERFACE,
10193 .doit = nl80211_new_interface,
10194 .policy = nl80211_policy,
10195 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010196 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10197 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010198 },
10199 {
10200 .cmd = NL80211_CMD_DEL_INTERFACE,
10201 .doit = nl80211_del_interface,
10202 .policy = nl80211_policy,
10203 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010204 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010205 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010206 },
Johannes Berg41ade002007-12-19 02:03:29 +010010207 {
10208 .cmd = NL80211_CMD_GET_KEY,
10209 .doit = nl80211_get_key,
10210 .policy = nl80211_policy,
10211 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010212 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010213 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010214 },
10215 {
10216 .cmd = NL80211_CMD_SET_KEY,
10217 .doit = nl80211_set_key,
10218 .policy = nl80211_policy,
10219 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010220 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010221 NL80211_FLAG_NEED_RTNL |
10222 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010223 },
10224 {
10225 .cmd = NL80211_CMD_NEW_KEY,
10226 .doit = nl80211_new_key,
10227 .policy = nl80211_policy,
10228 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010230 NL80211_FLAG_NEED_RTNL |
10231 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010232 },
10233 {
10234 .cmd = NL80211_CMD_DEL_KEY,
10235 .doit = nl80211_del_key,
10236 .policy = nl80211_policy,
10237 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010238 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010239 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010240 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010241 {
10242 .cmd = NL80211_CMD_SET_BEACON,
10243 .policy = nl80211_policy,
10244 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010245 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010246 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010247 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010248 },
10249 {
Johannes Berg88600202012-02-13 15:17:18 +010010250 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010251 .policy = nl80211_policy,
10252 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010253 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010254 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010255 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010256 },
10257 {
Johannes Berg88600202012-02-13 15:17:18 +010010258 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010259 .policy = nl80211_policy,
10260 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010261 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010262 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010263 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010264 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010265 {
10266 .cmd = NL80211_CMD_GET_STATION,
10267 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010268 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010269 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010270 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10271 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010272 },
10273 {
10274 .cmd = NL80211_CMD_SET_STATION,
10275 .doit = nl80211_set_station,
10276 .policy = nl80211_policy,
10277 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010278 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010279 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010280 },
10281 {
10282 .cmd = NL80211_CMD_NEW_STATION,
10283 .doit = nl80211_new_station,
10284 .policy = nl80211_policy,
10285 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010286 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010287 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010288 },
10289 {
10290 .cmd = NL80211_CMD_DEL_STATION,
10291 .doit = nl80211_del_station,
10292 .policy = nl80211_policy,
10293 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010294 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010295 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010296 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010297 {
10298 .cmd = NL80211_CMD_GET_MPATH,
10299 .doit = nl80211_get_mpath,
10300 .dumpit = nl80211_dump_mpath,
10301 .policy = nl80211_policy,
10302 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010303 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010304 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010305 },
10306 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010307 .cmd = NL80211_CMD_GET_MPP,
10308 .doit = nl80211_get_mpp,
10309 .dumpit = nl80211_dump_mpp,
10310 .policy = nl80211_policy,
10311 .flags = GENL_ADMIN_PERM,
10312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10313 NL80211_FLAG_NEED_RTNL,
10314 },
10315 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010316 .cmd = NL80211_CMD_SET_MPATH,
10317 .doit = nl80211_set_mpath,
10318 .policy = nl80211_policy,
10319 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010320 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010321 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010322 },
10323 {
10324 .cmd = NL80211_CMD_NEW_MPATH,
10325 .doit = nl80211_new_mpath,
10326 .policy = nl80211_policy,
10327 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010329 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010330 },
10331 {
10332 .cmd = NL80211_CMD_DEL_MPATH,
10333 .doit = nl80211_del_mpath,
10334 .policy = nl80211_policy,
10335 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010336 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010337 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010338 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010339 {
10340 .cmd = NL80211_CMD_SET_BSS,
10341 .doit = nl80211_set_bss,
10342 .policy = nl80211_policy,
10343 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010344 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010345 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010346 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010347 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010348 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010349 .doit = nl80211_get_reg_do,
10350 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010351 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010352 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010353 /* can be retrieved by unprivileged users */
10354 },
10355 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010356 .cmd = NL80211_CMD_SET_REG,
10357 .doit = nl80211_set_reg,
10358 .policy = nl80211_policy,
10359 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010360 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010361 },
10362 {
10363 .cmd = NL80211_CMD_REQ_SET_REG,
10364 .doit = nl80211_req_set_reg,
10365 .policy = nl80211_policy,
10366 .flags = GENL_ADMIN_PERM,
10367 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010368 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010369 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10370 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010371 .policy = nl80211_policy,
10372 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010373 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010374 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010375 },
10376 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010377 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10378 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010379 .policy = nl80211_policy,
10380 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010381 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010382 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010383 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010384 {
Johannes Berg2a519312009-02-10 21:25:55 +010010385 .cmd = NL80211_CMD_TRIGGER_SCAN,
10386 .doit = nl80211_trigger_scan,
10387 .policy = nl80211_policy,
10388 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010389 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010390 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010391 },
10392 {
10393 .cmd = NL80211_CMD_GET_SCAN,
10394 .policy = nl80211_policy,
10395 .dumpit = nl80211_dump_scan,
10396 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010397 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010398 .cmd = NL80211_CMD_START_SCHED_SCAN,
10399 .doit = nl80211_start_sched_scan,
10400 .policy = nl80211_policy,
10401 .flags = GENL_ADMIN_PERM,
10402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10403 NL80211_FLAG_NEED_RTNL,
10404 },
10405 {
10406 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10407 .doit = nl80211_stop_sched_scan,
10408 .policy = nl80211_policy,
10409 .flags = GENL_ADMIN_PERM,
10410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10411 NL80211_FLAG_NEED_RTNL,
10412 },
10413 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010414 .cmd = NL80211_CMD_AUTHENTICATE,
10415 .doit = nl80211_authenticate,
10416 .policy = nl80211_policy,
10417 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010418 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010419 NL80211_FLAG_NEED_RTNL |
10420 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010421 },
10422 {
10423 .cmd = NL80211_CMD_ASSOCIATE,
10424 .doit = nl80211_associate,
10425 .policy = nl80211_policy,
10426 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010428 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010429 },
10430 {
10431 .cmd = NL80211_CMD_DEAUTHENTICATE,
10432 .doit = nl80211_deauthenticate,
10433 .policy = nl80211_policy,
10434 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010436 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010437 },
10438 {
10439 .cmd = NL80211_CMD_DISASSOCIATE,
10440 .doit = nl80211_disassociate,
10441 .policy = nl80211_policy,
10442 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010444 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010445 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010446 {
10447 .cmd = NL80211_CMD_JOIN_IBSS,
10448 .doit = nl80211_join_ibss,
10449 .policy = nl80211_policy,
10450 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010452 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010453 },
10454 {
10455 .cmd = NL80211_CMD_LEAVE_IBSS,
10456 .doit = nl80211_leave_ibss,
10457 .policy = nl80211_policy,
10458 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010460 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010461 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010462#ifdef CONFIG_NL80211_TESTMODE
10463 {
10464 .cmd = NL80211_CMD_TESTMODE,
10465 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010466 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010467 .policy = nl80211_policy,
10468 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010469 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10470 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010471 },
10472#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010473 {
10474 .cmd = NL80211_CMD_CONNECT,
10475 .doit = nl80211_connect,
10476 .policy = nl80211_policy,
10477 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010478 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010479 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010480 },
10481 {
10482 .cmd = NL80211_CMD_DISCONNECT,
10483 .doit = nl80211_disconnect,
10484 .policy = nl80211_policy,
10485 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010486 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010487 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010488 },
Johannes Berg463d0182009-07-14 00:33:35 +020010489 {
10490 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10491 .doit = nl80211_wiphy_netns,
10492 .policy = nl80211_policy,
10493 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010494 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10495 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010496 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010497 {
10498 .cmd = NL80211_CMD_GET_SURVEY,
10499 .policy = nl80211_policy,
10500 .dumpit = nl80211_dump_survey,
10501 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010502 {
10503 .cmd = NL80211_CMD_SET_PMKSA,
10504 .doit = nl80211_setdel_pmksa,
10505 .policy = nl80211_policy,
10506 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010508 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010509 },
10510 {
10511 .cmd = NL80211_CMD_DEL_PMKSA,
10512 .doit = nl80211_setdel_pmksa,
10513 .policy = nl80211_policy,
10514 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010516 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010517 },
10518 {
10519 .cmd = NL80211_CMD_FLUSH_PMKSA,
10520 .doit = nl80211_flush_pmksa,
10521 .policy = nl80211_policy,
10522 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010523 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010524 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010525 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010526 {
10527 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10528 .doit = nl80211_remain_on_channel,
10529 .policy = nl80211_policy,
10530 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010531 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010532 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010533 },
10534 {
10535 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10536 .doit = nl80211_cancel_remain_on_channel,
10537 .policy = nl80211_policy,
10538 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010539 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010540 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010541 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010542 {
10543 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10544 .doit = nl80211_set_tx_bitrate_mask,
10545 .policy = nl80211_policy,
10546 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010547 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10548 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010549 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010550 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010551 .cmd = NL80211_CMD_REGISTER_FRAME,
10552 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010553 .policy = nl80211_policy,
10554 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010555 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010556 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010557 },
10558 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010559 .cmd = NL80211_CMD_FRAME,
10560 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010561 .policy = nl80211_policy,
10562 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010563 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010564 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010565 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010566 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010567 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10568 .doit = nl80211_tx_mgmt_cancel_wait,
10569 .policy = nl80211_policy,
10570 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010571 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010572 NL80211_FLAG_NEED_RTNL,
10573 },
10574 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010575 .cmd = NL80211_CMD_SET_POWER_SAVE,
10576 .doit = nl80211_set_power_save,
10577 .policy = nl80211_policy,
10578 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010579 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10580 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010581 },
10582 {
10583 .cmd = NL80211_CMD_GET_POWER_SAVE,
10584 .doit = nl80211_get_power_save,
10585 .policy = nl80211_policy,
10586 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010587 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10588 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010589 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010590 {
10591 .cmd = NL80211_CMD_SET_CQM,
10592 .doit = nl80211_set_cqm,
10593 .policy = nl80211_policy,
10594 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010595 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10596 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010597 },
Johannes Bergf444de02010-05-05 15:25:02 +020010598 {
10599 .cmd = NL80211_CMD_SET_CHANNEL,
10600 .doit = nl80211_set_channel,
10601 .policy = nl80211_policy,
10602 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010603 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10604 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010605 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010606 {
10607 .cmd = NL80211_CMD_SET_WDS_PEER,
10608 .doit = nl80211_set_wds_peer,
10609 .policy = nl80211_policy,
10610 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010611 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10612 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010613 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010614 {
10615 .cmd = NL80211_CMD_JOIN_MESH,
10616 .doit = nl80211_join_mesh,
10617 .policy = nl80211_policy,
10618 .flags = GENL_ADMIN_PERM,
10619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10620 NL80211_FLAG_NEED_RTNL,
10621 },
10622 {
10623 .cmd = NL80211_CMD_LEAVE_MESH,
10624 .doit = nl80211_leave_mesh,
10625 .policy = nl80211_policy,
10626 .flags = GENL_ADMIN_PERM,
10627 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10628 NL80211_FLAG_NEED_RTNL,
10629 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010630 {
10631 .cmd = NL80211_CMD_JOIN_OCB,
10632 .doit = nl80211_join_ocb,
10633 .policy = nl80211_policy,
10634 .flags = GENL_ADMIN_PERM,
10635 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10636 NL80211_FLAG_NEED_RTNL,
10637 },
10638 {
10639 .cmd = NL80211_CMD_LEAVE_OCB,
10640 .doit = nl80211_leave_ocb,
10641 .policy = nl80211_policy,
10642 .flags = GENL_ADMIN_PERM,
10643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10644 NL80211_FLAG_NEED_RTNL,
10645 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010646#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010647 {
10648 .cmd = NL80211_CMD_GET_WOWLAN,
10649 .doit = nl80211_get_wowlan,
10650 .policy = nl80211_policy,
10651 /* can be retrieved by unprivileged users */
10652 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10653 NL80211_FLAG_NEED_RTNL,
10654 },
10655 {
10656 .cmd = NL80211_CMD_SET_WOWLAN,
10657 .doit = nl80211_set_wowlan,
10658 .policy = nl80211_policy,
10659 .flags = GENL_ADMIN_PERM,
10660 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10661 NL80211_FLAG_NEED_RTNL,
10662 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010663#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010664 {
10665 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10666 .doit = nl80211_set_rekey_data,
10667 .policy = nl80211_policy,
10668 .flags = GENL_ADMIN_PERM,
10669 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010670 NL80211_FLAG_NEED_RTNL |
10671 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010672 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010673 {
10674 .cmd = NL80211_CMD_TDLS_MGMT,
10675 .doit = nl80211_tdls_mgmt,
10676 .policy = nl80211_policy,
10677 .flags = GENL_ADMIN_PERM,
10678 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10679 NL80211_FLAG_NEED_RTNL,
10680 },
10681 {
10682 .cmd = NL80211_CMD_TDLS_OPER,
10683 .doit = nl80211_tdls_oper,
10684 .policy = nl80211_policy,
10685 .flags = GENL_ADMIN_PERM,
10686 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10687 NL80211_FLAG_NEED_RTNL,
10688 },
Johannes Berg28946da2011-11-04 11:18:12 +010010689 {
10690 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10691 .doit = nl80211_register_unexpected_frame,
10692 .policy = nl80211_policy,
10693 .flags = GENL_ADMIN_PERM,
10694 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10695 NL80211_FLAG_NEED_RTNL,
10696 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010697 {
10698 .cmd = NL80211_CMD_PROBE_CLIENT,
10699 .doit = nl80211_probe_client,
10700 .policy = nl80211_policy,
10701 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010702 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010703 NL80211_FLAG_NEED_RTNL,
10704 },
Johannes Berg5e760232011-11-04 11:18:17 +010010705 {
10706 .cmd = NL80211_CMD_REGISTER_BEACONS,
10707 .doit = nl80211_register_beacons,
10708 .policy = nl80211_policy,
10709 .flags = GENL_ADMIN_PERM,
10710 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10711 NL80211_FLAG_NEED_RTNL,
10712 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010713 {
10714 .cmd = NL80211_CMD_SET_NOACK_MAP,
10715 .doit = nl80211_set_noack_map,
10716 .policy = nl80211_policy,
10717 .flags = GENL_ADMIN_PERM,
10718 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10719 NL80211_FLAG_NEED_RTNL,
10720 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010721 {
10722 .cmd = NL80211_CMD_START_P2P_DEVICE,
10723 .doit = nl80211_start_p2p_device,
10724 .policy = nl80211_policy,
10725 .flags = GENL_ADMIN_PERM,
10726 .internal_flags = NL80211_FLAG_NEED_WDEV |
10727 NL80211_FLAG_NEED_RTNL,
10728 },
10729 {
10730 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10731 .doit = nl80211_stop_p2p_device,
10732 .policy = nl80211_policy,
10733 .flags = GENL_ADMIN_PERM,
10734 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10735 NL80211_FLAG_NEED_RTNL,
10736 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010737 {
10738 .cmd = NL80211_CMD_SET_MCAST_RATE,
10739 .doit = nl80211_set_mcast_rate,
10740 .policy = nl80211_policy,
10741 .flags = GENL_ADMIN_PERM,
10742 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10743 NL80211_FLAG_NEED_RTNL,
10744 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010745 {
10746 .cmd = NL80211_CMD_SET_MAC_ACL,
10747 .doit = nl80211_set_mac_acl,
10748 .policy = nl80211_policy,
10749 .flags = GENL_ADMIN_PERM,
10750 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10751 NL80211_FLAG_NEED_RTNL,
10752 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010753 {
10754 .cmd = NL80211_CMD_RADAR_DETECT,
10755 .doit = nl80211_start_radar_detection,
10756 .policy = nl80211_policy,
10757 .flags = GENL_ADMIN_PERM,
10758 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10759 NL80211_FLAG_NEED_RTNL,
10760 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010761 {
10762 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10763 .doit = nl80211_get_protocol_features,
10764 .policy = nl80211_policy,
10765 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010766 {
10767 .cmd = NL80211_CMD_UPDATE_FT_IES,
10768 .doit = nl80211_update_ft_ies,
10769 .policy = nl80211_policy,
10770 .flags = GENL_ADMIN_PERM,
10771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10772 NL80211_FLAG_NEED_RTNL,
10773 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010774 {
10775 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10776 .doit = nl80211_crit_protocol_start,
10777 .policy = nl80211_policy,
10778 .flags = GENL_ADMIN_PERM,
10779 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10780 NL80211_FLAG_NEED_RTNL,
10781 },
10782 {
10783 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10784 .doit = nl80211_crit_protocol_stop,
10785 .policy = nl80211_policy,
10786 .flags = GENL_ADMIN_PERM,
10787 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10788 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010789 },
10790 {
10791 .cmd = NL80211_CMD_GET_COALESCE,
10792 .doit = nl80211_get_coalesce,
10793 .policy = nl80211_policy,
10794 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10795 NL80211_FLAG_NEED_RTNL,
10796 },
10797 {
10798 .cmd = NL80211_CMD_SET_COALESCE,
10799 .doit = nl80211_set_coalesce,
10800 .policy = nl80211_policy,
10801 .flags = GENL_ADMIN_PERM,
10802 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10803 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010804 },
10805 {
10806 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10807 .doit = nl80211_channel_switch,
10808 .policy = nl80211_policy,
10809 .flags = GENL_ADMIN_PERM,
10810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10811 NL80211_FLAG_NEED_RTNL,
10812 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010813 {
10814 .cmd = NL80211_CMD_VENDOR,
10815 .doit = nl80211_vendor_cmd,
10816 .policy = nl80211_policy,
10817 .flags = GENL_ADMIN_PERM,
10818 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10819 NL80211_FLAG_NEED_RTNL,
10820 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010821 {
10822 .cmd = NL80211_CMD_SET_QOS_MAP,
10823 .doit = nl80211_set_qos_map,
10824 .policy = nl80211_policy,
10825 .flags = GENL_ADMIN_PERM,
10826 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10827 NL80211_FLAG_NEED_RTNL,
10828 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010829 {
10830 .cmd = NL80211_CMD_ADD_TX_TS,
10831 .doit = nl80211_add_tx_ts,
10832 .policy = nl80211_policy,
10833 .flags = GENL_ADMIN_PERM,
10834 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10835 NL80211_FLAG_NEED_RTNL,
10836 },
10837 {
10838 .cmd = NL80211_CMD_DEL_TX_TS,
10839 .doit = nl80211_del_tx_ts,
10840 .policy = nl80211_policy,
10841 .flags = GENL_ADMIN_PERM,
10842 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10843 NL80211_FLAG_NEED_RTNL,
10844 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020010845 {
10846 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
10847 .doit = nl80211_tdls_channel_switch,
10848 .policy = nl80211_policy,
10849 .flags = GENL_ADMIN_PERM,
10850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10851 NL80211_FLAG_NEED_RTNL,
10852 },
10853 {
10854 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
10855 .doit = nl80211_tdls_cancel_channel_switch,
10856 .policy = nl80211_policy,
10857 .flags = GENL_ADMIN_PERM,
10858 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10859 NL80211_FLAG_NEED_RTNL,
10860 },
Johannes Berg55682962007-09-20 13:09:35 -040010861};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010862
Johannes Berg55682962007-09-20 13:09:35 -040010863/* notification functions */
10864
Johannes Berg3bb20552014-05-26 13:52:25 +020010865void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10866 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010867{
10868 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010869 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010870
Johannes Berg3bb20552014-05-26 13:52:25 +020010871 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10872 cmd != NL80211_CMD_DEL_WIPHY);
10873
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010875 if (!msg)
10876 return;
10877
Johannes Berg3bb20552014-05-26 13:52:25 +020010878 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010879 nlmsg_free(msg);
10880 return;
10881 }
10882
Johannes Berg68eb5502013-11-19 15:19:38 +010010883 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010884 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010885}
10886
Johannes Berg362a4152009-05-24 16:43:15 +020010887static int nl80211_add_scan_req(struct sk_buff *msg,
10888 struct cfg80211_registered_device *rdev)
10889{
10890 struct cfg80211_scan_request *req = rdev->scan_req;
10891 struct nlattr *nest;
10892 int i;
10893
10894 if (WARN_ON(!req))
10895 return 0;
10896
10897 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10898 if (!nest)
10899 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010900 for (i = 0; i < req->n_ssids; i++) {
10901 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10902 goto nla_put_failure;
10903 }
Johannes Berg362a4152009-05-24 16:43:15 +020010904 nla_nest_end(msg, nest);
10905
10906 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10907 if (!nest)
10908 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010909 for (i = 0; i < req->n_channels; i++) {
10910 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10911 goto nla_put_failure;
10912 }
Johannes Berg362a4152009-05-24 16:43:15 +020010913 nla_nest_end(msg, nest);
10914
David S. Miller9360ffd2012-03-29 04:41:26 -040010915 if (req->ie &&
10916 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10917 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010918
Johannes Bergae917c92013-10-25 11:05:22 +020010919 if (req->flags &&
10920 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10921 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010922
Johannes Berg362a4152009-05-24 16:43:15 +020010923 return 0;
10924 nla_put_failure:
10925 return -ENOBUFS;
10926}
10927
Johannes Berga538e2d2009-06-16 19:56:42 +020010928static int nl80211_send_scan_msg(struct sk_buff *msg,
10929 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010930 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010931 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010932 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010933{
10934 void *hdr;
10935
Eric W. Biederman15e47302012-09-07 20:12:54 +000010936 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010937 if (!hdr)
10938 return -1;
10939
David S. Miller9360ffd2012-03-29 04:41:26 -040010940 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010941 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10942 wdev->netdev->ifindex)) ||
10943 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010944 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010945
Johannes Berg362a4152009-05-24 16:43:15 +020010946 /* ignore errors and send incomplete event anyway */
10947 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010948
10949 return genlmsg_end(msg, hdr);
10950
10951 nla_put_failure:
10952 genlmsg_cancel(msg, hdr);
10953 return -EMSGSIZE;
10954}
10955
Luciano Coelho807f8a82011-05-11 17:09:35 +030010956static int
10957nl80211_send_sched_scan_msg(struct sk_buff *msg,
10958 struct cfg80211_registered_device *rdev,
10959 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010960 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010961{
10962 void *hdr;
10963
Eric W. Biederman15e47302012-09-07 20:12:54 +000010964 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010965 if (!hdr)
10966 return -1;
10967
David S. Miller9360ffd2012-03-29 04:41:26 -040010968 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10969 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10970 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010971
10972 return genlmsg_end(msg, hdr);
10973
10974 nla_put_failure:
10975 genlmsg_cancel(msg, hdr);
10976 return -EMSGSIZE;
10977}
10978
Johannes Berga538e2d2009-06-16 19:56:42 +020010979void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010980 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010981{
10982 struct sk_buff *msg;
10983
Thomas Graf58050fc2012-06-28 03:57:45 +000010984 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010985 if (!msg)
10986 return;
10987
Johannes Bergfd014282012-06-18 19:17:03 +020010988 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010989 NL80211_CMD_TRIGGER_SCAN) < 0) {
10990 nlmsg_free(msg);
10991 return;
10992 }
10993
Johannes Berg68eb5502013-11-19 15:19:38 +010010994 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010995 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010996}
10997
Johannes Bergf9d15d12014-01-22 11:14:19 +020010998struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10999 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011000{
11001 struct sk_buff *msg;
11002
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011003 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011004 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011005 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011006
Johannes Bergfd014282012-06-18 19:17:03 +020011007 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011008 aborted ? NL80211_CMD_SCAN_ABORTED :
11009 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011010 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011011 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011012 }
11013
Johannes Bergf9d15d12014-01-22 11:14:19 +020011014 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011015}
11016
Johannes Bergf9d15d12014-01-22 11:14:19 +020011017void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11018 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011019{
Johannes Berg2a519312009-02-10 21:25:55 +010011020 if (!msg)
11021 return;
11022
Johannes Berg68eb5502013-11-19 15:19:38 +010011023 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011024 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011025}
11026
Luciano Coelho807f8a82011-05-11 17:09:35 +030011027void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11028 struct net_device *netdev)
11029{
11030 struct sk_buff *msg;
11031
11032 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11033 if (!msg)
11034 return;
11035
11036 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11037 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11038 nlmsg_free(msg);
11039 return;
11040 }
11041
Johannes Berg68eb5502013-11-19 15:19:38 +010011042 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011043 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011044}
11045
11046void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11047 struct net_device *netdev, u32 cmd)
11048{
11049 struct sk_buff *msg;
11050
Thomas Graf58050fc2012-06-28 03:57:45 +000011051 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011052 if (!msg)
11053 return;
11054
11055 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11056 nlmsg_free(msg);
11057 return;
11058 }
11059
Johannes Berg68eb5502013-11-19 15:19:38 +010011060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011061 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011062}
11063
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011064static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11065 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011066{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011067 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011068 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11069 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011070
David S. Miller9360ffd2012-03-29 04:41:26 -040011071 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11072 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11073 NL80211_REGDOM_TYPE_WORLD))
11074 goto nla_put_failure;
11075 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11076 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11077 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11078 goto nla_put_failure;
11079 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11080 request->intersect) {
11081 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11082 NL80211_REGDOM_TYPE_INTERSECTION))
11083 goto nla_put_failure;
11084 } else {
11085 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11086 NL80211_REGDOM_TYPE_COUNTRY) ||
11087 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11088 request->alpha2))
11089 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011090 }
11091
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011092 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11093 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11094
11095 if (wiphy &&
11096 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11097 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011098
11099 if (wiphy &&
11100 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11101 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11102 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011103 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011104
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011105 return true;
11106
11107nla_put_failure:
11108 return false;
11109}
11110
11111/*
11112 * This can happen on global regulatory changes or device specific settings
11113 * based on custom regulatory domains.
11114 */
11115void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11116 struct regulatory_request *request)
11117{
11118 struct sk_buff *msg;
11119 void *hdr;
11120
11121 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11122 if (!msg)
11123 return;
11124
11125 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11126 if (!hdr) {
11127 nlmsg_free(msg);
11128 return;
11129 }
11130
11131 if (nl80211_reg_change_event_fill(msg, request) == false)
11132 goto nla_put_failure;
11133
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011134 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011135
Johannes Bergbc43b282009-07-25 10:54:13 +020011136 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011137 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011138 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011139 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011140
11141 return;
11142
11143nla_put_failure:
11144 genlmsg_cancel(msg, hdr);
11145 nlmsg_free(msg);
11146}
11147
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011148static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11149 struct net_device *netdev,
11150 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011151 enum nl80211_commands cmd, gfp_t gfp,
11152 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011153{
11154 struct sk_buff *msg;
11155 void *hdr;
11156
Johannes Berge6d6e342009-07-01 21:26:47 +020011157 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011158 if (!msg)
11159 return;
11160
11161 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11162 if (!hdr) {
11163 nlmsg_free(msg);
11164 return;
11165 }
11166
David S. Miller9360ffd2012-03-29 04:41:26 -040011167 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11168 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11169 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11170 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011171
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011172 if (uapsd_queues >= 0) {
11173 struct nlattr *nla_wmm =
11174 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11175 if (!nla_wmm)
11176 goto nla_put_failure;
11177
11178 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11179 uapsd_queues))
11180 goto nla_put_failure;
11181
11182 nla_nest_end(msg, nla_wmm);
11183 }
11184
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011185 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011186
Johannes Berg68eb5502013-11-19 15:19:38 +010011187 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011188 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011189 return;
11190
11191 nla_put_failure:
11192 genlmsg_cancel(msg, hdr);
11193 nlmsg_free(msg);
11194}
11195
11196void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011197 struct net_device *netdev, const u8 *buf,
11198 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011199{
11200 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011201 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011202}
11203
11204void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11205 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011206 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011207{
Johannes Berge6d6e342009-07-01 21:26:47 +020011208 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011209 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011210}
11211
Jouni Malinen53b46b82009-03-27 20:53:56 +020011212void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011213 struct net_device *netdev, const u8 *buf,
11214 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011215{
11216 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011217 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011218}
11219
Jouni Malinen53b46b82009-03-27 20:53:56 +020011220void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11221 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011222 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011223{
11224 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011225 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011226}
11227
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011228void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11229 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011230{
Johannes Berg947add32013-02-22 22:05:20 +010011231 struct wireless_dev *wdev = dev->ieee80211_ptr;
11232 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011233 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011234 const struct ieee80211_mgmt *mgmt = (void *)buf;
11235 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011236
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011237 if (WARN_ON(len < 2))
11238 return;
11239
11240 if (ieee80211_is_deauth(mgmt->frame_control))
11241 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11242 else
11243 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11244
11245 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011246 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011247}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011248EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011249
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011250static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11251 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011252 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011253{
11254 struct sk_buff *msg;
11255 void *hdr;
11256
Johannes Berge6d6e342009-07-01 21:26:47 +020011257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011258 if (!msg)
11259 return;
11260
11261 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11262 if (!hdr) {
11263 nlmsg_free(msg);
11264 return;
11265 }
11266
David S. Miller9360ffd2012-03-29 04:41:26 -040011267 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11268 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11269 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11270 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11271 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011272
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011273 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011274
Johannes Berg68eb5502013-11-19 15:19:38 +010011275 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011276 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011277 return;
11278
11279 nla_put_failure:
11280 genlmsg_cancel(msg, hdr);
11281 nlmsg_free(msg);
11282}
11283
11284void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011285 struct net_device *netdev, const u8 *addr,
11286 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011287{
11288 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011289 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011290}
11291
11292void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011293 struct net_device *netdev, const u8 *addr,
11294 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011295{
Johannes Berge6d6e342009-07-01 21:26:47 +020011296 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11297 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011298}
11299
Samuel Ortizb23aa672009-07-01 21:26:54 +020011300void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11301 struct net_device *netdev, const u8 *bssid,
11302 const u8 *req_ie, size_t req_ie_len,
11303 const u8 *resp_ie, size_t resp_ie_len,
11304 u16 status, gfp_t gfp)
11305{
11306 struct sk_buff *msg;
11307 void *hdr;
11308
Thomas Graf58050fc2012-06-28 03:57:45 +000011309 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011310 if (!msg)
11311 return;
11312
11313 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11314 if (!hdr) {
11315 nlmsg_free(msg);
11316 return;
11317 }
11318
David S. Miller9360ffd2012-03-29 04:41:26 -040011319 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11320 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11321 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11322 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11323 (req_ie &&
11324 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11325 (resp_ie &&
11326 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11327 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011328
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011329 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011330
Johannes Berg68eb5502013-11-19 15:19:38 +010011331 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011332 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011333 return;
11334
11335 nla_put_failure:
11336 genlmsg_cancel(msg, hdr);
11337 nlmsg_free(msg);
11338
11339}
11340
11341void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11342 struct net_device *netdev, const u8 *bssid,
11343 const u8 *req_ie, size_t req_ie_len,
11344 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11345{
11346 struct sk_buff *msg;
11347 void *hdr;
11348
Thomas Graf58050fc2012-06-28 03:57:45 +000011349 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011350 if (!msg)
11351 return;
11352
11353 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11354 if (!hdr) {
11355 nlmsg_free(msg);
11356 return;
11357 }
11358
David S. Miller9360ffd2012-03-29 04:41:26 -040011359 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11360 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11361 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11362 (req_ie &&
11363 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11364 (resp_ie &&
11365 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11366 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011367
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011368 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011369
Johannes Berg68eb5502013-11-19 15:19:38 +010011370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011371 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011372 return;
11373
11374 nla_put_failure:
11375 genlmsg_cancel(msg, hdr);
11376 nlmsg_free(msg);
11377
11378}
11379
11380void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11381 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020011382 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011383{
11384 struct sk_buff *msg;
11385 void *hdr;
11386
Thomas Graf58050fc2012-06-28 03:57:45 +000011387 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011388 if (!msg)
11389 return;
11390
11391 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11392 if (!hdr) {
11393 nlmsg_free(msg);
11394 return;
11395 }
11396
David S. Miller9360ffd2012-03-29 04:41:26 -040011397 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11398 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11399 (from_ap && reason &&
11400 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11401 (from_ap &&
11402 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11403 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11404 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011405
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011406 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011407
Johannes Berg68eb5502013-11-19 15:19:38 +010011408 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011409 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011410 return;
11411
11412 nla_put_failure:
11413 genlmsg_cancel(msg, hdr);
11414 nlmsg_free(msg);
11415
11416}
11417
Johannes Berg04a773a2009-04-19 21:24:32 +020011418void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11419 struct net_device *netdev, const u8 *bssid,
11420 gfp_t gfp)
11421{
11422 struct sk_buff *msg;
11423 void *hdr;
11424
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011425 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011426 if (!msg)
11427 return;
11428
11429 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11430 if (!hdr) {
11431 nlmsg_free(msg);
11432 return;
11433 }
11434
David S. Miller9360ffd2012-03-29 04:41:26 -040011435 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11436 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11437 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11438 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011439
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011440 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011441
Johannes Berg68eb5502013-11-19 15:19:38 +010011442 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011443 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011444 return;
11445
11446 nla_put_failure:
11447 genlmsg_cancel(msg, hdr);
11448 nlmsg_free(msg);
11449}
11450
Johannes Berg947add32013-02-22 22:05:20 +010011451void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11452 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011453{
Johannes Berg947add32013-02-22 22:05:20 +010011454 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011455 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011456 struct sk_buff *msg;
11457 void *hdr;
11458
Johannes Berg947add32013-02-22 22:05:20 +010011459 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11460 return;
11461
11462 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11463
Javier Cardonac93b5e72011-04-07 15:08:34 -070011464 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11465 if (!msg)
11466 return;
11467
11468 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11469 if (!hdr) {
11470 nlmsg_free(msg);
11471 return;
11472 }
11473
David S. Miller9360ffd2012-03-29 04:41:26 -040011474 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011475 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11476 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011477 (ie_len && ie &&
11478 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11479 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011480
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011481 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011482
Johannes Berg68eb5502013-11-19 15:19:38 +010011483 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011484 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011485 return;
11486
11487 nla_put_failure:
11488 genlmsg_cancel(msg, hdr);
11489 nlmsg_free(msg);
11490}
Johannes Berg947add32013-02-22 22:05:20 +010011491EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011492
Jouni Malinena3b8b052009-03-27 21:59:49 +020011493void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11494 struct net_device *netdev, const u8 *addr,
11495 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011496 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011497{
11498 struct sk_buff *msg;
11499 void *hdr;
11500
Johannes Berge6d6e342009-07-01 21:26:47 +020011501 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011502 if (!msg)
11503 return;
11504
11505 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11506 if (!hdr) {
11507 nlmsg_free(msg);
11508 return;
11509 }
11510
David S. Miller9360ffd2012-03-29 04:41:26 -040011511 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11512 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11513 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11514 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11515 (key_id != -1 &&
11516 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11517 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11518 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011519
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011520 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011521
Johannes Berg68eb5502013-11-19 15:19:38 +010011522 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011523 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011524 return;
11525
11526 nla_put_failure:
11527 genlmsg_cancel(msg, hdr);
11528 nlmsg_free(msg);
11529}
11530
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011531void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11532 struct ieee80211_channel *channel_before,
11533 struct ieee80211_channel *channel_after)
11534{
11535 struct sk_buff *msg;
11536 void *hdr;
11537 struct nlattr *nl_freq;
11538
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011539 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011540 if (!msg)
11541 return;
11542
11543 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11544 if (!hdr) {
11545 nlmsg_free(msg);
11546 return;
11547 }
11548
11549 /*
11550 * Since we are applying the beacon hint to a wiphy we know its
11551 * wiphy_idx is valid
11552 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011553 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11554 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011555
11556 /* Before */
11557 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11558 if (!nl_freq)
11559 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011560 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011561 goto nla_put_failure;
11562 nla_nest_end(msg, nl_freq);
11563
11564 /* After */
11565 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11566 if (!nl_freq)
11567 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011568 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011569 goto nla_put_failure;
11570 nla_nest_end(msg, nl_freq);
11571
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011572 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011573
Johannes Berg463d0182009-07-14 00:33:35 +020011574 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011575 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011576 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011577 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011578
11579 return;
11580
11581nla_put_failure:
11582 genlmsg_cancel(msg, hdr);
11583 nlmsg_free(msg);
11584}
11585
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011586static void nl80211_send_remain_on_chan_event(
11587 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011588 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011589 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011590 unsigned int duration, gfp_t gfp)
11591{
11592 struct sk_buff *msg;
11593 void *hdr;
11594
11595 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11596 if (!msg)
11597 return;
11598
11599 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11600 if (!hdr) {
11601 nlmsg_free(msg);
11602 return;
11603 }
11604
David S. Miller9360ffd2012-03-29 04:41:26 -040011605 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011606 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11607 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011608 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011609 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011610 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11611 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011612 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11613 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011614
David S. Miller9360ffd2012-03-29 04:41:26 -040011615 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11616 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11617 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011618
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011619 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011620
Johannes Berg68eb5502013-11-19 15:19:38 +010011621 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011622 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011623 return;
11624
11625 nla_put_failure:
11626 genlmsg_cancel(msg, hdr);
11627 nlmsg_free(msg);
11628}
11629
Johannes Berg947add32013-02-22 22:05:20 +010011630void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11631 struct ieee80211_channel *chan,
11632 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011633{
Johannes Berg947add32013-02-22 22:05:20 +010011634 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011635 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011636
11637 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011638 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011639 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011640 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011641}
Johannes Berg947add32013-02-22 22:05:20 +010011642EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011643
Johannes Berg947add32013-02-22 22:05:20 +010011644void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11645 struct ieee80211_channel *chan,
11646 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011647{
Johannes Berg947add32013-02-22 22:05:20 +010011648 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011649 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011650
11651 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011652 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011653 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011654}
Johannes Berg947add32013-02-22 22:05:20 +010011655EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011656
Johannes Berg947add32013-02-22 22:05:20 +010011657void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11658 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011659{
Johannes Berg947add32013-02-22 22:05:20 +010011660 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011661 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011662 struct sk_buff *msg;
11663
Johannes Berg947add32013-02-22 22:05:20 +010011664 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11665
Thomas Graf58050fc2012-06-28 03:57:45 +000011666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011667 if (!msg)
11668 return;
11669
John W. Linville66266b32012-03-15 13:25:41 -040011670 if (nl80211_send_station(msg, 0, 0, 0,
11671 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011672 nlmsg_free(msg);
11673 return;
11674 }
11675
Johannes Berg68eb5502013-11-19 15:19:38 +010011676 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011677 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011678}
Johannes Berg947add32013-02-22 22:05:20 +010011679EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011680
Johannes Berg947add32013-02-22 22:05:20 +010011681void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011682{
Johannes Berg947add32013-02-22 22:05:20 +010011683 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011684 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011685 struct sk_buff *msg;
11686 void *hdr;
11687
Johannes Berg947add32013-02-22 22:05:20 +010011688 trace_cfg80211_del_sta(dev, mac_addr);
11689
Thomas Graf58050fc2012-06-28 03:57:45 +000011690 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011691 if (!msg)
11692 return;
11693
11694 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11695 if (!hdr) {
11696 nlmsg_free(msg);
11697 return;
11698 }
11699
David S. Miller9360ffd2012-03-29 04:41:26 -040011700 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11701 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11702 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011703
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011704 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011705
Johannes Berg68eb5502013-11-19 15:19:38 +010011706 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011707 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011708 return;
11709
11710 nla_put_failure:
11711 genlmsg_cancel(msg, hdr);
11712 nlmsg_free(msg);
11713}
Johannes Berg947add32013-02-22 22:05:20 +010011714EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011715
Johannes Berg947add32013-02-22 22:05:20 +010011716void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11717 enum nl80211_connect_failed_reason reason,
11718 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011719{
Johannes Berg947add32013-02-22 22:05:20 +010011720 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011721 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011722 struct sk_buff *msg;
11723 void *hdr;
11724
11725 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11726 if (!msg)
11727 return;
11728
11729 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11730 if (!hdr) {
11731 nlmsg_free(msg);
11732 return;
11733 }
11734
11735 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11736 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11737 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11738 goto nla_put_failure;
11739
11740 genlmsg_end(msg, hdr);
11741
Johannes Berg68eb5502013-11-19 15:19:38 +010011742 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011743 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011744 return;
11745
11746 nla_put_failure:
11747 genlmsg_cancel(msg, hdr);
11748 nlmsg_free(msg);
11749}
Johannes Berg947add32013-02-22 22:05:20 +010011750EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011751
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011752static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11753 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011754{
11755 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011756 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011757 struct sk_buff *msg;
11758 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011759 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011760
Eric W. Biederman15e47302012-09-07 20:12:54 +000011761 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011762 return false;
11763
11764 msg = nlmsg_new(100, gfp);
11765 if (!msg)
11766 return true;
11767
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011768 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011769 if (!hdr) {
11770 nlmsg_free(msg);
11771 return true;
11772 }
11773
David S. Miller9360ffd2012-03-29 04:41:26 -040011774 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11775 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11776 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11777 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011778
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011779 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011780 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011781 return true;
11782
11783 nla_put_failure:
11784 genlmsg_cancel(msg, hdr);
11785 nlmsg_free(msg);
11786 return true;
11787}
11788
Johannes Berg947add32013-02-22 22:05:20 +010011789bool cfg80211_rx_spurious_frame(struct net_device *dev,
11790 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011791{
Johannes Berg947add32013-02-22 22:05:20 +010011792 struct wireless_dev *wdev = dev->ieee80211_ptr;
11793 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011794
Johannes Berg947add32013-02-22 22:05:20 +010011795 trace_cfg80211_rx_spurious_frame(dev, addr);
11796
11797 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11798 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11799 trace_cfg80211_return_bool(false);
11800 return false;
11801 }
11802 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11803 addr, gfp);
11804 trace_cfg80211_return_bool(ret);
11805 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011806}
Johannes Berg947add32013-02-22 22:05:20 +010011807EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11808
11809bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11810 const u8 *addr, gfp_t gfp)
11811{
11812 struct wireless_dev *wdev = dev->ieee80211_ptr;
11813 bool ret;
11814
11815 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11816
11817 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11818 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11819 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11820 trace_cfg80211_return_bool(false);
11821 return false;
11822 }
11823 ret = __nl80211_unexpected_frame(dev,
11824 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11825 addr, gfp);
11826 trace_cfg80211_return_bool(ret);
11827 return ret;
11828}
11829EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011830
Johannes Berg2e161f72010-08-12 15:38:38 +020011831int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011832 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011833 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011834 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011835{
Johannes Berg71bbc992012-06-15 15:30:18 +020011836 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011837 struct sk_buff *msg;
11838 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011839
11840 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11841 if (!msg)
11842 return -ENOMEM;
11843
Johannes Berg2e161f72010-08-12 15:38:38 +020011844 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011845 if (!hdr) {
11846 nlmsg_free(msg);
11847 return -ENOMEM;
11848 }
11849
David S. Miller9360ffd2012-03-29 04:41:26 -040011850 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011851 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11852 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011853 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011854 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11855 (sig_dbm &&
11856 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011857 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11858 (flags &&
11859 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011860 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011861
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011862 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011863
Eric W. Biederman15e47302012-09-07 20:12:54 +000011864 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011865
11866 nla_put_failure:
11867 genlmsg_cancel(msg, hdr);
11868 nlmsg_free(msg);
11869 return -ENOBUFS;
11870}
11871
Johannes Berg947add32013-02-22 22:05:20 +010011872void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11873 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011874{
Johannes Berg947add32013-02-22 22:05:20 +010011875 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011876 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011877 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011878 struct sk_buff *msg;
11879 void *hdr;
11880
Johannes Berg947add32013-02-22 22:05:20 +010011881 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11882
Jouni Malinen026331c2010-02-15 12:53:10 +020011883 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11884 if (!msg)
11885 return;
11886
Johannes Berg2e161f72010-08-12 15:38:38 +020011887 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011888 if (!hdr) {
11889 nlmsg_free(msg);
11890 return;
11891 }
11892
David S. Miller9360ffd2012-03-29 04:41:26 -040011893 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011894 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11895 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011896 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011897 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11898 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11899 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11900 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011901
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011902 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011903
Johannes Berg68eb5502013-11-19 15:19:38 +010011904 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011905 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011906 return;
11907
11908 nla_put_failure:
11909 genlmsg_cancel(msg, hdr);
11910 nlmsg_free(msg);
11911}
Johannes Berg947add32013-02-22 22:05:20 +010011912EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011913
Johannes Berg5b97f492014-11-26 12:37:43 +010011914static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
11915 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011916{
Johannes Berg947add32013-02-22 22:05:20 +010011917 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010011918 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
11919 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11920 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011921
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011922 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010011923 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011924
Johannes Berg5b97f492014-11-26 12:37:43 +010011925 cb = (void **)msg->cb;
11926
11927 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11928 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011929 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010011930 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011931 }
11932
David S. Miller9360ffd2012-03-29 04:41:26 -040011933 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011934 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011935 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011936
Johannes Berg5b97f492014-11-26 12:37:43 +010011937 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011938 goto nla_put_failure;
11939
Johannes Berg5b97f492014-11-26 12:37:43 +010011940 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
11941 if (!cb[1])
11942 goto nla_put_failure;
11943
11944 cb[2] = rdev;
11945
11946 return msg;
11947 nla_put_failure:
11948 nlmsg_free(msg);
11949 return NULL;
11950}
11951
11952static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
11953{
11954 void **cb = (void **)msg->cb;
11955 struct cfg80211_registered_device *rdev = cb[2];
11956
11957 nla_nest_end(msg, cb[1]);
11958 genlmsg_end(msg, cb[0]);
11959
11960 memset(msg->cb, 0, sizeof(msg->cb));
11961
11962 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11963 NL80211_MCGRP_MLME, gfp);
11964}
11965
11966void cfg80211_cqm_rssi_notify(struct net_device *dev,
11967 enum nl80211_cqm_rssi_threshold_event rssi_event,
11968 gfp_t gfp)
11969{
11970 struct sk_buff *msg;
11971
11972 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11973
Johannes Berg98f03342014-11-26 12:42:02 +010011974 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
11975 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
11976 return;
11977
Johannes Berg5b97f492014-11-26 12:37:43 +010011978 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
11979 if (!msg)
11980 return;
11981
David S. Miller9360ffd2012-03-29 04:41:26 -040011982 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11983 rssi_event))
11984 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011985
Johannes Berg5b97f492014-11-26 12:37:43 +010011986 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011987
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011988 return;
11989
11990 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011991 nlmsg_free(msg);
11992}
Johannes Berg947add32013-02-22 22:05:20 +010011993EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011994
Johannes Berg5b97f492014-11-26 12:37:43 +010011995void cfg80211_cqm_txe_notify(struct net_device *dev,
11996 const u8 *peer, u32 num_packets,
11997 u32 rate, u32 intvl, gfp_t gfp)
11998{
11999 struct sk_buff *msg;
12000
12001 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12002 if (!msg)
12003 return;
12004
12005 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12006 goto nla_put_failure;
12007
12008 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12009 goto nla_put_failure;
12010
12011 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12012 goto nla_put_failure;
12013
12014 cfg80211_send_cqm(msg, gfp);
12015 return;
12016
12017 nla_put_failure:
12018 nlmsg_free(msg);
12019}
12020EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12021
12022void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12023 const u8 *peer, u32 num_packets, gfp_t gfp)
12024{
12025 struct sk_buff *msg;
12026
12027 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12028
12029 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12030 if (!msg)
12031 return;
12032
12033 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12034 goto nla_put_failure;
12035
12036 cfg80211_send_cqm(msg, gfp);
12037 return;
12038
12039 nla_put_failure:
12040 nlmsg_free(msg);
12041}
12042EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12043
Johannes Berg98f03342014-11-26 12:42:02 +010012044void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12045{
12046 struct sk_buff *msg;
12047
12048 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12049 if (!msg)
12050 return;
12051
12052 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12053 goto nla_put_failure;
12054
12055 cfg80211_send_cqm(msg, gfp);
12056 return;
12057
12058 nla_put_failure:
12059 nlmsg_free(msg);
12060}
12061EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12062
Johannes Berg947add32013-02-22 22:05:20 +010012063static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12064 struct net_device *netdev, const u8 *bssid,
12065 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012066{
12067 struct sk_buff *msg;
12068 struct nlattr *rekey_attr;
12069 void *hdr;
12070
Thomas Graf58050fc2012-06-28 03:57:45 +000012071 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012072 if (!msg)
12073 return;
12074
12075 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12076 if (!hdr) {
12077 nlmsg_free(msg);
12078 return;
12079 }
12080
David S. Miller9360ffd2012-03-29 04:41:26 -040012081 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12082 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12083 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12084 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012085
12086 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12087 if (!rekey_attr)
12088 goto nla_put_failure;
12089
David S. Miller9360ffd2012-03-29 04:41:26 -040012090 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12091 NL80211_REPLAY_CTR_LEN, replay_ctr))
12092 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012093
12094 nla_nest_end(msg, rekey_attr);
12095
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012096 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012097
Johannes Berg68eb5502013-11-19 15:19:38 +010012098 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012099 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012100 return;
12101
12102 nla_put_failure:
12103 genlmsg_cancel(msg, hdr);
12104 nlmsg_free(msg);
12105}
12106
Johannes Berg947add32013-02-22 22:05:20 +010012107void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12108 const u8 *replay_ctr, gfp_t gfp)
12109{
12110 struct wireless_dev *wdev = dev->ieee80211_ptr;
12111 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012112 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012113
12114 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12115 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12116}
12117EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12118
12119static void
12120nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12121 struct net_device *netdev, int index,
12122 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012123{
12124 struct sk_buff *msg;
12125 struct nlattr *attr;
12126 void *hdr;
12127
Thomas Graf58050fc2012-06-28 03:57:45 +000012128 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012129 if (!msg)
12130 return;
12131
12132 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12133 if (!hdr) {
12134 nlmsg_free(msg);
12135 return;
12136 }
12137
David S. Miller9360ffd2012-03-29 04:41:26 -040012138 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12139 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12140 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012141
12142 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12143 if (!attr)
12144 goto nla_put_failure;
12145
David S. Miller9360ffd2012-03-29 04:41:26 -040012146 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12147 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12148 (preauth &&
12149 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12150 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012151
12152 nla_nest_end(msg, attr);
12153
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012154 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012155
Johannes Berg68eb5502013-11-19 15:19:38 +010012156 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012157 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012158 return;
12159
12160 nla_put_failure:
12161 genlmsg_cancel(msg, hdr);
12162 nlmsg_free(msg);
12163}
12164
Johannes Berg947add32013-02-22 22:05:20 +010012165void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12166 const u8 *bssid, bool preauth, gfp_t gfp)
12167{
12168 struct wireless_dev *wdev = dev->ieee80211_ptr;
12169 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012170 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012171
12172 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12173 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12174}
12175EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12176
12177static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12178 struct net_device *netdev,
12179 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012180 gfp_t gfp,
12181 enum nl80211_commands notif,
12182 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012183{
12184 struct sk_buff *msg;
12185 void *hdr;
12186
Thomas Graf58050fc2012-06-28 03:57:45 +000012187 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012188 if (!msg)
12189 return;
12190
Luciano Coelhof8d75522014-11-07 14:31:35 +020012191 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012192 if (!hdr) {
12193 nlmsg_free(msg);
12194 return;
12195 }
12196
Johannes Berg683b6d32012-11-08 21:25:48 +010012197 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12198 goto nla_put_failure;
12199
12200 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012201 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012202
Luciano Coelhof8d75522014-11-07 14:31:35 +020012203 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12204 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12205 goto nla_put_failure;
12206
Thomas Pedersen53145262012-04-06 13:35:47 -070012207 genlmsg_end(msg, hdr);
12208
Johannes Berg68eb5502013-11-19 15:19:38 +010012209 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012210 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012211 return;
12212
12213 nla_put_failure:
12214 genlmsg_cancel(msg, hdr);
12215 nlmsg_free(msg);
12216}
12217
Johannes Berg947add32013-02-22 22:05:20 +010012218void cfg80211_ch_switch_notify(struct net_device *dev,
12219 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012220{
Johannes Berg947add32013-02-22 22:05:20 +010012221 struct wireless_dev *wdev = dev->ieee80211_ptr;
12222 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012223 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012224
Simon Wunderliche487eae2013-11-21 18:19:51 +010012225 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012226
Simon Wunderliche487eae2013-11-21 18:19:51 +010012227 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012228
Michal Kazior9e0e2962014-01-29 14:22:27 +010012229 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012230 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012231 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12232 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012233}
12234EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12235
Luciano Coelhof8d75522014-11-07 14:31:35 +020012236void cfg80211_ch_switch_started_notify(struct net_device *dev,
12237 struct cfg80211_chan_def *chandef,
12238 u8 count)
12239{
12240 struct wireless_dev *wdev = dev->ieee80211_ptr;
12241 struct wiphy *wiphy = wdev->wiphy;
12242 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12243
12244 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12245
12246 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12247 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12248}
12249EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12250
Thomas Pedersen84f10702012-07-12 16:17:33 -070012251void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012252nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012253 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012254 enum nl80211_radar_event event,
12255 struct net_device *netdev, gfp_t gfp)
12256{
12257 struct sk_buff *msg;
12258 void *hdr;
12259
12260 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12261 if (!msg)
12262 return;
12263
12264 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12265 if (!hdr) {
12266 nlmsg_free(msg);
12267 return;
12268 }
12269
12270 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12271 goto nla_put_failure;
12272
12273 /* NOP and radar events don't need a netdev parameter */
12274 if (netdev) {
12275 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12276
12277 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12278 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12279 goto nla_put_failure;
12280 }
12281
12282 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12283 goto nla_put_failure;
12284
12285 if (nl80211_send_chandef(msg, chandef))
12286 goto nla_put_failure;
12287
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012288 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012289
Johannes Berg68eb5502013-11-19 15:19:38 +010012290 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012291 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012292 return;
12293
12294 nla_put_failure:
12295 genlmsg_cancel(msg, hdr);
12296 nlmsg_free(msg);
12297}
12298
Johannes Berg7f6cf312011-11-04 11:18:15 +010012299void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12300 u64 cookie, bool acked, gfp_t gfp)
12301{
12302 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012303 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012304 struct sk_buff *msg;
12305 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012306
Beni Lev4ee3e062012-08-27 12:49:39 +030012307 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12308
Thomas Graf58050fc2012-06-28 03:57:45 +000012309 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012310
Johannes Berg7f6cf312011-11-04 11:18:15 +010012311 if (!msg)
12312 return;
12313
12314 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12315 if (!hdr) {
12316 nlmsg_free(msg);
12317 return;
12318 }
12319
David S. Miller9360ffd2012-03-29 04:41:26 -040012320 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12321 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12322 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12323 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12324 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12325 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012326
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012327 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012328
Johannes Berg68eb5502013-11-19 15:19:38 +010012329 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012330 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012331 return;
12332
12333 nla_put_failure:
12334 genlmsg_cancel(msg, hdr);
12335 nlmsg_free(msg);
12336}
12337EXPORT_SYMBOL(cfg80211_probe_status);
12338
Johannes Berg5e760232011-11-04 11:18:17 +010012339void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12340 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012341 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012342{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012343 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012344 struct sk_buff *msg;
12345 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012346 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012347
Beni Lev4ee3e062012-08-27 12:49:39 +030012348 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12349
Ben Greear37c73b52012-10-26 14:49:25 -070012350 spin_lock_bh(&rdev->beacon_registrations_lock);
12351 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12352 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12353 if (!msg) {
12354 spin_unlock_bh(&rdev->beacon_registrations_lock);
12355 return;
12356 }
Johannes Berg5e760232011-11-04 11:18:17 +010012357
Ben Greear37c73b52012-10-26 14:49:25 -070012358 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12359 if (!hdr)
12360 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012361
Ben Greear37c73b52012-10-26 14:49:25 -070012362 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12363 (freq &&
12364 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12365 (sig_dbm &&
12366 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12367 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12368 goto nla_put_failure;
12369
12370 genlmsg_end(msg, hdr);
12371
12372 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012373 }
Ben Greear37c73b52012-10-26 14:49:25 -070012374 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012375 return;
12376
12377 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012378 spin_unlock_bh(&rdev->beacon_registrations_lock);
12379 if (hdr)
12380 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012381 nlmsg_free(msg);
12382}
12383EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12384
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012385#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012386static int cfg80211_net_detect_results(struct sk_buff *msg,
12387 struct cfg80211_wowlan_wakeup *wakeup)
12388{
12389 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12390 struct nlattr *nl_results, *nl_match, *nl_freqs;
12391 int i, j;
12392
12393 nl_results = nla_nest_start(
12394 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12395 if (!nl_results)
12396 return -EMSGSIZE;
12397
12398 for (i = 0; i < nd->n_matches; i++) {
12399 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12400
12401 nl_match = nla_nest_start(msg, i);
12402 if (!nl_match)
12403 break;
12404
12405 /* The SSID attribute is optional in nl80211, but for
12406 * simplicity reasons it's always present in the
12407 * cfg80211 structure. If a driver can't pass the
12408 * SSID, that needs to be changed. A zero length SSID
12409 * is still a valid SSID (wildcard), so it cannot be
12410 * used for this purpose.
12411 */
12412 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12413 match->ssid.ssid)) {
12414 nla_nest_cancel(msg, nl_match);
12415 goto out;
12416 }
12417
12418 if (match->n_channels) {
12419 nl_freqs = nla_nest_start(
12420 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12421 if (!nl_freqs) {
12422 nla_nest_cancel(msg, nl_match);
12423 goto out;
12424 }
12425
12426 for (j = 0; j < match->n_channels; j++) {
12427 if (nla_put_u32(msg,
12428 NL80211_ATTR_WIPHY_FREQ,
12429 match->channels[j])) {
12430 nla_nest_cancel(msg, nl_freqs);
12431 nla_nest_cancel(msg, nl_match);
12432 goto out;
12433 }
12434 }
12435
12436 nla_nest_end(msg, nl_freqs);
12437 }
12438
12439 nla_nest_end(msg, nl_match);
12440 }
12441
12442out:
12443 nla_nest_end(msg, nl_results);
12444 return 0;
12445}
12446
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012447void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12448 struct cfg80211_wowlan_wakeup *wakeup,
12449 gfp_t gfp)
12450{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012451 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012452 struct sk_buff *msg;
12453 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012454 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012455
12456 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12457
12458 if (wakeup)
12459 size += wakeup->packet_present_len;
12460
12461 msg = nlmsg_new(size, gfp);
12462 if (!msg)
12463 return;
12464
12465 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12466 if (!hdr)
12467 goto free_msg;
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 free_msg;
12472
12473 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12474 wdev->netdev->ifindex))
12475 goto free_msg;
12476
12477 if (wakeup) {
12478 struct nlattr *reasons;
12479
12480 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012481 if (!reasons)
12482 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012483
12484 if (wakeup->disconnect &&
12485 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12486 goto free_msg;
12487 if (wakeup->magic_pkt &&
12488 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12489 goto free_msg;
12490 if (wakeup->gtk_rekey_failure &&
12491 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12492 goto free_msg;
12493 if (wakeup->eap_identity_req &&
12494 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12495 goto free_msg;
12496 if (wakeup->four_way_handshake &&
12497 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12498 goto free_msg;
12499 if (wakeup->rfkill_release &&
12500 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12501 goto free_msg;
12502
12503 if (wakeup->pattern_idx >= 0 &&
12504 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12505 wakeup->pattern_idx))
12506 goto free_msg;
12507
Johannes Bergae917c92013-10-25 11:05:22 +020012508 if (wakeup->tcp_match &&
12509 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12510 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012511
Johannes Bergae917c92013-10-25 11:05:22 +020012512 if (wakeup->tcp_connlost &&
12513 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12514 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012515
Johannes Bergae917c92013-10-25 11:05:22 +020012516 if (wakeup->tcp_nomoretokens &&
12517 nla_put_flag(msg,
12518 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12519 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012520
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012521 if (wakeup->packet) {
12522 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12523 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12524
12525 if (!wakeup->packet_80211) {
12526 pkt_attr =
12527 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12528 len_attr =
12529 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12530 }
12531
12532 if (wakeup->packet_len &&
12533 nla_put_u32(msg, len_attr, wakeup->packet_len))
12534 goto free_msg;
12535
12536 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12537 wakeup->packet))
12538 goto free_msg;
12539 }
12540
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012541 if (wakeup->net_detect &&
12542 cfg80211_net_detect_results(msg, wakeup))
12543 goto free_msg;
12544
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012545 nla_nest_end(msg, reasons);
12546 }
12547
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012548 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012549
Johannes Berg68eb5502013-11-19 15:19:38 +010012550 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012551 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012552 return;
12553
12554 free_msg:
12555 nlmsg_free(msg);
12556}
12557EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12558#endif
12559
Jouni Malinen3475b092012-11-16 22:49:57 +020012560void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12561 enum nl80211_tdls_operation oper,
12562 u16 reason_code, gfp_t gfp)
12563{
12564 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012565 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012566 struct sk_buff *msg;
12567 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012568
12569 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12570 reason_code);
12571
12572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12573 if (!msg)
12574 return;
12575
12576 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12577 if (!hdr) {
12578 nlmsg_free(msg);
12579 return;
12580 }
12581
12582 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12583 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12584 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12585 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12586 (reason_code > 0 &&
12587 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12588 goto nla_put_failure;
12589
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012590 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012591
Johannes Berg68eb5502013-11-19 15:19:38 +010012592 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012593 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012594 return;
12595
12596 nla_put_failure:
12597 genlmsg_cancel(msg, hdr);
12598 nlmsg_free(msg);
12599}
12600EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12601
Jouni Malinen026331c2010-02-15 12:53:10 +020012602static int nl80211_netlink_notify(struct notifier_block * nb,
12603 unsigned long state,
12604 void *_notify)
12605{
12606 struct netlink_notify *notify = _notify;
12607 struct cfg80211_registered_device *rdev;
12608 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012609 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012610
12611 if (state != NETLINK_URELEASE)
12612 return NOTIFY_DONE;
12613
12614 rcu_read_lock();
12615
Johannes Berg5e760232011-11-04 11:18:17 +010012616 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012617 bool schedule_destroy_work = false;
12618
12619 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012620 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012621
Johannes Berg78f22b62014-03-24 17:57:27 +010012622 if (wdev->owner_nlportid == notify->portid)
12623 schedule_destroy_work = true;
12624 }
12625
Ben Greear37c73b52012-10-26 14:49:25 -070012626 spin_lock_bh(&rdev->beacon_registrations_lock);
12627 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12628 list) {
12629 if (reg->nlportid == notify->portid) {
12630 list_del(&reg->list);
12631 kfree(reg);
12632 break;
12633 }
12634 }
12635 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012636
12637 if (schedule_destroy_work) {
12638 struct cfg80211_iface_destroy *destroy;
12639
12640 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12641 if (destroy) {
12642 destroy->nlportid = notify->portid;
12643 spin_lock(&rdev->destroy_list_lock);
12644 list_add(&destroy->list, &rdev->destroy_list);
12645 spin_unlock(&rdev->destroy_list_lock);
12646 schedule_work(&rdev->destroy_work);
12647 }
12648 }
Johannes Berg5e760232011-11-04 11:18:17 +010012649 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012650
12651 rcu_read_unlock();
12652
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012653 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012654}
12655
12656static struct notifier_block nl80211_netlink_notifier = {
12657 .notifier_call = nl80211_netlink_notify,
12658};
12659
Jouni Malinen355199e2013-02-27 17:14:27 +020012660void cfg80211_ft_event(struct net_device *netdev,
12661 struct cfg80211_ft_event_params *ft_event)
12662{
12663 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012664 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012665 struct sk_buff *msg;
12666 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012667
12668 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12669
12670 if (!ft_event->target_ap)
12671 return;
12672
12673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12674 if (!msg)
12675 return;
12676
12677 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012678 if (!hdr)
12679 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012680
Johannes Bergae917c92013-10-25 11:05:22 +020012681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12682 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12683 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12684 goto out;
12685
12686 if (ft_event->ies &&
12687 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12688 goto out;
12689 if (ft_event->ric_ies &&
12690 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12691 ft_event->ric_ies))
12692 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012693
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012694 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012695
Johannes Berg68eb5502013-11-19 15:19:38 +010012696 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012697 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012698 return;
12699 out:
12700 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012701}
12702EXPORT_SYMBOL(cfg80211_ft_event);
12703
Arend van Spriel5de17982013-04-18 15:49:00 +020012704void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12705{
12706 struct cfg80211_registered_device *rdev;
12707 struct sk_buff *msg;
12708 void *hdr;
12709 u32 nlportid;
12710
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012711 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012712 if (!rdev->crit_proto_nlportid)
12713 return;
12714
12715 nlportid = rdev->crit_proto_nlportid;
12716 rdev->crit_proto_nlportid = 0;
12717
12718 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12719 if (!msg)
12720 return;
12721
12722 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12723 if (!hdr)
12724 goto nla_put_failure;
12725
12726 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12727 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12728 goto nla_put_failure;
12729
12730 genlmsg_end(msg, hdr);
12731
12732 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12733 return;
12734
12735 nla_put_failure:
12736 if (hdr)
12737 genlmsg_cancel(msg, hdr);
12738 nlmsg_free(msg);
12739
12740}
12741EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12742
Johannes Berg348baf02014-01-24 14:06:29 +010012743void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12744{
12745 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012746 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012747 struct sk_buff *msg;
12748 void *hdr;
12749
12750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12751 if (!msg)
12752 return;
12753
12754 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12755 if (!hdr)
12756 goto out;
12757
12758 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12759 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12760 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12761 goto out;
12762
12763 genlmsg_end(msg, hdr);
12764
12765 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12766 NL80211_MCGRP_MLME, GFP_KERNEL);
12767 return;
12768 out:
12769 nlmsg_free(msg);
12770}
12771
Johannes Berg55682962007-09-20 13:09:35 -040012772/* initialisation/exit functions */
12773
12774int nl80211_init(void)
12775{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012776 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012777
Johannes Berg2a94fe42013-11-19 15:19:39 +010012778 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12779 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012780 if (err)
12781 return err;
12782
Jouni Malinen026331c2010-02-15 12:53:10 +020012783 err = netlink_register_notifier(&nl80211_netlink_notifier);
12784 if (err)
12785 goto err_out;
12786
Johannes Berg55682962007-09-20 13:09:35 -040012787 return 0;
12788 err_out:
12789 genl_unregister_family(&nl80211_fam);
12790 return err;
12791}
12792
12793void nl80211_exit(void)
12794{
Jouni Malinen026331c2010-02-15 12:53:10 +020012795 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012796 genl_unregister_family(&nl80211_fam);
12797}