blob: 42b968a1f9941c4c7bbd2b1c2a59653384281beb [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010062 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
63 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
64 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
65 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
66 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010068 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010069#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-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 Berg7fee47782012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee47782012-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 Berg2e161f782010-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Berg2e161f782010-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 Berg2e161f782010-08-12 15:38:38 +02001537 goto nla_put_failure;
Johannes Berg2e161f782010-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 Berg2e161f782010-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 Berg2e161f782010-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001709 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1710 sizeof(rdev->wiphy.ext_features),
1711 rdev->wiphy.ext_features))
1712 goto nla_put_failure;
1713
Johannes Berg3713b4e2013-02-14 16:19:38 +01001714 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001715 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001716 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001717 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001718 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001719 return genlmsg_end(msg, hdr);
1720
1721 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001722 genlmsg_cancel(msg, hdr);
1723 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001724}
1725
Johannes Berg86e8cf92013-06-19 10:57:22 +02001726static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1727 struct netlink_callback *cb,
1728 struct nl80211_dump_wiphy_state *state)
1729{
1730 struct nlattr **tb = nl80211_fam.attrbuf;
1731 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1732 tb, nl80211_fam.maxattr, nl80211_policy);
1733 /* ignore parse errors for backward compatibility */
1734 if (ret)
1735 return 0;
1736
1737 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1738 if (tb[NL80211_ATTR_WIPHY])
1739 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1740 if (tb[NL80211_ATTR_WDEV])
1741 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1742 if (tb[NL80211_ATTR_IFINDEX]) {
1743 struct net_device *netdev;
1744 struct cfg80211_registered_device *rdev;
1745 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1746
Ying Xue7f2b8562014-01-15 10:23:45 +08001747 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001748 if (!netdev)
1749 return -ENODEV;
1750 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001751 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 netdev->ieee80211_ptr->wiphy);
1753 state->filter_wiphy = rdev->wiphy_idx;
1754 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001755 }
1756
1757 return 0;
1758}
1759
Johannes Berg55682962007-09-20 13:09:35 -04001760static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1761{
Johannes Berg645e77d2013-03-01 14:03:49 +01001762 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001763 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001764 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001765
Johannes Berg5fe231e2013-05-08 21:45:15 +02001766 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001767 if (!state) {
1768 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001769 if (!state) {
1770 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001771 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001772 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001773 state->filter_wiphy = -1;
1774 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1775 if (ret) {
1776 kfree(state);
1777 rtnl_unlock();
1778 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001780 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001781 }
1782
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001783 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1784 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001785 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001786 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001787 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001788 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001789 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001790 continue;
1791 /* attempt to fit multiple wiphy data chunks into the skb */
1792 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001793 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1794 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001795 NETLINK_CB(cb->skb).portid,
1796 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001797 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001798 if (ret < 0) {
1799 /*
1800 * If sending the wiphy data didn't fit (ENOBUFS
1801 * or EMSGSIZE returned), this SKB is still
1802 * empty (so it's not too big because another
1803 * wiphy dataset is already in the skb) and
1804 * we've not tried to adjust the dump allocation
1805 * yet ... then adjust the alloc size to be
1806 * bigger, and return 1 but with the empty skb.
1807 * This results in an empty message being RX'ed
1808 * in userspace, but that is ignored.
1809 *
1810 * We can then retry with the larger buffer.
1811 */
1812 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001813 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 cb->min_dump_alloc < 4096) {
1815 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001816 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001817 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001818 return 1;
1819 }
1820 idx--;
1821 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001822 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001823 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001824 break;
Johannes Berg55682962007-09-20 13:09:35 -04001825 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001826 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001827
Johannes Berg86e8cf92013-06-19 10:57:22 +02001828 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001829
1830 return skb->len;
1831}
1832
Johannes Berg86e8cf92013-06-19 10:57:22 +02001833static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1834{
1835 kfree((void *)cb->args[0]);
1836 return 0;
1837}
1838
Johannes Berg55682962007-09-20 13:09:35 -04001839static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1840{
1841 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001843 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001844
Johannes Berg645e77d2013-03-01 14:03:49 +01001845 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001846 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001847 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001848
Johannes Berg3bb20552014-05-26 13:52:25 +02001849 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1850 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001851 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001852 nlmsg_free(msg);
1853 return -ENOBUFS;
1854 }
Johannes Berg55682962007-09-20 13:09:35 -04001855
Johannes Berg134e6372009-07-10 09:51:34 +00001856 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001857}
1858
Jouni Malinen31888482008-10-30 16:59:24 +02001859static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1860 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1861 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1862 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1863 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1864 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1865};
1866
1867static int parse_txq_params(struct nlattr *tb[],
1868 struct ieee80211_txq_params *txq_params)
1869{
Johannes Berga3304b02012-03-28 11:04:24 +02001870 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001871 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1872 !tb[NL80211_TXQ_ATTR_AIFS])
1873 return -EINVAL;
1874
Johannes Berga3304b02012-03-28 11:04:24 +02001875 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001876 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1877 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1878 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1879 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1880
Johannes Berga3304b02012-03-28 11:04:24 +02001881 if (txq_params->ac >= NL80211_NUM_ACS)
1882 return -EINVAL;
1883
Jouni Malinen31888482008-10-30 16:59:24 +02001884 return 0;
1885}
1886
Johannes Bergf444de02010-05-05 15:25:02 +02001887static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1888{
1889 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001890 * You can only set the channel explicitly for WDS interfaces,
1891 * all others have their channel managed via their respective
1892 * "establish a connection" command (connect, join, ...)
1893 *
1894 * For AP/GO and mesh mode, the channel can be set with the
1895 * channel userspace API, but is only stored and passed to the
1896 * low-level driver when the AP starts or the mesh is joined.
1897 * This is for backward compatibility, userspace can also give
1898 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001899 *
1900 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001901 * whatever else is going on, so they have their own special
1902 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001903 */
1904 return !wdev ||
1905 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001906 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001907 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1908 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001909}
1910
Johannes Berg683b6d32012-11-08 21:25:48 +01001911static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1912 struct genl_info *info,
1913 struct cfg80211_chan_def *chandef)
1914{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301915 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001916
1917 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1918 return -EINVAL;
1919
1920 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1921
1922 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001923 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1924 chandef->center_freq1 = control_freq;
1925 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001926
1927 /* Primary channel not allowed */
1928 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1929 return -EINVAL;
1930
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001931 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1932 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001933
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001934 chantype = nla_get_u32(
1935 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1936
1937 switch (chantype) {
1938 case NL80211_CHAN_NO_HT:
1939 case NL80211_CHAN_HT20:
1940 case NL80211_CHAN_HT40PLUS:
1941 case NL80211_CHAN_HT40MINUS:
1942 cfg80211_chandef_create(chandef, chandef->chan,
1943 chantype);
1944 break;
1945 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001946 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001947 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001948 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1949 chandef->width =
1950 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1951 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1952 chandef->center_freq1 =
1953 nla_get_u32(
1954 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1955 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1956 chandef->center_freq2 =
1957 nla_get_u32(
1958 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1959 }
1960
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001961 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001962 return -EINVAL;
1963
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001964 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1965 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001966 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001967
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001968 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1969 chandef->width == NL80211_CHAN_WIDTH_10) &&
1970 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1971 return -EINVAL;
1972
Johannes Berg683b6d32012-11-08 21:25:48 +01001973 return 0;
1974}
1975
Johannes Bergf444de02010-05-05 15:25:02 +02001976static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001977 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001978 struct genl_info *info)
1979{
Johannes Berg683b6d32012-11-08 21:25:48 +01001980 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001981 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001982 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001983 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001984
Jouni Malinene16821b2014-04-28 11:22:08 +03001985 if (dev)
1986 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001987 if (!nl80211_can_set_dev_channel(wdev))
1988 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001989 if (wdev)
1990 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001991
Johannes Berg683b6d32012-11-08 21:25:48 +01001992 result = nl80211_parse_chandef(rdev, info, &chandef);
1993 if (result)
1994 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001995
Johannes Berge8c9bd52012-06-06 08:18:22 +02001996 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001997 case NL80211_IFTYPE_AP:
1998 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001999 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002000 result = -EINVAL;
2001 break;
2002 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002003 if (wdev->beacon_interval) {
2004 if (!dev || !rdev->ops->set_ap_chanwidth ||
2005 !(rdev->wiphy.features &
2006 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2007 result = -EBUSY;
2008 break;
2009 }
2010
2011 /* Only allow dynamic channel width changes */
2012 if (chandef.chan != wdev->preset_chandef.chan) {
2013 result = -EBUSY;
2014 break;
2015 }
2016 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2017 if (result)
2018 break;
2019 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002020 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002021 result = 0;
2022 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002023 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002024 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002025 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002026 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002027 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002028 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002029 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002030 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002031 }
Johannes Bergf444de02010-05-05 15:25:02 +02002032
2033 return result;
2034}
2035
2036static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2037{
Johannes Berg4c476992010-10-04 21:36:35 +02002038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2039 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002040
Jouni Malinene16821b2014-04-28 11:22:08 +03002041 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002042}
2043
Bill Jordane8347eb2010-10-01 13:54:28 -04002044static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2045{
Johannes Berg43b19952010-10-07 13:10:30 +02002046 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2047 struct net_device *dev = info->user_ptr[1];
2048 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002049 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002050
2051 if (!info->attrs[NL80211_ATTR_MAC])
2052 return -EINVAL;
2053
Johannes Berg43b19952010-10-07 13:10:30 +02002054 if (netif_running(dev))
2055 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002056
Johannes Berg43b19952010-10-07 13:10:30 +02002057 if (!rdev->ops->set_wds_peer)
2058 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002059
Johannes Berg43b19952010-10-07 13:10:30 +02002060 if (wdev->iftype != NL80211_IFTYPE_WDS)
2061 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002062
2063 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002064 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002065}
2066
2067
Johannes Berg55682962007-09-20 13:09:35 -04002068static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2069{
2070 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002071 struct net_device *netdev = NULL;
2072 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002073 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002074 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002075 u32 changed;
2076 u8 retry_short = 0, retry_long = 0;
2077 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002078 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002079
Johannes Berg5fe231e2013-05-08 21:45:15 +02002080 ASSERT_RTNL();
2081
Johannes Bergf444de02010-05-05 15:25:02 +02002082 /*
2083 * Try to find the wiphy and netdev. Normally this
2084 * function shouldn't need the netdev, but this is
2085 * done for backward compatibility -- previously
2086 * setting the channel was done per wiphy, but now
2087 * it is per netdev. Previous userland like hostapd
2088 * also passed a netdev to set_wiphy, so that it is
2089 * possible to let that go to the right netdev!
2090 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002091
Johannes Bergf444de02010-05-05 15:25:02 +02002092 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2093 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2094
Ying Xue7f2b8562014-01-15 10:23:45 +08002095 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002096 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002097 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002098 else
Johannes Bergf444de02010-05-05 15:25:02 +02002099 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002100 }
2101
Johannes Bergf444de02010-05-05 15:25:02 +02002102 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002103 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2104 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002105 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002106 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002107 wdev = NULL;
2108 netdev = NULL;
2109 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002110 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002111 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002112
2113 /*
2114 * end workaround code, by now the rdev is available
2115 * and locked, and wdev may or may not be NULL.
2116 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002117
2118 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002119 result = cfg80211_dev_rename(
2120 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002121
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002122 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002123 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002124
Jouni Malinen31888482008-10-30 16:59:24 +02002125 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2126 struct ieee80211_txq_params txq_params;
2127 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2128
Ying Xue7f2b8562014-01-15 10:23:45 +08002129 if (!rdev->ops->set_txq_params)
2130 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002131
Ying Xue7f2b8562014-01-15 10:23:45 +08002132 if (!netdev)
2133 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002134
Johannes Berg133a3ff2011-11-03 14:50:13 +01002135 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002136 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2137 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002138
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 if (!netif_running(netdev))
2140 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002141
Jouni Malinen31888482008-10-30 16:59:24 +02002142 nla_for_each_nested(nl_txq_params,
2143 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2144 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002145 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2146 nla_data(nl_txq_params),
2147 nla_len(nl_txq_params),
2148 txq_params_policy);
2149 if (result)
2150 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002151 result = parse_txq_params(tb, &txq_params);
2152 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002153 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002154
Hila Gonene35e4d22012-06-27 17:19:42 +03002155 result = rdev_set_txq_params(rdev, netdev,
2156 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002157 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002158 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002159 }
2160 }
2161
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002162 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002163 result = __nl80211_set_channel(
2164 rdev,
2165 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2166 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002167 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002168 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002169 }
2170
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002171 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002172 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002173 enum nl80211_tx_power_setting type;
2174 int idx, mbm = 0;
2175
Johannes Bergc8442112012-10-24 10:17:18 +02002176 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2177 txp_wdev = NULL;
2178
Ying Xue7f2b8562014-01-15 10:23:45 +08002179 if (!rdev->ops->set_tx_power)
2180 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002181
2182 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2183 type = nla_get_u32(info->attrs[idx]);
2184
2185 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002186 (type != NL80211_TX_POWER_AUTOMATIC))
2187 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002188
2189 if (type != NL80211_TX_POWER_AUTOMATIC) {
2190 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2191 mbm = nla_get_u32(info->attrs[idx]);
2192 }
2193
Johannes Bergc8442112012-10-24 10:17:18 +02002194 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002195 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002196 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002197 }
2198
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002199 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2200 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2201 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002202 if ((!rdev->wiphy.available_antennas_tx &&
2203 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002204 !rdev->ops->set_antenna)
2205 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002206
2207 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2208 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2209
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002210 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002211 * available antenna masks, except for the "all" mask */
2212 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002213 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2214 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002215
Bruno Randolf7f531e02010-12-16 11:30:22 +09002216 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2217 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002218
Hila Gonene35e4d22012-06-27 17:19:42 +03002219 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002220 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002221 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002222 }
2223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002224 changed = 0;
2225
2226 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2227 retry_short = nla_get_u8(
2228 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002229 if (retry_short == 0)
2230 return -EINVAL;
2231
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002232 changed |= WIPHY_PARAM_RETRY_SHORT;
2233 }
2234
2235 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2236 retry_long = nla_get_u8(
2237 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 if (retry_long == 0)
2239 return -EINVAL;
2240
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002241 changed |= WIPHY_PARAM_RETRY_LONG;
2242 }
2243
2244 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2245 frag_threshold = nla_get_u32(
2246 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002247 if (frag_threshold < 256)
2248 return -EINVAL;
2249
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002250 if (frag_threshold != (u32) -1) {
2251 /*
2252 * Fragments (apart from the last one) are required to
2253 * have even length. Make the fragmentation code
2254 * simpler by stripping LSB should someone try to use
2255 * odd threshold value.
2256 */
2257 frag_threshold &= ~0x1;
2258 }
2259 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2260 }
2261
2262 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2263 rts_threshold = nla_get_u32(
2264 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2265 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2266 }
2267
Lukáš Turek81077e82009-12-21 22:50:47 +01002268 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002269 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2270 return -EINVAL;
2271
Lukáš Turek81077e82009-12-21 22:50:47 +01002272 coverage_class = nla_get_u8(
2273 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2274 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2275 }
2276
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002277 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2278 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2279 return -EOPNOTSUPP;
2280
2281 changed |= WIPHY_PARAM_DYN_ACK;
2282 }
2283
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002284 if (changed) {
2285 u8 old_retry_short, old_retry_long;
2286 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002287 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002288
Ying Xue7f2b8562014-01-15 10:23:45 +08002289 if (!rdev->ops->set_wiphy_params)
2290 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002291
2292 old_retry_short = rdev->wiphy.retry_short;
2293 old_retry_long = rdev->wiphy.retry_long;
2294 old_frag_threshold = rdev->wiphy.frag_threshold;
2295 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002296 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002297
2298 if (changed & WIPHY_PARAM_RETRY_SHORT)
2299 rdev->wiphy.retry_short = retry_short;
2300 if (changed & WIPHY_PARAM_RETRY_LONG)
2301 rdev->wiphy.retry_long = retry_long;
2302 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2303 rdev->wiphy.frag_threshold = frag_threshold;
2304 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2305 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002306 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2307 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002308
Hila Gonene35e4d22012-06-27 17:19:42 +03002309 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002310 if (result) {
2311 rdev->wiphy.retry_short = old_retry_short;
2312 rdev->wiphy.retry_long = old_retry_long;
2313 rdev->wiphy.frag_threshold = old_frag_threshold;
2314 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002315 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002316 }
2317 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002318 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002319}
2320
Johannes Berg71bbc992012-06-15 15:30:18 +02002321static inline u64 wdev_id(struct wireless_dev *wdev)
2322{
2323 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002324 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002325}
Johannes Berg55682962007-09-20 13:09:35 -04002326
Johannes Berg683b6d32012-11-08 21:25:48 +01002327static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002328 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002329{
Johannes Berg601555c2014-11-27 17:26:56 +01002330 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2331 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002332
Johannes Berg683b6d32012-11-08 21:25:48 +01002333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2334 chandef->chan->center_freq))
2335 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002336 switch (chandef->width) {
2337 case NL80211_CHAN_WIDTH_20_NOHT:
2338 case NL80211_CHAN_WIDTH_20:
2339 case NL80211_CHAN_WIDTH_40:
2340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2341 cfg80211_get_chandef_type(chandef)))
2342 return -ENOBUFS;
2343 break;
2344 default:
2345 break;
2346 }
2347 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2348 return -ENOBUFS;
2349 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2350 return -ENOBUFS;
2351 if (chandef->center_freq2 &&
2352 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002353 return -ENOBUFS;
2354 return 0;
2355}
2356
Eric W. Biederman15e47302012-09-07 20:12:54 +00002357static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002358 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002359 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002360{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002361 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002362 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002363 void *hdr;
2364
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002365 if (removal)
2366 cmd = NL80211_CMD_DEL_INTERFACE;
2367
2368 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002369 if (!hdr)
2370 return -1;
2371
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002372 if (dev &&
2373 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002374 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002375 goto nla_put_failure;
2376
2377 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2378 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002379 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002380 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002381 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2382 rdev->devlist_generation ^
2383 (cfg80211_rdev_list_generation << 2)))
2384 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002385
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002386 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002387 int ret;
2388 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002389
Johannes Berg683b6d32012-11-08 21:25:48 +01002390 ret = rdev_get_channel(rdev, wdev, &chandef);
2391 if (ret == 0) {
2392 if (nl80211_send_chandef(msg, &chandef))
2393 goto nla_put_failure;
2394 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002395 }
2396
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002397 if (wdev->ssid_len) {
2398 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2399 goto nla_put_failure;
2400 }
2401
Johannes Berg55682962007-09-20 13:09:35 -04002402 return genlmsg_end(msg, hdr);
2403
2404 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002405 genlmsg_cancel(msg, hdr);
2406 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002407}
2408
2409static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2410{
2411 int wp_idx = 0;
2412 int if_idx = 0;
2413 int wp_start = cb->args[0];
2414 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002415 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002416 struct wireless_dev *wdev;
2417
Johannes Berg5fe231e2013-05-08 21:45:15 +02002418 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002419 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2420 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002421 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002422 if (wp_idx < wp_start) {
2423 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002424 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002425 }
Johannes Berg55682962007-09-20 13:09:35 -04002426 if_idx = 0;
2427
Johannes Berg89a54e42012-06-15 14:33:17 +02002428 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002429 if (if_idx < if_start) {
2430 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002431 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002432 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002433 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002434 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002435 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002436 goto out;
2437 }
2438 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002439 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002440
2441 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002442 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002443 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002444 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002445
2446 cb->args[0] = wp_idx;
2447 cb->args[1] = if_idx;
2448
2449 return skb->len;
2450}
2451
2452static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2453{
2454 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002455 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002456 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002457
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002458 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002459 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002460 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002461
Eric W. Biederman15e47302012-09-07 20:12:54 +00002462 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002463 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002464 nlmsg_free(msg);
2465 return -ENOBUFS;
2466 }
Johannes Berg55682962007-09-20 13:09:35 -04002467
Johannes Berg134e6372009-07-10 09:51:34 +00002468 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002469}
2470
Michael Wu66f7ac52008-01-31 19:48:22 +01002471static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2472 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2473 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2474 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2475 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2476 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002477 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002478};
2479
2480static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2481{
2482 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2483 int flag;
2484
2485 *mntrflags = 0;
2486
2487 if (!nla)
2488 return -EINVAL;
2489
2490 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2491 nla, mntr_flags_policy))
2492 return -EINVAL;
2493
2494 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2495 if (flags[flag])
2496 *mntrflags |= (1<<flag);
2497
2498 return 0;
2499}
2500
Johannes Berg9bc383d2009-11-19 11:55:19 +01002501static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002502 struct net_device *netdev, u8 use_4addr,
2503 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002504{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002505 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002506 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002507 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002508 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002509 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002510
2511 switch (iftype) {
2512 case NL80211_IFTYPE_AP_VLAN:
2513 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2514 return 0;
2515 break;
2516 case NL80211_IFTYPE_STATION:
2517 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2518 return 0;
2519 break;
2520 default:
2521 break;
2522 }
2523
2524 return -EOPNOTSUPP;
2525}
2526
Johannes Berg55682962007-09-20 13:09:35 -04002527static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2528{
Johannes Berg4c476992010-10-04 21:36:35 +02002529 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002530 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002531 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002532 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002533 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002534 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002535 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002536
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002537 memset(&params, 0, sizeof(params));
2538
Johannes Berg04a773a2009-04-19 21:24:32 +02002539 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002540
Johannes Berg723b0382008-09-16 20:22:09 +02002541 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002542 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002543 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002544 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002545 if (ntype > NL80211_IFTYPE_MAX)
2546 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002547 }
2548
Johannes Berg92ffe052008-09-16 20:39:36 +02002549 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002550 struct wireless_dev *wdev = dev->ieee80211_ptr;
2551
Johannes Berg4c476992010-10-04 21:36:35 +02002552 if (ntype != NL80211_IFTYPE_MESH_POINT)
2553 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002554 if (netif_running(dev))
2555 return -EBUSY;
2556
2557 wdev_lock(wdev);
2558 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2559 IEEE80211_MAX_MESH_ID_LEN);
2560 wdev->mesh_id_up_len =
2561 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2562 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2563 wdev->mesh_id_up_len);
2564 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002565 }
2566
Felix Fietkau8b787642009-11-10 18:53:10 +01002567 if (info->attrs[NL80211_ATTR_4ADDR]) {
2568 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2569 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002570 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002571 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002572 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002573 } else {
2574 params.use_4addr = -1;
2575 }
2576
Johannes Berg92ffe052008-09-16 20:39:36 +02002577 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002578 if (ntype != NL80211_IFTYPE_MONITOR)
2579 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002580 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2581 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002582 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002583 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002584
2585 flags = &_flags;
2586 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002587 }
Johannes Berg3b858752009-03-12 09:55:09 +01002588
Luciano Coelho18003292013-08-29 13:26:57 +03002589 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002590 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2591 return -EOPNOTSUPP;
2592
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002593 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002594 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002595 else
2596 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002597
Johannes Berg9bc383d2009-11-19 11:55:19 +01002598 if (!err && params.use_4addr != -1)
2599 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2600
Johannes Berg55682962007-09-20 13:09:35 -04002601 return err;
2602}
2603
2604static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2605{
Johannes Berg4c476992010-10-04 21:36:35 +02002606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002607 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002608 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002609 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002610 int err;
2611 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002612 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002613
Johannes Berg78f22b62014-03-24 17:57:27 +01002614 /* to avoid failing a new interface creation due to pending removal */
2615 cfg80211_destroy_ifaces(rdev);
2616
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002617 memset(&params, 0, sizeof(params));
2618
Johannes Berg55682962007-09-20 13:09:35 -04002619 if (!info->attrs[NL80211_ATTR_IFNAME])
2620 return -EINVAL;
2621
2622 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2623 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2624 if (type > NL80211_IFTYPE_MAX)
2625 return -EINVAL;
2626 }
2627
Johannes Berg79c97e92009-07-07 03:56:12 +02002628 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002629 !(rdev->wiphy.interface_modes & (1 << type)))
2630 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002631
Ben Greeare8f479b2014-10-22 12:23:05 -07002632 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2633 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2634 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002635 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2636 ETH_ALEN);
2637 if (!is_valid_ether_addr(params.macaddr))
2638 return -EADDRNOTAVAIL;
2639 }
2640
Johannes Berg9bc383d2009-11-19 11:55:19 +01002641 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002642 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002643 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002644 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002645 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002646 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002647
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002648 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2649 if (!msg)
2650 return -ENOMEM;
2651
Michael Wu66f7ac52008-01-31 19:48:22 +01002652 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2653 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2654 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002655
Luciano Coelho18003292013-08-29 13:26:57 +03002656 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002657 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2658 return -EOPNOTSUPP;
2659
Hila Gonene35e4d22012-06-27 17:19:42 +03002660 wdev = rdev_add_virtual_intf(rdev,
2661 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2662 type, err ? NULL : &flags, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002663 if (WARN_ON(!wdev)) {
2664 nlmsg_free(msg);
2665 return -EPROTO;
2666 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002667 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002668 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002669 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002670
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002671 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002672 wdev->owner_nlportid = info->snd_portid;
2673
Johannes Berg98104fde2012-06-16 00:19:54 +02002674 switch (type) {
2675 case NL80211_IFTYPE_MESH_POINT:
2676 if (!info->attrs[NL80211_ATTR_MESH_ID])
2677 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002678 wdev_lock(wdev);
2679 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2680 IEEE80211_MAX_MESH_ID_LEN);
2681 wdev->mesh_id_up_len =
2682 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2683 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2684 wdev->mesh_id_up_len);
2685 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002686 break;
2687 case NL80211_IFTYPE_P2P_DEVICE:
2688 /*
2689 * P2P Device doesn't have a netdev, so doesn't go
2690 * through the netdev notifier and must be added here
2691 */
2692 mutex_init(&wdev->mtx);
2693 INIT_LIST_HEAD(&wdev->event_list);
2694 spin_lock_init(&wdev->event_lock);
2695 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2696 spin_lock_init(&wdev->mgmt_registrations_lock);
2697
Johannes Berg98104fde2012-06-16 00:19:54 +02002698 wdev->identifier = ++rdev->wdev_id;
2699 list_add_rcu(&wdev->list, &rdev->wdev_list);
2700 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002701 break;
2702 default:
2703 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002704 }
2705
Eric W. Biederman15e47302012-09-07 20:12:54 +00002706 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002707 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002708 nlmsg_free(msg);
2709 return -ENOBUFS;
2710 }
2711
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002712 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2713 if (event) {
2714 if (nl80211_send_iface(event, 0, 0, 0,
2715 rdev, wdev, false) < 0) {
2716 nlmsg_free(event);
2717 goto out;
2718 }
2719
2720 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2721 event, 0, NL80211_MCGRP_CONFIG,
2722 GFP_KERNEL);
2723 }
2724
2725out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002726 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002727}
2728
2729static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2730{
Johannes Berg4c476992010-10-04 21:36:35 +02002731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002732 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002733 struct sk_buff *msg;
2734 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002735
Johannes Berg4c476992010-10-04 21:36:35 +02002736 if (!rdev->ops->del_virtual_intf)
2737 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002738
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002739 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2740 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2741 nlmsg_free(msg);
2742 msg = NULL;
2743 }
2744
Johannes Berg84efbb82012-06-16 00:00:26 +02002745 /*
2746 * If we remove a wireless device without a netdev then clear
2747 * user_ptr[1] so that nl80211_post_doit won't dereference it
2748 * to check if it needs to do dev_put(). Otherwise it crashes
2749 * since the wdev has been freed, unlike with a netdev where
2750 * we need the dev_put() for the netdev to really be freed.
2751 */
2752 if (!wdev->netdev)
2753 info->user_ptr[1] = NULL;
2754
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002755 status = rdev_del_virtual_intf(rdev, wdev);
2756 if (status >= 0 && msg)
2757 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2758 msg, 0, NL80211_MCGRP_CONFIG,
2759 GFP_KERNEL);
2760 else
2761 nlmsg_free(msg);
2762
2763 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002764}
2765
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002766static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2767{
2768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2769 struct net_device *dev = info->user_ptr[1];
2770 u16 noack_map;
2771
2772 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2773 return -EINVAL;
2774
2775 if (!rdev->ops->set_noack_map)
2776 return -EOPNOTSUPP;
2777
2778 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2779
Hila Gonene35e4d22012-06-27 17:19:42 +03002780 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002781}
2782
Johannes Berg41ade002007-12-19 02:03:29 +01002783struct get_key_cookie {
2784 struct sk_buff *msg;
2785 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002786 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002787};
2788
2789static void get_key_callback(void *c, struct key_params *params)
2790{
Johannes Bergb9454e82009-07-08 13:29:08 +02002791 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002792 struct get_key_cookie *cookie = c;
2793
David S. Miller9360ffd2012-03-29 04:41:26 -04002794 if ((params->key &&
2795 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2796 params->key_len, params->key)) ||
2797 (params->seq &&
2798 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2799 params->seq_len, params->seq)) ||
2800 (params->cipher &&
2801 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2802 params->cipher)))
2803 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002804
Johannes Bergb9454e82009-07-08 13:29:08 +02002805 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2806 if (!key)
2807 goto nla_put_failure;
2808
David S. Miller9360ffd2012-03-29 04:41:26 -04002809 if ((params->key &&
2810 nla_put(cookie->msg, NL80211_KEY_DATA,
2811 params->key_len, params->key)) ||
2812 (params->seq &&
2813 nla_put(cookie->msg, NL80211_KEY_SEQ,
2814 params->seq_len, params->seq)) ||
2815 (params->cipher &&
2816 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2817 params->cipher)))
2818 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002819
David S. Miller9360ffd2012-03-29 04:41:26 -04002820 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2821 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002822
2823 nla_nest_end(cookie->msg, key);
2824
Johannes Berg41ade002007-12-19 02:03:29 +01002825 return;
2826 nla_put_failure:
2827 cookie->error = 1;
2828}
2829
2830static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2831{
Johannes Berg4c476992010-10-04 21:36:35 +02002832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002833 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002834 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002835 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002836 const u8 *mac_addr = NULL;
2837 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002838 struct get_key_cookie cookie = {
2839 .error = 0,
2840 };
2841 void *hdr;
2842 struct sk_buff *msg;
2843
2844 if (info->attrs[NL80211_ATTR_KEY_IDX])
2845 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2846
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002847 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002848 return -EINVAL;
2849
2850 if (info->attrs[NL80211_ATTR_MAC])
2851 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2852
Johannes Berge31b8212010-10-05 19:39:30 +02002853 pairwise = !!mac_addr;
2854 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2855 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2856 if (kt >= NUM_NL80211_KEYTYPES)
2857 return -EINVAL;
2858 if (kt != NL80211_KEYTYPE_GROUP &&
2859 kt != NL80211_KEYTYPE_PAIRWISE)
2860 return -EINVAL;
2861 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2862 }
2863
Johannes Berg4c476992010-10-04 21:36:35 +02002864 if (!rdev->ops->get_key)
2865 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002866
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002867 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002868 if (!msg)
2869 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002870
Eric W. Biederman15e47302012-09-07 20:12:54 +00002871 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002872 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002873 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002874 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002875
2876 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002877 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002878
David S. Miller9360ffd2012-03-29 04:41:26 -04002879 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2880 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2881 goto nla_put_failure;
2882 if (mac_addr &&
2883 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2884 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002885
Johannes Berge31b8212010-10-05 19:39:30 +02002886 if (pairwise && mac_addr &&
2887 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2888 return -ENOENT;
2889
Hila Gonene35e4d22012-06-27 17:19:42 +03002890 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2891 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002892
2893 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002894 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002895
2896 if (cookie.error)
2897 goto nla_put_failure;
2898
2899 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002900 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002901
2902 nla_put_failure:
2903 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002904 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002905 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002906 return err;
2907}
2908
2909static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2910{
Johannes Berg4c476992010-10-04 21:36:35 +02002911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002912 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002913 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002914 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002915
Johannes Bergb9454e82009-07-08 13:29:08 +02002916 err = nl80211_parse_key(info, &key);
2917 if (err)
2918 return err;
2919
2920 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002921 return -EINVAL;
2922
Johannes Bergb9454e82009-07-08 13:29:08 +02002923 /* only support setting default key */
2924 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002925 return -EINVAL;
2926
Johannes Bergfffd0932009-07-08 14:22:54 +02002927 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002928
2929 if (key.def) {
2930 if (!rdev->ops->set_default_key) {
2931 err = -EOPNOTSUPP;
2932 goto out;
2933 }
2934
2935 err = nl80211_key_allowed(dev->ieee80211_ptr);
2936 if (err)
2937 goto out;
2938
Hila Gonene35e4d22012-06-27 17:19:42 +03002939 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002940 key.def_uni, key.def_multi);
2941
2942 if (err)
2943 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002944
Johannes Berg3d23e342009-09-29 23:27:28 +02002945#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002946 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002947#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002948 } else {
2949 if (key.def_uni || !key.def_multi) {
2950 err = -EINVAL;
2951 goto out;
2952 }
2953
2954 if (!rdev->ops->set_default_mgmt_key) {
2955 err = -EOPNOTSUPP;
2956 goto out;
2957 }
2958
2959 err = nl80211_key_allowed(dev->ieee80211_ptr);
2960 if (err)
2961 goto out;
2962
Hila Gonene35e4d22012-06-27 17:19:42 +03002963 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002964 if (err)
2965 goto out;
2966
2967#ifdef CONFIG_CFG80211_WEXT
2968 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2969#endif
2970 }
2971
2972 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002973 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002974
Johannes Berg41ade002007-12-19 02:03:29 +01002975 return err;
2976}
2977
2978static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2979{
Johannes Berg4c476992010-10-04 21:36:35 +02002980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002981 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002982 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002983 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002984 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002985
Johannes Bergb9454e82009-07-08 13:29:08 +02002986 err = nl80211_parse_key(info, &key);
2987 if (err)
2988 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002989
Johannes Bergb9454e82009-07-08 13:29:08 +02002990 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002991 return -EINVAL;
2992
Johannes Berg41ade002007-12-19 02:03:29 +01002993 if (info->attrs[NL80211_ATTR_MAC])
2994 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2995
Johannes Berge31b8212010-10-05 19:39:30 +02002996 if (key.type == -1) {
2997 if (mac_addr)
2998 key.type = NL80211_KEYTYPE_PAIRWISE;
2999 else
3000 key.type = NL80211_KEYTYPE_GROUP;
3001 }
3002
3003 /* for now */
3004 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3005 key.type != NL80211_KEYTYPE_GROUP)
3006 return -EINVAL;
3007
Johannes Berg4c476992010-10-04 21:36:35 +02003008 if (!rdev->ops->add_key)
3009 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003010
Johannes Berge31b8212010-10-05 19:39:30 +02003011 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3012 key.type == NL80211_KEYTYPE_PAIRWISE,
3013 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003014 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003015
3016 wdev_lock(dev->ieee80211_ptr);
3017 err = nl80211_key_allowed(dev->ieee80211_ptr);
3018 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003019 err = rdev_add_key(rdev, dev, key.idx,
3020 key.type == NL80211_KEYTYPE_PAIRWISE,
3021 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003022 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003023
Johannes Berg41ade002007-12-19 02:03:29 +01003024 return err;
3025}
3026
3027static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3028{
Johannes Berg4c476992010-10-04 21:36:35 +02003029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003030 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003031 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003032 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003033 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003034
Johannes Bergb9454e82009-07-08 13:29:08 +02003035 err = nl80211_parse_key(info, &key);
3036 if (err)
3037 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003038
3039 if (info->attrs[NL80211_ATTR_MAC])
3040 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3041
Johannes Berge31b8212010-10-05 19:39:30 +02003042 if (key.type == -1) {
3043 if (mac_addr)
3044 key.type = NL80211_KEYTYPE_PAIRWISE;
3045 else
3046 key.type = NL80211_KEYTYPE_GROUP;
3047 }
3048
3049 /* for now */
3050 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3051 key.type != NL80211_KEYTYPE_GROUP)
3052 return -EINVAL;
3053
Johannes Berg4c476992010-10-04 21:36:35 +02003054 if (!rdev->ops->del_key)
3055 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003056
Johannes Bergfffd0932009-07-08 14:22:54 +02003057 wdev_lock(dev->ieee80211_ptr);
3058 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003059
3060 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3061 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3062 err = -ENOENT;
3063
Johannes Bergfffd0932009-07-08 14:22:54 +02003064 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003065 err = rdev_del_key(rdev, dev, key.idx,
3066 key.type == NL80211_KEYTYPE_PAIRWISE,
3067 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003068
Johannes Berg3d23e342009-09-29 23:27:28 +02003069#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003070 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003071 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003072 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003073 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003074 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3075 }
3076#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003077 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003078
Johannes Berg41ade002007-12-19 02:03:29 +01003079 return err;
3080}
3081
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303082/* This function returns an error or the number of nested attributes */
3083static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3084{
3085 struct nlattr *attr;
3086 int n_entries = 0, tmp;
3087
3088 nla_for_each_nested(attr, nl_attr, tmp) {
3089 if (nla_len(attr) != ETH_ALEN)
3090 return -EINVAL;
3091
3092 n_entries++;
3093 }
3094
3095 return n_entries;
3096}
3097
3098/*
3099 * This function parses ACL information and allocates memory for ACL data.
3100 * On successful return, the calling function is responsible to free the
3101 * ACL buffer returned by this function.
3102 */
3103static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3104 struct genl_info *info)
3105{
3106 enum nl80211_acl_policy acl_policy;
3107 struct nlattr *attr;
3108 struct cfg80211_acl_data *acl;
3109 int i = 0, n_entries, tmp;
3110
3111 if (!wiphy->max_acl_mac_addrs)
3112 return ERR_PTR(-EOPNOTSUPP);
3113
3114 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3115 return ERR_PTR(-EINVAL);
3116
3117 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3118 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3119 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3120 return ERR_PTR(-EINVAL);
3121
3122 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3123 return ERR_PTR(-EINVAL);
3124
3125 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3126 if (n_entries < 0)
3127 return ERR_PTR(n_entries);
3128
3129 if (n_entries > wiphy->max_acl_mac_addrs)
3130 return ERR_PTR(-ENOTSUPP);
3131
3132 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3133 GFP_KERNEL);
3134 if (!acl)
3135 return ERR_PTR(-ENOMEM);
3136
3137 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3138 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3139 i++;
3140 }
3141
3142 acl->n_acl_entries = n_entries;
3143 acl->acl_policy = acl_policy;
3144
3145 return acl;
3146}
3147
3148static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3149{
3150 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3151 struct net_device *dev = info->user_ptr[1];
3152 struct cfg80211_acl_data *acl;
3153 int err;
3154
3155 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3156 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3157 return -EOPNOTSUPP;
3158
3159 if (!dev->ieee80211_ptr->beacon_interval)
3160 return -EINVAL;
3161
3162 acl = parse_acl_data(&rdev->wiphy, info);
3163 if (IS_ERR(acl))
3164 return PTR_ERR(acl);
3165
3166 err = rdev_set_mac_acl(rdev, dev, acl);
3167
3168 kfree(acl);
3169
3170 return err;
3171}
3172
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003173static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003174 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003175{
Johannes Berg88600202012-02-13 15:17:18 +01003176 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003177
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003178 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3179 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3180 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3181 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003182 return -EINVAL;
3183
Johannes Berg88600202012-02-13 15:17:18 +01003184 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003185
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003186 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3187 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3188 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003189 if (!bcn->head_len)
3190 return -EINVAL;
3191 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003192 }
3193
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003194 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3195 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3196 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003197 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003198 }
3199
Johannes Berg4c476992010-10-04 21:36:35 +02003200 if (!haveinfo)
3201 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003202
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003203 if (attrs[NL80211_ATTR_IE]) {
3204 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3205 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003206 }
3207
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003208 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003209 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003210 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003211 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003212 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003213 }
3214
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003215 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003216 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003217 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003218 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003219 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003220 }
3221
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003222 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3223 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3224 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003225 }
3226
Johannes Berg88600202012-02-13 15:17:18 +01003227 return 0;
3228}
3229
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003230static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3231 struct cfg80211_ap_settings *params)
3232{
3233 struct wireless_dev *wdev;
3234 bool ret = false;
3235
Johannes Berg89a54e42012-06-15 14:33:17 +02003236 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003237 if (wdev->iftype != NL80211_IFTYPE_AP &&
3238 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3239 continue;
3240
Johannes Berg683b6d32012-11-08 21:25:48 +01003241 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003242 continue;
3243
Johannes Berg683b6d32012-11-08 21:25:48 +01003244 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003245 ret = true;
3246 break;
3247 }
3248
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003249 return ret;
3250}
3251
Jouni Malinene39e5b52012-09-30 19:29:39 +03003252static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3253 enum nl80211_auth_type auth_type,
3254 enum nl80211_commands cmd)
3255{
3256 if (auth_type > NL80211_AUTHTYPE_MAX)
3257 return false;
3258
3259 switch (cmd) {
3260 case NL80211_CMD_AUTHENTICATE:
3261 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3262 auth_type == NL80211_AUTHTYPE_SAE)
3263 return false;
3264 return true;
3265 case NL80211_CMD_CONNECT:
3266 case NL80211_CMD_START_AP:
3267 /* SAE not supported yet */
3268 if (auth_type == NL80211_AUTHTYPE_SAE)
3269 return false;
3270 return true;
3271 default:
3272 return false;
3273 }
3274}
3275
Johannes Berg88600202012-02-13 15:17:18 +01003276static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3277{
3278 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3279 struct net_device *dev = info->user_ptr[1];
3280 struct wireless_dev *wdev = dev->ieee80211_ptr;
3281 struct cfg80211_ap_settings params;
3282 int err;
3283
3284 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3285 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3286 return -EOPNOTSUPP;
3287
3288 if (!rdev->ops->start_ap)
3289 return -EOPNOTSUPP;
3290
3291 if (wdev->beacon_interval)
3292 return -EALREADY;
3293
3294 memset(&params, 0, sizeof(params));
3295
3296 /* these are required for START_AP */
3297 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3298 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3299 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3300 return -EINVAL;
3301
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003302 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003303 if (err)
3304 return err;
3305
3306 params.beacon_interval =
3307 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3308 params.dtim_period =
3309 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3310
3311 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3312 if (err)
3313 return err;
3314
3315 /*
3316 * In theory, some of these attributes should be required here
3317 * but since they were not used when the command was originally
3318 * added, keep them optional for old user space programs to let
3319 * them continue to work with drivers that do not need the
3320 * additional information -- drivers must check!
3321 */
3322 if (info->attrs[NL80211_ATTR_SSID]) {
3323 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3324 params.ssid_len =
3325 nla_len(info->attrs[NL80211_ATTR_SSID]);
3326 if (params.ssid_len == 0 ||
3327 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3328 return -EINVAL;
3329 }
3330
3331 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3332 params.hidden_ssid = nla_get_u32(
3333 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3334 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3335 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3336 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3337 return -EINVAL;
3338 }
3339
3340 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3341
3342 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3343 params.auth_type = nla_get_u32(
3344 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003345 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3346 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003347 return -EINVAL;
3348 } else
3349 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3350
3351 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3352 NL80211_MAX_NR_CIPHER_SUITES);
3353 if (err)
3354 return err;
3355
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303356 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3357 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3358 return -EOPNOTSUPP;
3359 params.inactivity_timeout = nla_get_u16(
3360 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3361 }
3362
Johannes Berg53cabad2012-11-14 15:17:28 +01003363 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3364 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3365 return -EINVAL;
3366 params.p2p_ctwindow =
3367 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3368 if (params.p2p_ctwindow > 127)
3369 return -EINVAL;
3370 if (params.p2p_ctwindow != 0 &&
3371 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3372 return -EINVAL;
3373 }
3374
3375 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3376 u8 tmp;
3377
3378 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3379 return -EINVAL;
3380 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3381 if (tmp > 1)
3382 return -EINVAL;
3383 params.p2p_opp_ps = tmp;
3384 if (params.p2p_opp_ps != 0 &&
3385 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3386 return -EINVAL;
3387 }
3388
Johannes Bergaa430da2012-05-16 23:50:18 +02003389 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003390 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3391 if (err)
3392 return err;
3393 } else if (wdev->preset_chandef.chan) {
3394 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003395 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003396 return -EINVAL;
3397
Ilan Peer174e0cd2014-02-23 09:13:01 +02003398 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3399 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003400 return -EINVAL;
3401
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303402 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3403 params.acl = parse_acl_data(&rdev->wiphy, info);
3404 if (IS_ERR(params.acl))
3405 return PTR_ERR(params.acl);
3406 }
3407
Eliad Peller18998c32014-09-10 14:07:34 +03003408 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3409 params.smps_mode =
3410 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3411 switch (params.smps_mode) {
3412 case NL80211_SMPS_OFF:
3413 break;
3414 case NL80211_SMPS_STATIC:
3415 if (!(rdev->wiphy.features &
3416 NL80211_FEATURE_STATIC_SMPS))
3417 return -EINVAL;
3418 break;
3419 case NL80211_SMPS_DYNAMIC:
3420 if (!(rdev->wiphy.features &
3421 NL80211_FEATURE_DYNAMIC_SMPS))
3422 return -EINVAL;
3423 break;
3424 default:
3425 return -EINVAL;
3426 }
3427 } else {
3428 params.smps_mode = NL80211_SMPS_OFF;
3429 }
3430
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003431 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003432 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003433 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003434 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003435 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003436 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003437 wdev->ssid_len = params.ssid_len;
3438 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003439 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003440 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303441
3442 kfree(params.acl);
3443
Johannes Berg56d18932011-05-09 18:41:15 +02003444 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003445}
3446
Johannes Berg88600202012-02-13 15:17:18 +01003447static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3448{
3449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3450 struct net_device *dev = info->user_ptr[1];
3451 struct wireless_dev *wdev = dev->ieee80211_ptr;
3452 struct cfg80211_beacon_data params;
3453 int err;
3454
3455 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3456 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3457 return -EOPNOTSUPP;
3458
3459 if (!rdev->ops->change_beacon)
3460 return -EOPNOTSUPP;
3461
3462 if (!wdev->beacon_interval)
3463 return -EINVAL;
3464
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003465 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003466 if (err)
3467 return err;
3468
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003469 wdev_lock(wdev);
3470 err = rdev_change_beacon(rdev, dev, &params);
3471 wdev_unlock(wdev);
3472
3473 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003474}
3475
3476static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003477{
Johannes Berg4c476992010-10-04 21:36:35 +02003478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3479 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003480
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003481 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003482}
3483
Johannes Berg5727ef12007-12-19 02:03:34 +01003484static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3485 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3486 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3487 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003488 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003489 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003490 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003491};
3492
Johannes Bergeccb8e82009-05-11 21:57:56 +03003493static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003494 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003495 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003496{
3497 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003498 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003499 int flag;
3500
Johannes Bergeccb8e82009-05-11 21:57:56 +03003501 /*
3502 * Try parsing the new attribute first so userspace
3503 * can specify both for older kernels.
3504 */
3505 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3506 if (nla) {
3507 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003508
Johannes Bergeccb8e82009-05-11 21:57:56 +03003509 sta_flags = nla_data(nla);
3510 params->sta_flags_mask = sta_flags->mask;
3511 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003512 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003513 if ((params->sta_flags_mask |
3514 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3515 return -EINVAL;
3516 return 0;
3517 }
3518
3519 /* if present, parse the old attribute */
3520
3521 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003522 if (!nla)
3523 return 0;
3524
3525 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3526 nla, sta_flags_policy))
3527 return -EINVAL;
3528
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003529 /*
3530 * Only allow certain flags for interface types so that
3531 * other attributes are silently ignored. Remember that
3532 * this is backward compatibility code with old userspace
3533 * and shouldn't be hit in other cases anyway.
3534 */
3535 switch (iftype) {
3536 case NL80211_IFTYPE_AP:
3537 case NL80211_IFTYPE_AP_VLAN:
3538 case NL80211_IFTYPE_P2P_GO:
3539 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3540 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3541 BIT(NL80211_STA_FLAG_WME) |
3542 BIT(NL80211_STA_FLAG_MFP);
3543 break;
3544 case NL80211_IFTYPE_P2P_CLIENT:
3545 case NL80211_IFTYPE_STATION:
3546 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3547 BIT(NL80211_STA_FLAG_TDLS_PEER);
3548 break;
3549 case NL80211_IFTYPE_MESH_POINT:
3550 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3551 BIT(NL80211_STA_FLAG_MFP) |
3552 BIT(NL80211_STA_FLAG_AUTHORIZED);
3553 default:
3554 return -EINVAL;
3555 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003556
Johannes Berg3383b5a2012-05-10 20:14:43 +02003557 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3558 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003559 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003560
Johannes Berg3383b5a2012-05-10 20:14:43 +02003561 /* no longer support new API additions in old API */
3562 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3563 return -EINVAL;
3564 }
3565 }
3566
Johannes Berg5727ef12007-12-19 02:03:34 +01003567 return 0;
3568}
3569
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003570static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3571 int attr)
3572{
3573 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003574 u32 bitrate;
3575 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003576
3577 rate = nla_nest_start(msg, attr);
3578 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003579 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003580
3581 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3582 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003583 /* report 16-bit bitrate only if we can */
3584 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003585 if (bitrate > 0 &&
3586 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3587 return false;
3588 if (bitrate_compat > 0 &&
3589 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3590 return false;
3591
3592 if (info->flags & RATE_INFO_FLAGS_MCS) {
3593 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3594 return false;
3595 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3596 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3597 return false;
3598 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3599 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3600 return false;
3601 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3602 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3603 return false;
3604 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3605 return false;
3606 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3607 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3608 return false;
3609 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3610 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3611 return false;
3612 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3613 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3614 return false;
3615 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3616 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3617 return false;
3618 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3619 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3620 return false;
3621 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003622
3623 nla_nest_end(msg, rate);
3624 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003625}
3626
Felix Fietkau119363c2013-04-22 16:29:30 +02003627static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3628 int id)
3629{
3630 void *attr;
3631 int i = 0;
3632
3633 if (!mask)
3634 return true;
3635
3636 attr = nla_nest_start(msg, id);
3637 if (!attr)
3638 return false;
3639
3640 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3641 if (!(mask & BIT(i)))
3642 continue;
3643
3644 if (nla_put_u8(msg, i, signal[i]))
3645 return false;
3646 }
3647
3648 nla_nest_end(msg, attr);
3649
3650 return true;
3651}
3652
Johannes Bergcf5ead82014-11-14 17:14:00 +01003653static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3654 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003655 struct cfg80211_registered_device *rdev,
3656 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003657 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003658{
3659 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003660 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003661
Johannes Bergcf5ead82014-11-14 17:14:00 +01003662 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003663 if (!hdr)
3664 return -1;
3665
David S. Miller9360ffd2012-03-29 04:41:26 -04003666 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3667 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3668 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3669 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003670
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003671 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3672 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003673 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003674
3675#define PUT_SINFO(attr, memb, type) do { \
3676 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3677 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3678 sinfo->memb)) \
3679 goto nla_put_failure; \
3680 } while (0)
3681
3682 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3683 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3684
3685 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3686 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003687 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003688 (u32)sinfo->rx_bytes))
3689 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003690
3691 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3692 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003693 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3694 (u32)sinfo->tx_bytes))
3695 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003696
3697 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3698 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3699 PUT_SINFO(LLID, llid, u16);
3700 PUT_SINFO(PLID, plid, u16);
3701 PUT_SINFO(PLINK_STATE, plink_state, u8);
3702
John W. Linville66266b32012-03-15 13:25:41 -04003703 switch (rdev->wiphy.signal_type) {
3704 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003705 PUT_SINFO(SIGNAL, signal, u8);
3706 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003707 break;
3708 default:
3709 break;
3710 }
Johannes Berg319090b2014-11-17 14:08:11 +01003711 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003712 if (!nl80211_put_signal(msg, sinfo->chains,
3713 sinfo->chain_signal,
3714 NL80211_STA_INFO_CHAIN_SIGNAL))
3715 goto nla_put_failure;
3716 }
Johannes Berg319090b2014-11-17 14:08:11 +01003717 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003718 if (!nl80211_put_signal(msg, sinfo->chains,
3719 sinfo->chain_signal_avg,
3720 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3721 goto nla_put_failure;
3722 }
Johannes Berg319090b2014-11-17 14:08:11 +01003723 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003724 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3725 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003726 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003727 }
Johannes Berg319090b2014-11-17 14:08:11 +01003728 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003729 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3730 NL80211_STA_INFO_RX_BITRATE))
3731 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003732 }
Johannes Berg319090b2014-11-17 14:08:11 +01003733
3734 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3735 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3736 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3737 PUT_SINFO(TX_FAILED, tx_failed, u32);
3738 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3739 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3740 PUT_SINFO(LOCAL_PM, local_pm, u32);
3741 PUT_SINFO(PEER_PM, peer_pm, u32);
3742 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3743
3744 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003745 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3746 if (!bss_param)
3747 goto nla_put_failure;
3748
David S. Miller9360ffd2012-03-29 04:41:26 -04003749 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3750 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3751 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3752 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3753 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3754 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3755 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3756 sinfo->bss_param.dtim_period) ||
3757 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3758 sinfo->bss_param.beacon_interval))
3759 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003760
3761 nla_nest_end(msg, bss_param);
3762 }
Johannes Berg319090b2014-11-17 14:08:11 +01003763 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003764 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3765 sizeof(struct nl80211_sta_flag_update),
3766 &sinfo->sta_flags))
3767 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003768
3769 PUT_SINFO(T_OFFSET, t_offset, u64);
3770 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003771 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3772 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003773
3774#undef PUT_SINFO
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003775 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003776
Johannes Berg319090b2014-11-17 14:08:11 +01003777 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003778 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3779 sinfo->assoc_req_ies))
3780 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003781
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003782 return genlmsg_end(msg, hdr);
3783
3784 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003785 genlmsg_cancel(msg, hdr);
3786 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003787}
3788
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003789static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003790 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003791{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003792 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003793 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003794 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003795 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003796 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003797 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003798
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003799 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003800 if (err)
3801 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003802
Johannes Berg97990a02013-04-19 01:02:55 +02003803 if (!wdev->netdev) {
3804 err = -EINVAL;
3805 goto out_err;
3806 }
3807
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003808 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003809 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003810 goto out_err;
3811 }
3812
Johannes Bergbba95fe2008-07-29 13:22:51 +02003813 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003814 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003815 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003816 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003817 if (err == -ENOENT)
3818 break;
3819 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003820 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003821
Johannes Bergcf5ead82014-11-14 17:14:00 +01003822 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003823 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003824 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003825 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003826 &sinfo) < 0)
3827 goto out;
3828
3829 sta_idx++;
3830 }
3831
3832
3833 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003834 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003835 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003836 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003837 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003838
3839 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003840}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003841
Johannes Berg5727ef12007-12-19 02:03:34 +01003842static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3843{
Johannes Berg4c476992010-10-04 21:36:35 +02003844 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3845 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003846 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003847 struct sk_buff *msg;
3848 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003849 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003850
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003851 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003852
3853 if (!info->attrs[NL80211_ATTR_MAC])
3854 return -EINVAL;
3855
3856 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3857
Johannes Berg4c476992010-10-04 21:36:35 +02003858 if (!rdev->ops->get_station)
3859 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003860
Hila Gonene35e4d22012-06-27 17:19:42 +03003861 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003862 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003863 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003864
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003865 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003866 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003867 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003868
Johannes Bergcf5ead82014-11-14 17:14:00 +01003869 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3870 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003871 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003872 nlmsg_free(msg);
3873 return -ENOBUFS;
3874 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003875
Johannes Berg4c476992010-10-04 21:36:35 +02003876 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003877}
3878
Johannes Berg77ee7c82013-02-15 00:48:33 +01003879int cfg80211_check_station_change(struct wiphy *wiphy,
3880 struct station_parameters *params,
3881 enum cfg80211_station_type statype)
3882{
3883 if (params->listen_interval != -1)
3884 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003885 if (params->aid &&
3886 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003887 return -EINVAL;
3888
3889 /* When you run into this, adjust the code below for the new flag */
3890 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3891
3892 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003893 case CFG80211_STA_MESH_PEER_KERNEL:
3894 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003895 /*
3896 * No ignoring the TDLS flag here -- the userspace mesh
3897 * code doesn't have the bug of including TDLS in the
3898 * mask everywhere.
3899 */
3900 if (params->sta_flags_mask &
3901 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3902 BIT(NL80211_STA_FLAG_MFP) |
3903 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3904 return -EINVAL;
3905 break;
3906 case CFG80211_STA_TDLS_PEER_SETUP:
3907 case CFG80211_STA_TDLS_PEER_ACTIVE:
3908 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3909 return -EINVAL;
3910 /* ignore since it can't change */
3911 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3912 break;
3913 default:
3914 /* disallow mesh-specific things */
3915 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3916 return -EINVAL;
3917 if (params->local_pm)
3918 return -EINVAL;
3919 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3920 return -EINVAL;
3921 }
3922
3923 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3924 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3925 /* TDLS can't be set, ... */
3926 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3927 return -EINVAL;
3928 /*
3929 * ... but don't bother the driver with it. This works around
3930 * a hostapd/wpa_supplicant issue -- it always includes the
3931 * TLDS_PEER flag in the mask even for AP mode.
3932 */
3933 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3934 }
3935
3936 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3937 /* reject other things that can't change */
3938 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3939 return -EINVAL;
3940 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3941 return -EINVAL;
3942 if (params->supported_rates)
3943 return -EINVAL;
3944 if (params->ext_capab || params->ht_capa || params->vht_capa)
3945 return -EINVAL;
3946 }
3947
3948 if (statype != CFG80211_STA_AP_CLIENT) {
3949 if (params->vlan)
3950 return -EINVAL;
3951 }
3952
3953 switch (statype) {
3954 case CFG80211_STA_AP_MLME_CLIENT:
3955 /* Use this only for authorizing/unauthorizing a station */
3956 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3957 return -EOPNOTSUPP;
3958 break;
3959 case CFG80211_STA_AP_CLIENT:
3960 /* accept only the listed bits */
3961 if (params->sta_flags_mask &
3962 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3963 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3964 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3965 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3966 BIT(NL80211_STA_FLAG_WME) |
3967 BIT(NL80211_STA_FLAG_MFP)))
3968 return -EINVAL;
3969
3970 /* but authenticated/associated only if driver handles it */
3971 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3972 params->sta_flags_mask &
3973 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3974 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3975 return -EINVAL;
3976 break;
3977 case CFG80211_STA_IBSS:
3978 case CFG80211_STA_AP_STA:
3979 /* reject any changes other than AUTHORIZED */
3980 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3981 return -EINVAL;
3982 break;
3983 case CFG80211_STA_TDLS_PEER_SETUP:
3984 /* reject any changes other than AUTHORIZED or WME */
3985 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3986 BIT(NL80211_STA_FLAG_WME)))
3987 return -EINVAL;
3988 /* force (at least) rates when authorizing */
3989 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3990 !params->supported_rates)
3991 return -EINVAL;
3992 break;
3993 case CFG80211_STA_TDLS_PEER_ACTIVE:
3994 /* reject any changes */
3995 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003996 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003997 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3998 return -EINVAL;
3999 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004000 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004001 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4002 return -EINVAL;
4003 break;
4004 }
4005
4006 return 0;
4007}
4008EXPORT_SYMBOL(cfg80211_check_station_change);
4009
Johannes Berg5727ef12007-12-19 02:03:34 +01004010/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004011 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004012 */
Johannes Berg80b99892011-11-18 16:23:01 +01004013static struct net_device *get_vlan(struct genl_info *info,
4014 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004015{
Johannes Berg463d0182009-07-14 00:33:35 +02004016 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004017 struct net_device *v;
4018 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004019
Johannes Berg80b99892011-11-18 16:23:01 +01004020 if (!vlanattr)
4021 return NULL;
4022
4023 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4024 if (!v)
4025 return ERR_PTR(-ENODEV);
4026
4027 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4028 ret = -EINVAL;
4029 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004030 }
Johannes Berg80b99892011-11-18 16:23:01 +01004031
Johannes Berg77ee7c82013-02-15 00:48:33 +01004032 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4033 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4034 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4035 ret = -EINVAL;
4036 goto error;
4037 }
4038
Johannes Berg80b99892011-11-18 16:23:01 +01004039 if (!netif_running(v)) {
4040 ret = -ENETDOWN;
4041 goto error;
4042 }
4043
4044 return v;
4045 error:
4046 dev_put(v);
4047 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004048}
4049
Johannes Berg94e860f2014-01-20 23:58:15 +01004050static const struct nla_policy
4051nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004052 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4053 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4054};
4055
Johannes Bergff276692013-02-15 00:09:01 +01004056static int nl80211_parse_sta_wme(struct genl_info *info,
4057 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004058{
Jouni Malinendf881292013-02-14 21:10:54 +02004059 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4060 struct nlattr *nla;
4061 int err;
4062
Jouni Malinendf881292013-02-14 21:10:54 +02004063 /* parse WME attributes if present */
4064 if (!info->attrs[NL80211_ATTR_STA_WME])
4065 return 0;
4066
4067 nla = info->attrs[NL80211_ATTR_STA_WME];
4068 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4069 nl80211_sta_wme_policy);
4070 if (err)
4071 return err;
4072
4073 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4074 params->uapsd_queues = nla_get_u8(
4075 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4076 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4077 return -EINVAL;
4078
4079 if (tb[NL80211_STA_WME_MAX_SP])
4080 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4081
4082 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4083 return -EINVAL;
4084
4085 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4086
4087 return 0;
4088}
4089
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304090static int nl80211_parse_sta_channel_info(struct genl_info *info,
4091 struct station_parameters *params)
4092{
4093 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4094 params->supported_channels =
4095 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4096 params->supported_channels_len =
4097 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4098 /*
4099 * Need to include at least one (first channel, number of
4100 * channels) tuple for each subband, and must have proper
4101 * tuples for the rest of the data as well.
4102 */
4103 if (params->supported_channels_len < 2)
4104 return -EINVAL;
4105 if (params->supported_channels_len % 2)
4106 return -EINVAL;
4107 }
4108
4109 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4110 params->supported_oper_classes =
4111 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4112 params->supported_oper_classes_len =
4113 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4114 /*
4115 * The value of the Length field of the Supported Operating
4116 * Classes element is between 2 and 253.
4117 */
4118 if (params->supported_oper_classes_len < 2 ||
4119 params->supported_oper_classes_len > 253)
4120 return -EINVAL;
4121 }
4122 return 0;
4123}
4124
Johannes Bergff276692013-02-15 00:09:01 +01004125static int nl80211_set_station_tdls(struct genl_info *info,
4126 struct station_parameters *params)
4127{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304128 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004129 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004130 if (info->attrs[NL80211_ATTR_PEER_AID])
4131 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004132 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4133 params->ht_capa =
4134 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4135 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4136 params->vht_capa =
4137 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4138
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304139 err = nl80211_parse_sta_channel_info(info, params);
4140 if (err)
4141 return err;
4142
Johannes Bergff276692013-02-15 00:09:01 +01004143 return nl80211_parse_sta_wme(info, params);
4144}
4145
Johannes Berg5727ef12007-12-19 02:03:34 +01004146static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4147{
Johannes Berg4c476992010-10-04 21:36:35 +02004148 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004149 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004150 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004151 u8 *mac_addr;
4152 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004153
4154 memset(&params, 0, sizeof(params));
4155
4156 params.listen_interval = -1;
4157
Johannes Berg77ee7c82013-02-15 00:48:33 +01004158 if (!rdev->ops->change_station)
4159 return -EOPNOTSUPP;
4160
Johannes Berg5727ef12007-12-19 02:03:34 +01004161 if (info->attrs[NL80211_ATTR_STA_AID])
4162 return -EINVAL;
4163
4164 if (!info->attrs[NL80211_ATTR_MAC])
4165 return -EINVAL;
4166
4167 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4168
4169 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4170 params.supported_rates =
4171 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4172 params.supported_rates_len =
4173 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4174 }
4175
Jouni Malinen9d62a982013-02-14 21:10:13 +02004176 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4177 params.capability =
4178 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4179 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4180 }
4181
4182 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4183 params.ext_capab =
4184 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4185 params.ext_capab_len =
4186 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4187 }
4188
Jouni Malinendf881292013-02-14 21:10:54 +02004189 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004190 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004191
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004192 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004193 return -EINVAL;
4194
Johannes Bergf8bacc22013-02-14 23:27:01 +01004195 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004196 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004197 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4198 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4199 return -EINVAL;
4200 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004201
Johannes Bergf8bacc22013-02-14 23:27:01 +01004202 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004203 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004204 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4205 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4206 return -EINVAL;
4207 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4208 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004209
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004210 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4211 enum nl80211_mesh_power_mode pm = nla_get_u32(
4212 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4213
4214 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4215 pm > NL80211_MESH_POWER_MAX)
4216 return -EINVAL;
4217
4218 params.local_pm = pm;
4219 }
4220
Johannes Berg77ee7c82013-02-15 00:48:33 +01004221 /* Include parameters for TDLS peer (will check later) */
4222 err = nl80211_set_station_tdls(info, &params);
4223 if (err)
4224 return err;
4225
4226 params.vlan = get_vlan(info, rdev);
4227 if (IS_ERR(params.vlan))
4228 return PTR_ERR(params.vlan);
4229
Johannes Berga97f4422009-06-18 17:23:43 +02004230 switch (dev->ieee80211_ptr->iftype) {
4231 case NL80211_IFTYPE_AP:
4232 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004233 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004234 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004235 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004236 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004237 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004238 break;
4239 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004240 err = -EOPNOTSUPP;
4241 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004242 }
4243
Johannes Berg77ee7c82013-02-15 00:48:33 +01004244 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004245 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004246
Johannes Berg77ee7c82013-02-15 00:48:33 +01004247 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004248 if (params.vlan)
4249 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004250
Johannes Berg5727ef12007-12-19 02:03:34 +01004251 return err;
4252}
4253
4254static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4255{
Johannes Berg4c476992010-10-04 21:36:35 +02004256 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004257 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004258 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004259 struct station_parameters params;
4260 u8 *mac_addr = NULL;
4261
4262 memset(&params, 0, sizeof(params));
4263
Johannes Berg984c3112013-02-14 23:43:25 +01004264 if (!rdev->ops->add_station)
4265 return -EOPNOTSUPP;
4266
Johannes Berg5727ef12007-12-19 02:03:34 +01004267 if (!info->attrs[NL80211_ATTR_MAC])
4268 return -EINVAL;
4269
Johannes Berg5727ef12007-12-19 02:03:34 +01004270 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4271 return -EINVAL;
4272
4273 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4274 return -EINVAL;
4275
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004276 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4277 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004278 return -EINVAL;
4279
Johannes Berg5727ef12007-12-19 02:03:34 +01004280 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4281 params.supported_rates =
4282 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4283 params.supported_rates_len =
4284 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4285 params.listen_interval =
4286 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004287
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004288 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004289 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004290 else
4291 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004292 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4293 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004294
Jouni Malinen9d62a982013-02-14 21:10:13 +02004295 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4296 params.capability =
4297 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4298 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4299 }
4300
4301 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4302 params.ext_capab =
4303 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4304 params.ext_capab_len =
4305 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4306 }
4307
Jouni Malinen36aedc92008-08-25 11:58:58 +03004308 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4309 params.ht_capa =
4310 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004311
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004312 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4313 params.vht_capa =
4314 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4315
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004316 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4317 params.opmode_notif_used = true;
4318 params.opmode_notif =
4319 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4320 }
4321
Johannes Bergf8bacc22013-02-14 23:27:01 +01004322 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004323 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004324 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4325 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4326 return -EINVAL;
4327 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004328
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304329 err = nl80211_parse_sta_channel_info(info, &params);
4330 if (err)
4331 return err;
4332
Johannes Bergff276692013-02-15 00:09:01 +01004333 err = nl80211_parse_sta_wme(info, &params);
4334 if (err)
4335 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004336
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004337 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004338 return -EINVAL;
4339
Johannes Berg77ee7c82013-02-15 00:48:33 +01004340 /* When you run into this, adjust the code below for the new flag */
4341 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4342
Johannes Bergbdd90d52011-12-14 12:20:27 +01004343 switch (dev->ieee80211_ptr->iftype) {
4344 case NL80211_IFTYPE_AP:
4345 case NL80211_IFTYPE_AP_VLAN:
4346 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004347 /* ignore WME attributes if iface/sta is not capable */
4348 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4349 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4350 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004351
Johannes Bergbdd90d52011-12-14 12:20:27 +01004352 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004353 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4354 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004355 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004356 /* but don't bother the driver with it */
4357 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004358
Johannes Bergd582cff2012-10-26 17:53:44 +02004359 /* allow authenticated/associated only if driver handles it */
4360 if (!(rdev->wiphy.features &
4361 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4362 params.sta_flags_mask &
4363 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4364 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4365 return -EINVAL;
4366
Johannes Bergbdd90d52011-12-14 12:20:27 +01004367 /* must be last in here for error handling */
4368 params.vlan = get_vlan(info, rdev);
4369 if (IS_ERR(params.vlan))
4370 return PTR_ERR(params.vlan);
4371 break;
4372 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004373 /* ignore uAPSD data */
4374 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4375
Johannes Bergd582cff2012-10-26 17:53:44 +02004376 /* associated is disallowed */
4377 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4378 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004379 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004380 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4381 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004382 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004383 break;
4384 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004385 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004386 /* ignore uAPSD data */
4387 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4388
Johannes Berg77ee7c82013-02-15 00:48:33 +01004389 /* these are disallowed */
4390 if (params.sta_flags_mask &
4391 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4392 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004393 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004394 /* Only TDLS peers can be added */
4395 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4396 return -EINVAL;
4397 /* Can only add if TDLS ... */
4398 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4399 return -EOPNOTSUPP;
4400 /* ... with external setup is supported */
4401 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4402 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004403 /*
4404 * Older wpa_supplicant versions always mark the TDLS peer
4405 * as authorized, but it shouldn't yet be.
4406 */
4407 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004408 break;
4409 default:
4410 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004411 }
4412
Johannes Bergbdd90d52011-12-14 12:20:27 +01004413 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004414
Hila Gonene35e4d22012-06-27 17:19:42 +03004415 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004416
Johannes Berg5727ef12007-12-19 02:03:34 +01004417 if (params.vlan)
4418 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004419 return err;
4420}
4421
4422static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4423{
Johannes Berg4c476992010-10-04 21:36:35 +02004424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4425 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004426 struct station_del_parameters params;
4427
4428 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004429
4430 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004431 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004432
Johannes Berge80cf852009-05-11 14:43:13 +02004433 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004434 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004435 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004436 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4437 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004438
Johannes Berg4c476992010-10-04 21:36:35 +02004439 if (!rdev->ops->del_station)
4440 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004441
Jouni Malinen98856862014-10-20 13:20:45 +03004442 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4443 params.subtype =
4444 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4445 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4446 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4447 return -EINVAL;
4448 } else {
4449 /* Default to Deauthentication frame */
4450 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4451 }
4452
4453 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4454 params.reason_code =
4455 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4456 if (params.reason_code == 0)
4457 return -EINVAL; /* 0 is reserved */
4458 } else {
4459 /* Default to reason code 2 */
4460 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4461 }
4462
Jouni Malinen89c771e2014-10-10 20:52:40 +03004463 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004464}
4465
Eric W. Biederman15e47302012-09-07 20:12:54 +00004466static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004467 int flags, struct net_device *dev,
4468 u8 *dst, u8 *next_hop,
4469 struct mpath_info *pinfo)
4470{
4471 void *hdr;
4472 struct nlattr *pinfoattr;
4473
Henning Rogge1ef4c852014-11-04 16:14:58 +01004474 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004475 if (!hdr)
4476 return -1;
4477
David S. Miller9360ffd2012-03-29 04:41:26 -04004478 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4479 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4480 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4481 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4482 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004483
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004484 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4485 if (!pinfoattr)
4486 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004487 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4488 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4489 pinfo->frame_qlen))
4490 goto nla_put_failure;
4491 if (((pinfo->filled & MPATH_INFO_SN) &&
4492 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4493 ((pinfo->filled & MPATH_INFO_METRIC) &&
4494 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4495 pinfo->metric)) ||
4496 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4497 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4498 pinfo->exptime)) ||
4499 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4500 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4501 pinfo->flags)) ||
4502 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4503 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4504 pinfo->discovery_timeout)) ||
4505 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4506 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4507 pinfo->discovery_retries)))
4508 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004509
4510 nla_nest_end(msg, pinfoattr);
4511
4512 return genlmsg_end(msg, hdr);
4513
4514 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004515 genlmsg_cancel(msg, hdr);
4516 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517}
4518
4519static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004520 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004521{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004522 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004523 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004524 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004525 u8 dst[ETH_ALEN];
4526 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004527 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004528 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004529
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004530 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004531 if (err)
4532 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004533
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004534 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004535 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004536 goto out_err;
4537 }
4538
Johannes Berg97990a02013-04-19 01:02:55 +02004539 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004540 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004541 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004542 }
4543
Johannes Bergbba95fe2008-07-29 13:22:51 +02004544 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004545 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004546 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004547 if (err == -ENOENT)
4548 break;
4549 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004550 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004551
Eric W. Biederman15e47302012-09-07 20:12:54 +00004552 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004553 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004554 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004555 &pinfo) < 0)
4556 goto out;
4557
4558 path_idx++;
4559 }
4560
4561
4562 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004563 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004564 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004565 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004566 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004567 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004568}
4569
4570static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4571{
Johannes Berg4c476992010-10-04 21:36:35 +02004572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004573 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004575 struct mpath_info pinfo;
4576 struct sk_buff *msg;
4577 u8 *dst = NULL;
4578 u8 next_hop[ETH_ALEN];
4579
4580 memset(&pinfo, 0, sizeof(pinfo));
4581
4582 if (!info->attrs[NL80211_ATTR_MAC])
4583 return -EINVAL;
4584
4585 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4586
Johannes Berg4c476992010-10-04 21:36:35 +02004587 if (!rdev->ops->get_mpath)
4588 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004589
Johannes Berg4c476992010-10-04 21:36:35 +02004590 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4591 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004592
Hila Gonene35e4d22012-06-27 17:19:42 +03004593 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004594 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004595 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004596
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004598 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004599 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004600
Eric W. Biederman15e47302012-09-07 20:12:54 +00004601 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004602 dev, dst, next_hop, &pinfo) < 0) {
4603 nlmsg_free(msg);
4604 return -ENOBUFS;
4605 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004606
Johannes Berg4c476992010-10-04 21:36:35 +02004607 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004608}
4609
4610static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4611{
Johannes Berg4c476992010-10-04 21:36:35 +02004612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4613 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004614 u8 *dst = NULL;
4615 u8 *next_hop = NULL;
4616
4617 if (!info->attrs[NL80211_ATTR_MAC])
4618 return -EINVAL;
4619
4620 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4621 return -EINVAL;
4622
4623 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4624 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4625
Johannes Berg4c476992010-10-04 21:36:35 +02004626 if (!rdev->ops->change_mpath)
4627 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004628
Johannes Berg4c476992010-10-04 21:36:35 +02004629 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4630 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004631
Hila Gonene35e4d22012-06-27 17:19:42 +03004632 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004633}
Johannes Berg4c476992010-10-04 21:36:35 +02004634
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004635static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4636{
Johannes Berg4c476992010-10-04 21:36:35 +02004637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4638 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004639 u8 *dst = NULL;
4640 u8 *next_hop = NULL;
4641
4642 if (!info->attrs[NL80211_ATTR_MAC])
4643 return -EINVAL;
4644
4645 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4646 return -EINVAL;
4647
4648 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4649 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4650
Johannes Berg4c476992010-10-04 21:36:35 +02004651 if (!rdev->ops->add_mpath)
4652 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004653
Johannes Berg4c476992010-10-04 21:36:35 +02004654 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4655 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004656
Hila Gonene35e4d22012-06-27 17:19:42 +03004657 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004658}
4659
4660static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4661{
Johannes Berg4c476992010-10-04 21:36:35 +02004662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4663 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004664 u8 *dst = NULL;
4665
4666 if (info->attrs[NL80211_ATTR_MAC])
4667 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4668
Johannes Berg4c476992010-10-04 21:36:35 +02004669 if (!rdev->ops->del_mpath)
4670 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004671
Hila Gonene35e4d22012-06-27 17:19:42 +03004672 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004673}
4674
Henning Rogge66be7d22014-09-12 08:58:49 +02004675static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4676{
4677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4678 int err;
4679 struct net_device *dev = info->user_ptr[1];
4680 struct mpath_info pinfo;
4681 struct sk_buff *msg;
4682 u8 *dst = NULL;
4683 u8 mpp[ETH_ALEN];
4684
4685 memset(&pinfo, 0, sizeof(pinfo));
4686
4687 if (!info->attrs[NL80211_ATTR_MAC])
4688 return -EINVAL;
4689
4690 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4691
4692 if (!rdev->ops->get_mpp)
4693 return -EOPNOTSUPP;
4694
4695 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4696 return -EOPNOTSUPP;
4697
4698 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4699 if (err)
4700 return err;
4701
4702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4703 if (!msg)
4704 return -ENOMEM;
4705
4706 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4707 dev, dst, mpp, &pinfo) < 0) {
4708 nlmsg_free(msg);
4709 return -ENOBUFS;
4710 }
4711
4712 return genlmsg_reply(msg, info);
4713}
4714
4715static int nl80211_dump_mpp(struct sk_buff *skb,
4716 struct netlink_callback *cb)
4717{
4718 struct mpath_info pinfo;
4719 struct cfg80211_registered_device *rdev;
4720 struct wireless_dev *wdev;
4721 u8 dst[ETH_ALEN];
4722 u8 mpp[ETH_ALEN];
4723 int path_idx = cb->args[2];
4724 int err;
4725
4726 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4727 if (err)
4728 return err;
4729
4730 if (!rdev->ops->dump_mpp) {
4731 err = -EOPNOTSUPP;
4732 goto out_err;
4733 }
4734
4735 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4736 err = -EOPNOTSUPP;
4737 goto out_err;
4738 }
4739
4740 while (1) {
4741 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4742 mpp, &pinfo);
4743 if (err == -ENOENT)
4744 break;
4745 if (err)
4746 goto out_err;
4747
4748 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4749 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4750 wdev->netdev, dst, mpp,
4751 &pinfo) < 0)
4752 goto out;
4753
4754 path_idx++;
4755 }
4756
4757 out:
4758 cb->args[2] = path_idx;
4759 err = skb->len;
4760 out_err:
4761 nl80211_finish_wdev_dump(rdev);
4762 return err;
4763}
4764
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004765static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4766{
Johannes Berg4c476992010-10-04 21:36:35 +02004767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4768 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004769 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004770 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004771 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004772
4773 memset(&params, 0, sizeof(params));
4774 /* default to not changing parameters */
4775 params.use_cts_prot = -1;
4776 params.use_short_preamble = -1;
4777 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004778 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004779 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004780 params.p2p_ctwindow = -1;
4781 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004782
4783 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4784 params.use_cts_prot =
4785 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4786 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4787 params.use_short_preamble =
4788 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4789 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4790 params.use_short_slot_time =
4791 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004792 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4793 params.basic_rates =
4794 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4795 params.basic_rates_len =
4796 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4797 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004798 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4799 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004800 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4801 params.ht_opmode =
4802 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004803
Johannes Berg53cabad2012-11-14 15:17:28 +01004804 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4805 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4806 return -EINVAL;
4807 params.p2p_ctwindow =
4808 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4809 if (params.p2p_ctwindow < 0)
4810 return -EINVAL;
4811 if (params.p2p_ctwindow != 0 &&
4812 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4813 return -EINVAL;
4814 }
4815
4816 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4817 u8 tmp;
4818
4819 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4820 return -EINVAL;
4821 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4822 if (tmp > 1)
4823 return -EINVAL;
4824 params.p2p_opp_ps = tmp;
4825 if (params.p2p_opp_ps &&
4826 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4827 return -EINVAL;
4828 }
4829
Johannes Berg4c476992010-10-04 21:36:35 +02004830 if (!rdev->ops->change_bss)
4831 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004832
Johannes Berg074ac8d2010-09-16 14:58:22 +02004833 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004834 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4835 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004836
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004837 wdev_lock(wdev);
4838 err = rdev_change_bss(rdev, dev, &params);
4839 wdev_unlock(wdev);
4840
4841 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004842}
4843
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004844static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004845 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4846 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4847 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4848 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4849 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4850 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004851 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004852};
4853
4854static int parse_reg_rule(struct nlattr *tb[],
4855 struct ieee80211_reg_rule *reg_rule)
4856{
4857 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4858 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4859
4860 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4861 return -EINVAL;
4862 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4863 return -EINVAL;
4864 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4865 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004866 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4867 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004868 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4869 return -EINVAL;
4870
4871 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4872
4873 freq_range->start_freq_khz =
4874 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4875 freq_range->end_freq_khz =
4876 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004877 freq_range->max_bandwidth_khz =
4878 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004879
4880 power_rule->max_eirp =
4881 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4882
4883 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4884 power_rule->max_antenna_gain =
4885 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4886
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004887 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4888 reg_rule->dfs_cac_ms =
4889 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4890
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004891 return 0;
4892}
4893
4894static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4895{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004896 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004897 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004898
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004899 /*
4900 * You should only get this when cfg80211 hasn't yet initialized
4901 * completely when built-in to the kernel right between the time
4902 * window between nl80211_init() and regulatory_init(), if that is
4903 * even possible.
4904 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004905 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004906 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004907
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004908 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4909 user_reg_hint_type =
4910 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4911 else
4912 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4913
4914 switch (user_reg_hint_type) {
4915 case NL80211_USER_REG_HINT_USER:
4916 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004917 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4918 return -EINVAL;
4919
4920 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4921 return regulatory_hint_user(data, user_reg_hint_type);
4922 case NL80211_USER_REG_HINT_INDOOR:
4923 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004924 default:
4925 return -EINVAL;
4926 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004927}
4928
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004929static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004930 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004931{
Johannes Berg4c476992010-10-04 21:36:35 +02004932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004933 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004934 struct wireless_dev *wdev = dev->ieee80211_ptr;
4935 struct mesh_config cur_params;
4936 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004937 void *hdr;
4938 struct nlattr *pinfoattr;
4939 struct sk_buff *msg;
4940
Johannes Berg29cbe682010-12-03 09:20:44 +01004941 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4942 return -EOPNOTSUPP;
4943
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004944 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004945 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004946
Johannes Berg29cbe682010-12-03 09:20:44 +01004947 wdev_lock(wdev);
4948 /* If not connected, get default parameters */
4949 if (!wdev->mesh_id_len)
4950 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4951 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004952 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004953 wdev_unlock(wdev);
4954
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004955 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004956 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004957
4958 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004959 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004960 if (!msg)
4961 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004962 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004963 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004964 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004965 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004966 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004967 if (!pinfoattr)
4968 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004969 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4970 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4971 cur_params.dot11MeshRetryTimeout) ||
4972 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4973 cur_params.dot11MeshConfirmTimeout) ||
4974 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4975 cur_params.dot11MeshHoldingTimeout) ||
4976 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4977 cur_params.dot11MeshMaxPeerLinks) ||
4978 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4979 cur_params.dot11MeshMaxRetries) ||
4980 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4981 cur_params.dot11MeshTTL) ||
4982 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4983 cur_params.element_ttl) ||
4984 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4985 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004986 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4987 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004988 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4989 cur_params.dot11MeshHWMPmaxPREQretries) ||
4990 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4991 cur_params.path_refresh_time) ||
4992 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4993 cur_params.min_discovery_timeout) ||
4994 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4995 cur_params.dot11MeshHWMPactivePathTimeout) ||
4996 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4997 cur_params.dot11MeshHWMPpreqMinInterval) ||
4998 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4999 cur_params.dot11MeshHWMPperrMinInterval) ||
5000 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5001 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5002 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5003 cur_params.dot11MeshHWMPRootMode) ||
5004 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5005 cur_params.dot11MeshHWMPRannInterval) ||
5006 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5007 cur_params.dot11MeshGateAnnouncementProtocol) ||
5008 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5009 cur_params.dot11MeshForwarding) ||
5010 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005011 cur_params.rssi_threshold) ||
5012 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005013 cur_params.ht_opmode) ||
5014 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5015 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5016 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005017 cur_params.dot11MeshHWMProotInterval) ||
5018 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005019 cur_params.dot11MeshHWMPconfirmationInterval) ||
5020 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5021 cur_params.power_mode) ||
5022 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005023 cur_params.dot11MeshAwakeWindowDuration) ||
5024 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5025 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005026 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005027 nla_nest_end(msg, pinfoattr);
5028 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005029 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005030
Johannes Berg3b858752009-03-12 09:55:09 +01005031 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005032 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005033 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005034 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005035 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005036}
5037
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005038static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005039 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5040 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5041 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5042 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5043 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5044 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005045 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005046 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005047 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005048 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5049 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5050 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5051 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5052 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005053 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005054 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005055 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005056 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005057 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005058 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005059 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5060 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005061 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5062 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005063 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005064 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5065 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005066 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005067};
5068
Javier Cardonac80d5452010-12-16 17:37:49 -08005069static const struct nla_policy
5070 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005071 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005072 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5073 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005074 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005075 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005076 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005077 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005078 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005079 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005080};
5081
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005082static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005083 struct mesh_config *cfg,
5084 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005085{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005086 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005087 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005088
Marco Porschea54fba2013-01-07 16:04:48 +01005089#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5090do { \
5091 if (tb[attr]) { \
5092 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5093 return -EINVAL; \
5094 cfg->param = fn(tb[attr]); \
5095 mask |= (1 << (attr - 1)); \
5096 } \
5097} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005098
5099
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005100 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005101 return -EINVAL;
5102 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005103 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005104 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005105 return -EINVAL;
5106
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005107 /* This makes sure that there aren't more than 32 mesh config
5108 * parameters (otherwise our bitfield scheme would not work.) */
5109 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5110
5111 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005112 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005113 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5114 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005115 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005116 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5117 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005118 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005119 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5120 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005121 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005122 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5123 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005124 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005125 mask, NL80211_MESHCONF_MAX_RETRIES,
5126 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005127 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005128 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005129 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005130 mask, NL80211_MESHCONF_ELEMENT_TTL,
5131 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005132 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005133 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5134 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005135 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5136 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005137 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5138 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005139 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005140 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5141 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005142 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005143 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5144 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005145 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005146 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5147 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005148 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5149 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005150 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5151 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005152 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005153 1, 65535, mask,
5154 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005155 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005156 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005157 1, 65535, mask,
5158 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005159 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005160 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005161 dot11MeshHWMPnetDiameterTraversalTime,
5162 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005163 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5164 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005165 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5166 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5167 nla_get_u8);
5168 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5169 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005170 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005171 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005172 dot11MeshGateAnnouncementProtocol, 0, 1,
5173 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005174 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005175 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005176 mask, NL80211_MESHCONF_FORWARDING,
5177 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005178 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005179 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005180 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005181 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005182 mask, NL80211_MESHCONF_HT_OPMODE,
5183 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005184 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005185 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005186 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5187 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005188 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005189 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5190 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005191 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005192 dot11MeshHWMPconfirmationInterval,
5193 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005194 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5195 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005196 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5197 NL80211_MESH_POWER_ACTIVE,
5198 NL80211_MESH_POWER_MAX,
5199 mask, NL80211_MESHCONF_POWER_MODE,
5200 nla_get_u32);
5201 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5202 0, 65535, mask,
5203 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005204 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5205 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5206 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005207 if (mask_out)
5208 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005209
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005210 return 0;
5211
5212#undef FILL_IN_MESH_PARAM_IF_SET
5213}
5214
Javier Cardonac80d5452010-12-16 17:37:49 -08005215static int nl80211_parse_mesh_setup(struct genl_info *info,
5216 struct mesh_setup *setup)
5217{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005219 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5220
5221 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5222 return -EINVAL;
5223 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5224 info->attrs[NL80211_ATTR_MESH_SETUP],
5225 nl80211_mesh_setup_params_policy))
5226 return -EINVAL;
5227
Javier Cardonad299a1f2012-03-31 11:31:33 -07005228 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5229 setup->sync_method =
5230 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5231 IEEE80211_SYNC_METHOD_VENDOR :
5232 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5233
Javier Cardonac80d5452010-12-16 17:37:49 -08005234 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5235 setup->path_sel_proto =
5236 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5237 IEEE80211_PATH_PROTOCOL_VENDOR :
5238 IEEE80211_PATH_PROTOCOL_HWMP;
5239
5240 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5241 setup->path_metric =
5242 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5243 IEEE80211_PATH_METRIC_VENDOR :
5244 IEEE80211_PATH_METRIC_AIRTIME;
5245
Javier Cardona581a8b02011-04-07 15:08:27 -07005246
5247 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005248 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005249 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005250 if (!is_valid_ie_attr(ieattr))
5251 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005252 setup->ie = nla_data(ieattr);
5253 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005254 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005255 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5256 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5257 return -EINVAL;
5258 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005259 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5260 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005261 if (setup->is_secure)
5262 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005263
Colleen Twitty6e16d902013-05-08 11:45:59 -07005264 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5265 if (!setup->user_mpm)
5266 return -EINVAL;
5267 setup->auth_id =
5268 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5269 }
5270
Javier Cardonac80d5452010-12-16 17:37:49 -08005271 return 0;
5272}
5273
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005274static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005275 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005276{
5277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5278 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005279 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005280 struct mesh_config cfg;
5281 u32 mask;
5282 int err;
5283
Johannes Berg29cbe682010-12-03 09:20:44 +01005284 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5285 return -EOPNOTSUPP;
5286
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005287 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005288 return -EOPNOTSUPP;
5289
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005290 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005291 if (err)
5292 return err;
5293
Johannes Berg29cbe682010-12-03 09:20:44 +01005294 wdev_lock(wdev);
5295 if (!wdev->mesh_id_len)
5296 err = -ENOLINK;
5297
5298 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005299 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005300
5301 wdev_unlock(wdev);
5302
5303 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005304}
5305
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005306static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5307 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005308{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005309 struct nlattr *nl_reg_rules;
5310 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005311
Johannes Berg458f4f92012-12-06 15:47:38 +01005312 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5313 (regdom->dfs_region &&
5314 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005315 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005316
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005317 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5318 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005319 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005320
Johannes Berg458f4f92012-12-06 15:47:38 +01005321 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005322 struct nlattr *nl_reg_rule;
5323 const struct ieee80211_reg_rule *reg_rule;
5324 const struct ieee80211_freq_range *freq_range;
5325 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005326 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005327
Johannes Berg458f4f92012-12-06 15:47:38 +01005328 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005329 freq_range = &reg_rule->freq_range;
5330 power_rule = &reg_rule->power_rule;
5331
5332 nl_reg_rule = nla_nest_start(msg, i);
5333 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005334 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005335
Janusz Dziedzic97524822014-01-30 09:52:20 +01005336 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5337 if (!max_bandwidth_khz)
5338 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5339 reg_rule);
5340
David S. Miller9360ffd2012-03-29 04:41:26 -04005341 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5342 reg_rule->flags) ||
5343 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5344 freq_range->start_freq_khz) ||
5345 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5346 freq_range->end_freq_khz) ||
5347 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005348 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005349 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5350 power_rule->max_antenna_gain) ||
5351 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005352 power_rule->max_eirp) ||
5353 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5354 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005355 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005356
5357 nla_nest_end(msg, nl_reg_rule);
5358 }
5359
5360 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005361 return 0;
5362
5363nla_put_failure:
5364 return -EMSGSIZE;
5365}
5366
5367static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5368{
5369 const struct ieee80211_regdomain *regdom = NULL;
5370 struct cfg80211_registered_device *rdev;
5371 struct wiphy *wiphy = NULL;
5372 struct sk_buff *msg;
5373 void *hdr;
5374
5375 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5376 if (!msg)
5377 return -ENOBUFS;
5378
5379 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5380 NL80211_CMD_GET_REG);
5381 if (!hdr)
5382 goto put_failure;
5383
5384 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005385 bool self_managed;
5386
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005387 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5388 if (IS_ERR(rdev)) {
5389 nlmsg_free(msg);
5390 return PTR_ERR(rdev);
5391 }
5392
5393 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005394 self_managed = wiphy->regulatory_flags &
5395 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005396 regdom = get_wiphy_regdom(wiphy);
5397
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005398 /* a self-managed-reg device must have a private regdom */
5399 if (WARN_ON(!regdom && self_managed)) {
5400 nlmsg_free(msg);
5401 return -EINVAL;
5402 }
5403
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005404 if (regdom &&
5405 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5406 goto nla_put_failure;
5407 }
5408
5409 if (!wiphy && reg_last_request_cell_base() &&
5410 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5411 NL80211_USER_REG_HINT_CELL_BASE))
5412 goto nla_put_failure;
5413
5414 rcu_read_lock();
5415
5416 if (!regdom)
5417 regdom = rcu_dereference(cfg80211_regdomain);
5418
5419 if (nl80211_put_regdom(regdom, msg))
5420 goto nla_put_failure_rcu;
5421
5422 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005423
5424 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005425 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005426
Johannes Berg458f4f92012-12-06 15:47:38 +01005427nla_put_failure_rcu:
5428 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005429nla_put_failure:
5430 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005431put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005432 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005433 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005434}
5435
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005436static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5437 u32 seq, int flags, struct wiphy *wiphy,
5438 const struct ieee80211_regdomain *regdom)
5439{
5440 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5441 NL80211_CMD_GET_REG);
5442
5443 if (!hdr)
5444 return -1;
5445
5446 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5447
5448 if (nl80211_put_regdom(regdom, msg))
5449 goto nla_put_failure;
5450
5451 if (!wiphy && reg_last_request_cell_base() &&
5452 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5453 NL80211_USER_REG_HINT_CELL_BASE))
5454 goto nla_put_failure;
5455
5456 if (wiphy &&
5457 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5458 goto nla_put_failure;
5459
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005460 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5461 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5462 goto nla_put_failure;
5463
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005464 return genlmsg_end(msg, hdr);
5465
5466nla_put_failure:
5467 genlmsg_cancel(msg, hdr);
5468 return -EMSGSIZE;
5469}
5470
5471static int nl80211_get_reg_dump(struct sk_buff *skb,
5472 struct netlink_callback *cb)
5473{
5474 const struct ieee80211_regdomain *regdom = NULL;
5475 struct cfg80211_registered_device *rdev;
5476 int err, reg_idx, start = cb->args[2];
5477
5478 rtnl_lock();
5479
5480 if (cfg80211_regdomain && start == 0) {
5481 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5482 NLM_F_MULTI, NULL,
5483 rtnl_dereference(cfg80211_regdomain));
5484 if (err < 0)
5485 goto out_err;
5486 }
5487
5488 /* the global regdom is idx 0 */
5489 reg_idx = 1;
5490 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5491 regdom = get_wiphy_regdom(&rdev->wiphy);
5492 if (!regdom)
5493 continue;
5494
5495 if (++reg_idx <= start)
5496 continue;
5497
5498 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5499 NLM_F_MULTI, &rdev->wiphy, regdom);
5500 if (err < 0) {
5501 reg_idx--;
5502 break;
5503 }
5504 }
5505
5506 cb->args[2] = reg_idx;
5507 err = skb->len;
5508out_err:
5509 rtnl_unlock();
5510 return err;
5511}
5512
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005513static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5514{
5515 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5516 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005517 char *alpha2;
5518 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005519 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005520 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005521 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005522
5523 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5524 return -EINVAL;
5525
5526 if (!info->attrs[NL80211_ATTR_REG_RULES])
5527 return -EINVAL;
5528
5529 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5530
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005531 if (info->attrs[NL80211_ATTR_DFS_REGION])
5532 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5533
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005534 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005535 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005536 num_rules++;
5537 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005538 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005539 }
5540
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005541 if (!reg_is_valid_request(alpha2))
5542 return -EINVAL;
5543
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005544 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005545 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005546
5547 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005548 if (!rd)
5549 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005550
5551 rd->n_reg_rules = num_rules;
5552 rd->alpha2[0] = alpha2[0];
5553 rd->alpha2[1] = alpha2[1];
5554
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005555 /*
5556 * Disable DFS master mode if the DFS region was
5557 * not supported or known on this kernel.
5558 */
5559 if (reg_supported_dfs_region(dfs_region))
5560 rd->dfs_region = dfs_region;
5561
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005562 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005563 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005564 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5565 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5566 reg_rule_policy);
5567 if (r)
5568 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005569 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5570 if (r)
5571 goto bad_reg;
5572
5573 rule_idx++;
5574
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005575 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5576 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005577 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005578 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005579 }
5580
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005581 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005582 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005583 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005584
Johannes Bergd2372b32008-10-24 20:32:20 +02005585 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005586 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005587 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005588}
5589
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005590static int validate_scan_freqs(struct nlattr *freqs)
5591{
5592 struct nlattr *attr1, *attr2;
5593 int n_channels = 0, tmp1, tmp2;
5594
5595 nla_for_each_nested(attr1, freqs, tmp1) {
5596 n_channels++;
5597 /*
5598 * Some hardware has a limited channel list for
5599 * scanning, and it is pretty much nonsensical
5600 * to scan for a channel twice, so disallow that
5601 * and don't require drivers to check that the
5602 * channel list they get isn't longer than what
5603 * they can scan, as long as they can scan all
5604 * the channels they registered at once.
5605 */
5606 nla_for_each_nested(attr2, freqs, tmp2)
5607 if (attr1 != attr2 &&
5608 nla_get_u32(attr1) == nla_get_u32(attr2))
5609 return 0;
5610 }
5611
5612 return n_channels;
5613}
5614
Johannes Bergad2b26a2014-06-12 21:39:05 +02005615static int nl80211_parse_random_mac(struct nlattr **attrs,
5616 u8 *mac_addr, u8 *mac_addr_mask)
5617{
5618 int i;
5619
5620 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5621 memset(mac_addr, 0, ETH_ALEN);
5622 memset(mac_addr_mask, 0, ETH_ALEN);
5623 mac_addr[0] = 0x2;
5624 mac_addr_mask[0] = 0x3;
5625
5626 return 0;
5627 }
5628
5629 /* need both or none */
5630 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5631 return -EINVAL;
5632
5633 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5634 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5635
5636 /* don't allow or configure an mcast address */
5637 if (!is_multicast_ether_addr(mac_addr_mask) ||
5638 is_multicast_ether_addr(mac_addr))
5639 return -EINVAL;
5640
5641 /*
5642 * allow users to pass a MAC address that has bits set outside
5643 * of the mask, but don't bother drivers with having to deal
5644 * with such bits
5645 */
5646 for (i = 0; i < ETH_ALEN; i++)
5647 mac_addr[i] &= mac_addr_mask[i];
5648
5649 return 0;
5650}
5651
Johannes Berg2a519312009-02-10 21:25:55 +01005652static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5653{
Johannes Berg4c476992010-10-04 21:36:35 +02005654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005655 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005656 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005657 struct nlattr *attr;
5658 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005659 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005660 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005661
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005662 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5663 return -EINVAL;
5664
Johannes Berg79c97e92009-07-07 03:56:12 +02005665 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005666
Johannes Berg4c476992010-10-04 21:36:35 +02005667 if (!rdev->ops->scan)
5668 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005669
Johannes Bergf9d15d12014-01-22 11:14:19 +02005670 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005671 err = -EBUSY;
5672 goto unlock;
5673 }
Johannes Berg2a519312009-02-10 21:25:55 +01005674
5675 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005676 n_channels = validate_scan_freqs(
5677 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005678 if (!n_channels) {
5679 err = -EINVAL;
5680 goto unlock;
5681 }
Johannes Berg2a519312009-02-10 21:25:55 +01005682 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005683 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005684 }
5685
5686 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5687 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5688 n_ssids++;
5689
Johannes Bergf9f47522013-03-19 15:04:07 +01005690 if (n_ssids > wiphy->max_scan_ssids) {
5691 err = -EINVAL;
5692 goto unlock;
5693 }
Johannes Berg2a519312009-02-10 21:25:55 +01005694
Jouni Malinen70692ad2009-02-16 19:39:13 +02005695 if (info->attrs[NL80211_ATTR_IE])
5696 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5697 else
5698 ie_len = 0;
5699
Johannes Bergf9f47522013-03-19 15:04:07 +01005700 if (ie_len > wiphy->max_scan_ie_len) {
5701 err = -EINVAL;
5702 goto unlock;
5703 }
Johannes Berg18a83652009-03-31 12:12:05 +02005704
Johannes Berg2a519312009-02-10 21:25:55 +01005705 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005706 + sizeof(*request->ssids) * n_ssids
5707 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005708 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005709 if (!request) {
5710 err = -ENOMEM;
5711 goto unlock;
5712 }
Johannes Berg2a519312009-02-10 21:25:55 +01005713
Johannes Berg2a519312009-02-10 21:25:55 +01005714 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005715 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005716 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005717 if (ie_len) {
5718 if (request->ssids)
5719 request->ie = (void *)(request->ssids + n_ssids);
5720 else
5721 request->ie = (void *)(request->channels + n_channels);
5722 }
Johannes Berg2a519312009-02-10 21:25:55 +01005723
Johannes Berg584991d2009-11-02 13:32:03 +01005724 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005725 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5726 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005727 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005728 struct ieee80211_channel *chan;
5729
5730 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5731
5732 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005733 err = -EINVAL;
5734 goto out_free;
5735 }
Johannes Berg584991d2009-11-02 13:32:03 +01005736
5737 /* ignore disabled channels */
5738 if (chan->flags & IEEE80211_CHAN_DISABLED)
5739 continue;
5740
5741 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005742 i++;
5743 }
5744 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005745 enum ieee80211_band band;
5746
Johannes Berg2a519312009-02-10 21:25:55 +01005747 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005748 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5749 int j;
5750 if (!wiphy->bands[band])
5751 continue;
5752 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005753 struct ieee80211_channel *chan;
5754
5755 chan = &wiphy->bands[band]->channels[j];
5756
5757 if (chan->flags & IEEE80211_CHAN_DISABLED)
5758 continue;
5759
5760 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005761 i++;
5762 }
5763 }
5764 }
5765
Johannes Berg584991d2009-11-02 13:32:03 +01005766 if (!i) {
5767 err = -EINVAL;
5768 goto out_free;
5769 }
5770
5771 request->n_channels = i;
5772
Johannes Berg2a519312009-02-10 21:25:55 +01005773 i = 0;
5774 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5775 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005776 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005777 err = -EINVAL;
5778 goto out_free;
5779 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005780 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005781 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005782 i++;
5783 }
5784 }
5785
Jouni Malinen70692ad2009-02-16 19:39:13 +02005786 if (info->attrs[NL80211_ATTR_IE]) {
5787 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02005788 memcpy((void *)request->ie,
5789 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005790 request->ie_len);
5791 }
5792
Johannes Berg34850ab2011-07-18 18:08:35 +02005793 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005794 if (wiphy->bands[i])
5795 request->rates[i] =
5796 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005797
5798 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5799 nla_for_each_nested(attr,
5800 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5801 tmp) {
5802 enum ieee80211_band band = nla_type(attr);
5803
Dan Carpenter84404622011-07-29 11:52:18 +03005804 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005805 err = -EINVAL;
5806 goto out_free;
5807 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005808
5809 if (!wiphy->bands[band])
5810 continue;
5811
Johannes Berg34850ab2011-07-18 18:08:35 +02005812 err = ieee80211_get_ratemask(wiphy->bands[band],
5813 nla_data(attr),
5814 nla_len(attr),
5815 &request->rates[band]);
5816 if (err)
5817 goto out_free;
5818 }
5819 }
5820
Sam Leffler46856bb2012-10-11 21:03:32 -07005821 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005822 request->flags = nla_get_u32(
5823 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005824 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5825 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005826 err = -EOPNOTSUPP;
5827 goto out_free;
5828 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005829
5830 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5831 if (!(wiphy->features &
5832 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5833 err = -EOPNOTSUPP;
5834 goto out_free;
5835 }
5836
5837 if (wdev->current_bss) {
5838 err = -EOPNOTSUPP;
5839 goto out_free;
5840 }
5841
5842 err = nl80211_parse_random_mac(info->attrs,
5843 request->mac_addr,
5844 request->mac_addr_mask);
5845 if (err)
5846 goto out_free;
5847 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005848 }
Sam Lefflered4737712012-10-11 21:03:31 -07005849
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305850 request->no_cck =
5851 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5852
Johannes Bergfd014282012-06-18 19:17:03 +02005853 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005854 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005855 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005856
Johannes Berg79c97e92009-07-07 03:56:12 +02005857 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005858 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005859
Johannes Berg463d0182009-07-14 00:33:35 +02005860 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005861 nl80211_send_scan_start(rdev, wdev);
5862 if (wdev->netdev)
5863 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005864 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005865 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005866 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005867 kfree(request);
5868 }
Johannes Berg3b858752009-03-12 09:55:09 +01005869
Johannes Bergf9f47522013-03-19 15:04:07 +01005870 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005871 return err;
5872}
5873
Luciano Coelho256da022014-11-10 16:13:46 +02005874static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005875nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005876 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005877{
5878 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005879 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005880 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005881 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005882 enum ieee80211_band band;
5883 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005884 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005885 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005886
Luciano Coelho256da022014-11-10 16:13:46 +02005887 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5888 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005889
Luciano Coelho256da022014-11-10 16:13:46 +02005890 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5891 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005892
Luciano Coelho256da022014-11-10 16:13:46 +02005893 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005894 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005895 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005896
Luciano Coelho256da022014-11-10 16:13:46 +02005897 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005898 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005899 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005900 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005901 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005902 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005903 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005904 }
5905
Luciano Coelho256da022014-11-10 16:13:46 +02005906 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5907 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005908 tmp)
5909 n_ssids++;
5910
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005911 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005912 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005913
Johannes Bergea73cbc2014-01-24 10:53:53 +01005914 /*
5915 * First, count the number of 'real' matchsets. Due to an issue with
5916 * the old implementation, matchsets containing only the RSSI attribute
5917 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5918 * RSSI for all matchsets, rather than their own matchset for reporting
5919 * all APs with a strong RSSI. This is needed to be compatible with
5920 * older userspace that treated a matchset with only the RSSI as the
5921 * global RSSI for all other matchsets - if there are other matchsets.
5922 */
Luciano Coelho256da022014-11-10 16:13:46 +02005923 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005924 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005925 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005926 tmp) {
5927 struct nlattr *rssi;
5928
5929 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5930 nla_data(attr), nla_len(attr),
5931 nl80211_match_policy);
5932 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02005933 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005934 /* add other standalone attributes here */
5935 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5936 n_match_sets++;
5937 continue;
5938 }
5939 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5940 if (rssi)
5941 default_match_rssi = nla_get_s32(rssi);
5942 }
5943 }
5944
5945 /* However, if there's no other matchset, add the RSSI one */
5946 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5947 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005948
5949 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02005950 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005951
Luciano Coelho256da022014-11-10 16:13:46 +02005952 if (attrs[NL80211_ATTR_IE])
5953 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005954 else
5955 ie_len = 0;
5956
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005957 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02005958 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005959
Luciano Coelho807f8a82011-05-11 17:09:35 +03005960 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005961 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005962 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005963 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005964 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02005965 if (!request)
5966 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005967
5968 if (n_ssids)
5969 request->ssids = (void *)&request->channels[n_channels];
5970 request->n_ssids = n_ssids;
5971 if (ie_len) {
5972 if (request->ssids)
5973 request->ie = (void *)(request->ssids + n_ssids);
5974 else
5975 request->ie = (void *)(request->channels + n_channels);
5976 }
5977
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005978 if (n_match_sets) {
5979 if (request->ie)
5980 request->match_sets = (void *)(request->ie + ie_len);
5981 else if (request->ssids)
5982 request->match_sets =
5983 (void *)(request->ssids + n_ssids);
5984 else
5985 request->match_sets =
5986 (void *)(request->channels + n_channels);
5987 }
5988 request->n_match_sets = n_match_sets;
5989
Luciano Coelho807f8a82011-05-11 17:09:35 +03005990 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005991 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005992 /* user specified, bail out if channel not found */
5993 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005994 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005995 tmp) {
5996 struct ieee80211_channel *chan;
5997
5998 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5999
6000 if (!chan) {
6001 err = -EINVAL;
6002 goto out_free;
6003 }
6004
6005 /* ignore disabled channels */
6006 if (chan->flags & IEEE80211_CHAN_DISABLED)
6007 continue;
6008
6009 request->channels[i] = chan;
6010 i++;
6011 }
6012 } else {
6013 /* all channels */
6014 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6015 int j;
6016 if (!wiphy->bands[band])
6017 continue;
6018 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6019 struct ieee80211_channel *chan;
6020
6021 chan = &wiphy->bands[band]->channels[j];
6022
6023 if (chan->flags & IEEE80211_CHAN_DISABLED)
6024 continue;
6025
6026 request->channels[i] = chan;
6027 i++;
6028 }
6029 }
6030 }
6031
6032 if (!i) {
6033 err = -EINVAL;
6034 goto out_free;
6035 }
6036
6037 request->n_channels = i;
6038
6039 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006040 if (attrs[NL80211_ATTR_SCAN_SSIDS]) {
6041 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006042 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006043 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006044 err = -EINVAL;
6045 goto out_free;
6046 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006047 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006048 memcpy(request->ssids[i].ssid, nla_data(attr),
6049 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006050 i++;
6051 }
6052 }
6053
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006054 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006055 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006056 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006057 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006058 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006059 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006060
Johannes Bergae811e22014-01-24 10:17:47 +01006061 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6062 nla_data(attr), nla_len(attr),
6063 nl80211_match_policy);
6064 if (err)
6065 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006066 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006067 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006068 if (WARN_ON(i >= n_match_sets)) {
6069 /* this indicates a programming error,
6070 * the loop above should have verified
6071 * things properly
6072 */
6073 err = -EINVAL;
6074 goto out_free;
6075 }
6076
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006077 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6078 err = -EINVAL;
6079 goto out_free;
6080 }
6081 memcpy(request->match_sets[i].ssid.ssid,
6082 nla_data(ssid), nla_len(ssid));
6083 request->match_sets[i].ssid.ssid_len =
6084 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006085 /* special attribute - old implemenation w/a */
6086 request->match_sets[i].rssi_thold =
6087 default_match_rssi;
6088 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6089 if (rssi)
6090 request->match_sets[i].rssi_thold =
6091 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006092 }
6093 i++;
6094 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006095
6096 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006097 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006098 request->match_sets[0].rssi_thold = default_match_rssi;
6099
6100 request->min_rssi_thold = INT_MAX;
6101 for (i = 0; i < n_match_sets; i++)
6102 request->min_rssi_thold =
6103 min(request->match_sets[i].rssi_thold,
6104 request->min_rssi_thold);
6105 } else {
6106 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006107 }
6108
Johannes Berg9900e482014-02-04 21:01:25 +01006109 if (ie_len) {
6110 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006111 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006112 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006113 request->ie_len);
6114 }
6115
Luciano Coelho256da022014-11-10 16:13:46 +02006116 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006117 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006118 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006119 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6120 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006121 err = -EOPNOTSUPP;
6122 goto out_free;
6123 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006124
6125 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6126 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6127
6128 if (!wdev) /* must be net-detect */
6129 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6130
6131 if (!(wiphy->features & flg)) {
6132 err = -EOPNOTSUPP;
6133 goto out_free;
6134 }
6135
6136 if (wdev && wdev->current_bss) {
6137 err = -EOPNOTSUPP;
6138 goto out_free;
6139 }
6140
6141 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6142 request->mac_addr_mask);
6143 if (err)
6144 goto out_free;
6145 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006146 }
Sam Lefflered4737712012-10-11 21:03:31 -07006147
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006148 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006149 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006150
Luciano Coelho256da022014-11-10 16:13:46 +02006151 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006152
6153out_free:
6154 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006155 return ERR_PTR(err);
6156}
6157
6158static int nl80211_start_sched_scan(struct sk_buff *skb,
6159 struct genl_info *info)
6160{
6161 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6162 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006163 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006164 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006165 int err;
6166
6167 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6168 !rdev->ops->sched_scan_start)
6169 return -EOPNOTSUPP;
6170
6171 if (rdev->sched_scan_req)
6172 return -EINPROGRESS;
6173
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006174 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6175 info->attrs);
6176
6177 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006178 if (err)
6179 goto out_err;
6180
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006181 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006182 if (err)
6183 goto out_free;
6184
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006185 sched_scan_req->dev = dev;
6186 sched_scan_req->wiphy = &rdev->wiphy;
6187
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006188 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6189 sched_scan_req->owner_nlportid = info->snd_portid;
6190
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006191 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006192
6193 nl80211_send_sched_scan(rdev, dev,
6194 NL80211_CMD_START_SCHED_SCAN);
6195 return 0;
6196
6197out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006198 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006199out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006200 return err;
6201}
6202
6203static int nl80211_stop_sched_scan(struct sk_buff *skb,
6204 struct genl_info *info)
6205{
6206 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6207
6208 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6209 !rdev->ops->sched_scan_stop)
6210 return -EOPNOTSUPP;
6211
Johannes Berg5fe231e2013-05-08 21:45:15 +02006212 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006213}
6214
Simon Wunderlich04f39042013-02-08 18:16:19 +01006215static int nl80211_start_radar_detection(struct sk_buff *skb,
6216 struct genl_info *info)
6217{
6218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6219 struct net_device *dev = info->user_ptr[1];
6220 struct wireless_dev *wdev = dev->ieee80211_ptr;
6221 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006222 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006223 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006224 int err;
6225
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006226 dfs_region = reg_get_dfs_region(wdev->wiphy);
6227 if (dfs_region == NL80211_DFS_UNSET)
6228 return -EINVAL;
6229
Simon Wunderlich04f39042013-02-08 18:16:19 +01006230 err = nl80211_parse_chandef(rdev, info, &chandef);
6231 if (err)
6232 return err;
6233
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006234 if (netif_carrier_ok(dev))
6235 return -EBUSY;
6236
Simon Wunderlich04f39042013-02-08 18:16:19 +01006237 if (wdev->cac_started)
6238 return -EBUSY;
6239
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006240 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006241 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006242 if (err < 0)
6243 return err;
6244
6245 if (err == 0)
6246 return -EINVAL;
6247
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006248 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006249 return -EINVAL;
6250
6251 if (!rdev->ops->start_radar_detection)
6252 return -EOPNOTSUPP;
6253
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006254 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6255 if (WARN_ON(!cac_time_ms))
6256 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6257
6258 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6259 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006260 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006261 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006262 wdev->cac_started = true;
6263 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006264 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006265 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006266 return err;
6267}
6268
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006269static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6270{
6271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6272 struct net_device *dev = info->user_ptr[1];
6273 struct wireless_dev *wdev = dev->ieee80211_ptr;
6274 struct cfg80211_csa_settings params;
6275 /* csa_attrs is defined static to avoid waste of stack size - this
6276 * function is called under RTNL lock, so this should not be a problem.
6277 */
6278 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006279 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006280 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006281 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006282 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006283
6284 if (!rdev->ops->channel_switch ||
6285 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6286 return -EOPNOTSUPP;
6287
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006288 switch (dev->ieee80211_ptr->iftype) {
6289 case NL80211_IFTYPE_AP:
6290 case NL80211_IFTYPE_P2P_GO:
6291 need_new_beacon = true;
6292
6293 /* useless if AP is not running */
6294 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006295 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006296 break;
6297 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006298 if (!wdev->ssid_len)
6299 return -ENOTCONN;
6300 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006301 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006302 if (!wdev->mesh_id_len)
6303 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006304 break;
6305 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006306 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006307 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006308
6309 memset(&params, 0, sizeof(params));
6310
6311 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6312 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6313 return -EINVAL;
6314
6315 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006316 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006317 return -EINVAL;
6318
Luciano Coelho252e07c2014-10-08 09:48:34 +03006319 /* Even though the attribute is u32, the specification says
6320 * u8, so let's make sure we don't overflow.
6321 */
6322 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6323 if (cs_count > 255)
6324 return -EINVAL;
6325
6326 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006327
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006328 if (!need_new_beacon)
6329 goto skip_beacons;
6330
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006331 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6332 if (err)
6333 return err;
6334
6335 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6336 info->attrs[NL80211_ATTR_CSA_IES],
6337 nl80211_policy);
6338 if (err)
6339 return err;
6340
6341 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6342 if (err)
6343 return err;
6344
6345 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6346 return -EINVAL;
6347
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006348 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6349 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006350 return -EINVAL;
6351
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006352 params.n_counter_offsets_beacon = len / sizeof(u16);
6353 if (rdev->wiphy.max_num_csa_counters &&
6354 (params.n_counter_offsets_beacon >
6355 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006356 return -EINVAL;
6357
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006358 params.counter_offsets_beacon =
6359 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6360
6361 /* sanity checks - counters should fit and be the same */
6362 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6363 u16 offset = params.counter_offsets_beacon[i];
6364
6365 if (offset >= params.beacon_csa.tail_len)
6366 return -EINVAL;
6367
6368 if (params.beacon_csa.tail[offset] != params.count)
6369 return -EINVAL;
6370 }
6371
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006372 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006373 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6374 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006375 return -EINVAL;
6376
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006377 params.n_counter_offsets_presp = len / sizeof(u16);
6378 if (rdev->wiphy.max_num_csa_counters &&
6379 (params.n_counter_offsets_beacon >
6380 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006381 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006382
6383 params.counter_offsets_presp =
6384 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6385
6386 /* sanity checks - counters should fit and be the same */
6387 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6388 u16 offset = params.counter_offsets_presp[i];
6389
6390 if (offset >= params.beacon_csa.probe_resp_len)
6391 return -EINVAL;
6392
6393 if (params.beacon_csa.probe_resp[offset] !=
6394 params.count)
6395 return -EINVAL;
6396 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006397 }
6398
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006399skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006400 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6401 if (err)
6402 return err;
6403
Ilan Peer174e0cd2014-02-23 09:13:01 +02006404 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6405 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006406 return -EINVAL;
6407
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006408 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6409 &params.chandef,
6410 wdev->iftype);
6411 if (err < 0)
6412 return err;
6413
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006414 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006415 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006416
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006417 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6418 params.block_tx = true;
6419
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006420 wdev_lock(wdev);
6421 err = rdev_channel_switch(rdev, dev, &params);
6422 wdev_unlock(wdev);
6423
6424 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006425}
6426
Johannes Berg9720bb32011-06-21 09:45:33 +02006427static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6428 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006429 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006430 struct wireless_dev *wdev,
6431 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006432{
Johannes Berg48ab9052009-07-10 18:42:31 +02006433 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006434 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006435 void *hdr;
6436 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006437
6438 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006439
Eric W. Biederman15e47302012-09-07 20:12:54 +00006440 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006441 NL80211_CMD_NEW_SCAN_RESULTS);
6442 if (!hdr)
6443 return -1;
6444
Johannes Berg9720bb32011-06-21 09:45:33 +02006445 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6446
Johannes Berg97990a02013-04-19 01:02:55 +02006447 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6448 goto nla_put_failure;
6449 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006450 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6451 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006452 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6453 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006454
6455 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6456 if (!bss)
6457 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006458 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006459 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006460 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006461
6462 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006463 /* indicate whether we have probe response data or not */
6464 if (rcu_access_pointer(res->proberesp_ies) &&
6465 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6466 goto fail_unlock_rcu;
6467
6468 /* this pointer prefers to be pointed to probe response data
6469 * but is always valid
6470 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006471 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006472 if (ies) {
6473 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6474 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006475 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6476 ies->len, ies->data))
6477 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006478 }
Johannes Berg0e227082014-08-12 20:34:30 +02006479
6480 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006481 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006482 if (ies && ies->from_beacon) {
6483 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006484 goto fail_unlock_rcu;
6485 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6486 ies->len, ies->data))
6487 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006488 }
6489 rcu_read_unlock();
6490
David S. Miller9360ffd2012-03-29 04:41:26 -04006491 if (res->beacon_interval &&
6492 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6493 goto nla_put_failure;
6494 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6495 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006496 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006497 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6498 jiffies_to_msecs(jiffies - intbss->ts)))
6499 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006500
Johannes Berg77965c972009-02-18 18:45:06 +01006501 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006502 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006503 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6504 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006505 break;
6506 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006507 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6508 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006509 break;
6510 default:
6511 break;
6512 }
6513
Johannes Berg48ab9052009-07-10 18:42:31 +02006514 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006515 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006516 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006517 if (intbss == wdev->current_bss &&
6518 nla_put_u32(msg, NL80211_BSS_STATUS,
6519 NL80211_BSS_STATUS_ASSOCIATED))
6520 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006521 break;
6522 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006523 if (intbss == wdev->current_bss &&
6524 nla_put_u32(msg, NL80211_BSS_STATUS,
6525 NL80211_BSS_STATUS_IBSS_JOINED))
6526 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006527 break;
6528 default:
6529 break;
6530 }
6531
Johannes Berg2a519312009-02-10 21:25:55 +01006532 nla_nest_end(msg, bss);
6533
6534 return genlmsg_end(msg, hdr);
6535
Johannes Berg8cef2c92013-02-05 16:54:31 +01006536 fail_unlock_rcu:
6537 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006538 nla_put_failure:
6539 genlmsg_cancel(msg, hdr);
6540 return -EMSGSIZE;
6541}
6542
Johannes Berg97990a02013-04-19 01:02:55 +02006543static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006544{
Johannes Berg48ab9052009-07-10 18:42:31 +02006545 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006546 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006547 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006548 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006549 int err;
6550
Johannes Berg97990a02013-04-19 01:02:55 +02006551 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006552 if (err)
6553 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006554
Johannes Berg48ab9052009-07-10 18:42:31 +02006555 wdev_lock(wdev);
6556 spin_lock_bh(&rdev->bss_lock);
6557 cfg80211_bss_expire(rdev);
6558
Johannes Berg9720bb32011-06-21 09:45:33 +02006559 cb->seq = rdev->bss_generation;
6560
Johannes Berg48ab9052009-07-10 18:42:31 +02006561 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006562 if (++idx <= start)
6563 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006564 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006565 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006566 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006567 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006568 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006569 }
6570 }
6571
Johannes Berg48ab9052009-07-10 18:42:31 +02006572 spin_unlock_bh(&rdev->bss_lock);
6573 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006574
Johannes Berg97990a02013-04-19 01:02:55 +02006575 cb->args[2] = idx;
6576 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006577
Johannes Berg67748892010-10-04 21:14:06 +02006578 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006579}
6580
Eric W. Biederman15e47302012-09-07 20:12:54 +00006581static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006582 int flags, struct net_device *dev,
6583 bool allow_radio_stats,
6584 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006585{
6586 void *hdr;
6587 struct nlattr *infoattr;
6588
Johannes Berg11f78ac2014-11-14 16:43:50 +01006589 /* skip radio stats if userspace didn't request them */
6590 if (!survey->channel && !allow_radio_stats)
6591 return 0;
6592
Eric W. Biederman15e47302012-09-07 20:12:54 +00006593 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006594 NL80211_CMD_NEW_SURVEY_RESULTS);
6595 if (!hdr)
6596 return -ENOMEM;
6597
David S. Miller9360ffd2012-03-29 04:41:26 -04006598 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6599 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006600
6601 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6602 if (!infoattr)
6603 goto nla_put_failure;
6604
Johannes Berg11f78ac2014-11-14 16:43:50 +01006605 if (survey->channel &&
6606 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006607 survey->channel->center_freq))
6608 goto nla_put_failure;
6609
6610 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6611 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6612 goto nla_put_failure;
6613 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6614 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6615 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006616 if ((survey->filled & SURVEY_INFO_TIME) &&
6617 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6618 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006619 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006620 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6621 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6622 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006623 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006624 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6625 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6626 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006627 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006628 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6629 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6630 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006631 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006632 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6633 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6634 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006635 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006636 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6637 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6638 survey->time_scan))
6639 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006640
6641 nla_nest_end(msg, infoattr);
6642
6643 return genlmsg_end(msg, hdr);
6644
6645 nla_put_failure:
6646 genlmsg_cancel(msg, hdr);
6647 return -EMSGSIZE;
6648}
6649
Johannes Berg11f78ac2014-11-14 16:43:50 +01006650static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006651{
6652 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006653 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006654 struct wireless_dev *wdev;
6655 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006656 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006657 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006658
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006659 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006660 if (res)
6661 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006662
Johannes Berg11f78ac2014-11-14 16:43:50 +01006663 /* prepare_wdev_dump parsed the attributes */
6664 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6665
Johannes Berg97990a02013-04-19 01:02:55 +02006666 if (!wdev->netdev) {
6667 res = -EINVAL;
6668 goto out_err;
6669 }
6670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006671 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006672 res = -EOPNOTSUPP;
6673 goto out_err;
6674 }
6675
6676 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006677 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006678 if (res == -ENOENT)
6679 break;
6680 if (res)
6681 goto out_err;
6682
Johannes Berg11f78ac2014-11-14 16:43:50 +01006683 /* don't send disabled channels, but do send non-channel data */
6684 if (survey.channel &&
6685 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006686 survey_idx++;
6687 continue;
6688 }
6689
Holger Schurig61fa7132009-11-11 12:25:40 +01006690 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006691 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006692 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006693 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006694 goto out;
6695 survey_idx++;
6696 }
6697
6698 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006699 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006700 res = skb->len;
6701 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006702 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006703 return res;
6704}
6705
Samuel Ortizb23aa672009-07-01 21:26:54 +02006706static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6707{
6708 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6709 NL80211_WPA_VERSION_2));
6710}
6711
Jouni Malinen636a5d32009-03-19 13:39:22 +02006712static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6713{
Johannes Berg4c476992010-10-04 21:36:35 +02006714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6715 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006716 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006717 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6718 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006719 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006720 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006721 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006722
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006723 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6724 return -EINVAL;
6725
6726 if (!info->attrs[NL80211_ATTR_MAC])
6727 return -EINVAL;
6728
Jouni Malinen17780922009-03-27 20:52:47 +02006729 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6730 return -EINVAL;
6731
Johannes Berg19957bb2009-07-02 17:20:43 +02006732 if (!info->attrs[NL80211_ATTR_SSID])
6733 return -EINVAL;
6734
6735 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6736 return -EINVAL;
6737
Johannes Bergfffd0932009-07-08 14:22:54 +02006738 err = nl80211_parse_key(info, &key);
6739 if (err)
6740 return err;
6741
6742 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006743 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6744 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006745 if (!key.p.key || !key.p.key_len)
6746 return -EINVAL;
6747 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6748 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6749 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6750 key.p.key_len != WLAN_KEY_LEN_WEP104))
6751 return -EINVAL;
6752 if (key.idx > 4)
6753 return -EINVAL;
6754 } else {
6755 key.p.key_len = 0;
6756 key.p.key = NULL;
6757 }
6758
Johannes Bergafea0b72010-08-10 09:46:42 +02006759 if (key.idx >= 0) {
6760 int i;
6761 bool ok = false;
6762 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6763 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6764 ok = true;
6765 break;
6766 }
6767 }
Johannes Berg4c476992010-10-04 21:36:35 +02006768 if (!ok)
6769 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006770 }
6771
Johannes Berg4c476992010-10-04 21:36:35 +02006772 if (!rdev->ops->auth)
6773 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006774
Johannes Berg074ac8d2010-09-16 14:58:22 +02006775 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006776 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6777 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006778
Johannes Berg19957bb2009-07-02 17:20:43 +02006779 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006780 chan = nl80211_get_valid_chan(&rdev->wiphy,
6781 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6782 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006783 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006784
Johannes Berg19957bb2009-07-02 17:20:43 +02006785 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6786 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6787
6788 if (info->attrs[NL80211_ATTR_IE]) {
6789 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6790 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6791 }
6792
6793 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006794 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006795 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006796
Jouni Malinene39e5b52012-09-30 19:29:39 +03006797 if (auth_type == NL80211_AUTHTYPE_SAE &&
6798 !info->attrs[NL80211_ATTR_SAE_DATA])
6799 return -EINVAL;
6800
6801 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6802 if (auth_type != NL80211_AUTHTYPE_SAE)
6803 return -EINVAL;
6804 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6805 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6806 /* need to include at least Auth Transaction and Status Code */
6807 if (sae_data_len < 4)
6808 return -EINVAL;
6809 }
6810
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006811 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6812
Johannes Berg95de8172012-01-20 13:55:25 +01006813 /*
6814 * Since we no longer track auth state, ignore
6815 * requests to only change local state.
6816 */
6817 if (local_state_change)
6818 return 0;
6819
Johannes Berg91bf9b22013-05-15 17:44:01 +02006820 wdev_lock(dev->ieee80211_ptr);
6821 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6822 ssid, ssid_len, ie, ie_len,
6823 key.p.key, key.p.key_len, key.idx,
6824 sae_data, sae_data_len);
6825 wdev_unlock(dev->ieee80211_ptr);
6826 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006827}
6828
Johannes Bergc0692b82010-08-27 14:26:53 +03006829static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6830 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006831 struct cfg80211_crypto_settings *settings,
6832 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006833{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006834 memset(settings, 0, sizeof(*settings));
6835
Samuel Ortizb23aa672009-07-01 21:26:54 +02006836 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6837
Johannes Bergc0692b82010-08-27 14:26:53 +03006838 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6839 u16 proto;
6840 proto = nla_get_u16(
6841 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6842 settings->control_port_ethertype = cpu_to_be16(proto);
6843 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6844 proto != ETH_P_PAE)
6845 return -EINVAL;
6846 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6847 settings->control_port_no_encrypt = true;
6848 } else
6849 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6850
Samuel Ortizb23aa672009-07-01 21:26:54 +02006851 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6852 void *data;
6853 int len, i;
6854
6855 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6856 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6857 settings->n_ciphers_pairwise = len / sizeof(u32);
6858
6859 if (len % sizeof(u32))
6860 return -EINVAL;
6861
Johannes Berg3dc27d22009-07-02 21:36:37 +02006862 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006863 return -EINVAL;
6864
6865 memcpy(settings->ciphers_pairwise, data, len);
6866
6867 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006868 if (!cfg80211_supported_cipher_suite(
6869 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006870 settings->ciphers_pairwise[i]))
6871 return -EINVAL;
6872 }
6873
6874 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6875 settings->cipher_group =
6876 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006877 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6878 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006879 return -EINVAL;
6880 }
6881
6882 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6883 settings->wpa_versions =
6884 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6885 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6886 return -EINVAL;
6887 }
6888
6889 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6890 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006891 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006892
6893 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6894 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6895 settings->n_akm_suites = len / sizeof(u32);
6896
6897 if (len % sizeof(u32))
6898 return -EINVAL;
6899
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006900 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6901 return -EINVAL;
6902
Samuel Ortizb23aa672009-07-01 21:26:54 +02006903 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006904 }
6905
6906 return 0;
6907}
6908
Jouni Malinen636a5d32009-03-19 13:39:22 +02006909static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6910{
Johannes Berg4c476992010-10-04 21:36:35 +02006911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6912 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006913 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006914 struct cfg80211_assoc_request req = {};
6915 const u8 *bssid, *ssid;
6916 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006917
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006918 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6919 return -EINVAL;
6920
6921 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006922 !info->attrs[NL80211_ATTR_SSID] ||
6923 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006924 return -EINVAL;
6925
Johannes Berg4c476992010-10-04 21:36:35 +02006926 if (!rdev->ops->assoc)
6927 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006928
Johannes Berg074ac8d2010-09-16 14:58:22 +02006929 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006930 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6931 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006932
Johannes Berg19957bb2009-07-02 17:20:43 +02006933 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006934
Jouni Malinen664834d2014-01-15 00:01:44 +02006935 chan = nl80211_get_valid_chan(&rdev->wiphy,
6936 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6937 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006938 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006939
Johannes Berg19957bb2009-07-02 17:20:43 +02006940 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6941 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006942
6943 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006944 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6945 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006946 }
6947
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006948 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006949 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006950 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006951 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006952 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006953 else if (mfp != NL80211_MFP_NO)
6954 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006955 }
6956
Johannes Berg3e5d7642009-07-07 14:37:26 +02006957 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006958 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006959
Ben Greear7e7c8922011-11-18 11:31:59 -08006960 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006961 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006962
6963 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006964 memcpy(&req.ht_capa_mask,
6965 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6966 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006967
6968 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006969 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006970 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006971 memcpy(&req.ht_capa,
6972 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6973 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006974 }
6975
Johannes Bergee2aca32013-02-21 17:36:01 +01006976 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006977 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006978
6979 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006980 memcpy(&req.vht_capa_mask,
6981 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6982 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006983
6984 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006985 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006986 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006987 memcpy(&req.vht_capa,
6988 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6989 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006990 }
6991
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006992 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6993 if (!(rdev->wiphy.features &
6994 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6995 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6996 return -EINVAL;
6997 req.flags |= ASSOC_REQ_USE_RRM;
6998 }
6999
Johannes Bergf62fab72013-02-21 20:09:09 +01007000 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007001 if (!err) {
7002 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007003 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7004 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007005 wdev_unlock(dev->ieee80211_ptr);
7006 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007007
Jouni Malinen636a5d32009-03-19 13:39:22 +02007008 return err;
7009}
7010
7011static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7012{
Johannes Berg4c476992010-10-04 21:36:35 +02007013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7014 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007015 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007016 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007017 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007018 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007019
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007020 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7021 return -EINVAL;
7022
7023 if (!info->attrs[NL80211_ATTR_MAC])
7024 return -EINVAL;
7025
7026 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7027 return -EINVAL;
7028
Johannes Berg4c476992010-10-04 21:36:35 +02007029 if (!rdev->ops->deauth)
7030 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007031
Johannes Berg074ac8d2010-09-16 14:58:22 +02007032 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007033 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7034 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007035
Johannes Berg19957bb2009-07-02 17:20:43 +02007036 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007037
Johannes Berg19957bb2009-07-02 17:20:43 +02007038 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7039 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007040 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007041 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007042 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007043
7044 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007045 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7046 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007047 }
7048
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007049 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7050
Johannes Berg91bf9b22013-05-15 17:44:01 +02007051 wdev_lock(dev->ieee80211_ptr);
7052 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7053 local_state_change);
7054 wdev_unlock(dev->ieee80211_ptr);
7055 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007056}
7057
7058static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7059{
Johannes Berg4c476992010-10-04 21:36:35 +02007060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7061 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007062 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007063 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007064 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007065 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007066
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007067 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7068 return -EINVAL;
7069
7070 if (!info->attrs[NL80211_ATTR_MAC])
7071 return -EINVAL;
7072
7073 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7074 return -EINVAL;
7075
Johannes Berg4c476992010-10-04 21:36:35 +02007076 if (!rdev->ops->disassoc)
7077 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007078
Johannes Berg074ac8d2010-09-16 14:58:22 +02007079 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007080 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7081 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007082
Johannes Berg19957bb2009-07-02 17:20:43 +02007083 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007084
Johannes Berg19957bb2009-07-02 17:20:43 +02007085 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7086 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007087 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007088 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007089 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007090
7091 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007092 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7093 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007094 }
7095
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007096 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7097
Johannes Berg91bf9b22013-05-15 17:44:01 +02007098 wdev_lock(dev->ieee80211_ptr);
7099 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7100 local_state_change);
7101 wdev_unlock(dev->ieee80211_ptr);
7102 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007103}
7104
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007105static bool
7106nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7107 int mcast_rate[IEEE80211_NUM_BANDS],
7108 int rateval)
7109{
7110 struct wiphy *wiphy = &rdev->wiphy;
7111 bool found = false;
7112 int band, i;
7113
7114 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7115 struct ieee80211_supported_band *sband;
7116
7117 sband = wiphy->bands[band];
7118 if (!sband)
7119 continue;
7120
7121 for (i = 0; i < sband->n_bitrates; i++) {
7122 if (sband->bitrates[i].bitrate == rateval) {
7123 mcast_rate[band] = i + 1;
7124 found = true;
7125 break;
7126 }
7127 }
7128 }
7129
7130 return found;
7131}
7132
Johannes Berg04a773a2009-04-19 21:24:32 +02007133static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7134{
Johannes Berg4c476992010-10-04 21:36:35 +02007135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7136 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007137 struct cfg80211_ibss_params ibss;
7138 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007139 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007140 int err;
7141
Johannes Berg8e30bc52009-04-22 17:45:38 +02007142 memset(&ibss, 0, sizeof(ibss));
7143
Johannes Berg04a773a2009-04-19 21:24:32 +02007144 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7145 return -EINVAL;
7146
Johannes Berg683b6d32012-11-08 21:25:48 +01007147 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007148 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7149 return -EINVAL;
7150
Johannes Berg8e30bc52009-04-22 17:45:38 +02007151 ibss.beacon_interval = 100;
7152
7153 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7154 ibss.beacon_interval =
7155 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7156 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7157 return -EINVAL;
7158 }
7159
Johannes Berg4c476992010-10-04 21:36:35 +02007160 if (!rdev->ops->join_ibss)
7161 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007162
Johannes Berg4c476992010-10-04 21:36:35 +02007163 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7164 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007165
Johannes Berg79c97e92009-07-07 03:56:12 +02007166 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007167
Johannes Berg39193492011-09-16 13:45:25 +02007168 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007169 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007170
7171 if (!is_valid_ether_addr(ibss.bssid))
7172 return -EINVAL;
7173 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007174 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7175 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7176
7177 if (info->attrs[NL80211_ATTR_IE]) {
7178 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7179 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7180 }
7181
Johannes Berg683b6d32012-11-08 21:25:48 +01007182 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7183 if (err)
7184 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007185
Ilan Peer174e0cd2014-02-23 09:13:01 +02007186 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7187 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007188 return -EINVAL;
7189
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007190 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007191 case NL80211_CHAN_WIDTH_5:
7192 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007193 case NL80211_CHAN_WIDTH_20_NOHT:
7194 break;
7195 case NL80211_CHAN_WIDTH_20:
7196 case NL80211_CHAN_WIDTH_40:
7197 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
7198 break;
7199 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007200 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007201 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007202
Johannes Berg04a773a2009-04-19 21:24:32 +02007203 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007204 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007205
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007206 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7207 u8 *rates =
7208 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7209 int n_rates =
7210 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7211 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007212 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007213
Johannes Berg34850ab2011-07-18 18:08:35 +02007214 err = ieee80211_get_ratemask(sband, rates, n_rates,
7215 &ibss.basic_rates);
7216 if (err)
7217 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007218 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007219
Simon Wunderlich803768f2013-06-28 10:39:58 +02007220 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7221 memcpy(&ibss.ht_capa_mask,
7222 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7223 sizeof(ibss.ht_capa_mask));
7224
7225 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7226 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7227 return -EINVAL;
7228 memcpy(&ibss.ht_capa,
7229 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7230 sizeof(ibss.ht_capa));
7231 }
7232
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007233 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7234 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7235 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7236 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007237
Johannes Berg4c476992010-10-04 21:36:35 +02007238 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307239 bool no_ht = false;
7240
Johannes Berg4c476992010-10-04 21:36:35 +02007241 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307242 info->attrs[NL80211_ATTR_KEYS],
7243 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007244 if (IS_ERR(connkeys))
7245 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307246
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007247 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7248 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307249 kfree(connkeys);
7250 return -EINVAL;
7251 }
Johannes Berg4c476992010-10-04 21:36:35 +02007252 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007253
Antonio Quartulli267335d2012-01-31 20:25:47 +01007254 ibss.control_port =
7255 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7256
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007257 ibss.userspace_handles_dfs =
7258 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7259
Johannes Berg4c476992010-10-04 21:36:35 +02007260 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007261 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007262 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007263 return err;
7264}
7265
7266static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7267{
Johannes Berg4c476992010-10-04 21:36:35 +02007268 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7269 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007270
Johannes Berg4c476992010-10-04 21:36:35 +02007271 if (!rdev->ops->leave_ibss)
7272 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007273
Johannes Berg4c476992010-10-04 21:36:35 +02007274 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7275 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007276
Johannes Berg4c476992010-10-04 21:36:35 +02007277 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007278}
7279
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007280static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7281{
7282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7283 struct net_device *dev = info->user_ptr[1];
7284 int mcast_rate[IEEE80211_NUM_BANDS];
7285 u32 nla_rate;
7286 int err;
7287
7288 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7290 return -EOPNOTSUPP;
7291
7292 if (!rdev->ops->set_mcast_rate)
7293 return -EOPNOTSUPP;
7294
7295 memset(mcast_rate, 0, sizeof(mcast_rate));
7296
7297 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7298 return -EINVAL;
7299
7300 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7301 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7302 return -EINVAL;
7303
7304 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7305
7306 return err;
7307}
7308
Johannes Bergad7e7182013-11-13 13:37:47 +01007309static struct sk_buff *
7310__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7311 int approxlen, u32 portid, u32 seq,
7312 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007313 enum nl80211_attrs attr,
7314 const struct nl80211_vendor_cmd_info *info,
7315 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007316{
7317 struct sk_buff *skb;
7318 void *hdr;
7319 struct nlattr *data;
7320
7321 skb = nlmsg_new(approxlen + 100, gfp);
7322 if (!skb)
7323 return NULL;
7324
7325 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7326 if (!hdr) {
7327 kfree_skb(skb);
7328 return NULL;
7329 }
7330
7331 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7332 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007333
7334 if (info) {
7335 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7336 info->vendor_id))
7337 goto nla_put_failure;
7338 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7339 info->subcmd))
7340 goto nla_put_failure;
7341 }
7342
Johannes Bergad7e7182013-11-13 13:37:47 +01007343 data = nla_nest_start(skb, attr);
7344
7345 ((void **)skb->cb)[0] = rdev;
7346 ((void **)skb->cb)[1] = hdr;
7347 ((void **)skb->cb)[2] = data;
7348
7349 return skb;
7350
7351 nla_put_failure:
7352 kfree_skb(skb);
7353 return NULL;
7354}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007355
Johannes Berge03ad6e2014-01-01 17:22:30 +01007356struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7357 enum nl80211_commands cmd,
7358 enum nl80211_attrs attr,
7359 int vendor_event_idx,
7360 int approxlen, gfp_t gfp)
7361{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007362 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007363 const struct nl80211_vendor_cmd_info *info;
7364
7365 switch (cmd) {
7366 case NL80211_CMD_TESTMODE:
7367 if (WARN_ON(vendor_event_idx != -1))
7368 return NULL;
7369 info = NULL;
7370 break;
7371 case NL80211_CMD_VENDOR:
7372 if (WARN_ON(vendor_event_idx < 0 ||
7373 vendor_event_idx >= wiphy->n_vendor_events))
7374 return NULL;
7375 info = &wiphy->vendor_events[vendor_event_idx];
7376 break;
7377 default:
7378 WARN_ON(1);
7379 return NULL;
7380 }
7381
7382 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7383 cmd, attr, info, gfp);
7384}
7385EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7386
7387void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7388{
7389 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7390 void *hdr = ((void **)skb->cb)[1];
7391 struct nlattr *data = ((void **)skb->cb)[2];
7392 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7393
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007394 /* clear CB data for netlink core to own from now on */
7395 memset(skb->cb, 0, sizeof(skb->cb));
7396
Johannes Berge03ad6e2014-01-01 17:22:30 +01007397 nla_nest_end(skb, data);
7398 genlmsg_end(skb, hdr);
7399
7400 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7401 mcgrp = NL80211_MCGRP_VENDOR;
7402
7403 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7404 mcgrp, gfp);
7405}
7406EXPORT_SYMBOL(__cfg80211_send_event_skb);
7407
Johannes Bergaff89a92009-07-01 21:26:51 +02007408#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007409static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7410{
Johannes Berg4c476992010-10-04 21:36:35 +02007411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007412 struct wireless_dev *wdev =
7413 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007414 int err;
7415
David Spinadelfc73f112013-07-31 18:04:15 +03007416 if (!rdev->ops->testmode_cmd)
7417 return -EOPNOTSUPP;
7418
7419 if (IS_ERR(wdev)) {
7420 err = PTR_ERR(wdev);
7421 if (err != -EINVAL)
7422 return err;
7423 wdev = NULL;
7424 } else if (wdev->wiphy != &rdev->wiphy) {
7425 return -EINVAL;
7426 }
7427
Johannes Bergaff89a92009-07-01 21:26:51 +02007428 if (!info->attrs[NL80211_ATTR_TESTDATA])
7429 return -EINVAL;
7430
Johannes Bergad7e7182013-11-13 13:37:47 +01007431 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007432 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007433 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7434 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007435 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007436
Johannes Bergaff89a92009-07-01 21:26:51 +02007437 return err;
7438}
7439
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007440static int nl80211_testmode_dump(struct sk_buff *skb,
7441 struct netlink_callback *cb)
7442{
Johannes Berg00918d32011-12-13 17:22:05 +01007443 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007444 int err;
7445 long phy_idx;
7446 void *data = NULL;
7447 int data_len = 0;
7448
Johannes Berg5fe231e2013-05-08 21:45:15 +02007449 rtnl_lock();
7450
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007451 if (cb->args[0]) {
7452 /*
7453 * 0 is a valid index, but not valid for args[0],
7454 * so we need to offset by 1.
7455 */
7456 phy_idx = cb->args[0] - 1;
7457 } else {
7458 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7459 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7460 nl80211_policy);
7461 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007462 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007463
Johannes Berg2bd7e352012-06-15 14:23:16 +02007464 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7465 nl80211_fam.attrbuf);
7466 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007467 err = PTR_ERR(rdev);
7468 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007469 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007470 phy_idx = rdev->wiphy_idx;
7471 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007472
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007473 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7474 cb->args[1] =
7475 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7476 }
7477
7478 if (cb->args[1]) {
7479 data = nla_data((void *)cb->args[1]);
7480 data_len = nla_len((void *)cb->args[1]);
7481 }
7482
Johannes Berg00918d32011-12-13 17:22:05 +01007483 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7484 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007485 err = -ENOENT;
7486 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007487 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007488
Johannes Berg00918d32011-12-13 17:22:05 +01007489 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007490 err = -EOPNOTSUPP;
7491 goto out_err;
7492 }
7493
7494 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007495 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007496 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7497 NL80211_CMD_TESTMODE);
7498 struct nlattr *tmdata;
7499
Dan Carpentercb35fba2013-08-14 14:50:01 +03007500 if (!hdr)
7501 break;
7502
David S. Miller9360ffd2012-03-29 04:41:26 -04007503 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007504 genlmsg_cancel(skb, hdr);
7505 break;
7506 }
7507
7508 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7509 if (!tmdata) {
7510 genlmsg_cancel(skb, hdr);
7511 break;
7512 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007513 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007514 nla_nest_end(skb, tmdata);
7515
7516 if (err == -ENOBUFS || err == -ENOENT) {
7517 genlmsg_cancel(skb, hdr);
7518 break;
7519 } else if (err) {
7520 genlmsg_cancel(skb, hdr);
7521 goto out_err;
7522 }
7523
7524 genlmsg_end(skb, hdr);
7525 }
7526
7527 err = skb->len;
7528 /* see above */
7529 cb->args[0] = phy_idx + 1;
7530 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007531 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007532 return err;
7533}
Johannes Bergaff89a92009-07-01 21:26:51 +02007534#endif
7535
Samuel Ortizb23aa672009-07-01 21:26:54 +02007536static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7537{
Johannes Berg4c476992010-10-04 21:36:35 +02007538 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7539 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007540 struct cfg80211_connect_params connect;
7541 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007542 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007543 int err;
7544
7545 memset(&connect, 0, sizeof(connect));
7546
7547 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7548 return -EINVAL;
7549
7550 if (!info->attrs[NL80211_ATTR_SSID] ||
7551 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7552 return -EINVAL;
7553
7554 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7555 connect.auth_type =
7556 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007557 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7558 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007559 return -EINVAL;
7560 } else
7561 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7562
7563 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7564
Johannes Bergc0692b82010-08-27 14:26:53 +03007565 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007566 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007567 if (err)
7568 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007569
Johannes Berg074ac8d2010-09-16 14:58:22 +02007570 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007571 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7572 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007573
Johannes Berg79c97e92009-07-07 03:56:12 +02007574 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007575
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307576 connect.bg_scan_period = -1;
7577 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7578 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7579 connect.bg_scan_period =
7580 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7581 }
7582
Samuel Ortizb23aa672009-07-01 21:26:54 +02007583 if (info->attrs[NL80211_ATTR_MAC])
7584 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007585 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7586 connect.bssid_hint =
7587 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007588 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7589 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7590
7591 if (info->attrs[NL80211_ATTR_IE]) {
7592 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7593 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7594 }
7595
Jouni Malinencee00a92013-01-15 17:15:57 +02007596 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7597 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7598 if (connect.mfp != NL80211_MFP_REQUIRED &&
7599 connect.mfp != NL80211_MFP_NO)
7600 return -EINVAL;
7601 } else {
7602 connect.mfp = NL80211_MFP_NO;
7603 }
7604
Samuel Ortizb23aa672009-07-01 21:26:54 +02007605 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007606 connect.channel = nl80211_get_valid_chan(
7607 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7608 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007609 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007610 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007611 connect.channel_hint = nl80211_get_valid_chan(
7612 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7613 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007614 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007615 }
7616
Johannes Bergfffd0932009-07-08 14:22:54 +02007617 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7618 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307619 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007620 if (IS_ERR(connkeys))
7621 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007622 }
7623
Ben Greear7e7c8922011-11-18 11:31:59 -08007624 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7625 connect.flags |= ASSOC_REQ_DISABLE_HT;
7626
7627 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7628 memcpy(&connect.ht_capa_mask,
7629 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7630 sizeof(connect.ht_capa_mask));
7631
7632 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007633 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007634 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007635 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007636 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007637 memcpy(&connect.ht_capa,
7638 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7639 sizeof(connect.ht_capa));
7640 }
7641
Johannes Bergee2aca32013-02-21 17:36:01 +01007642 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7643 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7644
7645 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7646 memcpy(&connect.vht_capa_mask,
7647 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7648 sizeof(connect.vht_capa_mask));
7649
7650 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7651 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007652 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007653 return -EINVAL;
7654 }
7655 memcpy(&connect.vht_capa,
7656 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7657 sizeof(connect.vht_capa));
7658 }
7659
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007660 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7661 if (!(rdev->wiphy.features &
7662 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7663 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7664 return -EINVAL;
7665 connect.flags |= ASSOC_REQ_USE_RRM;
7666 }
7667
Johannes Berg83739b02013-05-15 17:44:01 +02007668 wdev_lock(dev->ieee80211_ptr);
7669 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7670 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007671 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007672 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007673 return err;
7674}
7675
7676static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7677{
Johannes Berg4c476992010-10-04 21:36:35 +02007678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7679 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007680 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007681 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007682
7683 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7684 reason = WLAN_REASON_DEAUTH_LEAVING;
7685 else
7686 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7687
7688 if (reason == 0)
7689 return -EINVAL;
7690
Johannes Berg074ac8d2010-09-16 14:58:22 +02007691 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007692 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7693 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007694
Johannes Berg83739b02013-05-15 17:44:01 +02007695 wdev_lock(dev->ieee80211_ptr);
7696 ret = cfg80211_disconnect(rdev, dev, reason, true);
7697 wdev_unlock(dev->ieee80211_ptr);
7698 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007699}
7700
Johannes Berg463d0182009-07-14 00:33:35 +02007701static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7702{
Johannes Berg4c476992010-10-04 21:36:35 +02007703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007704 struct net *net;
7705 int err;
7706 u32 pid;
7707
7708 if (!info->attrs[NL80211_ATTR_PID])
7709 return -EINVAL;
7710
7711 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7712
Johannes Berg463d0182009-07-14 00:33:35 +02007713 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007714 if (IS_ERR(net))
7715 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007716
7717 err = 0;
7718
7719 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007720 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7721 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007722
Johannes Berg463d0182009-07-14 00:33:35 +02007723 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007724 return err;
7725}
7726
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007727static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7728{
Johannes Berg4c476992010-10-04 21:36:35 +02007729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007730 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7731 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007732 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007733 struct cfg80211_pmksa pmksa;
7734
7735 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7736
7737 if (!info->attrs[NL80211_ATTR_MAC])
7738 return -EINVAL;
7739
7740 if (!info->attrs[NL80211_ATTR_PMKID])
7741 return -EINVAL;
7742
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007743 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7744 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7745
Johannes Berg074ac8d2010-09-16 14:58:22 +02007746 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007747 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7748 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007749
7750 switch (info->genlhdr->cmd) {
7751 case NL80211_CMD_SET_PMKSA:
7752 rdev_ops = rdev->ops->set_pmksa;
7753 break;
7754 case NL80211_CMD_DEL_PMKSA:
7755 rdev_ops = rdev->ops->del_pmksa;
7756 break;
7757 default:
7758 WARN_ON(1);
7759 break;
7760 }
7761
Johannes Berg4c476992010-10-04 21:36:35 +02007762 if (!rdev_ops)
7763 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007764
Johannes Berg4c476992010-10-04 21:36:35 +02007765 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007766}
7767
7768static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7769{
Johannes Berg4c476992010-10-04 21:36:35 +02007770 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7771 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007772
Johannes Berg074ac8d2010-09-16 14:58:22 +02007773 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007774 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7775 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007776
Johannes Berg4c476992010-10-04 21:36:35 +02007777 if (!rdev->ops->flush_pmksa)
7778 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007779
Hila Gonene35e4d22012-06-27 17:19:42 +03007780 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007781}
7782
Arik Nemtsov109086c2011-09-28 14:12:50 +03007783static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7784{
7785 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7786 struct net_device *dev = info->user_ptr[1];
7787 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307788 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007789 u16 status_code;
7790 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007791 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007792
7793 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7794 !rdev->ops->tdls_mgmt)
7795 return -EOPNOTSUPP;
7796
7797 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7798 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7799 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7800 !info->attrs[NL80211_ATTR_IE] ||
7801 !info->attrs[NL80211_ATTR_MAC])
7802 return -EINVAL;
7803
7804 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7805 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7806 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7807 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007808 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307809 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7810 peer_capability =
7811 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007812
Hila Gonene35e4d22012-06-27 17:19:42 +03007813 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307814 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007815 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007816 nla_data(info->attrs[NL80211_ATTR_IE]),
7817 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007818}
7819
7820static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7821{
7822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7823 struct net_device *dev = info->user_ptr[1];
7824 enum nl80211_tdls_operation operation;
7825 u8 *peer;
7826
7827 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7828 !rdev->ops->tdls_oper)
7829 return -EOPNOTSUPP;
7830
7831 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7832 !info->attrs[NL80211_ATTR_MAC])
7833 return -EINVAL;
7834
7835 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7836 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7837
Hila Gonene35e4d22012-06-27 17:19:42 +03007838 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007839}
7840
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007841static int nl80211_remain_on_channel(struct sk_buff *skb,
7842 struct genl_info *info)
7843{
Johannes Berg4c476992010-10-04 21:36:35 +02007844 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007845 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007846 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007847 struct sk_buff *msg;
7848 void *hdr;
7849 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007850 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007851 int err;
7852
7853 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7854 !info->attrs[NL80211_ATTR_DURATION])
7855 return -EINVAL;
7856
7857 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7858
Johannes Berg7c4ef712011-11-18 15:33:48 +01007859 if (!rdev->ops->remain_on_channel ||
7860 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007861 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007862
Johannes Bergebf348f2012-06-01 12:50:54 +02007863 /*
7864 * We should be on that channel for at least a minimum amount of
7865 * time (10ms) but no longer than the driver supports.
7866 */
7867 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7868 duration > rdev->wiphy.max_remain_on_channel_duration)
7869 return -EINVAL;
7870
Johannes Berg683b6d32012-11-08 21:25:48 +01007871 err = nl80211_parse_chandef(rdev, info, &chandef);
7872 if (err)
7873 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007874
7875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007876 if (!msg)
7877 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007878
Eric W. Biederman15e47302012-09-07 20:12:54 +00007879 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007880 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007881 if (!hdr) {
7882 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007883 goto free_msg;
7884 }
7885
Johannes Berg683b6d32012-11-08 21:25:48 +01007886 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7887 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007888
7889 if (err)
7890 goto free_msg;
7891
David S. Miller9360ffd2012-03-29 04:41:26 -04007892 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7893 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007894
7895 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007896
7897 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007898
7899 nla_put_failure:
7900 err = -ENOBUFS;
7901 free_msg:
7902 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007903 return err;
7904}
7905
7906static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7907 struct genl_info *info)
7908{
Johannes Berg4c476992010-10-04 21:36:35 +02007909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007910 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007911 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007912
7913 if (!info->attrs[NL80211_ATTR_COOKIE])
7914 return -EINVAL;
7915
Johannes Berg4c476992010-10-04 21:36:35 +02007916 if (!rdev->ops->cancel_remain_on_channel)
7917 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007918
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007919 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7920
Hila Gonene35e4d22012-06-27 17:19:42 +03007921 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007922}
7923
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007924static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7925 u8 *rates, u8 rates_len)
7926{
7927 u8 i;
7928 u32 mask = 0;
7929
7930 for (i = 0; i < rates_len; i++) {
7931 int rate = (rates[i] & 0x7f) * 5;
7932 int ridx;
7933 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7934 struct ieee80211_rate *srate =
7935 &sband->bitrates[ridx];
7936 if (rate == srate->bitrate) {
7937 mask |= 1 << ridx;
7938 break;
7939 }
7940 }
7941 if (ridx == sband->n_bitrates)
7942 return 0; /* rate not found */
7943 }
7944
7945 return mask;
7946}
7947
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007948static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7949 u8 *rates, u8 rates_len,
7950 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7951{
7952 u8 i;
7953
7954 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7955
7956 for (i = 0; i < rates_len; i++) {
7957 int ridx, rbit;
7958
7959 ridx = rates[i] / 8;
7960 rbit = BIT(rates[i] % 8);
7961
7962 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007963 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007964 return false;
7965
7966 /* check availability */
7967 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7968 mcs[ridx] |= rbit;
7969 else
7970 return false;
7971 }
7972
7973 return true;
7974}
7975
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007976static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7977{
7978 u16 mcs_mask = 0;
7979
7980 switch (vht_mcs_map) {
7981 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7982 break;
7983 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7984 mcs_mask = 0x00FF;
7985 break;
7986 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7987 mcs_mask = 0x01FF;
7988 break;
7989 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7990 mcs_mask = 0x03FF;
7991 break;
7992 default:
7993 break;
7994 }
7995
7996 return mcs_mask;
7997}
7998
7999static void vht_build_mcs_mask(u16 vht_mcs_map,
8000 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8001{
8002 u8 nss;
8003
8004 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8005 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8006 vht_mcs_map >>= 2;
8007 }
8008}
8009
8010static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8011 struct nl80211_txrate_vht *txrate,
8012 u16 mcs[NL80211_VHT_NSS_MAX])
8013{
8014 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8015 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8016 u8 i;
8017
8018 if (!sband->vht_cap.vht_supported)
8019 return false;
8020
8021 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8022
8023 /* Build vht_mcs_mask from VHT capabilities */
8024 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8025
8026 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8027 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8028 mcs[i] = txrate->mcs[i];
8029 else
8030 return false;
8031 }
8032
8033 return true;
8034}
8035
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008036static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008037 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8038 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008039 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8040 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008041 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008042 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008043};
8044
8045static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8046 struct genl_info *info)
8047{
8048 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008050 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008051 int rem, i;
8052 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008053 struct nlattr *tx_rates;
8054 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008055 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008056
Johannes Berg4c476992010-10-04 21:36:35 +02008057 if (!rdev->ops->set_bitrate_mask)
8058 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008059
8060 memset(&mask, 0, sizeof(mask));
8061 /* Default to all rates enabled */
8062 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8063 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008064
8065 if (!sband)
8066 continue;
8067
8068 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008069 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008070 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008071 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008072
8073 if (!sband->vht_cap.vht_supported)
8074 continue;
8075
8076 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8077 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008078 }
8079
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008080 /* if no rates are given set it back to the defaults */
8081 if (!info->attrs[NL80211_ATTR_TX_RATES])
8082 goto out;
8083
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008084 /*
8085 * The nested attribute uses enum nl80211_band as the index. This maps
8086 * directly to the enum ieee80211_band values used in cfg80211.
8087 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008088 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008089 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008090 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008091 int err;
8092
Johannes Berg4c476992010-10-04 21:36:35 +02008093 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8094 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008095 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008096 if (sband == NULL)
8097 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008098 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8099 nla_len(tx_rates), nl80211_txattr_policy);
8100 if (err)
8101 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008102 if (tb[NL80211_TXRATE_LEGACY]) {
8103 mask.control[band].legacy = rateset_to_mask(
8104 sband,
8105 nla_data(tb[NL80211_TXRATE_LEGACY]),
8106 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308107 if ((mask.control[band].legacy == 0) &&
8108 nla_len(tb[NL80211_TXRATE_LEGACY]))
8109 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008110 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008111 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008112 if (!ht_rateset_to_mask(
8113 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008114 nla_data(tb[NL80211_TXRATE_HT]),
8115 nla_len(tb[NL80211_TXRATE_HT]),
8116 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008117 return -EINVAL;
8118 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008119 if (tb[NL80211_TXRATE_VHT]) {
8120 if (!vht_set_mcs_mask(
8121 sband,
8122 nla_data(tb[NL80211_TXRATE_VHT]),
8123 mask.control[band].vht_mcs))
8124 return -EINVAL;
8125 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008126 if (tb[NL80211_TXRATE_GI]) {
8127 mask.control[band].gi =
8128 nla_get_u8(tb[NL80211_TXRATE_GI]);
8129 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8130 return -EINVAL;
8131 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008132
8133 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008134 /* don't allow empty legacy rates if HT or VHT
8135 * are not even supported.
8136 */
8137 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8138 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008139 return -EINVAL;
8140
8141 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008142 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008143 goto out;
8144
8145 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8146 if (mask.control[band].vht_mcs[i])
8147 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008148
8149 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008150 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008151 }
8152 }
8153
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008154out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008155 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008156}
8157
Johannes Berg2e161f782010-08-12 15:38:38 +02008158static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008159{
Johannes Berg4c476992010-10-04 21:36:35 +02008160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008161 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02008162 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008163
8164 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8165 return -EINVAL;
8166
Johannes Berg2e161f782010-08-12 15:38:38 +02008167 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8168 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008169
Johannes Berg71bbc992012-06-15 15:30:18 +02008170 switch (wdev->iftype) {
8171 case NL80211_IFTYPE_STATION:
8172 case NL80211_IFTYPE_ADHOC:
8173 case NL80211_IFTYPE_P2P_CLIENT:
8174 case NL80211_IFTYPE_AP:
8175 case NL80211_IFTYPE_AP_VLAN:
8176 case NL80211_IFTYPE_MESH_POINT:
8177 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008178 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008179 break;
8180 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008181 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008182 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008183
8184 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008185 if (!rdev->ops->mgmt_tx)
8186 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008187
Eric W. Biederman15e47302012-09-07 20:12:54 +00008188 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008189 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8190 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008191}
8192
Johannes Berg2e161f782010-08-12 15:38:38 +02008193static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008194{
Johannes Berg4c476992010-10-04 21:36:35 +02008195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008196 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008197 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008198 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008199 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008200 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008201 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008202 struct cfg80211_mgmt_tx_params params = {
8203 .dont_wait_for_ack =
8204 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8205 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008206
Johannes Berg683b6d32012-11-08 21:25:48 +01008207 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008208 return -EINVAL;
8209
Johannes Berg4c476992010-10-04 21:36:35 +02008210 if (!rdev->ops->mgmt_tx)
8211 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008212
Johannes Berg71bbc992012-06-15 15:30:18 +02008213 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008214 case NL80211_IFTYPE_P2P_DEVICE:
8215 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8216 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008217 case NL80211_IFTYPE_STATION:
8218 case NL80211_IFTYPE_ADHOC:
8219 case NL80211_IFTYPE_P2P_CLIENT:
8220 case NL80211_IFTYPE_AP:
8221 case NL80211_IFTYPE_AP_VLAN:
8222 case NL80211_IFTYPE_MESH_POINT:
8223 case NL80211_IFTYPE_P2P_GO:
8224 break;
8225 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008226 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008227 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008228
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008229 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008230 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008231 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008232 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008233
8234 /*
8235 * We should wait on the channel for at least a minimum amount
8236 * of time (10ms) but no longer than the driver supports.
8237 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008238 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8239 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008240 return -EINVAL;
8241
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008242 }
8243
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008244 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008245
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008246 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008247 return -EINVAL;
8248
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008249 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308250
Antonio Quartulliea141b752013-06-11 14:20:03 +02008251 /* get the channel if any has been specified, otherwise pass NULL to
8252 * the driver. The latter will use the current one
8253 */
8254 chandef.chan = NULL;
8255 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8256 err = nl80211_parse_chandef(rdev, info, &chandef);
8257 if (err)
8258 return err;
8259 }
8260
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008261 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008262 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008263
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008264 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8265 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8266
8267 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8268 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8269 int i;
8270
8271 if (len % sizeof(u16))
8272 return -EINVAL;
8273
8274 params.n_csa_offsets = len / sizeof(u16);
8275 params.csa_offsets =
8276 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8277
8278 /* check that all the offsets fit the frame */
8279 for (i = 0; i < params.n_csa_offsets; i++) {
8280 if (params.csa_offsets[i] >= params.len)
8281 return -EINVAL;
8282 }
8283 }
8284
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008285 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008286 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8287 if (!msg)
8288 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008289
Eric W. Biederman15e47302012-09-07 20:12:54 +00008290 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008291 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008292 if (!hdr) {
8293 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008294 goto free_msg;
8295 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008296 }
Johannes Berge247bd902011-11-04 11:18:21 +01008297
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008298 params.chan = chandef.chan;
8299 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008300 if (err)
8301 goto free_msg;
8302
Johannes Berge247bd902011-11-04 11:18:21 +01008303 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008304 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8305 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008306
Johannes Berge247bd902011-11-04 11:18:21 +01008307 genlmsg_end(msg, hdr);
8308 return genlmsg_reply(msg, info);
8309 }
8310
8311 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008312
8313 nla_put_failure:
8314 err = -ENOBUFS;
8315 free_msg:
8316 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008317 return err;
8318}
8319
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008320static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8321{
8322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008323 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008324 u64 cookie;
8325
8326 if (!info->attrs[NL80211_ATTR_COOKIE])
8327 return -EINVAL;
8328
8329 if (!rdev->ops->mgmt_tx_cancel_wait)
8330 return -EOPNOTSUPP;
8331
Johannes Berg71bbc992012-06-15 15:30:18 +02008332 switch (wdev->iftype) {
8333 case NL80211_IFTYPE_STATION:
8334 case NL80211_IFTYPE_ADHOC:
8335 case NL80211_IFTYPE_P2P_CLIENT:
8336 case NL80211_IFTYPE_AP:
8337 case NL80211_IFTYPE_AP_VLAN:
8338 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008339 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008340 break;
8341 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008342 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008343 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008344
8345 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8346
Hila Gonene35e4d22012-06-27 17:19:42 +03008347 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008348}
8349
Kalle Valoffb9eb32010-02-17 17:58:10 +02008350static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8351{
Johannes Berg4c476992010-10-04 21:36:35 +02008352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008353 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008354 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008355 u8 ps_state;
8356 bool state;
8357 int err;
8358
Johannes Berg4c476992010-10-04 21:36:35 +02008359 if (!info->attrs[NL80211_ATTR_PS_STATE])
8360 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008361
8362 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8363
Johannes Berg4c476992010-10-04 21:36:35 +02008364 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8365 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008366
8367 wdev = dev->ieee80211_ptr;
8368
Johannes Berg4c476992010-10-04 21:36:35 +02008369 if (!rdev->ops->set_power_mgmt)
8370 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008371
8372 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8373
8374 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008375 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008376
Hila Gonene35e4d22012-06-27 17:19:42 +03008377 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008378 if (!err)
8379 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008380 return err;
8381}
8382
8383static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8384{
Johannes Berg4c476992010-10-04 21:36:35 +02008385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008386 enum nl80211_ps_state ps_state;
8387 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008388 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008389 struct sk_buff *msg;
8390 void *hdr;
8391 int err;
8392
Kalle Valoffb9eb32010-02-17 17:58:10 +02008393 wdev = dev->ieee80211_ptr;
8394
Johannes Berg4c476992010-10-04 21:36:35 +02008395 if (!rdev->ops->set_power_mgmt)
8396 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008397
8398 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008399 if (!msg)
8400 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008401
Eric W. Biederman15e47302012-09-07 20:12:54 +00008402 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008403 NL80211_CMD_GET_POWER_SAVE);
8404 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008405 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008406 goto free_msg;
8407 }
8408
8409 if (wdev->ps)
8410 ps_state = NL80211_PS_ENABLED;
8411 else
8412 ps_state = NL80211_PS_DISABLED;
8413
David S. Miller9360ffd2012-03-29 04:41:26 -04008414 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8415 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008416
8417 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008418 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008419
Johannes Berg4c476992010-10-04 21:36:35 +02008420 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008421 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008422 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008423 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008424 return err;
8425}
8426
Johannes Berg94e860f2014-01-20 23:58:15 +01008427static const struct nla_policy
8428nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008429 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8430 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8431 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008432 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8433 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8434 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008435};
8436
Thomas Pedersen84f10702012-07-12 16:17:33 -07008437static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008438 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008439{
8440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008441 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008442 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008443
Johannes Bergd9d8b012012-11-26 12:51:52 +01008444 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008445 return -EINVAL;
8446
Thomas Pedersen84f10702012-07-12 16:17:33 -07008447 if (!rdev->ops->set_cqm_txe_config)
8448 return -EOPNOTSUPP;
8449
8450 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8451 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8452 return -EOPNOTSUPP;
8453
Hila Gonene35e4d22012-06-27 17:19:42 +03008454 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008455}
8456
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008457static int nl80211_set_cqm_rssi(struct genl_info *info,
8458 s32 threshold, u32 hysteresis)
8459{
Johannes Berg4c476992010-10-04 21:36:35 +02008460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008461 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008462 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008463
8464 if (threshold > 0)
8465 return -EINVAL;
8466
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008467 /* disabling - hysteresis should also be zero then */
8468 if (threshold == 0)
8469 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008470
Johannes Berg4c476992010-10-04 21:36:35 +02008471 if (!rdev->ops->set_cqm_rssi_config)
8472 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008473
Johannes Berg074ac8d2010-09-16 14:58:22 +02008474 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008475 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8476 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008477
Hila Gonene35e4d22012-06-27 17:19:42 +03008478 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008479}
8480
8481static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8482{
8483 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8484 struct nlattr *cqm;
8485 int err;
8486
8487 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008488 if (!cqm)
8489 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008490
8491 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8492 nl80211_attr_cqm_policy);
8493 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008494 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008495
8496 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8497 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008498 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8499 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008500
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008501 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8502 }
8503
8504 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8505 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8506 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8507 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8508 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8509 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8510
8511 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8512 }
8513
8514 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008515}
8516
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008517static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8518{
8519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8520 struct net_device *dev = info->user_ptr[1];
8521 struct ocb_setup setup = {};
8522 int err;
8523
8524 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8525 if (err)
8526 return err;
8527
8528 return cfg80211_join_ocb(rdev, dev, &setup);
8529}
8530
8531static int nl80211_leave_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
8536 return cfg80211_leave_ocb(rdev, dev);
8537}
8538
Johannes Berg29cbe682010-12-03 09:20:44 +01008539static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8540{
8541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8542 struct net_device *dev = info->user_ptr[1];
8543 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008544 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008545 int err;
8546
8547 /* start with default */
8548 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008549 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008550
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008551 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008552 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008553 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008554 if (err)
8555 return err;
8556 }
8557
8558 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8559 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8560 return -EINVAL;
8561
Javier Cardonac80d5452010-12-16 17:37:49 -08008562 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8563 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8564
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008565 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8566 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8567 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8568 return -EINVAL;
8569
Marco Porsch9bdbf042013-01-07 16:04:51 +01008570 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8571 setup.beacon_interval =
8572 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8573 if (setup.beacon_interval < 10 ||
8574 setup.beacon_interval > 10000)
8575 return -EINVAL;
8576 }
8577
8578 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8579 setup.dtim_period =
8580 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8581 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8582 return -EINVAL;
8583 }
8584
Javier Cardonac80d5452010-12-16 17:37:49 -08008585 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8586 /* parse additional setup parameters if given */
8587 err = nl80211_parse_mesh_setup(info, &setup);
8588 if (err)
8589 return err;
8590 }
8591
Thomas Pedersend37bb182013-03-04 13:06:13 -08008592 if (setup.user_mpm)
8593 cfg.auto_open_plinks = false;
8594
Johannes Bergcc1d2802012-05-16 23:50:20 +02008595 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008596 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8597 if (err)
8598 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008599 } else {
8600 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008601 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008602 }
8603
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008604 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8605 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8606 int n_rates =
8607 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8608 struct ieee80211_supported_band *sband;
8609
8610 if (!setup.chandef.chan)
8611 return -EINVAL;
8612
8613 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8614
8615 err = ieee80211_get_ratemask(sband, rates, n_rates,
8616 &setup.basic_rates);
8617 if (err)
8618 return err;
8619 }
8620
Javier Cardonac80d5452010-12-16 17:37:49 -08008621 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008622}
8623
8624static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8625{
8626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8627 struct net_device *dev = info->user_ptr[1];
8628
8629 return cfg80211_leave_mesh(rdev, dev);
8630}
8631
Johannes Bergdfb89c52012-06-27 09:23:48 +02008632#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008633static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8634 struct cfg80211_registered_device *rdev)
8635{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008636 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008637 struct nlattr *nl_pats, *nl_pat;
8638 int i, pat_len;
8639
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008640 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008641 return 0;
8642
8643 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8644 if (!nl_pats)
8645 return -ENOBUFS;
8646
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008647 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008648 nl_pat = nla_nest_start(msg, i + 1);
8649 if (!nl_pat)
8650 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008651 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008652 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008653 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008654 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8655 wowlan->patterns[i].pattern) ||
8656 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008657 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008658 return -ENOBUFS;
8659 nla_nest_end(msg, nl_pat);
8660 }
8661 nla_nest_end(msg, nl_pats);
8662
8663 return 0;
8664}
8665
Johannes Berg2a0e0472013-01-23 22:57:40 +01008666static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8667 struct cfg80211_wowlan_tcp *tcp)
8668{
8669 struct nlattr *nl_tcp;
8670
8671 if (!tcp)
8672 return 0;
8673
8674 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8675 if (!nl_tcp)
8676 return -ENOBUFS;
8677
8678 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8679 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8680 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8681 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8682 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8683 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8684 tcp->payload_len, tcp->payload) ||
8685 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8686 tcp->data_interval) ||
8687 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8688 tcp->wake_len, tcp->wake_data) ||
8689 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8690 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8691 return -ENOBUFS;
8692
8693 if (tcp->payload_seq.len &&
8694 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8695 sizeof(tcp->payload_seq), &tcp->payload_seq))
8696 return -ENOBUFS;
8697
8698 if (tcp->payload_tok.len &&
8699 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8700 sizeof(tcp->payload_tok) + tcp->tokens_size,
8701 &tcp->payload_tok))
8702 return -ENOBUFS;
8703
Johannes Berge248ad32013-05-16 10:24:28 +02008704 nla_nest_end(msg, nl_tcp);
8705
Johannes Berg2a0e0472013-01-23 22:57:40 +01008706 return 0;
8707}
8708
Johannes Bergff1b6e62011-05-04 15:37:28 +02008709static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8710{
8711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8712 struct sk_buff *msg;
8713 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008714 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008715
Johannes Berg964dc9e2013-06-03 17:25:34 +02008716 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008717 return -EOPNOTSUPP;
8718
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008719 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008720 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008721 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8722 rdev->wiphy.wowlan_config->tcp->payload_len +
8723 rdev->wiphy.wowlan_config->tcp->wake_len +
8724 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008725 }
8726
8727 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008728 if (!msg)
8729 return -ENOMEM;
8730
Eric W. Biederman15e47302012-09-07 20:12:54 +00008731 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008732 NL80211_CMD_GET_WOWLAN);
8733 if (!hdr)
8734 goto nla_put_failure;
8735
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008736 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008737 struct nlattr *nl_wowlan;
8738
8739 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8740 if (!nl_wowlan)
8741 goto nla_put_failure;
8742
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008743 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008744 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008745 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008746 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008747 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008748 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008749 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008750 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008751 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008752 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008753 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008754 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008755 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008756 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8757 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008758
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008759 if (nl80211_send_wowlan_patterns(msg, rdev))
8760 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008761
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008762 if (nl80211_send_wowlan_tcp(msg,
8763 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008764 goto nla_put_failure;
8765
Johannes Bergff1b6e62011-05-04 15:37:28 +02008766 nla_nest_end(msg, nl_wowlan);
8767 }
8768
8769 genlmsg_end(msg, hdr);
8770 return genlmsg_reply(msg, info);
8771
8772nla_put_failure:
8773 nlmsg_free(msg);
8774 return -ENOBUFS;
8775}
8776
Johannes Berg2a0e0472013-01-23 22:57:40 +01008777static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8778 struct nlattr *attr,
8779 struct cfg80211_wowlan *trig)
8780{
8781 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8782 struct cfg80211_wowlan_tcp *cfg;
8783 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8784 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8785 u32 size;
8786 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8787 int err, port;
8788
Johannes Berg964dc9e2013-06-03 17:25:34 +02008789 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008790 return -EINVAL;
8791
8792 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8793 nla_data(attr), nla_len(attr),
8794 nl80211_wowlan_tcp_policy);
8795 if (err)
8796 return err;
8797
8798 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8799 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8800 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8801 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8802 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8803 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8804 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8805 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8806 return -EINVAL;
8807
8808 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008809 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008810 return -EINVAL;
8811
8812 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008813 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008814 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008815 return -EINVAL;
8816
8817 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008818 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008819 return -EINVAL;
8820
8821 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8822 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8823 return -EINVAL;
8824
8825 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8826 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8827
8828 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8829 tokens_size = tokln - sizeof(*tok);
8830
8831 if (!tok->len || tokens_size % tok->len)
8832 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008833 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008834 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008835 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008836 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008837 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008838 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008839 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008840 return -EINVAL;
8841 if (tok->offset + tok->len > data_size)
8842 return -EINVAL;
8843 }
8844
8845 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8846 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008847 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008848 return -EINVAL;
8849 if (seq->len == 0 || seq->len > 4)
8850 return -EINVAL;
8851 if (seq->len + seq->offset > data_size)
8852 return -EINVAL;
8853 }
8854
8855 size = sizeof(*cfg);
8856 size += data_size;
8857 size += wake_size + wake_mask_size;
8858 size += tokens_size;
8859
8860 cfg = kzalloc(size, GFP_KERNEL);
8861 if (!cfg)
8862 return -ENOMEM;
8863 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8864 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8865 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8866 ETH_ALEN);
8867 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8868 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8869 else
8870 port = 0;
8871#ifdef CONFIG_INET
8872 /* allocate a socket and port for it and use it */
8873 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8874 IPPROTO_TCP, &cfg->sock, 1);
8875 if (err) {
8876 kfree(cfg);
8877 return err;
8878 }
8879 if (inet_csk_get_port(cfg->sock->sk, port)) {
8880 sock_release(cfg->sock);
8881 kfree(cfg);
8882 return -EADDRINUSE;
8883 }
8884 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8885#else
8886 if (!port) {
8887 kfree(cfg);
8888 return -EINVAL;
8889 }
8890 cfg->src_port = port;
8891#endif
8892
8893 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8894 cfg->payload_len = data_size;
8895 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8896 memcpy((void *)cfg->payload,
8897 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8898 data_size);
8899 if (seq)
8900 cfg->payload_seq = *seq;
8901 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8902 cfg->wake_len = wake_size;
8903 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8904 memcpy((void *)cfg->wake_data,
8905 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8906 wake_size);
8907 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8908 data_size + wake_size;
8909 memcpy((void *)cfg->wake_mask,
8910 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8911 wake_mask_size);
8912 if (tok) {
8913 cfg->tokens_size = tokens_size;
8914 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8915 }
8916
8917 trig->tcp = cfg;
8918
8919 return 0;
8920}
8921
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008922static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
8923 const struct wiphy_wowlan_support *wowlan,
8924 struct nlattr *attr,
8925 struct cfg80211_wowlan *trig)
8926{
8927 struct nlattr **tb;
8928 int err;
8929
8930 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
8931 if (!tb)
8932 return -ENOMEM;
8933
8934 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
8935 err = -EOPNOTSUPP;
8936 goto out;
8937 }
8938
8939 err = nla_parse(tb, NL80211_ATTR_MAX,
8940 nla_data(attr), nla_len(attr),
8941 nl80211_policy);
8942 if (err)
8943 goto out;
8944
Johannes Bergad2b26a2014-06-12 21:39:05 +02008945 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008946 err = PTR_ERR_OR_ZERO(trig->nd_config);
8947 if (err)
8948 trig->nd_config = NULL;
8949
8950out:
8951 kfree(tb);
8952 return err;
8953}
8954
Johannes Bergff1b6e62011-05-04 15:37:28 +02008955static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8956{
8957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8958 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008959 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008960 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008961 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008962 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008963 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008964
Johannes Berg964dc9e2013-06-03 17:25:34 +02008965 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008966 return -EOPNOTSUPP;
8967
Johannes Bergae33bd82012-07-12 16:25:02 +02008968 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8969 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008970 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008971 goto set_wakeup;
8972 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008973
8974 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8975 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8976 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8977 nl80211_wowlan_policy);
8978 if (err)
8979 return err;
8980
8981 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8982 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8983 return -EINVAL;
8984 new_triggers.any = true;
8985 }
8986
8987 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8988 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8989 return -EINVAL;
8990 new_triggers.disconnect = true;
8991 }
8992
8993 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8994 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8995 return -EINVAL;
8996 new_triggers.magic_pkt = true;
8997 }
8998
Johannes Berg77dbbb12011-07-13 10:48:55 +02008999 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9000 return -EINVAL;
9001
9002 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9003 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9004 return -EINVAL;
9005 new_triggers.gtk_rekey_failure = true;
9006 }
9007
9008 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9009 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9010 return -EINVAL;
9011 new_triggers.eap_identity_req = true;
9012 }
9013
9014 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9015 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9016 return -EINVAL;
9017 new_triggers.four_way_handshake = true;
9018 }
9019
9020 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9021 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9022 return -EINVAL;
9023 new_triggers.rfkill_release = true;
9024 }
9025
Johannes Bergff1b6e62011-05-04 15:37:28 +02009026 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9027 struct nlattr *pat;
9028 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009029 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009030 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009031
9032 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9033 rem)
9034 n_patterns++;
9035 if (n_patterns > wowlan->n_patterns)
9036 return -EINVAL;
9037
9038 new_triggers.patterns = kcalloc(n_patterns,
9039 sizeof(new_triggers.patterns[0]),
9040 GFP_KERNEL);
9041 if (!new_triggers.patterns)
9042 return -ENOMEM;
9043
9044 new_triggers.n_patterns = n_patterns;
9045 i = 0;
9046
9047 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9048 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009049 u8 *mask_pat;
9050
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009051 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9052 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009053 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009054 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9055 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009056 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009057 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009058 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009059 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009060 goto error;
9061 if (pat_len > wowlan->pattern_max_len ||
9062 pat_len < wowlan->pattern_min_len)
9063 goto error;
9064
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009065 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009066 pkt_offset = 0;
9067 else
9068 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009069 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009070 if (pkt_offset > wowlan->max_pkt_offset)
9071 goto error;
9072 new_triggers.patterns[i].pkt_offset = pkt_offset;
9073
Johannes Berg922bd802014-05-19 17:59:50 +02009074 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9075 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009076 err = -ENOMEM;
9077 goto error;
9078 }
Johannes Berg922bd802014-05-19 17:59:50 +02009079 new_triggers.patterns[i].mask = mask_pat;
9080 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009081 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009082 mask_pat += mask_len;
9083 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009084 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009085 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009086 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009087 pat_len);
9088 i++;
9089 }
9090 }
9091
Johannes Berg2a0e0472013-01-23 22:57:40 +01009092 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
9093 err = nl80211_parse_wowlan_tcp(
9094 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9095 &new_triggers);
9096 if (err)
9097 goto error;
9098 }
9099
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009100 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
9101 err = nl80211_parse_wowlan_nd(
9102 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9103 &new_triggers);
9104 if (err)
9105 goto error;
9106 }
9107
Johannes Bergae33bd82012-07-12 16:25:02 +02009108 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9109 if (!ntrig) {
9110 err = -ENOMEM;
9111 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009112 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009113 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009114 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009115
Johannes Bergae33bd82012-07-12 16:25:02 +02009116 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009117 if (rdev->ops->set_wakeup &&
9118 prev_enabled != !!rdev->wiphy.wowlan_config)
9119 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009120
Johannes Bergff1b6e62011-05-04 15:37:28 +02009121 return 0;
9122 error:
9123 for (i = 0; i < new_triggers.n_patterns; i++)
9124 kfree(new_triggers.patterns[i].mask);
9125 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009126 if (new_triggers.tcp && new_triggers.tcp->sock)
9127 sock_release(new_triggers.tcp->sock);
9128 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009129 return err;
9130}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009131#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009132
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009133static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9134 struct cfg80211_registered_device *rdev)
9135{
9136 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9137 int i, j, pat_len;
9138 struct cfg80211_coalesce_rules *rule;
9139
9140 if (!rdev->coalesce->n_rules)
9141 return 0;
9142
9143 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9144 if (!nl_rules)
9145 return -ENOBUFS;
9146
9147 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9148 nl_rule = nla_nest_start(msg, i + 1);
9149 if (!nl_rule)
9150 return -ENOBUFS;
9151
9152 rule = &rdev->coalesce->rules[i];
9153 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9154 rule->delay))
9155 return -ENOBUFS;
9156
9157 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9158 rule->condition))
9159 return -ENOBUFS;
9160
9161 nl_pats = nla_nest_start(msg,
9162 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9163 if (!nl_pats)
9164 return -ENOBUFS;
9165
9166 for (j = 0; j < rule->n_patterns; j++) {
9167 nl_pat = nla_nest_start(msg, j + 1);
9168 if (!nl_pat)
9169 return -ENOBUFS;
9170 pat_len = rule->patterns[j].pattern_len;
9171 if (nla_put(msg, NL80211_PKTPAT_MASK,
9172 DIV_ROUND_UP(pat_len, 8),
9173 rule->patterns[j].mask) ||
9174 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9175 rule->patterns[j].pattern) ||
9176 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9177 rule->patterns[j].pkt_offset))
9178 return -ENOBUFS;
9179 nla_nest_end(msg, nl_pat);
9180 }
9181 nla_nest_end(msg, nl_pats);
9182 nla_nest_end(msg, nl_rule);
9183 }
9184 nla_nest_end(msg, nl_rules);
9185
9186 return 0;
9187}
9188
9189static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9190{
9191 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9192 struct sk_buff *msg;
9193 void *hdr;
9194
9195 if (!rdev->wiphy.coalesce)
9196 return -EOPNOTSUPP;
9197
9198 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9199 if (!msg)
9200 return -ENOMEM;
9201
9202 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9203 NL80211_CMD_GET_COALESCE);
9204 if (!hdr)
9205 goto nla_put_failure;
9206
9207 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9208 goto nla_put_failure;
9209
9210 genlmsg_end(msg, hdr);
9211 return genlmsg_reply(msg, info);
9212
9213nla_put_failure:
9214 nlmsg_free(msg);
9215 return -ENOBUFS;
9216}
9217
9218void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9219{
9220 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9221 int i, j;
9222 struct cfg80211_coalesce_rules *rule;
9223
9224 if (!coalesce)
9225 return;
9226
9227 for (i = 0; i < coalesce->n_rules; i++) {
9228 rule = &coalesce->rules[i];
9229 for (j = 0; j < rule->n_patterns; j++)
9230 kfree(rule->patterns[j].mask);
9231 kfree(rule->patterns);
9232 }
9233 kfree(coalesce->rules);
9234 kfree(coalesce);
9235 rdev->coalesce = NULL;
9236}
9237
9238static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9239 struct nlattr *rule,
9240 struct cfg80211_coalesce_rules *new_rule)
9241{
9242 int err, i;
9243 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9244 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9245 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9246 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9247
9248 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9249 nla_len(rule), nl80211_coalesce_policy);
9250 if (err)
9251 return err;
9252
9253 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9254 new_rule->delay =
9255 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9256 if (new_rule->delay > coalesce->max_delay)
9257 return -EINVAL;
9258
9259 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9260 new_rule->condition =
9261 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9262 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9263 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9264 return -EINVAL;
9265
9266 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9267 return -EINVAL;
9268
9269 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9270 rem)
9271 n_patterns++;
9272 if (n_patterns > coalesce->n_patterns)
9273 return -EINVAL;
9274
9275 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9276 GFP_KERNEL);
9277 if (!new_rule->patterns)
9278 return -ENOMEM;
9279
9280 new_rule->n_patterns = n_patterns;
9281 i = 0;
9282
9283 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9284 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009285 u8 *mask_pat;
9286
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009287 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9288 nla_len(pat), NULL);
9289 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9290 !pat_tb[NL80211_PKTPAT_PATTERN])
9291 return -EINVAL;
9292 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9293 mask_len = DIV_ROUND_UP(pat_len, 8);
9294 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9295 return -EINVAL;
9296 if (pat_len > coalesce->pattern_max_len ||
9297 pat_len < coalesce->pattern_min_len)
9298 return -EINVAL;
9299
9300 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9301 pkt_offset = 0;
9302 else
9303 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9304 if (pkt_offset > coalesce->max_pkt_offset)
9305 return -EINVAL;
9306 new_rule->patterns[i].pkt_offset = pkt_offset;
9307
Johannes Berg922bd802014-05-19 17:59:50 +02009308 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9309 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009310 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009311
9312 new_rule->patterns[i].mask = mask_pat;
9313 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9314 mask_len);
9315
9316 mask_pat += mask_len;
9317 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009318 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009319 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9320 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009321 i++;
9322 }
9323
9324 return 0;
9325}
9326
9327static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9328{
9329 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9330 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9331 struct cfg80211_coalesce new_coalesce = {};
9332 struct cfg80211_coalesce *n_coalesce;
9333 int err, rem_rule, n_rules = 0, i, j;
9334 struct nlattr *rule;
9335 struct cfg80211_coalesce_rules *tmp_rule;
9336
9337 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9338 return -EOPNOTSUPP;
9339
9340 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9341 cfg80211_rdev_free_coalesce(rdev);
9342 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9343 return 0;
9344 }
9345
9346 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9347 rem_rule)
9348 n_rules++;
9349 if (n_rules > coalesce->n_rules)
9350 return -EINVAL;
9351
9352 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9353 GFP_KERNEL);
9354 if (!new_coalesce.rules)
9355 return -ENOMEM;
9356
9357 new_coalesce.n_rules = n_rules;
9358 i = 0;
9359
9360 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9361 rem_rule) {
9362 err = nl80211_parse_coalesce_rule(rdev, rule,
9363 &new_coalesce.rules[i]);
9364 if (err)
9365 goto error;
9366
9367 i++;
9368 }
9369
9370 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9371 if (err)
9372 goto error;
9373
9374 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9375 if (!n_coalesce) {
9376 err = -ENOMEM;
9377 goto error;
9378 }
9379 cfg80211_rdev_free_coalesce(rdev);
9380 rdev->coalesce = n_coalesce;
9381
9382 return 0;
9383error:
9384 for (i = 0; i < new_coalesce.n_rules; i++) {
9385 tmp_rule = &new_coalesce.rules[i];
9386 for (j = 0; j < tmp_rule->n_patterns; j++)
9387 kfree(tmp_rule->patterns[j].mask);
9388 kfree(tmp_rule->patterns);
9389 }
9390 kfree(new_coalesce.rules);
9391
9392 return err;
9393}
9394
Johannes Berge5497d72011-07-05 16:35:40 +02009395static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9396{
9397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9398 struct net_device *dev = info->user_ptr[1];
9399 struct wireless_dev *wdev = dev->ieee80211_ptr;
9400 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9401 struct cfg80211_gtk_rekey_data rekey_data;
9402 int err;
9403
9404 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9405 return -EINVAL;
9406
9407 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9408 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9409 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9410 nl80211_rekey_policy);
9411 if (err)
9412 return err;
9413
9414 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9415 return -ERANGE;
9416 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9417 return -ERANGE;
9418 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9419 return -ERANGE;
9420
Johannes Berg78f686c2014-09-10 22:28:06 +03009421 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9422 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9423 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009424
9425 wdev_lock(wdev);
9426 if (!wdev->current_bss) {
9427 err = -ENOTCONN;
9428 goto out;
9429 }
9430
9431 if (!rdev->ops->set_rekey_data) {
9432 err = -EOPNOTSUPP;
9433 goto out;
9434 }
9435
Hila Gonene35e4d22012-06-27 17:19:42 +03009436 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009437 out:
9438 wdev_unlock(wdev);
9439 return err;
9440}
9441
Johannes Berg28946da2011-11-04 11:18:12 +01009442static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9443 struct genl_info *info)
9444{
9445 struct net_device *dev = info->user_ptr[1];
9446 struct wireless_dev *wdev = dev->ieee80211_ptr;
9447
9448 if (wdev->iftype != NL80211_IFTYPE_AP &&
9449 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9450 return -EINVAL;
9451
Eric W. Biederman15e47302012-09-07 20:12:54 +00009452 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009453 return -EBUSY;
9454
Eric W. Biederman15e47302012-09-07 20:12:54 +00009455 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009456 return 0;
9457}
9458
Johannes Berg7f6cf312011-11-04 11:18:15 +01009459static int nl80211_probe_client(struct sk_buff *skb,
9460 struct genl_info *info)
9461{
9462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9463 struct net_device *dev = info->user_ptr[1];
9464 struct wireless_dev *wdev = dev->ieee80211_ptr;
9465 struct sk_buff *msg;
9466 void *hdr;
9467 const u8 *addr;
9468 u64 cookie;
9469 int err;
9470
9471 if (wdev->iftype != NL80211_IFTYPE_AP &&
9472 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9473 return -EOPNOTSUPP;
9474
9475 if (!info->attrs[NL80211_ATTR_MAC])
9476 return -EINVAL;
9477
9478 if (!rdev->ops->probe_client)
9479 return -EOPNOTSUPP;
9480
9481 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9482 if (!msg)
9483 return -ENOMEM;
9484
Eric W. Biederman15e47302012-09-07 20:12:54 +00009485 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009486 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009487 if (!hdr) {
9488 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009489 goto free_msg;
9490 }
9491
9492 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9493
Hila Gonene35e4d22012-06-27 17:19:42 +03009494 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009495 if (err)
9496 goto free_msg;
9497
David S. Miller9360ffd2012-03-29 04:41:26 -04009498 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9499 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009500
9501 genlmsg_end(msg, hdr);
9502
9503 return genlmsg_reply(msg, info);
9504
9505 nla_put_failure:
9506 err = -ENOBUFS;
9507 free_msg:
9508 nlmsg_free(msg);
9509 return err;
9510}
9511
Johannes Berg5e760232011-11-04 11:18:17 +01009512static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9513{
9514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009515 struct cfg80211_beacon_registration *reg, *nreg;
9516 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009517
9518 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9519 return -EOPNOTSUPP;
9520
Ben Greear37c73b52012-10-26 14:49:25 -07009521 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9522 if (!nreg)
9523 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009524
Ben Greear37c73b52012-10-26 14:49:25 -07009525 /* First, check if already registered. */
9526 spin_lock_bh(&rdev->beacon_registrations_lock);
9527 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9528 if (reg->nlportid == info->snd_portid) {
9529 rv = -EALREADY;
9530 goto out_err;
9531 }
9532 }
9533 /* Add it to the list */
9534 nreg->nlportid = info->snd_portid;
9535 list_add(&nreg->list, &rdev->beacon_registrations);
9536
9537 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009538
9539 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009540out_err:
9541 spin_unlock_bh(&rdev->beacon_registrations_lock);
9542 kfree(nreg);
9543 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009544}
9545
Johannes Berg98104fde2012-06-16 00:19:54 +02009546static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9547{
9548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9549 struct wireless_dev *wdev = info->user_ptr[1];
9550 int err;
9551
9552 if (!rdev->ops->start_p2p_device)
9553 return -EOPNOTSUPP;
9554
9555 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9556 return -EOPNOTSUPP;
9557
9558 if (wdev->p2p_started)
9559 return 0;
9560
Luciano Coelhob6a55012014-02-27 11:07:21 +02009561 if (rfkill_blocked(rdev->rfkill))
9562 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009563
Johannes Bergeeb126e2012-10-23 15:16:50 +02009564 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009565 if (err)
9566 return err;
9567
9568 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009569 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009570
9571 return 0;
9572}
9573
9574static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9575{
9576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9577 struct wireless_dev *wdev = info->user_ptr[1];
9578
9579 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9580 return -EOPNOTSUPP;
9581
9582 if (!rdev->ops->stop_p2p_device)
9583 return -EOPNOTSUPP;
9584
Johannes Bergf9f47522013-03-19 15:04:07 +01009585 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009586
9587 return 0;
9588}
9589
Johannes Berg3713b4e2013-02-14 16:19:38 +01009590static int nl80211_get_protocol_features(struct sk_buff *skb,
9591 struct genl_info *info)
9592{
9593 void *hdr;
9594 struct sk_buff *msg;
9595
9596 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9597 if (!msg)
9598 return -ENOMEM;
9599
9600 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9601 NL80211_CMD_GET_PROTOCOL_FEATURES);
9602 if (!hdr)
9603 goto nla_put_failure;
9604
9605 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9606 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9607 goto nla_put_failure;
9608
9609 genlmsg_end(msg, hdr);
9610 return genlmsg_reply(msg, info);
9611
9612 nla_put_failure:
9613 kfree_skb(msg);
9614 return -ENOBUFS;
9615}
9616
Jouni Malinen355199e2013-02-27 17:14:27 +02009617static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9618{
9619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9620 struct cfg80211_update_ft_ies_params ft_params;
9621 struct net_device *dev = info->user_ptr[1];
9622
9623 if (!rdev->ops->update_ft_ies)
9624 return -EOPNOTSUPP;
9625
9626 if (!info->attrs[NL80211_ATTR_MDID] ||
9627 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9628 return -EINVAL;
9629
9630 memset(&ft_params, 0, sizeof(ft_params));
9631 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9632 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9633 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9634
9635 return rdev_update_ft_ies(rdev, dev, &ft_params);
9636}
9637
Arend van Spriel5de17982013-04-18 15:49:00 +02009638static int nl80211_crit_protocol_start(struct sk_buff *skb,
9639 struct genl_info *info)
9640{
9641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9642 struct wireless_dev *wdev = info->user_ptr[1];
9643 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9644 u16 duration;
9645 int ret;
9646
9647 if (!rdev->ops->crit_proto_start)
9648 return -EOPNOTSUPP;
9649
9650 if (WARN_ON(!rdev->ops->crit_proto_stop))
9651 return -EINVAL;
9652
9653 if (rdev->crit_proto_nlportid)
9654 return -EBUSY;
9655
9656 /* determine protocol if provided */
9657 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9658 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9659
9660 if (proto >= NUM_NL80211_CRIT_PROTO)
9661 return -EINVAL;
9662
9663 /* timeout must be provided */
9664 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9665 return -EINVAL;
9666
9667 duration =
9668 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9669
9670 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9671 return -ERANGE;
9672
9673 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9674 if (!ret)
9675 rdev->crit_proto_nlportid = info->snd_portid;
9676
9677 return ret;
9678}
9679
9680static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9681 struct genl_info *info)
9682{
9683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9684 struct wireless_dev *wdev = info->user_ptr[1];
9685
9686 if (!rdev->ops->crit_proto_stop)
9687 return -EOPNOTSUPP;
9688
9689 if (rdev->crit_proto_nlportid) {
9690 rdev->crit_proto_nlportid = 0;
9691 rdev_crit_proto_stop(rdev, wdev);
9692 }
9693 return 0;
9694}
9695
Johannes Bergad7e7182013-11-13 13:37:47 +01009696static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9697{
9698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9699 struct wireless_dev *wdev =
9700 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9701 int i, err;
9702 u32 vid, subcmd;
9703
9704 if (!rdev->wiphy.vendor_commands)
9705 return -EOPNOTSUPP;
9706
9707 if (IS_ERR(wdev)) {
9708 err = PTR_ERR(wdev);
9709 if (err != -EINVAL)
9710 return err;
9711 wdev = NULL;
9712 } else if (wdev->wiphy != &rdev->wiphy) {
9713 return -EINVAL;
9714 }
9715
9716 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9717 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9718 return -EINVAL;
9719
9720 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9721 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9722 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9723 const struct wiphy_vendor_command *vcmd;
9724 void *data = NULL;
9725 int len = 0;
9726
9727 vcmd = &rdev->wiphy.vendor_commands[i];
9728
9729 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9730 continue;
9731
9732 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9733 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9734 if (!wdev)
9735 return -EINVAL;
9736 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9737 !wdev->netdev)
9738 return -EINVAL;
9739
9740 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9741 if (wdev->netdev &&
9742 !netif_running(wdev->netdev))
9743 return -ENETDOWN;
9744 if (!wdev->netdev && !wdev->p2p_started)
9745 return -ENETDOWN;
9746 }
9747 } else {
9748 wdev = NULL;
9749 }
9750
9751 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9752 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9753 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9754 }
9755
9756 rdev->cur_cmd_info = info;
9757 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9758 data, len);
9759 rdev->cur_cmd_info = NULL;
9760 return err;
9761 }
9762
9763 return -EOPNOTSUPP;
9764}
9765
9766struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9767 enum nl80211_commands cmd,
9768 enum nl80211_attrs attr,
9769 int approxlen)
9770{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009771 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009772
9773 if (WARN_ON(!rdev->cur_cmd_info))
9774 return NULL;
9775
9776 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9777 rdev->cur_cmd_info->snd_portid,
9778 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009779 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009780}
9781EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9782
9783int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9784{
9785 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9786 void *hdr = ((void **)skb->cb)[1];
9787 struct nlattr *data = ((void **)skb->cb)[2];
9788
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009789 /* clear CB data for netlink core to own from now on */
9790 memset(skb->cb, 0, sizeof(skb->cb));
9791
Johannes Bergad7e7182013-11-13 13:37:47 +01009792 if (WARN_ON(!rdev->cur_cmd_info)) {
9793 kfree_skb(skb);
9794 return -EINVAL;
9795 }
9796
9797 nla_nest_end(skb, data);
9798 genlmsg_end(skb, hdr);
9799 return genlmsg_reply(skb, rdev->cur_cmd_info);
9800}
9801EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9802
9803
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009804static int nl80211_set_qos_map(struct sk_buff *skb,
9805 struct genl_info *info)
9806{
9807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9808 struct cfg80211_qos_map *qos_map = NULL;
9809 struct net_device *dev = info->user_ptr[1];
9810 u8 *pos, len, num_des, des_len, des;
9811 int ret;
9812
9813 if (!rdev->ops->set_qos_map)
9814 return -EOPNOTSUPP;
9815
9816 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9817 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9818 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9819
9820 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9821 len > IEEE80211_QOS_MAP_LEN_MAX)
9822 return -EINVAL;
9823
9824 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9825 if (!qos_map)
9826 return -ENOMEM;
9827
9828 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9829 if (num_des) {
9830 des_len = num_des *
9831 sizeof(struct cfg80211_dscp_exception);
9832 memcpy(qos_map->dscp_exception, pos, des_len);
9833 qos_map->num_des = num_des;
9834 for (des = 0; des < num_des; des++) {
9835 if (qos_map->dscp_exception[des].up > 7) {
9836 kfree(qos_map);
9837 return -EINVAL;
9838 }
9839 }
9840 pos += des_len;
9841 }
9842 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9843 }
9844
9845 wdev_lock(dev->ieee80211_ptr);
9846 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9847 if (!ret)
9848 ret = rdev_set_qos_map(rdev, dev, qos_map);
9849 wdev_unlock(dev->ieee80211_ptr);
9850
9851 kfree(qos_map);
9852 return ret;
9853}
9854
Johannes Berg960d01a2014-09-09 22:55:35 +03009855static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9856{
9857 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9858 struct net_device *dev = info->user_ptr[1];
9859 struct wireless_dev *wdev = dev->ieee80211_ptr;
9860 const u8 *peer;
9861 u8 tsid, up;
9862 u16 admitted_time = 0;
9863 int err;
9864
Johannes Berg723e73a2014-10-22 09:25:06 +02009865 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009866 return -EOPNOTSUPP;
9867
9868 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9869 !info->attrs[NL80211_ATTR_USER_PRIO])
9870 return -EINVAL;
9871
9872 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9873 if (tsid >= IEEE80211_NUM_TIDS)
9874 return -EINVAL;
9875
9876 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9877 if (up >= IEEE80211_NUM_UPS)
9878 return -EINVAL;
9879
9880 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009881 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009882 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009883 * need more attributes for that (e.g. BA session requirement);
9884 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009885 */
9886 return -EINVAL;
9887 }
9888
9889 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9890
9891 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9892 admitted_time =
9893 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9894 if (!admitted_time)
9895 return -EINVAL;
9896 }
9897
9898 wdev_lock(wdev);
9899 switch (wdev->iftype) {
9900 case NL80211_IFTYPE_STATION:
9901 case NL80211_IFTYPE_P2P_CLIENT:
9902 if (wdev->current_bss)
9903 break;
9904 err = -ENOTCONN;
9905 goto out;
9906 default:
9907 err = -EOPNOTSUPP;
9908 goto out;
9909 }
9910
9911 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9912
9913 out:
9914 wdev_unlock(wdev);
9915 return err;
9916}
9917
9918static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9919{
9920 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9921 struct net_device *dev = info->user_ptr[1];
9922 struct wireless_dev *wdev = dev->ieee80211_ptr;
9923 const u8 *peer;
9924 u8 tsid;
9925 int err;
9926
9927 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9928 return -EINVAL;
9929
9930 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9931 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9932
9933 wdev_lock(wdev);
9934 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9935 wdev_unlock(wdev);
9936
9937 return err;
9938}
9939
Arik Nemtsov1057d352014-11-19 12:54:26 +02009940static int nl80211_tdls_channel_switch(struct sk_buff *skb,
9941 struct genl_info *info)
9942{
9943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9944 struct net_device *dev = info->user_ptr[1];
9945 struct wireless_dev *wdev = dev->ieee80211_ptr;
9946 struct cfg80211_chan_def chandef = {};
9947 const u8 *addr;
9948 u8 oper_class;
9949 int err;
9950
9951 if (!rdev->ops->tdls_channel_switch ||
9952 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9953 return -EOPNOTSUPP;
9954
9955 switch (dev->ieee80211_ptr->iftype) {
9956 case NL80211_IFTYPE_STATION:
9957 case NL80211_IFTYPE_P2P_CLIENT:
9958 break;
9959 default:
9960 return -EOPNOTSUPP;
9961 }
9962
9963 if (!info->attrs[NL80211_ATTR_MAC] ||
9964 !info->attrs[NL80211_ATTR_OPER_CLASS])
9965 return -EINVAL;
9966
9967 err = nl80211_parse_chandef(rdev, info, &chandef);
9968 if (err)
9969 return err;
9970
9971 /*
9972 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
9973 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
9974 * specification is not defined for them.
9975 */
9976 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
9977 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
9978 chandef.width != NL80211_CHAN_WIDTH_20)
9979 return -EINVAL;
9980
9981 /* we will be active on the TDLS link */
9982 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
9983 return -EINVAL;
9984
9985 /* don't allow switching to DFS channels */
9986 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
9987 return -EINVAL;
9988
9989 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9990 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
9991
9992 wdev_lock(wdev);
9993 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
9994 wdev_unlock(wdev);
9995
9996 return err;
9997}
9998
9999static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10000 struct genl_info *info)
10001{
10002 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10003 struct net_device *dev = info->user_ptr[1];
10004 struct wireless_dev *wdev = dev->ieee80211_ptr;
10005 const u8 *addr;
10006
10007 if (!rdev->ops->tdls_channel_switch ||
10008 !rdev->ops->tdls_cancel_channel_switch ||
10009 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10010 return -EOPNOTSUPP;
10011
10012 switch (dev->ieee80211_ptr->iftype) {
10013 case NL80211_IFTYPE_STATION:
10014 case NL80211_IFTYPE_P2P_CLIENT:
10015 break;
10016 default:
10017 return -EOPNOTSUPP;
10018 }
10019
10020 if (!info->attrs[NL80211_ATTR_MAC])
10021 return -EINVAL;
10022
10023 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10024
10025 wdev_lock(wdev);
10026 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10027 wdev_unlock(wdev);
10028
10029 return 0;
10030}
10031
Johannes Berg4c476992010-10-04 21:36:35 +020010032#define NL80211_FLAG_NEED_WIPHY 0x01
10033#define NL80211_FLAG_NEED_NETDEV 0x02
10034#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010035#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10036#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10037 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010038#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010039/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010040#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10041 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010042#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010043
Johannes Bergf84f7712013-11-14 17:14:45 +010010044static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010045 struct genl_info *info)
10046{
10047 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010048 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010049 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010050 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10051
10052 if (rtnl)
10053 rtnl_lock();
10054
10055 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010056 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010057 if (IS_ERR(rdev)) {
10058 if (rtnl)
10059 rtnl_unlock();
10060 return PTR_ERR(rdev);
10061 }
10062 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010063 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10064 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010065 ASSERT_RTNL();
10066
Johannes Berg89a54e42012-06-15 14:33:17 +020010067 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10068 info->attrs);
10069 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010070 if (rtnl)
10071 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010072 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010073 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010074
Johannes Berg89a54e42012-06-15 14:33:17 +020010075 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010076 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010077
Johannes Berg1bf614e2012-06-15 15:23:36 +020010078 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10079 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010080 if (rtnl)
10081 rtnl_unlock();
10082 return -EINVAL;
10083 }
10084
10085 info->user_ptr[1] = dev;
10086 } else {
10087 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010088 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010089
Johannes Berg1bf614e2012-06-15 15:23:36 +020010090 if (dev) {
10091 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10092 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010093 if (rtnl)
10094 rtnl_unlock();
10095 return -ENETDOWN;
10096 }
10097
10098 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010099 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10100 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010101 if (rtnl)
10102 rtnl_unlock();
10103 return -ENETDOWN;
10104 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010105 }
10106
Johannes Berg4c476992010-10-04 21:36:35 +020010107 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010108 }
10109
10110 return 0;
10111}
10112
Johannes Bergf84f7712013-11-14 17:14:45 +010010113static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010114 struct genl_info *info)
10115{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010116 if (info->user_ptr[1]) {
10117 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10118 struct wireless_dev *wdev = info->user_ptr[1];
10119
10120 if (wdev->netdev)
10121 dev_put(wdev->netdev);
10122 } else {
10123 dev_put(info->user_ptr[1]);
10124 }
10125 }
Johannes Berg5393b912014-09-10 15:00:16 +030010126
Johannes Berg4c476992010-10-04 21:36:35 +020010127 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10128 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010129
10130 /* If needed, clear the netlink message payload from the SKB
10131 * as it might contain key data that shouldn't stick around on
10132 * the heap after the SKB is freed. The netlink message header
10133 * is still needed for further processing, so leave it intact.
10134 */
10135 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10136 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10137
10138 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10139 }
Johannes Berg4c476992010-10-04 21:36:35 +020010140}
10141
Johannes Berg4534de82013-11-14 17:14:46 +010010142static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010143 {
10144 .cmd = NL80211_CMD_GET_WIPHY,
10145 .doit = nl80211_get_wiphy,
10146 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010147 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010148 .policy = nl80211_policy,
10149 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010150 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10151 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010152 },
10153 {
10154 .cmd = NL80211_CMD_SET_WIPHY,
10155 .doit = nl80211_set_wiphy,
10156 .policy = nl80211_policy,
10157 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010158 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010159 },
10160 {
10161 .cmd = NL80211_CMD_GET_INTERFACE,
10162 .doit = nl80211_get_interface,
10163 .dumpit = nl80211_dump_interface,
10164 .policy = nl80211_policy,
10165 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010166 .internal_flags = NL80211_FLAG_NEED_WDEV |
10167 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010168 },
10169 {
10170 .cmd = NL80211_CMD_SET_INTERFACE,
10171 .doit = nl80211_set_interface,
10172 .policy = nl80211_policy,
10173 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010174 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10175 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010176 },
10177 {
10178 .cmd = NL80211_CMD_NEW_INTERFACE,
10179 .doit = nl80211_new_interface,
10180 .policy = nl80211_policy,
10181 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010182 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10183 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010184 },
10185 {
10186 .cmd = NL80211_CMD_DEL_INTERFACE,
10187 .doit = nl80211_del_interface,
10188 .policy = nl80211_policy,
10189 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010190 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010191 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010192 },
Johannes Berg41ade002007-12-19 02:03:29 +010010193 {
10194 .cmd = NL80211_CMD_GET_KEY,
10195 .doit = nl80211_get_key,
10196 .policy = nl80211_policy,
10197 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010198 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010199 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010200 },
10201 {
10202 .cmd = NL80211_CMD_SET_KEY,
10203 .doit = nl80211_set_key,
10204 .policy = nl80211_policy,
10205 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010206 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010207 NL80211_FLAG_NEED_RTNL |
10208 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010209 },
10210 {
10211 .cmd = NL80211_CMD_NEW_KEY,
10212 .doit = nl80211_new_key,
10213 .policy = nl80211_policy,
10214 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010216 NL80211_FLAG_NEED_RTNL |
10217 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010218 },
10219 {
10220 .cmd = NL80211_CMD_DEL_KEY,
10221 .doit = nl80211_del_key,
10222 .policy = nl80211_policy,
10223 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010224 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010225 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010226 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010227 {
10228 .cmd = NL80211_CMD_SET_BEACON,
10229 .policy = nl80211_policy,
10230 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010231 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010232 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010233 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010234 },
10235 {
Johannes Berg88600202012-02-13 15:17:18 +010010236 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010237 .policy = nl80211_policy,
10238 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010239 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010240 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010241 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010242 },
10243 {
Johannes Berg88600202012-02-13 15:17:18 +010010244 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010245 .policy = nl80211_policy,
10246 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010247 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010248 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010249 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010250 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010251 {
10252 .cmd = NL80211_CMD_GET_STATION,
10253 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010254 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010255 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010256 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10257 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010258 },
10259 {
10260 .cmd = NL80211_CMD_SET_STATION,
10261 .doit = nl80211_set_station,
10262 .policy = nl80211_policy,
10263 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010264 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010265 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010266 },
10267 {
10268 .cmd = NL80211_CMD_NEW_STATION,
10269 .doit = nl80211_new_station,
10270 .policy = nl80211_policy,
10271 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010272 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010273 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010274 },
10275 {
10276 .cmd = NL80211_CMD_DEL_STATION,
10277 .doit = nl80211_del_station,
10278 .policy = nl80211_policy,
10279 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010280 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010281 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010282 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010283 {
10284 .cmd = NL80211_CMD_GET_MPATH,
10285 .doit = nl80211_get_mpath,
10286 .dumpit = nl80211_dump_mpath,
10287 .policy = nl80211_policy,
10288 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010289 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010290 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010291 },
10292 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010293 .cmd = NL80211_CMD_GET_MPP,
10294 .doit = nl80211_get_mpp,
10295 .dumpit = nl80211_dump_mpp,
10296 .policy = nl80211_policy,
10297 .flags = GENL_ADMIN_PERM,
10298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10299 NL80211_FLAG_NEED_RTNL,
10300 },
10301 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010302 .cmd = NL80211_CMD_SET_MPATH,
10303 .doit = nl80211_set_mpath,
10304 .policy = nl80211_policy,
10305 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010307 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010308 },
10309 {
10310 .cmd = NL80211_CMD_NEW_MPATH,
10311 .doit = nl80211_new_mpath,
10312 .policy = nl80211_policy,
10313 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010315 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010316 },
10317 {
10318 .cmd = NL80211_CMD_DEL_MPATH,
10319 .doit = nl80211_del_mpath,
10320 .policy = nl80211_policy,
10321 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010322 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010323 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010324 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010325 {
10326 .cmd = NL80211_CMD_SET_BSS,
10327 .doit = nl80211_set_bss,
10328 .policy = nl80211_policy,
10329 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010331 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010332 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010333 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010334 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010335 .doit = nl80211_get_reg_do,
10336 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010337 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010338 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010339 /* can be retrieved by unprivileged users */
10340 },
10341 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010342 .cmd = NL80211_CMD_SET_REG,
10343 .doit = nl80211_set_reg,
10344 .policy = nl80211_policy,
10345 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010346 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010347 },
10348 {
10349 .cmd = NL80211_CMD_REQ_SET_REG,
10350 .doit = nl80211_req_set_reg,
10351 .policy = nl80211_policy,
10352 .flags = GENL_ADMIN_PERM,
10353 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010354 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010355 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10356 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010357 .policy = nl80211_policy,
10358 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010359 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010360 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010361 },
10362 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010363 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10364 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010365 .policy = nl80211_policy,
10366 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010367 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010368 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010369 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010370 {
Johannes Berg2a519312009-02-10 21:25:55 +010010371 .cmd = NL80211_CMD_TRIGGER_SCAN,
10372 .doit = nl80211_trigger_scan,
10373 .policy = nl80211_policy,
10374 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010375 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010376 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010377 },
10378 {
10379 .cmd = NL80211_CMD_GET_SCAN,
10380 .policy = nl80211_policy,
10381 .dumpit = nl80211_dump_scan,
10382 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010383 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010384 .cmd = NL80211_CMD_START_SCHED_SCAN,
10385 .doit = nl80211_start_sched_scan,
10386 .policy = nl80211_policy,
10387 .flags = GENL_ADMIN_PERM,
10388 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10389 NL80211_FLAG_NEED_RTNL,
10390 },
10391 {
10392 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10393 .doit = nl80211_stop_sched_scan,
10394 .policy = nl80211_policy,
10395 .flags = GENL_ADMIN_PERM,
10396 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10397 NL80211_FLAG_NEED_RTNL,
10398 },
10399 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010400 .cmd = NL80211_CMD_AUTHENTICATE,
10401 .doit = nl80211_authenticate,
10402 .policy = nl80211_policy,
10403 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010404 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010405 NL80211_FLAG_NEED_RTNL |
10406 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010407 },
10408 {
10409 .cmd = NL80211_CMD_ASSOCIATE,
10410 .doit = nl80211_associate,
10411 .policy = nl80211_policy,
10412 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010413 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010414 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010415 },
10416 {
10417 .cmd = NL80211_CMD_DEAUTHENTICATE,
10418 .doit = nl80211_deauthenticate,
10419 .policy = nl80211_policy,
10420 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010421 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010422 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010423 },
10424 {
10425 .cmd = NL80211_CMD_DISASSOCIATE,
10426 .doit = nl80211_disassociate,
10427 .policy = nl80211_policy,
10428 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010429 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010430 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010431 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010432 {
10433 .cmd = NL80211_CMD_JOIN_IBSS,
10434 .doit = nl80211_join_ibss,
10435 .policy = nl80211_policy,
10436 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010437 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010438 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010439 },
10440 {
10441 .cmd = NL80211_CMD_LEAVE_IBSS,
10442 .doit = nl80211_leave_ibss,
10443 .policy = nl80211_policy,
10444 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010445 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010446 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010447 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010448#ifdef CONFIG_NL80211_TESTMODE
10449 {
10450 .cmd = NL80211_CMD_TESTMODE,
10451 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010452 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010453 .policy = nl80211_policy,
10454 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010455 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10456 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010457 },
10458#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010459 {
10460 .cmd = NL80211_CMD_CONNECT,
10461 .doit = nl80211_connect,
10462 .policy = nl80211_policy,
10463 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010464 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010465 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010466 },
10467 {
10468 .cmd = NL80211_CMD_DISCONNECT,
10469 .doit = nl80211_disconnect,
10470 .policy = nl80211_policy,
10471 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010473 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010474 },
Johannes Berg463d0182009-07-14 00:33:35 +020010475 {
10476 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10477 .doit = nl80211_wiphy_netns,
10478 .policy = nl80211_policy,
10479 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010480 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10481 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010482 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010483 {
10484 .cmd = NL80211_CMD_GET_SURVEY,
10485 .policy = nl80211_policy,
10486 .dumpit = nl80211_dump_survey,
10487 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010488 {
10489 .cmd = NL80211_CMD_SET_PMKSA,
10490 .doit = nl80211_setdel_pmksa,
10491 .policy = nl80211_policy,
10492 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010494 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010495 },
10496 {
10497 .cmd = NL80211_CMD_DEL_PMKSA,
10498 .doit = nl80211_setdel_pmksa,
10499 .policy = nl80211_policy,
10500 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010502 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010503 },
10504 {
10505 .cmd = NL80211_CMD_FLUSH_PMKSA,
10506 .doit = nl80211_flush_pmksa,
10507 .policy = nl80211_policy,
10508 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010510 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010511 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010512 {
10513 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10514 .doit = nl80211_remain_on_channel,
10515 .policy = nl80211_policy,
10516 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010517 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010518 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010519 },
10520 {
10521 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10522 .doit = nl80211_cancel_remain_on_channel,
10523 .policy = nl80211_policy,
10524 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010525 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010526 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010527 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010528 {
10529 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10530 .doit = nl80211_set_tx_bitrate_mask,
10531 .policy = nl80211_policy,
10532 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010533 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10534 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010535 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010536 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010537 .cmd = NL80211_CMD_REGISTER_FRAME,
10538 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010539 .policy = nl80211_policy,
10540 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010541 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010542 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010543 },
10544 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010545 .cmd = NL80211_CMD_FRAME,
10546 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010547 .policy = nl80211_policy,
10548 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010549 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010550 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010551 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010552 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010553 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10554 .doit = nl80211_tx_mgmt_cancel_wait,
10555 .policy = nl80211_policy,
10556 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010557 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010558 NL80211_FLAG_NEED_RTNL,
10559 },
10560 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010561 .cmd = NL80211_CMD_SET_POWER_SAVE,
10562 .doit = nl80211_set_power_save,
10563 .policy = nl80211_policy,
10564 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010565 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10566 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010567 },
10568 {
10569 .cmd = NL80211_CMD_GET_POWER_SAVE,
10570 .doit = nl80211_get_power_save,
10571 .policy = nl80211_policy,
10572 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010573 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10574 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010575 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010576 {
10577 .cmd = NL80211_CMD_SET_CQM,
10578 .doit = nl80211_set_cqm,
10579 .policy = nl80211_policy,
10580 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010581 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10582 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010583 },
Johannes Bergf444de02010-05-05 15:25:02 +020010584 {
10585 .cmd = NL80211_CMD_SET_CHANNEL,
10586 .doit = nl80211_set_channel,
10587 .policy = nl80211_policy,
10588 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010589 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10590 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010591 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010592 {
10593 .cmd = NL80211_CMD_SET_WDS_PEER,
10594 .doit = nl80211_set_wds_peer,
10595 .policy = nl80211_policy,
10596 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010597 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10598 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010599 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010600 {
10601 .cmd = NL80211_CMD_JOIN_MESH,
10602 .doit = nl80211_join_mesh,
10603 .policy = nl80211_policy,
10604 .flags = GENL_ADMIN_PERM,
10605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10606 NL80211_FLAG_NEED_RTNL,
10607 },
10608 {
10609 .cmd = NL80211_CMD_LEAVE_MESH,
10610 .doit = nl80211_leave_mesh,
10611 .policy = nl80211_policy,
10612 .flags = GENL_ADMIN_PERM,
10613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10614 NL80211_FLAG_NEED_RTNL,
10615 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010616 {
10617 .cmd = NL80211_CMD_JOIN_OCB,
10618 .doit = nl80211_join_ocb,
10619 .policy = nl80211_policy,
10620 .flags = GENL_ADMIN_PERM,
10621 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10622 NL80211_FLAG_NEED_RTNL,
10623 },
10624 {
10625 .cmd = NL80211_CMD_LEAVE_OCB,
10626 .doit = nl80211_leave_ocb,
10627 .policy = nl80211_policy,
10628 .flags = GENL_ADMIN_PERM,
10629 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10630 NL80211_FLAG_NEED_RTNL,
10631 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010632#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010633 {
10634 .cmd = NL80211_CMD_GET_WOWLAN,
10635 .doit = nl80211_get_wowlan,
10636 .policy = nl80211_policy,
10637 /* can be retrieved by unprivileged users */
10638 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10639 NL80211_FLAG_NEED_RTNL,
10640 },
10641 {
10642 .cmd = NL80211_CMD_SET_WOWLAN,
10643 .doit = nl80211_set_wowlan,
10644 .policy = nl80211_policy,
10645 .flags = GENL_ADMIN_PERM,
10646 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10647 NL80211_FLAG_NEED_RTNL,
10648 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010649#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010650 {
10651 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10652 .doit = nl80211_set_rekey_data,
10653 .policy = nl80211_policy,
10654 .flags = GENL_ADMIN_PERM,
10655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010656 NL80211_FLAG_NEED_RTNL |
10657 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010658 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010659 {
10660 .cmd = NL80211_CMD_TDLS_MGMT,
10661 .doit = nl80211_tdls_mgmt,
10662 .policy = nl80211_policy,
10663 .flags = GENL_ADMIN_PERM,
10664 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10665 NL80211_FLAG_NEED_RTNL,
10666 },
10667 {
10668 .cmd = NL80211_CMD_TDLS_OPER,
10669 .doit = nl80211_tdls_oper,
10670 .policy = nl80211_policy,
10671 .flags = GENL_ADMIN_PERM,
10672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10673 NL80211_FLAG_NEED_RTNL,
10674 },
Johannes Berg28946da2011-11-04 11:18:12 +010010675 {
10676 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10677 .doit = nl80211_register_unexpected_frame,
10678 .policy = nl80211_policy,
10679 .flags = GENL_ADMIN_PERM,
10680 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10681 NL80211_FLAG_NEED_RTNL,
10682 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010683 {
10684 .cmd = NL80211_CMD_PROBE_CLIENT,
10685 .doit = nl80211_probe_client,
10686 .policy = nl80211_policy,
10687 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010689 NL80211_FLAG_NEED_RTNL,
10690 },
Johannes Berg5e760232011-11-04 11:18:17 +010010691 {
10692 .cmd = NL80211_CMD_REGISTER_BEACONS,
10693 .doit = nl80211_register_beacons,
10694 .policy = nl80211_policy,
10695 .flags = GENL_ADMIN_PERM,
10696 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10697 NL80211_FLAG_NEED_RTNL,
10698 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010699 {
10700 .cmd = NL80211_CMD_SET_NOACK_MAP,
10701 .doit = nl80211_set_noack_map,
10702 .policy = nl80211_policy,
10703 .flags = GENL_ADMIN_PERM,
10704 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10705 NL80211_FLAG_NEED_RTNL,
10706 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010707 {
10708 .cmd = NL80211_CMD_START_P2P_DEVICE,
10709 .doit = nl80211_start_p2p_device,
10710 .policy = nl80211_policy,
10711 .flags = GENL_ADMIN_PERM,
10712 .internal_flags = NL80211_FLAG_NEED_WDEV |
10713 NL80211_FLAG_NEED_RTNL,
10714 },
10715 {
10716 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10717 .doit = nl80211_stop_p2p_device,
10718 .policy = nl80211_policy,
10719 .flags = GENL_ADMIN_PERM,
10720 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10721 NL80211_FLAG_NEED_RTNL,
10722 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010723 {
10724 .cmd = NL80211_CMD_SET_MCAST_RATE,
10725 .doit = nl80211_set_mcast_rate,
10726 .policy = nl80211_policy,
10727 .flags = GENL_ADMIN_PERM,
10728 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10729 NL80211_FLAG_NEED_RTNL,
10730 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010731 {
10732 .cmd = NL80211_CMD_SET_MAC_ACL,
10733 .doit = nl80211_set_mac_acl,
10734 .policy = nl80211_policy,
10735 .flags = GENL_ADMIN_PERM,
10736 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10737 NL80211_FLAG_NEED_RTNL,
10738 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010739 {
10740 .cmd = NL80211_CMD_RADAR_DETECT,
10741 .doit = nl80211_start_radar_detection,
10742 .policy = nl80211_policy,
10743 .flags = GENL_ADMIN_PERM,
10744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10745 NL80211_FLAG_NEED_RTNL,
10746 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010747 {
10748 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10749 .doit = nl80211_get_protocol_features,
10750 .policy = nl80211_policy,
10751 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010752 {
10753 .cmd = NL80211_CMD_UPDATE_FT_IES,
10754 .doit = nl80211_update_ft_ies,
10755 .policy = nl80211_policy,
10756 .flags = GENL_ADMIN_PERM,
10757 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10758 NL80211_FLAG_NEED_RTNL,
10759 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010760 {
10761 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10762 .doit = nl80211_crit_protocol_start,
10763 .policy = nl80211_policy,
10764 .flags = GENL_ADMIN_PERM,
10765 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10766 NL80211_FLAG_NEED_RTNL,
10767 },
10768 {
10769 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10770 .doit = nl80211_crit_protocol_stop,
10771 .policy = nl80211_policy,
10772 .flags = GENL_ADMIN_PERM,
10773 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10774 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010775 },
10776 {
10777 .cmd = NL80211_CMD_GET_COALESCE,
10778 .doit = nl80211_get_coalesce,
10779 .policy = nl80211_policy,
10780 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10781 NL80211_FLAG_NEED_RTNL,
10782 },
10783 {
10784 .cmd = NL80211_CMD_SET_COALESCE,
10785 .doit = nl80211_set_coalesce,
10786 .policy = nl80211_policy,
10787 .flags = GENL_ADMIN_PERM,
10788 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10789 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010790 },
10791 {
10792 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10793 .doit = nl80211_channel_switch,
10794 .policy = nl80211_policy,
10795 .flags = GENL_ADMIN_PERM,
10796 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10797 NL80211_FLAG_NEED_RTNL,
10798 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010799 {
10800 .cmd = NL80211_CMD_VENDOR,
10801 .doit = nl80211_vendor_cmd,
10802 .policy = nl80211_policy,
10803 .flags = GENL_ADMIN_PERM,
10804 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10805 NL80211_FLAG_NEED_RTNL,
10806 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010807 {
10808 .cmd = NL80211_CMD_SET_QOS_MAP,
10809 .doit = nl80211_set_qos_map,
10810 .policy = nl80211_policy,
10811 .flags = GENL_ADMIN_PERM,
10812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10813 NL80211_FLAG_NEED_RTNL,
10814 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010815 {
10816 .cmd = NL80211_CMD_ADD_TX_TS,
10817 .doit = nl80211_add_tx_ts,
10818 .policy = nl80211_policy,
10819 .flags = GENL_ADMIN_PERM,
10820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10821 NL80211_FLAG_NEED_RTNL,
10822 },
10823 {
10824 .cmd = NL80211_CMD_DEL_TX_TS,
10825 .doit = nl80211_del_tx_ts,
10826 .policy = nl80211_policy,
10827 .flags = GENL_ADMIN_PERM,
10828 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10829 NL80211_FLAG_NEED_RTNL,
10830 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020010831 {
10832 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
10833 .doit = nl80211_tdls_channel_switch,
10834 .policy = nl80211_policy,
10835 .flags = GENL_ADMIN_PERM,
10836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10837 NL80211_FLAG_NEED_RTNL,
10838 },
10839 {
10840 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
10841 .doit = nl80211_tdls_cancel_channel_switch,
10842 .policy = nl80211_policy,
10843 .flags = GENL_ADMIN_PERM,
10844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10845 NL80211_FLAG_NEED_RTNL,
10846 },
Johannes Berg55682962007-09-20 13:09:35 -040010847};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010848
Johannes Berg55682962007-09-20 13:09:35 -040010849/* notification functions */
10850
Johannes Berg3bb20552014-05-26 13:52:25 +020010851void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10852 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010853{
10854 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010855 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010856
Johannes Berg3bb20552014-05-26 13:52:25 +020010857 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10858 cmd != NL80211_CMD_DEL_WIPHY);
10859
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010860 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010861 if (!msg)
10862 return;
10863
Johannes Berg3bb20552014-05-26 13:52:25 +020010864 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010865 nlmsg_free(msg);
10866 return;
10867 }
10868
Johannes Berg68eb5502013-11-19 15:19:38 +010010869 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010870 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010871}
10872
Johannes Berg362a4152009-05-24 16:43:15 +020010873static int nl80211_add_scan_req(struct sk_buff *msg,
10874 struct cfg80211_registered_device *rdev)
10875{
10876 struct cfg80211_scan_request *req = rdev->scan_req;
10877 struct nlattr *nest;
10878 int i;
10879
10880 if (WARN_ON(!req))
10881 return 0;
10882
10883 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10884 if (!nest)
10885 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010886 for (i = 0; i < req->n_ssids; i++) {
10887 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10888 goto nla_put_failure;
10889 }
Johannes Berg362a4152009-05-24 16:43:15 +020010890 nla_nest_end(msg, nest);
10891
10892 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10893 if (!nest)
10894 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010895 for (i = 0; i < req->n_channels; i++) {
10896 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10897 goto nla_put_failure;
10898 }
Johannes Berg362a4152009-05-24 16:43:15 +020010899 nla_nest_end(msg, nest);
10900
David S. Miller9360ffd2012-03-29 04:41:26 -040010901 if (req->ie &&
10902 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10903 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010904
Johannes Bergae917c92013-10-25 11:05:22 +020010905 if (req->flags &&
10906 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10907 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010908
Johannes Berg362a4152009-05-24 16:43:15 +020010909 return 0;
10910 nla_put_failure:
10911 return -ENOBUFS;
10912}
10913
Johannes Berga538e2d2009-06-16 19:56:42 +020010914static int nl80211_send_scan_msg(struct sk_buff *msg,
10915 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010916 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010917 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010918 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010919{
10920 void *hdr;
10921
Eric W. Biederman15e47302012-09-07 20:12:54 +000010922 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010923 if (!hdr)
10924 return -1;
10925
David S. Miller9360ffd2012-03-29 04:41:26 -040010926 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010927 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10928 wdev->netdev->ifindex)) ||
10929 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010930 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010931
Johannes Berg362a4152009-05-24 16:43:15 +020010932 /* ignore errors and send incomplete event anyway */
10933 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010934
10935 return genlmsg_end(msg, hdr);
10936
10937 nla_put_failure:
10938 genlmsg_cancel(msg, hdr);
10939 return -EMSGSIZE;
10940}
10941
Luciano Coelho807f8a82011-05-11 17:09:35 +030010942static int
10943nl80211_send_sched_scan_msg(struct sk_buff *msg,
10944 struct cfg80211_registered_device *rdev,
10945 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010946 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010947{
10948 void *hdr;
10949
Eric W. Biederman15e47302012-09-07 20:12:54 +000010950 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010951 if (!hdr)
10952 return -1;
10953
David S. Miller9360ffd2012-03-29 04:41:26 -040010954 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10955 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10956 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010957
10958 return genlmsg_end(msg, hdr);
10959
10960 nla_put_failure:
10961 genlmsg_cancel(msg, hdr);
10962 return -EMSGSIZE;
10963}
10964
Johannes Berga538e2d2009-06-16 19:56:42 +020010965void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010966 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010967{
10968 struct sk_buff *msg;
10969
Thomas Graf58050fc2012-06-28 03:57:45 +000010970 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010971 if (!msg)
10972 return;
10973
Johannes Bergfd014282012-06-18 19:17:03 +020010974 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010975 NL80211_CMD_TRIGGER_SCAN) < 0) {
10976 nlmsg_free(msg);
10977 return;
10978 }
10979
Johannes Berg68eb5502013-11-19 15:19:38 +010010980 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010981 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010982}
10983
Johannes Bergf9d15d12014-01-22 11:14:19 +020010984struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10985 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010986{
10987 struct sk_buff *msg;
10988
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010990 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010991 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010992
Johannes Bergfd014282012-06-18 19:17:03 +020010993 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010994 aborted ? NL80211_CMD_SCAN_ABORTED :
10995 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010996 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010997 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010998 }
10999
Johannes Bergf9d15d12014-01-22 11:14:19 +020011000 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011001}
11002
Johannes Bergf9d15d12014-01-22 11:14:19 +020011003void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11004 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011005{
Johannes Berg2a519312009-02-10 21:25:55 +010011006 if (!msg)
11007 return;
11008
Johannes Berg68eb5502013-11-19 15:19:38 +010011009 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011010 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011011}
11012
Luciano Coelho807f8a82011-05-11 17:09:35 +030011013void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11014 struct net_device *netdev)
11015{
11016 struct sk_buff *msg;
11017
11018 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11019 if (!msg)
11020 return;
11021
11022 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11023 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11024 nlmsg_free(msg);
11025 return;
11026 }
11027
Johannes Berg68eb5502013-11-19 15:19:38 +010011028 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011029 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011030}
11031
11032void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11033 struct net_device *netdev, u32 cmd)
11034{
11035 struct sk_buff *msg;
11036
Thomas Graf58050fc2012-06-28 03:57:45 +000011037 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011038 if (!msg)
11039 return;
11040
11041 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11042 nlmsg_free(msg);
11043 return;
11044 }
11045
Johannes Berg68eb5502013-11-19 15:19:38 +010011046 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011047 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011048}
11049
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011050static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11051 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011052{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011053 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011054 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11055 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011056
David S. Miller9360ffd2012-03-29 04:41:26 -040011057 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11058 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11059 NL80211_REGDOM_TYPE_WORLD))
11060 goto nla_put_failure;
11061 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11062 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11063 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11064 goto nla_put_failure;
11065 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11066 request->intersect) {
11067 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11068 NL80211_REGDOM_TYPE_INTERSECTION))
11069 goto nla_put_failure;
11070 } else {
11071 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11072 NL80211_REGDOM_TYPE_COUNTRY) ||
11073 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11074 request->alpha2))
11075 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011076 }
11077
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011078 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11079 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11080
11081 if (wiphy &&
11082 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11083 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011084
11085 if (wiphy &&
11086 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11087 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11088 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011089 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011090
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011091 return true;
11092
11093nla_put_failure:
11094 return false;
11095}
11096
11097/*
11098 * This can happen on global regulatory changes or device specific settings
11099 * based on custom regulatory domains.
11100 */
11101void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11102 struct regulatory_request *request)
11103{
11104 struct sk_buff *msg;
11105 void *hdr;
11106
11107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11108 if (!msg)
11109 return;
11110
11111 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11112 if (!hdr) {
11113 nlmsg_free(msg);
11114 return;
11115 }
11116
11117 if (nl80211_reg_change_event_fill(msg, request) == false)
11118 goto nla_put_failure;
11119
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011120 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011121
Johannes Bergbc43b282009-07-25 10:54:13 +020011122 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011123 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011124 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011125 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011126
11127 return;
11128
11129nla_put_failure:
11130 genlmsg_cancel(msg, hdr);
11131 nlmsg_free(msg);
11132}
11133
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011134static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11135 struct net_device *netdev,
11136 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011137 enum nl80211_commands cmd, gfp_t gfp,
11138 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011139{
11140 struct sk_buff *msg;
11141 void *hdr;
11142
Johannes Berge6d6e342009-07-01 21:26:47 +020011143 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011144 if (!msg)
11145 return;
11146
11147 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11148 if (!hdr) {
11149 nlmsg_free(msg);
11150 return;
11151 }
11152
David S. Miller9360ffd2012-03-29 04:41:26 -040011153 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11154 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11155 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11156 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011157
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011158 if (uapsd_queues >= 0) {
11159 struct nlattr *nla_wmm =
11160 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11161 if (!nla_wmm)
11162 goto nla_put_failure;
11163
11164 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11165 uapsd_queues))
11166 goto nla_put_failure;
11167
11168 nla_nest_end(msg, nla_wmm);
11169 }
11170
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011171 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011172
Johannes Berg68eb5502013-11-19 15:19:38 +010011173 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011174 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011175 return;
11176
11177 nla_put_failure:
11178 genlmsg_cancel(msg, hdr);
11179 nlmsg_free(msg);
11180}
11181
11182void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011183 struct net_device *netdev, const u8 *buf,
11184 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011185{
11186 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011187 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011188}
11189
11190void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11191 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011192 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011193{
Johannes Berge6d6e342009-07-01 21:26:47 +020011194 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011195 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011196}
11197
Jouni Malinen53b46b82009-03-27 20:53:56 +020011198void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011199 struct net_device *netdev, const u8 *buf,
11200 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011201{
11202 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011203 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011204}
11205
Jouni Malinen53b46b82009-03-27 20:53:56 +020011206void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11207 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011208 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011209{
11210 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011211 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011212}
11213
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011214void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11215 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011216{
Johannes Berg947add32013-02-22 22:05:20 +010011217 struct wireless_dev *wdev = dev->ieee80211_ptr;
11218 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011219 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011220 const struct ieee80211_mgmt *mgmt = (void *)buf;
11221 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011222
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011223 if (WARN_ON(len < 2))
11224 return;
11225
11226 if (ieee80211_is_deauth(mgmt->frame_control))
11227 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11228 else
11229 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11230
11231 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011232 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011233}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011234EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011235
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011236static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11237 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011238 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011239{
11240 struct sk_buff *msg;
11241 void *hdr;
11242
Johannes Berge6d6e342009-07-01 21:26:47 +020011243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011244 if (!msg)
11245 return;
11246
11247 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11248 if (!hdr) {
11249 nlmsg_free(msg);
11250 return;
11251 }
11252
David S. Miller9360ffd2012-03-29 04:41:26 -040011253 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11254 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11255 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11256 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11257 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011258
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011259 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011260
Johannes Berg68eb5502013-11-19 15:19:38 +010011261 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011262 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011263 return;
11264
11265 nla_put_failure:
11266 genlmsg_cancel(msg, hdr);
11267 nlmsg_free(msg);
11268}
11269
11270void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011271 struct net_device *netdev, const u8 *addr,
11272 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011273{
11274 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011275 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011276}
11277
11278void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011279 struct net_device *netdev, const u8 *addr,
11280 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011281{
Johannes Berge6d6e342009-07-01 21:26:47 +020011282 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11283 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011284}
11285
Samuel Ortizb23aa672009-07-01 21:26:54 +020011286void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11287 struct net_device *netdev, const u8 *bssid,
11288 const u8 *req_ie, size_t req_ie_len,
11289 const u8 *resp_ie, size_t resp_ie_len,
11290 u16 status, gfp_t gfp)
11291{
11292 struct sk_buff *msg;
11293 void *hdr;
11294
Thomas Graf58050fc2012-06-28 03:57:45 +000011295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011296 if (!msg)
11297 return;
11298
11299 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11300 if (!hdr) {
11301 nlmsg_free(msg);
11302 return;
11303 }
11304
David S. Miller9360ffd2012-03-29 04:41:26 -040011305 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11306 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11307 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11308 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11309 (req_ie &&
11310 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11311 (resp_ie &&
11312 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11313 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011314
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011315 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011316
Johannes Berg68eb5502013-11-19 15:19:38 +010011317 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011318 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011319 return;
11320
11321 nla_put_failure:
11322 genlmsg_cancel(msg, hdr);
11323 nlmsg_free(msg);
11324
11325}
11326
11327void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11328 struct net_device *netdev, const u8 *bssid,
11329 const u8 *req_ie, size_t req_ie_len,
11330 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11331{
11332 struct sk_buff *msg;
11333 void *hdr;
11334
Thomas Graf58050fc2012-06-28 03:57:45 +000011335 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011336 if (!msg)
11337 return;
11338
11339 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11340 if (!hdr) {
11341 nlmsg_free(msg);
11342 return;
11343 }
11344
David S. Miller9360ffd2012-03-29 04:41:26 -040011345 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11346 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11347 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11348 (req_ie &&
11349 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11350 (resp_ie &&
11351 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11352 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011353
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011354 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011355
Johannes Berg68eb5502013-11-19 15:19:38 +010011356 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011357 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011358 return;
11359
11360 nla_put_failure:
11361 genlmsg_cancel(msg, hdr);
11362 nlmsg_free(msg);
11363
11364}
11365
11366void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11367 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020011368 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011369{
11370 struct sk_buff *msg;
11371 void *hdr;
11372
Thomas Graf58050fc2012-06-28 03:57:45 +000011373 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011374 if (!msg)
11375 return;
11376
11377 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11378 if (!hdr) {
11379 nlmsg_free(msg);
11380 return;
11381 }
11382
David S. Miller9360ffd2012-03-29 04:41:26 -040011383 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11384 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11385 (from_ap && reason &&
11386 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11387 (from_ap &&
11388 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11389 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11390 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011391
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011392 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011393
Johannes Berg68eb5502013-11-19 15:19:38 +010011394 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011395 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011396 return;
11397
11398 nla_put_failure:
11399 genlmsg_cancel(msg, hdr);
11400 nlmsg_free(msg);
11401
11402}
11403
Johannes Berg04a773a2009-04-19 21:24:32 +020011404void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11405 struct net_device *netdev, const u8 *bssid,
11406 gfp_t gfp)
11407{
11408 struct sk_buff *msg;
11409 void *hdr;
11410
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011411 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011412 if (!msg)
11413 return;
11414
11415 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11416 if (!hdr) {
11417 nlmsg_free(msg);
11418 return;
11419 }
11420
David S. Miller9360ffd2012-03-29 04:41:26 -040011421 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11422 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11423 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11424 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011425
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011426 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011427
Johannes Berg68eb5502013-11-19 15:19:38 +010011428 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011429 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011430 return;
11431
11432 nla_put_failure:
11433 genlmsg_cancel(msg, hdr);
11434 nlmsg_free(msg);
11435}
11436
Johannes Berg947add32013-02-22 22:05:20 +010011437void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11438 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011439{
Johannes Berg947add32013-02-22 22:05:20 +010011440 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011441 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011442 struct sk_buff *msg;
11443 void *hdr;
11444
Johannes Berg947add32013-02-22 22:05:20 +010011445 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11446 return;
11447
11448 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11449
Javier Cardonac93b5e72011-04-07 15:08:34 -070011450 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11451 if (!msg)
11452 return;
11453
11454 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11455 if (!hdr) {
11456 nlmsg_free(msg);
11457 return;
11458 }
11459
David S. Miller9360ffd2012-03-29 04:41:26 -040011460 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011461 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11462 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011463 (ie_len && ie &&
11464 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11465 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011466
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011467 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011468
Johannes Berg68eb5502013-11-19 15:19:38 +010011469 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011470 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011471 return;
11472
11473 nla_put_failure:
11474 genlmsg_cancel(msg, hdr);
11475 nlmsg_free(msg);
11476}
Johannes Berg947add32013-02-22 22:05:20 +010011477EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011478
Jouni Malinena3b8b052009-03-27 21:59:49 +020011479void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11480 struct net_device *netdev, const u8 *addr,
11481 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011482 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011483{
11484 struct sk_buff *msg;
11485 void *hdr;
11486
Johannes Berge6d6e342009-07-01 21:26:47 +020011487 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011488 if (!msg)
11489 return;
11490
11491 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11492 if (!hdr) {
11493 nlmsg_free(msg);
11494 return;
11495 }
11496
David S. Miller9360ffd2012-03-29 04:41:26 -040011497 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11498 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11499 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11500 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11501 (key_id != -1 &&
11502 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11503 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11504 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011505
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011506 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011507
Johannes Berg68eb5502013-11-19 15:19:38 +010011508 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011509 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011510 return;
11511
11512 nla_put_failure:
11513 genlmsg_cancel(msg, hdr);
11514 nlmsg_free(msg);
11515}
11516
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011517void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11518 struct ieee80211_channel *channel_before,
11519 struct ieee80211_channel *channel_after)
11520{
11521 struct sk_buff *msg;
11522 void *hdr;
11523 struct nlattr *nl_freq;
11524
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011525 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011526 if (!msg)
11527 return;
11528
11529 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11530 if (!hdr) {
11531 nlmsg_free(msg);
11532 return;
11533 }
11534
11535 /*
11536 * Since we are applying the beacon hint to a wiphy we know its
11537 * wiphy_idx is valid
11538 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011539 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11540 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011541
11542 /* Before */
11543 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11544 if (!nl_freq)
11545 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011546 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011547 goto nla_put_failure;
11548 nla_nest_end(msg, nl_freq);
11549
11550 /* After */
11551 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11552 if (!nl_freq)
11553 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011554 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011555 goto nla_put_failure;
11556 nla_nest_end(msg, nl_freq);
11557
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011558 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011559
Johannes Berg463d0182009-07-14 00:33:35 +020011560 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011561 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011562 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011563 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011564
11565 return;
11566
11567nla_put_failure:
11568 genlmsg_cancel(msg, hdr);
11569 nlmsg_free(msg);
11570}
11571
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011572static void nl80211_send_remain_on_chan_event(
11573 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011574 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011575 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011576 unsigned int duration, gfp_t gfp)
11577{
11578 struct sk_buff *msg;
11579 void *hdr;
11580
11581 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11582 if (!msg)
11583 return;
11584
11585 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11586 if (!hdr) {
11587 nlmsg_free(msg);
11588 return;
11589 }
11590
David S. Miller9360ffd2012-03-29 04:41:26 -040011591 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011592 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11593 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011594 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011595 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011596 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11597 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011598 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11599 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011600
David S. Miller9360ffd2012-03-29 04:41:26 -040011601 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11602 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11603 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011604
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011605 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011606
Johannes Berg68eb5502013-11-19 15:19:38 +010011607 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011608 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011609 return;
11610
11611 nla_put_failure:
11612 genlmsg_cancel(msg, hdr);
11613 nlmsg_free(msg);
11614}
11615
Johannes Berg947add32013-02-22 22:05:20 +010011616void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11617 struct ieee80211_channel *chan,
11618 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011619{
Johannes Berg947add32013-02-22 22:05:20 +010011620 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011621 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011622
11623 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011624 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011625 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011626 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011627}
Johannes Berg947add32013-02-22 22:05:20 +010011628EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011629
Johannes Berg947add32013-02-22 22:05:20 +010011630void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11631 struct ieee80211_channel *chan,
11632 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_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011638 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011639 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011640}
Johannes Berg947add32013-02-22 22:05:20 +010011641EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011642
Johannes Berg947add32013-02-22 22:05:20 +010011643void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11644 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011645{
Johannes Berg947add32013-02-22 22:05:20 +010011646 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011647 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011648 struct sk_buff *msg;
11649
Johannes Berg947add32013-02-22 22:05:20 +010011650 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11651
Thomas Graf58050fc2012-06-28 03:57:45 +000011652 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011653 if (!msg)
11654 return;
11655
Johannes Bergcf5ead82014-11-14 17:14:00 +010011656 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040011657 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011658 nlmsg_free(msg);
11659 return;
11660 }
11661
Johannes Berg68eb5502013-11-19 15:19:38 +010011662 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011663 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011664}
Johannes Berg947add32013-02-22 22:05:20 +010011665EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011666
Johannes Bergcf5ead82014-11-14 17:14:00 +010011667void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
11668 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011669{
Johannes Berg947add32013-02-22 22:05:20 +010011670 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011671 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011672 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010011673 struct station_info empty_sinfo = {};
11674
11675 if (!sinfo)
11676 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020011677
Johannes Berg947add32013-02-22 22:05:20 +010011678 trace_cfg80211_del_sta(dev, mac_addr);
11679
Thomas Graf58050fc2012-06-28 03:57:45 +000011680 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011681 if (!msg)
11682 return;
11683
Johannes Bergcf5ead82014-11-14 17:14:00 +010011684 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
11685 rdev, dev, mac_addr, sinfo)) {
Jouni Malinenec15e682011-03-23 15:29:52 +020011686 nlmsg_free(msg);
11687 return;
11688 }
11689
Johannes Berg68eb5502013-11-19 15:19:38 +010011690 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011691 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011692}
Johannes Bergcf5ead82014-11-14 17:14:00 +010011693EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020011694
Johannes Berg947add32013-02-22 22:05:20 +010011695void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11696 enum nl80211_connect_failed_reason reason,
11697 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011698{
Johannes Berg947add32013-02-22 22:05:20 +010011699 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011700 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011701 struct sk_buff *msg;
11702 void *hdr;
11703
11704 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11705 if (!msg)
11706 return;
11707
11708 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11709 if (!hdr) {
11710 nlmsg_free(msg);
11711 return;
11712 }
11713
11714 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11715 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11716 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11717 goto nla_put_failure;
11718
11719 genlmsg_end(msg, hdr);
11720
Johannes Berg68eb5502013-11-19 15:19:38 +010011721 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011722 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011723 return;
11724
11725 nla_put_failure:
11726 genlmsg_cancel(msg, hdr);
11727 nlmsg_free(msg);
11728}
Johannes Berg947add32013-02-22 22:05:20 +010011729EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011730
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011731static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11732 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011733{
11734 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011735 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011736 struct sk_buff *msg;
11737 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011738 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011739
Eric W. Biederman15e47302012-09-07 20:12:54 +000011740 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011741 return false;
11742
11743 msg = nlmsg_new(100, gfp);
11744 if (!msg)
11745 return true;
11746
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011747 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011748 if (!hdr) {
11749 nlmsg_free(msg);
11750 return true;
11751 }
11752
David S. Miller9360ffd2012-03-29 04:41:26 -040011753 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11754 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11755 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11756 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011757
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011758 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011759 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011760 return true;
11761
11762 nla_put_failure:
11763 genlmsg_cancel(msg, hdr);
11764 nlmsg_free(msg);
11765 return true;
11766}
11767
Johannes Berg947add32013-02-22 22:05:20 +010011768bool cfg80211_rx_spurious_frame(struct net_device *dev,
11769 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011770{
Johannes Berg947add32013-02-22 22:05:20 +010011771 struct wireless_dev *wdev = dev->ieee80211_ptr;
11772 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011773
Johannes Berg947add32013-02-22 22:05:20 +010011774 trace_cfg80211_rx_spurious_frame(dev, addr);
11775
11776 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11777 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11778 trace_cfg80211_return_bool(false);
11779 return false;
11780 }
11781 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11782 addr, gfp);
11783 trace_cfg80211_return_bool(ret);
11784 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011785}
Johannes Berg947add32013-02-22 22:05:20 +010011786EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11787
11788bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11789 const u8 *addr, gfp_t gfp)
11790{
11791 struct wireless_dev *wdev = dev->ieee80211_ptr;
11792 bool ret;
11793
11794 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11795
11796 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11797 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11798 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11799 trace_cfg80211_return_bool(false);
11800 return false;
11801 }
11802 ret = __nl80211_unexpected_frame(dev,
11803 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11804 addr, gfp);
11805 trace_cfg80211_return_bool(ret);
11806 return ret;
11807}
11808EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011809
Johannes Berg2e161f782010-08-12 15:38:38 +020011810int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011811 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011812 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011813 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011814{
Johannes Berg71bbc992012-06-15 15:30:18 +020011815 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011816 struct sk_buff *msg;
11817 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011818
11819 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11820 if (!msg)
11821 return -ENOMEM;
11822
Johannes Berg2e161f782010-08-12 15:38:38 +020011823 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011824 if (!hdr) {
11825 nlmsg_free(msg);
11826 return -ENOMEM;
11827 }
11828
David S. Miller9360ffd2012-03-29 04:41:26 -040011829 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011830 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11831 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011832 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011833 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11834 (sig_dbm &&
11835 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011836 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11837 (flags &&
11838 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011839 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011840
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011841 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011842
Eric W. Biederman15e47302012-09-07 20:12:54 +000011843 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011844
11845 nla_put_failure:
11846 genlmsg_cancel(msg, hdr);
11847 nlmsg_free(msg);
11848 return -ENOBUFS;
11849}
11850
Johannes Berg947add32013-02-22 22:05:20 +010011851void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11852 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011853{
Johannes Berg947add32013-02-22 22:05:20 +010011854 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011855 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011856 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011857 struct sk_buff *msg;
11858 void *hdr;
11859
Johannes Berg947add32013-02-22 22:05:20 +010011860 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11861
Jouni Malinen026331c2010-02-15 12:53:10 +020011862 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11863 if (!msg)
11864 return;
11865
Johannes Berg2e161f782010-08-12 15:38:38 +020011866 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011867 if (!hdr) {
11868 nlmsg_free(msg);
11869 return;
11870 }
11871
David S. Miller9360ffd2012-03-29 04:41:26 -040011872 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011873 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11874 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011875 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011876 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11877 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11878 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11879 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011880
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011881 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011882
Johannes Berg68eb5502013-11-19 15:19:38 +010011883 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011884 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011885 return;
11886
11887 nla_put_failure:
11888 genlmsg_cancel(msg, hdr);
11889 nlmsg_free(msg);
11890}
Johannes Berg947add32013-02-22 22:05:20 +010011891EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011892
Johannes Berg5b97f492014-11-26 12:37:43 +010011893static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
11894 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011895{
Johannes Berg947add32013-02-22 22:05:20 +010011896 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010011897 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
11898 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11899 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011900
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011901 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010011902 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011903
Johannes Berg5b97f492014-11-26 12:37:43 +010011904 cb = (void **)msg->cb;
11905
11906 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11907 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011908 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010011909 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011910 }
11911
David S. Miller9360ffd2012-03-29 04:41:26 -040011912 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011913 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011914 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011915
Johannes Berg5b97f492014-11-26 12:37:43 +010011916 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011917 goto nla_put_failure;
11918
Johannes Berg5b97f492014-11-26 12:37:43 +010011919 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
11920 if (!cb[1])
11921 goto nla_put_failure;
11922
11923 cb[2] = rdev;
11924
11925 return msg;
11926 nla_put_failure:
11927 nlmsg_free(msg);
11928 return NULL;
11929}
11930
11931static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
11932{
11933 void **cb = (void **)msg->cb;
11934 struct cfg80211_registered_device *rdev = cb[2];
11935
11936 nla_nest_end(msg, cb[1]);
11937 genlmsg_end(msg, cb[0]);
11938
11939 memset(msg->cb, 0, sizeof(msg->cb));
11940
11941 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11942 NL80211_MCGRP_MLME, gfp);
11943}
11944
11945void cfg80211_cqm_rssi_notify(struct net_device *dev,
11946 enum nl80211_cqm_rssi_threshold_event rssi_event,
11947 gfp_t gfp)
11948{
11949 struct sk_buff *msg;
11950
11951 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11952
Johannes Berg98f03342014-11-26 12:42:02 +010011953 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
11954 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
11955 return;
11956
Johannes Berg5b97f492014-11-26 12:37:43 +010011957 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
11958 if (!msg)
11959 return;
11960
David S. Miller9360ffd2012-03-29 04:41:26 -040011961 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11962 rssi_event))
11963 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011964
Johannes Berg5b97f492014-11-26 12:37:43 +010011965 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011966
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011967 return;
11968
11969 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011970 nlmsg_free(msg);
11971}
Johannes Berg947add32013-02-22 22:05:20 +010011972EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011973
Johannes Berg5b97f492014-11-26 12:37:43 +010011974void cfg80211_cqm_txe_notify(struct net_device *dev,
11975 const u8 *peer, u32 num_packets,
11976 u32 rate, u32 intvl, gfp_t gfp)
11977{
11978 struct sk_buff *msg;
11979
11980 msg = cfg80211_prepare_cqm(dev, peer, gfp);
11981 if (!msg)
11982 return;
11983
11984 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11985 goto nla_put_failure;
11986
11987 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11988 goto nla_put_failure;
11989
11990 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11991 goto nla_put_failure;
11992
11993 cfg80211_send_cqm(msg, gfp);
11994 return;
11995
11996 nla_put_failure:
11997 nlmsg_free(msg);
11998}
11999EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12000
12001void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12002 const u8 *peer, u32 num_packets, gfp_t gfp)
12003{
12004 struct sk_buff *msg;
12005
12006 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12007
12008 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12009 if (!msg)
12010 return;
12011
12012 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12013 goto nla_put_failure;
12014
12015 cfg80211_send_cqm(msg, gfp);
12016 return;
12017
12018 nla_put_failure:
12019 nlmsg_free(msg);
12020}
12021EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12022
Johannes Berg98f03342014-11-26 12:42:02 +010012023void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12024{
12025 struct sk_buff *msg;
12026
12027 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12028 if (!msg)
12029 return;
12030
12031 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12032 goto nla_put_failure;
12033
12034 cfg80211_send_cqm(msg, gfp);
12035 return;
12036
12037 nla_put_failure:
12038 nlmsg_free(msg);
12039}
12040EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12041
Johannes Berg947add32013-02-22 22:05:20 +010012042static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12043 struct net_device *netdev, const u8 *bssid,
12044 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012045{
12046 struct sk_buff *msg;
12047 struct nlattr *rekey_attr;
12048 void *hdr;
12049
Thomas Graf58050fc2012-06-28 03:57:45 +000012050 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012051 if (!msg)
12052 return;
12053
12054 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12055 if (!hdr) {
12056 nlmsg_free(msg);
12057 return;
12058 }
12059
David S. Miller9360ffd2012-03-29 04:41:26 -040012060 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12061 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12062 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12063 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012064
12065 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12066 if (!rekey_attr)
12067 goto nla_put_failure;
12068
David S. Miller9360ffd2012-03-29 04:41:26 -040012069 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12070 NL80211_REPLAY_CTR_LEN, replay_ctr))
12071 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012072
12073 nla_nest_end(msg, rekey_attr);
12074
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012075 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012076
Johannes Berg68eb5502013-11-19 15:19:38 +010012077 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012078 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012079 return;
12080
12081 nla_put_failure:
12082 genlmsg_cancel(msg, hdr);
12083 nlmsg_free(msg);
12084}
12085
Johannes Berg947add32013-02-22 22:05:20 +010012086void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12087 const u8 *replay_ctr, gfp_t gfp)
12088{
12089 struct wireless_dev *wdev = dev->ieee80211_ptr;
12090 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012091 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012092
12093 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12094 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12095}
12096EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12097
12098static void
12099nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12100 struct net_device *netdev, int index,
12101 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012102{
12103 struct sk_buff *msg;
12104 struct nlattr *attr;
12105 void *hdr;
12106
Thomas Graf58050fc2012-06-28 03:57:45 +000012107 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012108 if (!msg)
12109 return;
12110
12111 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12112 if (!hdr) {
12113 nlmsg_free(msg);
12114 return;
12115 }
12116
David S. Miller9360ffd2012-03-29 04:41:26 -040012117 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12118 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12119 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012120
12121 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12122 if (!attr)
12123 goto nla_put_failure;
12124
David S. Miller9360ffd2012-03-29 04:41:26 -040012125 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12126 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12127 (preauth &&
12128 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12129 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012130
12131 nla_nest_end(msg, attr);
12132
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012133 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012134
Johannes Berg68eb5502013-11-19 15:19:38 +010012135 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012136 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012137 return;
12138
12139 nla_put_failure:
12140 genlmsg_cancel(msg, hdr);
12141 nlmsg_free(msg);
12142}
12143
Johannes Berg947add32013-02-22 22:05:20 +010012144void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12145 const u8 *bssid, bool preauth, gfp_t gfp)
12146{
12147 struct wireless_dev *wdev = dev->ieee80211_ptr;
12148 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012149 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012150
12151 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12152 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12153}
12154EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12155
12156static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12157 struct net_device *netdev,
12158 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012159 gfp_t gfp,
12160 enum nl80211_commands notif,
12161 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012162{
12163 struct sk_buff *msg;
12164 void *hdr;
12165
Thomas Graf58050fc2012-06-28 03:57:45 +000012166 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012167 if (!msg)
12168 return;
12169
Luciano Coelhof8d75522014-11-07 14:31:35 +020012170 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012171 if (!hdr) {
12172 nlmsg_free(msg);
12173 return;
12174 }
12175
Johannes Berg683b6d32012-11-08 21:25:48 +010012176 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12177 goto nla_put_failure;
12178
12179 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012180 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012181
Luciano Coelhof8d75522014-11-07 14:31:35 +020012182 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12183 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12184 goto nla_put_failure;
12185
Thomas Pedersen53145262012-04-06 13:35:47 -070012186 genlmsg_end(msg, hdr);
12187
Johannes Berg68eb5502013-11-19 15:19:38 +010012188 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012189 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012190 return;
12191
12192 nla_put_failure:
12193 genlmsg_cancel(msg, hdr);
12194 nlmsg_free(msg);
12195}
12196
Johannes Berg947add32013-02-22 22:05:20 +010012197void cfg80211_ch_switch_notify(struct net_device *dev,
12198 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012199{
Johannes Berg947add32013-02-22 22:05:20 +010012200 struct wireless_dev *wdev = dev->ieee80211_ptr;
12201 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012202 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012203
Simon Wunderliche487eae2013-11-21 18:19:51 +010012204 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012205
Simon Wunderliche487eae2013-11-21 18:19:51 +010012206 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012207
Michal Kazior9e0e2962014-01-29 14:22:27 +010012208 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012209 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012210 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12211 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012212}
12213EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12214
Luciano Coelhof8d75522014-11-07 14:31:35 +020012215void cfg80211_ch_switch_started_notify(struct net_device *dev,
12216 struct cfg80211_chan_def *chandef,
12217 u8 count)
12218{
12219 struct wireless_dev *wdev = dev->ieee80211_ptr;
12220 struct wiphy *wiphy = wdev->wiphy;
12221 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12222
12223 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12224
12225 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12226 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12227}
12228EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12229
Thomas Pedersen84f10702012-07-12 16:17:33 -070012230void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012231nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012232 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012233 enum nl80211_radar_event event,
12234 struct net_device *netdev, gfp_t gfp)
12235{
12236 struct sk_buff *msg;
12237 void *hdr;
12238
12239 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12240 if (!msg)
12241 return;
12242
12243 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12244 if (!hdr) {
12245 nlmsg_free(msg);
12246 return;
12247 }
12248
12249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12250 goto nla_put_failure;
12251
12252 /* NOP and radar events don't need a netdev parameter */
12253 if (netdev) {
12254 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12255
12256 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12257 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12258 goto nla_put_failure;
12259 }
12260
12261 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12262 goto nla_put_failure;
12263
12264 if (nl80211_send_chandef(msg, chandef))
12265 goto nla_put_failure;
12266
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012267 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012268
Johannes Berg68eb5502013-11-19 15:19:38 +010012269 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012270 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012271 return;
12272
12273 nla_put_failure:
12274 genlmsg_cancel(msg, hdr);
12275 nlmsg_free(msg);
12276}
12277
Johannes Berg7f6cf312011-11-04 11:18:15 +010012278void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12279 u64 cookie, bool acked, gfp_t gfp)
12280{
12281 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012283 struct sk_buff *msg;
12284 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012285
Beni Lev4ee3e062012-08-27 12:49:39 +030012286 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12287
Thomas Graf58050fc2012-06-28 03:57:45 +000012288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012289
Johannes Berg7f6cf312011-11-04 11:18:15 +010012290 if (!msg)
12291 return;
12292
12293 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12294 if (!hdr) {
12295 nlmsg_free(msg);
12296 return;
12297 }
12298
David S. Miller9360ffd2012-03-29 04:41:26 -040012299 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12300 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12301 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12302 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12303 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12304 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012305
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012306 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012307
Johannes Berg68eb5502013-11-19 15:19:38 +010012308 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012309 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012310 return;
12311
12312 nla_put_failure:
12313 genlmsg_cancel(msg, hdr);
12314 nlmsg_free(msg);
12315}
12316EXPORT_SYMBOL(cfg80211_probe_status);
12317
Johannes Berg5e760232011-11-04 11:18:17 +010012318void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12319 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012320 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012321{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012322 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012323 struct sk_buff *msg;
12324 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012325 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012326
Beni Lev4ee3e062012-08-27 12:49:39 +030012327 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12328
Ben Greear37c73b52012-10-26 14:49:25 -070012329 spin_lock_bh(&rdev->beacon_registrations_lock);
12330 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12331 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12332 if (!msg) {
12333 spin_unlock_bh(&rdev->beacon_registrations_lock);
12334 return;
12335 }
Johannes Berg5e760232011-11-04 11:18:17 +010012336
Ben Greear37c73b52012-10-26 14:49:25 -070012337 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12338 if (!hdr)
12339 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012340
Ben Greear37c73b52012-10-26 14:49:25 -070012341 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12342 (freq &&
12343 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12344 (sig_dbm &&
12345 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12346 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12347 goto nla_put_failure;
12348
12349 genlmsg_end(msg, hdr);
12350
12351 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012352 }
Ben Greear37c73b52012-10-26 14:49:25 -070012353 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012354 return;
12355
12356 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012357 spin_unlock_bh(&rdev->beacon_registrations_lock);
12358 if (hdr)
12359 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012360 nlmsg_free(msg);
12361}
12362EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12363
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012364#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012365static int cfg80211_net_detect_results(struct sk_buff *msg,
12366 struct cfg80211_wowlan_wakeup *wakeup)
12367{
12368 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12369 struct nlattr *nl_results, *nl_match, *nl_freqs;
12370 int i, j;
12371
12372 nl_results = nla_nest_start(
12373 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12374 if (!nl_results)
12375 return -EMSGSIZE;
12376
12377 for (i = 0; i < nd->n_matches; i++) {
12378 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12379
12380 nl_match = nla_nest_start(msg, i);
12381 if (!nl_match)
12382 break;
12383
12384 /* The SSID attribute is optional in nl80211, but for
12385 * simplicity reasons it's always present in the
12386 * cfg80211 structure. If a driver can't pass the
12387 * SSID, that needs to be changed. A zero length SSID
12388 * is still a valid SSID (wildcard), so it cannot be
12389 * used for this purpose.
12390 */
12391 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12392 match->ssid.ssid)) {
12393 nla_nest_cancel(msg, nl_match);
12394 goto out;
12395 }
12396
12397 if (match->n_channels) {
12398 nl_freqs = nla_nest_start(
12399 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12400 if (!nl_freqs) {
12401 nla_nest_cancel(msg, nl_match);
12402 goto out;
12403 }
12404
12405 for (j = 0; j < match->n_channels; j++) {
12406 if (nla_put_u32(msg,
12407 NL80211_ATTR_WIPHY_FREQ,
12408 match->channels[j])) {
12409 nla_nest_cancel(msg, nl_freqs);
12410 nla_nest_cancel(msg, nl_match);
12411 goto out;
12412 }
12413 }
12414
12415 nla_nest_end(msg, nl_freqs);
12416 }
12417
12418 nla_nest_end(msg, nl_match);
12419 }
12420
12421out:
12422 nla_nest_end(msg, nl_results);
12423 return 0;
12424}
12425
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012426void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12427 struct cfg80211_wowlan_wakeup *wakeup,
12428 gfp_t gfp)
12429{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012430 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012431 struct sk_buff *msg;
12432 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012433 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012434
12435 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12436
12437 if (wakeup)
12438 size += wakeup->packet_present_len;
12439
12440 msg = nlmsg_new(size, gfp);
12441 if (!msg)
12442 return;
12443
12444 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12445 if (!hdr)
12446 goto free_msg;
12447
12448 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12449 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12450 goto free_msg;
12451
12452 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12453 wdev->netdev->ifindex))
12454 goto free_msg;
12455
12456 if (wakeup) {
12457 struct nlattr *reasons;
12458
12459 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012460 if (!reasons)
12461 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012462
12463 if (wakeup->disconnect &&
12464 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12465 goto free_msg;
12466 if (wakeup->magic_pkt &&
12467 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12468 goto free_msg;
12469 if (wakeup->gtk_rekey_failure &&
12470 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12471 goto free_msg;
12472 if (wakeup->eap_identity_req &&
12473 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12474 goto free_msg;
12475 if (wakeup->four_way_handshake &&
12476 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12477 goto free_msg;
12478 if (wakeup->rfkill_release &&
12479 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12480 goto free_msg;
12481
12482 if (wakeup->pattern_idx >= 0 &&
12483 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12484 wakeup->pattern_idx))
12485 goto free_msg;
12486
Johannes Bergae917c92013-10-25 11:05:22 +020012487 if (wakeup->tcp_match &&
12488 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12489 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012490
Johannes Bergae917c92013-10-25 11:05:22 +020012491 if (wakeup->tcp_connlost &&
12492 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12493 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012494
Johannes Bergae917c92013-10-25 11:05:22 +020012495 if (wakeup->tcp_nomoretokens &&
12496 nla_put_flag(msg,
12497 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12498 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012499
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012500 if (wakeup->packet) {
12501 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12502 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12503
12504 if (!wakeup->packet_80211) {
12505 pkt_attr =
12506 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12507 len_attr =
12508 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12509 }
12510
12511 if (wakeup->packet_len &&
12512 nla_put_u32(msg, len_attr, wakeup->packet_len))
12513 goto free_msg;
12514
12515 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12516 wakeup->packet))
12517 goto free_msg;
12518 }
12519
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012520 if (wakeup->net_detect &&
12521 cfg80211_net_detect_results(msg, wakeup))
12522 goto free_msg;
12523
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012524 nla_nest_end(msg, reasons);
12525 }
12526
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012527 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012528
Johannes Berg68eb5502013-11-19 15:19:38 +010012529 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012530 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012531 return;
12532
12533 free_msg:
12534 nlmsg_free(msg);
12535}
12536EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12537#endif
12538
Jouni Malinen3475b092012-11-16 22:49:57 +020012539void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12540 enum nl80211_tdls_operation oper,
12541 u16 reason_code, gfp_t gfp)
12542{
12543 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012544 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012545 struct sk_buff *msg;
12546 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012547
12548 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12549 reason_code);
12550
12551 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12552 if (!msg)
12553 return;
12554
12555 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12556 if (!hdr) {
12557 nlmsg_free(msg);
12558 return;
12559 }
12560
12561 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12562 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12563 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12564 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12565 (reason_code > 0 &&
12566 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12567 goto nla_put_failure;
12568
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012569 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012570
Johannes Berg68eb5502013-11-19 15:19:38 +010012571 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012572 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012573 return;
12574
12575 nla_put_failure:
12576 genlmsg_cancel(msg, hdr);
12577 nlmsg_free(msg);
12578}
12579EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12580
Jouni Malinen026331c2010-02-15 12:53:10 +020012581static int nl80211_netlink_notify(struct notifier_block * nb,
12582 unsigned long state,
12583 void *_notify)
12584{
12585 struct netlink_notify *notify = _notify;
12586 struct cfg80211_registered_device *rdev;
12587 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012588 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012589
12590 if (state != NETLINK_URELEASE)
12591 return NOTIFY_DONE;
12592
12593 rcu_read_lock();
12594
Johannes Berg5e760232011-11-04 11:18:17 +010012595 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012596 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012597 bool schedule_scan_stop = false;
12598 struct cfg80211_sched_scan_request *sched_scan_req =
12599 rcu_dereference(rdev->sched_scan_req);
12600
12601 if (sched_scan_req && notify->portid &&
12602 sched_scan_req->owner_nlportid == notify->portid)
12603 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012604
12605 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012606 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012607
Johannes Berg78f22b62014-03-24 17:57:27 +010012608 if (wdev->owner_nlportid == notify->portid)
12609 schedule_destroy_work = true;
12610 }
12611
Ben Greear37c73b52012-10-26 14:49:25 -070012612 spin_lock_bh(&rdev->beacon_registrations_lock);
12613 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12614 list) {
12615 if (reg->nlportid == notify->portid) {
12616 list_del(&reg->list);
12617 kfree(reg);
12618 break;
12619 }
12620 }
12621 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012622
12623 if (schedule_destroy_work) {
12624 struct cfg80211_iface_destroy *destroy;
12625
12626 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12627 if (destroy) {
12628 destroy->nlportid = notify->portid;
12629 spin_lock(&rdev->destroy_list_lock);
12630 list_add(&destroy->list, &rdev->destroy_list);
12631 spin_unlock(&rdev->destroy_list_lock);
12632 schedule_work(&rdev->destroy_work);
12633 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012634 } else if (schedule_scan_stop) {
12635 sched_scan_req->owner_nlportid = 0;
12636
12637 if (rdev->ops->sched_scan_stop &&
12638 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12639 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012640 }
Johannes Berg5e760232011-11-04 11:18:17 +010012641 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012642
12643 rcu_read_unlock();
12644
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012645 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012646}
12647
12648static struct notifier_block nl80211_netlink_notifier = {
12649 .notifier_call = nl80211_netlink_notify,
12650};
12651
Jouni Malinen355199e2013-02-27 17:14:27 +020012652void cfg80211_ft_event(struct net_device *netdev,
12653 struct cfg80211_ft_event_params *ft_event)
12654{
12655 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012656 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012657 struct sk_buff *msg;
12658 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012659
12660 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12661
12662 if (!ft_event->target_ap)
12663 return;
12664
12665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12666 if (!msg)
12667 return;
12668
12669 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012670 if (!hdr)
12671 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012672
Johannes Bergae917c92013-10-25 11:05:22 +020012673 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12674 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12675 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12676 goto out;
12677
12678 if (ft_event->ies &&
12679 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12680 goto out;
12681 if (ft_event->ric_ies &&
12682 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12683 ft_event->ric_ies))
12684 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012685
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012686 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012687
Johannes Berg68eb5502013-11-19 15:19:38 +010012688 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012689 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012690 return;
12691 out:
12692 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012693}
12694EXPORT_SYMBOL(cfg80211_ft_event);
12695
Arend van Spriel5de17982013-04-18 15:49:00 +020012696void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12697{
12698 struct cfg80211_registered_device *rdev;
12699 struct sk_buff *msg;
12700 void *hdr;
12701 u32 nlportid;
12702
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012703 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012704 if (!rdev->crit_proto_nlportid)
12705 return;
12706
12707 nlportid = rdev->crit_proto_nlportid;
12708 rdev->crit_proto_nlportid = 0;
12709
12710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12711 if (!msg)
12712 return;
12713
12714 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12715 if (!hdr)
12716 goto nla_put_failure;
12717
12718 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12719 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12720 goto nla_put_failure;
12721
12722 genlmsg_end(msg, hdr);
12723
12724 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12725 return;
12726
12727 nla_put_failure:
12728 if (hdr)
12729 genlmsg_cancel(msg, hdr);
12730 nlmsg_free(msg);
12731
12732}
12733EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12734
Johannes Berg348baf02014-01-24 14:06:29 +010012735void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12736{
12737 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012738 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012739 struct sk_buff *msg;
12740 void *hdr;
12741
12742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12743 if (!msg)
12744 return;
12745
12746 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12747 if (!hdr)
12748 goto out;
12749
12750 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12751 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12752 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12753 goto out;
12754
12755 genlmsg_end(msg, hdr);
12756
12757 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12758 NL80211_MCGRP_MLME, GFP_KERNEL);
12759 return;
12760 out:
12761 nlmsg_free(msg);
12762}
12763
Johannes Berg55682962007-09-20 13:09:35 -040012764/* initialisation/exit functions */
12765
12766int nl80211_init(void)
12767{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012768 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012769
Johannes Berg2a94fe42013-11-19 15:19:39 +010012770 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12771 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012772 if (err)
12773 return err;
12774
Jouni Malinen026331c2010-02-15 12:53:10 +020012775 err = netlink_register_notifier(&nl80211_netlink_notifier);
12776 if (err)
12777 goto err_out;
12778
Johannes Berg55682962007-09-20 13:09:35 -040012779 return 0;
12780 err_out:
12781 genl_unregister_family(&nl80211_fam);
12782 return err;
12783}
12784
12785void nl80211_exit(void)
12786{
Jouni Malinen026331c2010-02-15 12:53:10 +020012787 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012788 genl_unregister_family(&nl80211_fam);
12789}