blob: f56309bd21bdc59b8f887dc599ecfd7ff89a23d1 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010062 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
63 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
64 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
65 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
66 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010068 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010069#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300212static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni 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 Malinendc6382c2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200391 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200398 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200399 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400400};
401
Johannes Berge31b8212010-10-05 19:39:30 +0200402/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000403static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200404 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200405 [NL80211_KEY_IDX] = { .type = NLA_U8 },
406 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200407 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
409 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200410 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100411 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
412};
413
414/* policy for the key default flags */
415static const struct nla_policy
416nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
417 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
418 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200419};
420
Johannes Bergff1b6e62011-05-04 15:37:28 +0200421/* policy for WoWLAN attributes */
422static const struct nla_policy
423nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
424 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
426 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
427 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200428 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
431 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100432 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300433 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100434};
435
436static const struct nla_policy
437nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
438 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
439 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
440 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
441 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
442 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
443 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
444 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
445 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
446 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
448 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
449 },
450 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
451 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
452 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200453};
454
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700455/* policy for coalesce rule attributes */
456static const struct nla_policy
457nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
458 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
459 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
460 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
461};
462
Johannes Berge5497d72011-07-05 16:35:40 +0200463/* policy for GTK rekey offload attributes */
464static const struct nla_policy
465nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
466 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
467 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
468 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
469};
470
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300471static const struct nla_policy
472nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200473 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700475 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300476};
477
Johannes Berg97990a02013-04-19 01:02:55 +0200478static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
479 struct netlink_callback *cb,
480 struct cfg80211_registered_device **rdev,
481 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100482{
Johannes Berg67748892010-10-04 21:14:06 +0200483 int err;
484
Johannes Berg67748892010-10-04 21:14:06 +0200485 rtnl_lock();
486
Johannes Berg97990a02013-04-19 01:02:55 +0200487 if (!cb->args[0]) {
488 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
489 nl80211_fam.attrbuf, nl80211_fam.maxattr,
490 nl80211_policy);
491 if (err)
492 goto out_unlock;
493
494 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
495 nl80211_fam.attrbuf);
496 if (IS_ERR(*wdev)) {
497 err = PTR_ERR(*wdev);
498 goto out_unlock;
499 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800500 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200501 /* 0 is the first index - add 1 to parse only once */
502 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200503 cb->args[1] = (*wdev)->identifier;
504 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200505 /* subtract the 1 again here */
506 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200507 struct wireless_dev *tmp;
508
509 if (!wiphy) {
510 err = -ENODEV;
511 goto out_unlock;
512 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800513 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200514 *wdev = NULL;
515
Johannes Berg97990a02013-04-19 01:02:55 +0200516 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
517 if (tmp->identifier == cb->args[1]) {
518 *wdev = tmp;
519 break;
520 }
521 }
Johannes Berg97990a02013-04-19 01:02:55 +0200522
523 if (!*wdev) {
524 err = -ENODEV;
525 goto out_unlock;
526 }
Johannes Berg67748892010-10-04 21:14:06 +0200527 }
528
Johannes Berg67748892010-10-04 21:14:06 +0200529 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200530 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200531 rtnl_unlock();
532 return err;
533}
534
Johannes Berg97990a02013-04-19 01:02:55 +0200535static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200536{
Johannes Berg67748892010-10-04 21:14:06 +0200537 rtnl_unlock();
538}
539
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100540/* IE validation */
541static bool is_valid_ie_attr(const struct nlattr *attr)
542{
543 const u8 *pos;
544 int len;
545
546 if (!attr)
547 return true;
548
549 pos = nla_data(attr);
550 len = nla_len(attr);
551
552 while (len) {
553 u8 elemlen;
554
555 if (len < 2)
556 return false;
557 len -= 2;
558
559 elemlen = pos[1];
560 if (elemlen > len)
561 return false;
562
563 len -= elemlen;
564 pos += 2 + elemlen;
565 }
566
567 return true;
568}
569
Johannes Berg55682962007-09-20 13:09:35 -0400570/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000571static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400572 int flags, u8 cmd)
573{
574 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000575 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400576}
577
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400578static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100579 struct ieee80211_channel *chan,
580 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200582 /* Some channels must be completely excluded from the
583 * list to protect old user-space tools from breaking
584 */
585 if (!large && chan->flags &
586 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
587 return 0;
588
David S. Miller9360ffd2012-03-29 04:41:26 -0400589 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
590 chan->center_freq))
591 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400592
David S. Miller9360ffd2012-03-29 04:41:26 -0400593 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
594 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
595 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200596 if (chan->flags & IEEE80211_CHAN_NO_IR) {
597 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
598 goto nla_put_failure;
599 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
600 goto nla_put_failure;
601 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100602 if (chan->flags & IEEE80211_CHAN_RADAR) {
603 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
604 goto nla_put_failure;
605 if (large) {
606 u32 time;
607
608 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
609
610 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
611 chan->dfs_state))
612 goto nla_put_failure;
613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
614 time))
615 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100616 if (nla_put_u32(msg,
617 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
618 chan->dfs_cac_ms))
619 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100620 }
621 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400622
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100623 if (large) {
624 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
625 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
626 goto nla_put_failure;
627 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
635 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200636 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
638 goto nla_put_failure;
639 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
641 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200642 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
644 goto nla_put_failure;
645 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
646 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
647 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100648 }
649
David S. Miller9360ffd2012-03-29 04:41:26 -0400650 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
651 DBM_TO_MBM(chan->max_power)))
652 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400653
654 return 0;
655
656 nla_put_failure:
657 return -ENOBUFS;
658}
659
Johannes Berg55682962007-09-20 13:09:35 -0400660/* netlink command implementations */
661
Johannes Bergb9454e82009-07-08 13:29:08 +0200662struct key_parse {
663 struct key_params p;
664 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200665 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200666 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100667 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200668};
669
670static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
671{
672 struct nlattr *tb[NL80211_KEY_MAX + 1];
673 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
674 nl80211_key_policy);
675 if (err)
676 return err;
677
678 k->def = !!tb[NL80211_KEY_DEFAULT];
679 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
680
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100681 if (k->def) {
682 k->def_uni = true;
683 k->def_multi = true;
684 }
685 if (k->defmgmt)
686 k->def_multi = true;
687
Johannes Bergb9454e82009-07-08 13:29:08 +0200688 if (tb[NL80211_KEY_IDX])
689 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
690
691 if (tb[NL80211_KEY_DATA]) {
692 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
693 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
694 }
695
696 if (tb[NL80211_KEY_SEQ]) {
697 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
698 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
699 }
700
701 if (tb[NL80211_KEY_CIPHER])
702 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
703
Johannes Berge31b8212010-10-05 19:39:30 +0200704 if (tb[NL80211_KEY_TYPE]) {
705 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
706 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
707 return -EINVAL;
708 }
709
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100710 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
711 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100712 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
713 tb[NL80211_KEY_DEFAULT_TYPES],
714 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100715 if (err)
716 return err;
717
718 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
719 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
720 }
721
Johannes Bergb9454e82009-07-08 13:29:08 +0200722 return 0;
723}
724
725static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
726{
727 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
728 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
729 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
730 }
731
732 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
733 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
734 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
735 }
736
737 if (info->attrs[NL80211_ATTR_KEY_IDX])
738 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
739
740 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
741 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
742
743 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
744 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
745
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100746 if (k->def) {
747 k->def_uni = true;
748 k->def_multi = true;
749 }
750 if (k->defmgmt)
751 k->def_multi = true;
752
Johannes Berge31b8212010-10-05 19:39:30 +0200753 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
754 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
755 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
756 return -EINVAL;
757 }
758
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100759 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
760 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
761 int err = nla_parse_nested(
762 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
763 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
764 nl80211_key_default_policy);
765 if (err)
766 return err;
767
768 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
769 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
770 }
771
Johannes Bergb9454e82009-07-08 13:29:08 +0200772 return 0;
773}
774
775static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
776{
777 int err;
778
779 memset(k, 0, sizeof(*k));
780 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200781 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200782
783 if (info->attrs[NL80211_ATTR_KEY])
784 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
785 else
786 err = nl80211_parse_key_old(info, k);
787
788 if (err)
789 return err;
790
791 if (k->def && k->defmgmt)
792 return -EINVAL;
793
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100794 if (k->defmgmt) {
795 if (k->def_uni || !k->def_multi)
796 return -EINVAL;
797 }
798
Johannes Bergb9454e82009-07-08 13:29:08 +0200799 if (k->idx != -1) {
800 if (k->defmgmt) {
801 if (k->idx < 4 || k->idx > 5)
802 return -EINVAL;
803 } else if (k->def) {
804 if (k->idx < 0 || k->idx > 3)
805 return -EINVAL;
806 } else {
807 if (k->idx < 0 || k->idx > 5)
808 return -EINVAL;
809 }
810 }
811
812 return 0;
813}
814
Johannes Bergfffd0932009-07-08 14:22:54 +0200815static struct cfg80211_cached_keys *
816nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530817 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200818{
819 struct key_parse parse;
820 struct nlattr *key;
821 struct cfg80211_cached_keys *result;
822 int rem, err, def = 0;
823
824 result = kzalloc(sizeof(*result), GFP_KERNEL);
825 if (!result)
826 return ERR_PTR(-ENOMEM);
827
828 result->def = -1;
829 result->defmgmt = -1;
830
831 nla_for_each_nested(key, keys, rem) {
832 memset(&parse, 0, sizeof(parse));
833 parse.idx = -1;
834
835 err = nl80211_parse_key_new(key, &parse);
836 if (err)
837 goto error;
838 err = -EINVAL;
839 if (!parse.p.key)
840 goto error;
841 if (parse.idx < 0 || parse.idx > 4)
842 goto error;
843 if (parse.def) {
844 if (def)
845 goto error;
846 def = 1;
847 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100848 if (!parse.def_uni || !parse.def_multi)
849 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200850 } else if (parse.defmgmt)
851 goto error;
852 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200853 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200854 if (err)
855 goto error;
856 result->params[parse.idx].cipher = parse.p.cipher;
857 result->params[parse.idx].key_len = parse.p.key_len;
858 result->params[parse.idx].key = result->data[parse.idx];
859 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530860
861 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
862 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
863 if (no_ht)
864 *no_ht = true;
865 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200866 }
867
868 return result;
869 error:
870 kfree(result);
871 return ERR_PTR(err);
872}
873
874static int nl80211_key_allowed(struct wireless_dev *wdev)
875{
876 ASSERT_WDEV_LOCK(wdev);
877
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 switch (wdev->iftype) {
879 case NL80211_IFTYPE_AP:
880 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200881 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700882 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200883 break;
884 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200885 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200886 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200887 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 return -ENOLINK;
889 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100890 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100891 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100892 case NL80211_IFTYPE_MONITOR:
893 case NL80211_IFTYPE_P2P_DEVICE:
894 case NL80211_IFTYPE_WDS:
895 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200896 return -EINVAL;
897 }
898
899 return 0;
900}
901
Jouni Malinen664834d2014-01-15 00:01:44 +0200902static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
903 struct nlattr *tb)
904{
905 struct ieee80211_channel *chan;
906
907 if (tb == NULL)
908 return NULL;
909 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
910 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
911 return NULL;
912 return chan;
913}
914
Johannes Berg7527a782011-05-13 10:58:57 +0200915static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
916{
917 struct nlattr *nl_modes = nla_nest_start(msg, attr);
918 int i;
919
920 if (!nl_modes)
921 goto nla_put_failure;
922
923 i = 0;
924 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400925 if ((ifmodes & 1) && nla_put_flag(msg, i))
926 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200927 ifmodes >>= 1;
928 i++;
929 }
930
931 nla_nest_end(msg, nl_modes);
932 return 0;
933
934nla_put_failure:
935 return -ENOBUFS;
936}
937
938static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100939 struct sk_buff *msg,
940 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200941{
942 struct nlattr *nl_combis;
943 int i, j;
944
945 nl_combis = nla_nest_start(msg,
946 NL80211_ATTR_INTERFACE_COMBINATIONS);
947 if (!nl_combis)
948 goto nla_put_failure;
949
950 for (i = 0; i < wiphy->n_iface_combinations; i++) {
951 const struct ieee80211_iface_combination *c;
952 struct nlattr *nl_combi, *nl_limits;
953
954 c = &wiphy->iface_combinations[i];
955
956 nl_combi = nla_nest_start(msg, i + 1);
957 if (!nl_combi)
958 goto nla_put_failure;
959
960 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
961 if (!nl_limits)
962 goto nla_put_failure;
963
964 for (j = 0; j < c->n_limits; j++) {
965 struct nlattr *nl_limit;
966
967 nl_limit = nla_nest_start(msg, j + 1);
968 if (!nl_limit)
969 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400970 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
971 c->limits[j].max))
972 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200973 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
974 c->limits[j].types))
975 goto nla_put_failure;
976 nla_nest_end(msg, nl_limit);
977 }
978
979 nla_nest_end(msg, nl_limits);
980
David S. Miller9360ffd2012-03-29 04:41:26 -0400981 if (c->beacon_int_infra_match &&
982 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
983 goto nla_put_failure;
984 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
985 c->num_different_channels) ||
986 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
987 c->max_interfaces))
988 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100989 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200990 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
991 c->radar_detect_widths) ||
992 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
993 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100994 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200995
996 nla_nest_end(msg, nl_combi);
997 }
998
999 nla_nest_end(msg, nl_combis);
1000
1001 return 0;
1002nla_put_failure:
1003 return -ENOBUFS;
1004}
1005
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001007static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1008 struct sk_buff *msg)
1009{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001010 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001011 struct nlattr *nl_tcp;
1012
1013 if (!tcp)
1014 return 0;
1015
1016 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1017 if (!nl_tcp)
1018 return -ENOBUFS;
1019
1020 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1021 tcp->data_payload_max))
1022 return -ENOBUFS;
1023
1024 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1025 tcp->data_payload_max))
1026 return -ENOBUFS;
1027
1028 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1029 return -ENOBUFS;
1030
1031 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1032 sizeof(*tcp->tok), tcp->tok))
1033 return -ENOBUFS;
1034
1035 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1036 tcp->data_interval_max))
1037 return -ENOBUFS;
1038
1039 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1040 tcp->wake_payload_max))
1041 return -ENOBUFS;
1042
1043 nla_nest_end(msg, nl_tcp);
1044 return 0;
1045}
1046
Johannes Berg3713b4e2013-02-14 16:19:38 +01001047static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001048 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001049 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050{
1051 struct nlattr *nl_wowlan;
1052
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001053 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054 return 0;
1055
1056 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1057 if (!nl_wowlan)
1058 return -ENOBUFS;
1059
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001060 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001067 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001068 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001073 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001074 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1076 return -ENOBUFS;
1077
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001078 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001079 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001080 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1081 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1082 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1083 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001084 };
1085
1086 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1087 sizeof(pat), &pat))
1088 return -ENOBUFS;
1089 }
1090
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001091 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001092 return -ENOBUFS;
1093
Luciano Coelho8cd4d452014-09-17 11:55:28 +03001094 /* TODO: send wowlan net detect */
1095
Johannes Berg3713b4e2013-02-14 16:19:38 +01001096 nla_nest_end(msg, nl_wowlan);
1097
1098 return 0;
1099}
1100#endif
1101
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001102static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001103 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001104{
1105 struct nl80211_coalesce_rule_support rule;
1106
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001107 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001108 return 0;
1109
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001110 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1111 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1112 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1113 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1114 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1115 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001116
1117 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1118 return -ENOBUFS;
1119
1120 return 0;
1121}
1122
Johannes Berg3713b4e2013-02-14 16:19:38 +01001123static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1124 struct ieee80211_supported_band *sband)
1125{
1126 struct nlattr *nl_rates, *nl_rate;
1127 struct ieee80211_rate *rate;
1128 int i;
1129
1130 /* add HT info */
1131 if (sband->ht_cap.ht_supported &&
1132 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1133 sizeof(sband->ht_cap.mcs),
1134 &sband->ht_cap.mcs) ||
1135 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1136 sband->ht_cap.cap) ||
1137 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1138 sband->ht_cap.ampdu_factor) ||
1139 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1140 sband->ht_cap.ampdu_density)))
1141 return -ENOBUFS;
1142
1143 /* add VHT info */
1144 if (sband->vht_cap.vht_supported &&
1145 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1146 sizeof(sband->vht_cap.vht_mcs),
1147 &sband->vht_cap.vht_mcs) ||
1148 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1149 sband->vht_cap.cap)))
1150 return -ENOBUFS;
1151
1152 /* add bitrates */
1153 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1154 if (!nl_rates)
1155 return -ENOBUFS;
1156
1157 for (i = 0; i < sband->n_bitrates; i++) {
1158 nl_rate = nla_nest_start(msg, i);
1159 if (!nl_rate)
1160 return -ENOBUFS;
1161
1162 rate = &sband->bitrates[i];
1163 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1164 rate->bitrate))
1165 return -ENOBUFS;
1166 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1167 nla_put_flag(msg,
1168 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1169 return -ENOBUFS;
1170
1171 nla_nest_end(msg, nl_rate);
1172 }
1173
1174 nla_nest_end(msg, nl_rates);
1175
1176 return 0;
1177}
1178
1179static int
1180nl80211_send_mgmt_stypes(struct sk_buff *msg,
1181 const struct ieee80211_txrx_stypes *mgmt_stypes)
1182{
1183 u16 stypes;
1184 struct nlattr *nl_ftypes, *nl_ifs;
1185 enum nl80211_iftype ift;
1186 int i;
1187
1188 if (!mgmt_stypes)
1189 return 0;
1190
1191 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1192 if (!nl_ifs)
1193 return -ENOBUFS;
1194
1195 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1196 nl_ftypes = nla_nest_start(msg, ift);
1197 if (!nl_ftypes)
1198 return -ENOBUFS;
1199 i = 0;
1200 stypes = mgmt_stypes[ift].tx;
1201 while (stypes) {
1202 if ((stypes & 1) &&
1203 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1204 (i << 4) | IEEE80211_FTYPE_MGMT))
1205 return -ENOBUFS;
1206 stypes >>= 1;
1207 i++;
1208 }
1209 nla_nest_end(msg, nl_ftypes);
1210 }
1211
1212 nla_nest_end(msg, nl_ifs);
1213
1214 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1215 if (!nl_ifs)
1216 return -ENOBUFS;
1217
1218 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1219 nl_ftypes = nla_nest_start(msg, ift);
1220 if (!nl_ftypes)
1221 return -ENOBUFS;
1222 i = 0;
1223 stypes = mgmt_stypes[ift].rx;
1224 while (stypes) {
1225 if ((stypes & 1) &&
1226 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1227 (i << 4) | IEEE80211_FTYPE_MGMT))
1228 return -ENOBUFS;
1229 stypes >>= 1;
1230 i++;
1231 }
1232 nla_nest_end(msg, nl_ftypes);
1233 }
1234 nla_nest_end(msg, nl_ifs);
1235
1236 return 0;
1237}
1238
Johannes Berg86e8cf92013-06-19 10:57:22 +02001239struct nl80211_dump_wiphy_state {
1240 s64 filter_wiphy;
1241 long start;
1242 long split_start, band_start, chan_start;
1243 bool split;
1244};
1245
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001246static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001247 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001249 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001250{
1251 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001252 struct nlattr *nl_bands, *nl_band;
1253 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001254 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001255 enum ieee80211_band band;
1256 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001257 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001258 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001259 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001260 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001261
Johannes Berg3bb20552014-05-26 13:52:25 +02001262 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001263 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 return -ENOBUFS;
1265
Johannes Berg86e8cf92013-06-19 10:57:22 +02001266 if (WARN_ON(!state))
1267 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001268
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001272 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001274 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001275
Johannes Berg3bb20552014-05-26 13:52:25 +02001276 if (cmd != NL80211_CMD_NEW_WIPHY)
1277 goto finish;
1278
Johannes Berg86e8cf92013-06-19 10:57:22 +02001279 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 case 0:
1281 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001301 goto nla_put_failure;
1302
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001303 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1305 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001307 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1308 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1311 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001312 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1314 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1317 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001318 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001320 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001321 state->split_start++;
1322 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 break;
1324 case 1:
1325 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001326 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1327 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001328 goto nla_put_failure;
1329
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001332 goto nla_put_failure;
1333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1336 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001337
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001341 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001343
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001344 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001348
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 if ((rdev->wiphy.available_antennas_tx ||
1350 rdev->wiphy.available_antennas_rx) &&
1351 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001352 u32 tx_ant = 0, rx_ant = 0;
1353 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001354 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 if (!res) {
1356 if (nla_put_u32(msg,
1357 NL80211_ATTR_WIPHY_ANTENNA_TX,
1358 tx_ant) ||
1359 nla_put_u32(msg,
1360 NL80211_ATTR_WIPHY_ANTENNA_RX,
1361 rx_ant))
1362 goto nla_put_failure;
1363 }
Johannes Bergee688b002008-01-24 19:38:39 +01001364 }
1365
Johannes Berg86e8cf92013-06-19 10:57:22 +02001366 state->split_start++;
1367 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368 break;
1369 case 2:
1370 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001373 state->split_start++;
1374 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 break;
1376 case 3:
1377 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1378 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001379 goto nla_put_failure;
1380
Johannes Berg86e8cf92013-06-19 10:57:22 +02001381 for (band = state->band_start;
1382 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 struct ieee80211_supported_band *sband;
1384
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001385 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386
1387 if (!sband)
1388 continue;
1389
1390 nl_band = nla_nest_start(msg, band);
1391 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001392 goto nla_put_failure;
1393
Johannes Berg86e8cf92013-06-19 10:57:22 +02001394 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 case 0:
1396 if (nl80211_send_band_rateinfo(msg, sband))
1397 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001398 state->chan_start++;
1399 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001400 break;
1401 default:
1402 /* add frequencies */
1403 nl_freqs = nla_nest_start(
1404 msg, NL80211_BAND_ATTR_FREQS);
1405 if (!nl_freqs)
1406 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001407
Johannes Berg86e8cf92013-06-19 10:57:22 +02001408 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001409 i < sband->n_channels;
1410 i++) {
1411 nl_freq = nla_nest_start(msg, i);
1412 if (!nl_freq)
1413 goto nla_put_failure;
1414
1415 chan = &sband->channels[i];
1416
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 if (nl80211_msg_put_channel(
1418 msg, chan,
1419 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 goto nla_put_failure;
1421
1422 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001423 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424 break;
1425 }
1426 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 nla_nest_end(msg, nl_freqs);
1431 }
1432
1433 nla_nest_end(msg, nl_band);
1434
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001437 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 band--;
1439 break;
1440 }
Johannes Bergee688b002008-01-24 19:38:39 +01001441 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001443
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001445 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001447 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001448
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001450 if (state->band_start == 0 && state->chan_start == 0)
1451 state->split_start++;
1452 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 break;
1454 case 4:
1455 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1456 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001457 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458
1459 i = 0;
1460#define CMD(op, n) \
1461 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001462 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 i++; \
1464 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1465 goto nla_put_failure; \
1466 } \
1467 } while (0)
1468
1469 CMD(add_virtual_intf, NEW_INTERFACE);
1470 CMD(change_virtual_intf, SET_INTERFACE);
1471 CMD(add_key, NEW_KEY);
1472 CMD(start_ap, START_AP);
1473 CMD(add_station, NEW_STATION);
1474 CMD(add_mpath, NEW_MPATH);
1475 CMD(update_mesh_config, SET_MESH_CONFIG);
1476 CMD(change_bss, SET_BSS);
1477 CMD(auth, AUTHENTICATE);
1478 CMD(assoc, ASSOCIATE);
1479 CMD(deauth, DEAUTHENTICATE);
1480 CMD(disassoc, DISASSOCIATE);
1481 CMD(join_ibss, JOIN_IBSS);
1482 CMD(join_mesh, JOIN_MESH);
1483 CMD(set_pmksa, SET_PMKSA);
1484 CMD(del_pmksa, DEL_PMKSA);
1485 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1488 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1489 CMD(mgmt_tx, FRAME);
1490 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001491 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 i++;
1493 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1494 goto nla_put_failure;
1495 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1497 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 i++;
1499 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1500 goto nla_put_failure;
1501 }
1502 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001503 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 CMD(tdls_mgmt, TDLS_MGMT);
1505 CMD(tdls_oper, TDLS_OPER);
1506 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001507 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001508 CMD(sched_scan_start, START_SCHED_SCAN);
1509 CMD(probe_client, PROBE_CLIENT);
1510 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001511 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 i++;
1513 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1514 goto nla_put_failure;
1515 }
1516 CMD(start_p2p_device, START_P2P_DEVICE);
1517 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001518#ifdef CONFIG_NL80211_TESTMODE
1519 CMD(testmode_cmd, TESTMODE);
1520#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001521 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001522 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1523 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001525 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001526 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001527 if (rdev->wiphy.features &
1528 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001529 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001530 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001531 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001532#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001533
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 i++;
1536 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001537 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001538 }
1539
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 i++;
1542 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1543 goto nla_put_failure;
1544 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001545
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001547 state->split_start++;
1548 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 break;
1550 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001551 if (rdev->ops->remain_on_channel &&
1552 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 nla_put_u32(msg,
1554 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001556 goto nla_put_failure;
1557
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001558 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1560 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001561
Johannes Berg3713b4e2013-02-14 16:19:38 +01001562 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1563 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001564 state->split_start++;
1565 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 break;
1567 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001568#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001569 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001571 state->split_start++;
1572 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 break;
1574#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001575 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576#endif
1577 case 7:
1578 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001579 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001580 goto nla_put_failure;
1581
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001585
Johannes Berg86e8cf92013-06-19 10:57:22 +02001586 state->split_start++;
1587 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 break;
1589 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001590 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001592 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 goto nla_put_failure;
1594
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001595 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001596 /*
1597 * We can only add the per-channel limit information if the
1598 * dump is split, otherwise it makes it too big. Therefore
1599 * only advertise it in that case.
1600 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001601 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001602 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1603 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 goto nla_put_failure;
1605
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001606 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001608 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1609 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 goto nla_put_failure;
1611
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1613 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001614 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 goto nla_put_failure;
1617
1618 /*
1619 * Any information below this point is only available to
1620 * applications that can deal with it being split. This
1621 * helps ensure that newly added capabilities don't break
1622 * older tools by overrunning their buffers.
1623 *
1624 * We still increment split_start so that in the split
1625 * case we'll continue with more data in the next round,
1626 * but break unconditionally so unsplit data stops here.
1627 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001628 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 break;
1630 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001632 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 rdev->wiphy.extended_capabilities_len,
1634 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001635 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001636 rdev->wiphy.extended_capabilities_len,
1637 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001638 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001639
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001641 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1643 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001644 goto nla_put_failure;
1645
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001646 state->split_start++;
1647 break;
1648 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001650 goto nla_put_failure;
1651
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001652 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001653 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1654 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1655 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001656
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001657 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001658 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001659 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001660 goto nla_put_failure;
1661
Johannes Bergad7e7182013-11-13 13:37:47 +01001662 state->split_start++;
1663 break;
1664 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001666 const struct nl80211_vendor_cmd_info *info;
1667 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001668
Johannes Berg567ffc32013-12-18 14:43:31 +01001669 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1670 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001671 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001672
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1674 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001675 if (nla_put(msg, i + 1, sizeof(*info), info))
1676 goto nla_put_failure;
1677 }
1678 nla_nest_end(msg, nested);
1679 }
1680
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001681 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001682 const struct nl80211_vendor_cmd_info *info;
1683 struct nlattr *nested;
1684
1685 nested = nla_nest_start(msg,
1686 NL80211_ATTR_VENDOR_EVENTS);
1687 if (!nested)
1688 goto nla_put_failure;
1689
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001690 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1691 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001692 if (nla_put(msg, i + 1, sizeof(*info), info))
1693 goto nla_put_failure;
1694 }
1695 nla_nest_end(msg, nested);
1696 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001697 state->split_start++;
1698 break;
1699 case 12:
1700 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1701 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1702 rdev->wiphy.max_num_csa_counters))
1703 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001704
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001705 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1706 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1707 goto nla_put_failure;
1708
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
Eric W. Biederman15e47302012-09-07 20:12:54 +00003653static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003654 int flags,
3655 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
Eric W. Biederman15e47302012-09-07 20:12:54 +00003662 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
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;
David S. Miller9360ffd2012-03-29 04:41:26 -04003674 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3675 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3676 sinfo->connected_time))
3677 goto nla_put_failure;
3678 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3679 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3680 sinfo->inactive_time))
3681 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003682 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3683 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003684 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003685 (u32)sinfo->rx_bytes))
3686 goto nla_put_failure;
3687 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003688 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003689 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3690 (u32)sinfo->tx_bytes))
3691 goto nla_put_failure;
3692 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3693 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003694 sinfo->rx_bytes))
3695 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003696 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3697 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003698 sinfo->tx_bytes))
3699 goto nla_put_failure;
3700 if ((sinfo->filled & STATION_INFO_LLID) &&
3701 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3702 goto nla_put_failure;
3703 if ((sinfo->filled & STATION_INFO_PLID) &&
3704 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3705 goto nla_put_failure;
3706 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3707 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3708 sinfo->plink_state))
3709 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003710 switch (rdev->wiphy.signal_type) {
3711 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003712 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3713 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3714 sinfo->signal))
3715 goto nla_put_failure;
3716 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3717 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3718 sinfo->signal_avg))
3719 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003720 break;
3721 default:
3722 break;
3723 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003724 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3725 if (!nl80211_put_signal(msg, sinfo->chains,
3726 sinfo->chain_signal,
3727 NL80211_STA_INFO_CHAIN_SIGNAL))
3728 goto nla_put_failure;
3729 }
3730 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3731 if (!nl80211_put_signal(msg, sinfo->chains,
3732 sinfo->chain_signal_avg,
3733 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3734 goto nla_put_failure;
3735 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003736 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003737 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3738 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003739 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003740 }
3741 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3742 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3743 NL80211_STA_INFO_RX_BITRATE))
3744 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003745 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003746 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3747 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3748 sinfo->rx_packets))
3749 goto nla_put_failure;
3750 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3751 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3752 sinfo->tx_packets))
3753 goto nla_put_failure;
3754 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3755 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3756 sinfo->tx_retries))
3757 goto nla_put_failure;
3758 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3759 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3760 sinfo->tx_failed))
3761 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003762 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3763 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3764 sinfo->expected_throughput))
3765 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003766 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3767 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3768 sinfo->beacon_loss_count))
3769 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003770 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3771 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3772 sinfo->local_pm))
3773 goto nla_put_failure;
3774 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3775 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3776 sinfo->peer_pm))
3777 goto nla_put_failure;
3778 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3779 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3780 sinfo->nonpeer_pm))
3781 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003782 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3783 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3784 if (!bss_param)
3785 goto nla_put_failure;
3786
David S. Miller9360ffd2012-03-29 04:41:26 -04003787 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3788 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3789 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3790 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3791 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3792 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3793 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3794 sinfo->bss_param.dtim_period) ||
3795 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3796 sinfo->bss_param.beacon_interval))
3797 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003798
3799 nla_nest_end(msg, bss_param);
3800 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003801 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3802 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3803 sizeof(struct nl80211_sta_flag_update),
3804 &sinfo->sta_flags))
3805 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003806 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3807 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3808 sinfo->t_offset))
3809 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003810 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003811
David S. Miller9360ffd2012-03-29 04:41:26 -04003812 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3813 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3814 sinfo->assoc_req_ies))
3815 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003816
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003817 return genlmsg_end(msg, hdr);
3818
3819 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003820 genlmsg_cancel(msg, hdr);
3821 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003822}
3823
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003824static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003825 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003826{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003827 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003828 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003829 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003830 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003831 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003832 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003833
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003834 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003835 if (err)
3836 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003837
Johannes Berg97990a02013-04-19 01:02:55 +02003838 if (!wdev->netdev) {
3839 err = -EINVAL;
3840 goto out_err;
3841 }
3842
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003843 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003844 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003845 goto out_err;
3846 }
3847
Johannes Bergbba95fe2008-07-29 13:22:51 +02003848 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003849 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003850 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003851 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003852 if (err == -ENOENT)
3853 break;
3854 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003855 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003856
3857 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003858 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003859 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003860 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003861 &sinfo) < 0)
3862 goto out;
3863
3864 sta_idx++;
3865 }
3866
3867
3868 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003869 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003870 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003871 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003872 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003873
3874 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003875}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003876
Johannes Berg5727ef12007-12-19 02:03:34 +01003877static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3878{
Johannes Berg4c476992010-10-04 21:36:35 +02003879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3880 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003881 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003882 struct sk_buff *msg;
3883 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003884 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003885
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003886 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003887
3888 if (!info->attrs[NL80211_ATTR_MAC])
3889 return -EINVAL;
3890
3891 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3892
Johannes Berg4c476992010-10-04 21:36:35 +02003893 if (!rdev->ops->get_station)
3894 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003895
Hila Gonene35e4d22012-06-27 17:19:42 +03003896 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003897 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003898 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003899
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003900 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003901 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003902 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003903
Eric W. Biederman15e47302012-09-07 20:12:54 +00003904 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003905 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003906 nlmsg_free(msg);
3907 return -ENOBUFS;
3908 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003909
Johannes Berg4c476992010-10-04 21:36:35 +02003910 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003911}
3912
Johannes Berg77ee7c82013-02-15 00:48:33 +01003913int cfg80211_check_station_change(struct wiphy *wiphy,
3914 struct station_parameters *params,
3915 enum cfg80211_station_type statype)
3916{
3917 if (params->listen_interval != -1)
3918 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003919 if (params->aid &&
3920 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003921 return -EINVAL;
3922
3923 /* When you run into this, adjust the code below for the new flag */
3924 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3925
3926 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003927 case CFG80211_STA_MESH_PEER_KERNEL:
3928 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003929 /*
3930 * No ignoring the TDLS flag here -- the userspace mesh
3931 * code doesn't have the bug of including TDLS in the
3932 * mask everywhere.
3933 */
3934 if (params->sta_flags_mask &
3935 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3936 BIT(NL80211_STA_FLAG_MFP) |
3937 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3938 return -EINVAL;
3939 break;
3940 case CFG80211_STA_TDLS_PEER_SETUP:
3941 case CFG80211_STA_TDLS_PEER_ACTIVE:
3942 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3943 return -EINVAL;
3944 /* ignore since it can't change */
3945 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3946 break;
3947 default:
3948 /* disallow mesh-specific things */
3949 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3950 return -EINVAL;
3951 if (params->local_pm)
3952 return -EINVAL;
3953 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3954 return -EINVAL;
3955 }
3956
3957 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3958 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3959 /* TDLS can't be set, ... */
3960 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3961 return -EINVAL;
3962 /*
3963 * ... but don't bother the driver with it. This works around
3964 * a hostapd/wpa_supplicant issue -- it always includes the
3965 * TLDS_PEER flag in the mask even for AP mode.
3966 */
3967 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3968 }
3969
3970 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3971 /* reject other things that can't change */
3972 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3973 return -EINVAL;
3974 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3975 return -EINVAL;
3976 if (params->supported_rates)
3977 return -EINVAL;
3978 if (params->ext_capab || params->ht_capa || params->vht_capa)
3979 return -EINVAL;
3980 }
3981
3982 if (statype != CFG80211_STA_AP_CLIENT) {
3983 if (params->vlan)
3984 return -EINVAL;
3985 }
3986
3987 switch (statype) {
3988 case CFG80211_STA_AP_MLME_CLIENT:
3989 /* Use this only for authorizing/unauthorizing a station */
3990 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3991 return -EOPNOTSUPP;
3992 break;
3993 case CFG80211_STA_AP_CLIENT:
3994 /* accept only the listed bits */
3995 if (params->sta_flags_mask &
3996 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3997 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3998 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3999 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4000 BIT(NL80211_STA_FLAG_WME) |
4001 BIT(NL80211_STA_FLAG_MFP)))
4002 return -EINVAL;
4003
4004 /* but authenticated/associated only if driver handles it */
4005 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4006 params->sta_flags_mask &
4007 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4008 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4009 return -EINVAL;
4010 break;
4011 case CFG80211_STA_IBSS:
4012 case CFG80211_STA_AP_STA:
4013 /* reject any changes other than AUTHORIZED */
4014 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4015 return -EINVAL;
4016 break;
4017 case CFG80211_STA_TDLS_PEER_SETUP:
4018 /* reject any changes other than AUTHORIZED or WME */
4019 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4020 BIT(NL80211_STA_FLAG_WME)))
4021 return -EINVAL;
4022 /* force (at least) rates when authorizing */
4023 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4024 !params->supported_rates)
4025 return -EINVAL;
4026 break;
4027 case CFG80211_STA_TDLS_PEER_ACTIVE:
4028 /* reject any changes */
4029 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004030 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004031 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4032 return -EINVAL;
4033 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004034 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004035 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4036 return -EINVAL;
4037 break;
4038 }
4039
4040 return 0;
4041}
4042EXPORT_SYMBOL(cfg80211_check_station_change);
4043
Johannes Berg5727ef12007-12-19 02:03:34 +01004044/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004045 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004046 */
Johannes Berg80b99892011-11-18 16:23:01 +01004047static struct net_device *get_vlan(struct genl_info *info,
4048 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004049{
Johannes Berg463d0182009-07-14 00:33:35 +02004050 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004051 struct net_device *v;
4052 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004053
Johannes Berg80b99892011-11-18 16:23:01 +01004054 if (!vlanattr)
4055 return NULL;
4056
4057 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4058 if (!v)
4059 return ERR_PTR(-ENODEV);
4060
4061 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4062 ret = -EINVAL;
4063 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004064 }
Johannes Berg80b99892011-11-18 16:23:01 +01004065
Johannes Berg77ee7c82013-02-15 00:48:33 +01004066 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4067 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4068 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4069 ret = -EINVAL;
4070 goto error;
4071 }
4072
Johannes Berg80b99892011-11-18 16:23:01 +01004073 if (!netif_running(v)) {
4074 ret = -ENETDOWN;
4075 goto error;
4076 }
4077
4078 return v;
4079 error:
4080 dev_put(v);
4081 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004082}
4083
Johannes Berg94e860f2014-01-20 23:58:15 +01004084static const struct nla_policy
4085nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004086 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4087 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4088};
4089
Johannes Bergff276692013-02-15 00:09:01 +01004090static int nl80211_parse_sta_wme(struct genl_info *info,
4091 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004092{
Jouni Malinendf881292013-02-14 21:10:54 +02004093 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4094 struct nlattr *nla;
4095 int err;
4096
Jouni Malinendf881292013-02-14 21:10:54 +02004097 /* parse WME attributes if present */
4098 if (!info->attrs[NL80211_ATTR_STA_WME])
4099 return 0;
4100
4101 nla = info->attrs[NL80211_ATTR_STA_WME];
4102 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4103 nl80211_sta_wme_policy);
4104 if (err)
4105 return err;
4106
4107 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4108 params->uapsd_queues = nla_get_u8(
4109 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4110 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4111 return -EINVAL;
4112
4113 if (tb[NL80211_STA_WME_MAX_SP])
4114 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4115
4116 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4117 return -EINVAL;
4118
4119 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4120
4121 return 0;
4122}
4123
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304124static int nl80211_parse_sta_channel_info(struct genl_info *info,
4125 struct station_parameters *params)
4126{
4127 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4128 params->supported_channels =
4129 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4130 params->supported_channels_len =
4131 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4132 /*
4133 * Need to include at least one (first channel, number of
4134 * channels) tuple for each subband, and must have proper
4135 * tuples for the rest of the data as well.
4136 */
4137 if (params->supported_channels_len < 2)
4138 return -EINVAL;
4139 if (params->supported_channels_len % 2)
4140 return -EINVAL;
4141 }
4142
4143 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4144 params->supported_oper_classes =
4145 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4146 params->supported_oper_classes_len =
4147 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4148 /*
4149 * The value of the Length field of the Supported Operating
4150 * Classes element is between 2 and 253.
4151 */
4152 if (params->supported_oper_classes_len < 2 ||
4153 params->supported_oper_classes_len > 253)
4154 return -EINVAL;
4155 }
4156 return 0;
4157}
4158
Johannes Bergff276692013-02-15 00:09:01 +01004159static int nl80211_set_station_tdls(struct genl_info *info,
4160 struct station_parameters *params)
4161{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304162 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004163 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004164 if (info->attrs[NL80211_ATTR_PEER_AID])
4165 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004166 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4167 params->ht_capa =
4168 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4169 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4170 params->vht_capa =
4171 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4172
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304173 err = nl80211_parse_sta_channel_info(info, params);
4174 if (err)
4175 return err;
4176
Johannes Bergff276692013-02-15 00:09:01 +01004177 return nl80211_parse_sta_wme(info, params);
4178}
4179
Johannes Berg5727ef12007-12-19 02:03:34 +01004180static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4181{
Johannes Berg4c476992010-10-04 21:36:35 +02004182 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004183 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004184 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004185 u8 *mac_addr;
4186 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004187
4188 memset(&params, 0, sizeof(params));
4189
4190 params.listen_interval = -1;
4191
Johannes Berg77ee7c82013-02-15 00:48:33 +01004192 if (!rdev->ops->change_station)
4193 return -EOPNOTSUPP;
4194
Johannes Berg5727ef12007-12-19 02:03:34 +01004195 if (info->attrs[NL80211_ATTR_STA_AID])
4196 return -EINVAL;
4197
4198 if (!info->attrs[NL80211_ATTR_MAC])
4199 return -EINVAL;
4200
4201 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4202
4203 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4204 params.supported_rates =
4205 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4206 params.supported_rates_len =
4207 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4208 }
4209
Jouni Malinen9d62a982013-02-14 21:10:13 +02004210 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4211 params.capability =
4212 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4213 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4214 }
4215
4216 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4217 params.ext_capab =
4218 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4219 params.ext_capab_len =
4220 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4221 }
4222
Jouni Malinendf881292013-02-14 21:10:54 +02004223 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004224 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004225
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004226 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004227 return -EINVAL;
4228
Johannes Bergf8bacc22013-02-14 23:27:01 +01004229 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004230 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004231 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4232 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4233 return -EINVAL;
4234 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004235
Johannes Bergf8bacc22013-02-14 23:27:01 +01004236 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004237 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004238 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4239 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4240 return -EINVAL;
4241 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4242 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004243
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004244 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4245 enum nl80211_mesh_power_mode pm = nla_get_u32(
4246 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4247
4248 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4249 pm > NL80211_MESH_POWER_MAX)
4250 return -EINVAL;
4251
4252 params.local_pm = pm;
4253 }
4254
Johannes Berg77ee7c82013-02-15 00:48:33 +01004255 /* Include parameters for TDLS peer (will check later) */
4256 err = nl80211_set_station_tdls(info, &params);
4257 if (err)
4258 return err;
4259
4260 params.vlan = get_vlan(info, rdev);
4261 if (IS_ERR(params.vlan))
4262 return PTR_ERR(params.vlan);
4263
Johannes Berga97f4422009-06-18 17:23:43 +02004264 switch (dev->ieee80211_ptr->iftype) {
4265 case NL80211_IFTYPE_AP:
4266 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004267 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004268 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004269 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004270 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004271 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004272 break;
4273 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004274 err = -EOPNOTSUPP;
4275 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004276 }
4277
Johannes Berg77ee7c82013-02-15 00:48:33 +01004278 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004279 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004280
Johannes Berg77ee7c82013-02-15 00:48:33 +01004281 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004282 if (params.vlan)
4283 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004284
Johannes Berg5727ef12007-12-19 02:03:34 +01004285 return err;
4286}
4287
4288static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4289{
Johannes Berg4c476992010-10-04 21:36:35 +02004290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004291 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004292 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004293 struct station_parameters params;
4294 u8 *mac_addr = NULL;
4295
4296 memset(&params, 0, sizeof(params));
4297
Johannes Berg984c3112013-02-14 23:43:25 +01004298 if (!rdev->ops->add_station)
4299 return -EOPNOTSUPP;
4300
Johannes Berg5727ef12007-12-19 02:03:34 +01004301 if (!info->attrs[NL80211_ATTR_MAC])
4302 return -EINVAL;
4303
Johannes Berg5727ef12007-12-19 02:03:34 +01004304 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4305 return -EINVAL;
4306
4307 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4308 return -EINVAL;
4309
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004310 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4311 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004312 return -EINVAL;
4313
Johannes Berg5727ef12007-12-19 02:03:34 +01004314 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4315 params.supported_rates =
4316 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4317 params.supported_rates_len =
4318 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4319 params.listen_interval =
4320 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004321
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004322 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004323 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004324 else
4325 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004326 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4327 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004328
Jouni Malinen9d62a982013-02-14 21:10:13 +02004329 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4330 params.capability =
4331 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4332 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4333 }
4334
4335 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4336 params.ext_capab =
4337 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4338 params.ext_capab_len =
4339 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4340 }
4341
Jouni Malinen36aedc92008-08-25 11:58:58 +03004342 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4343 params.ht_capa =
4344 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004345
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004346 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4347 params.vht_capa =
4348 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4349
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004350 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4351 params.opmode_notif_used = true;
4352 params.opmode_notif =
4353 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4354 }
4355
Johannes Bergf8bacc22013-02-14 23:27:01 +01004356 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004357 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004358 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4359 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4360 return -EINVAL;
4361 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004362
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304363 err = nl80211_parse_sta_channel_info(info, &params);
4364 if (err)
4365 return err;
4366
Johannes Bergff276692013-02-15 00:09:01 +01004367 err = nl80211_parse_sta_wme(info, &params);
4368 if (err)
4369 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004370
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004371 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004372 return -EINVAL;
4373
Johannes Berg77ee7c82013-02-15 00:48:33 +01004374 /* When you run into this, adjust the code below for the new flag */
4375 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4376
Johannes Bergbdd90d52011-12-14 12:20:27 +01004377 switch (dev->ieee80211_ptr->iftype) {
4378 case NL80211_IFTYPE_AP:
4379 case NL80211_IFTYPE_AP_VLAN:
4380 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004381 /* ignore WME attributes if iface/sta is not capable */
4382 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4383 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4384 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004385
Johannes Bergbdd90d52011-12-14 12:20:27 +01004386 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004387 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4388 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004389 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004390 /* but don't bother the driver with it */
4391 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004392
Johannes Bergd582cff2012-10-26 17:53:44 +02004393 /* allow authenticated/associated only if driver handles it */
4394 if (!(rdev->wiphy.features &
4395 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4396 params.sta_flags_mask &
4397 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4398 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4399 return -EINVAL;
4400
Johannes Bergbdd90d52011-12-14 12:20:27 +01004401 /* must be last in here for error handling */
4402 params.vlan = get_vlan(info, rdev);
4403 if (IS_ERR(params.vlan))
4404 return PTR_ERR(params.vlan);
4405 break;
4406 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004407 /* ignore uAPSD data */
4408 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4409
Johannes Bergd582cff2012-10-26 17:53:44 +02004410 /* associated is disallowed */
4411 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4412 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004413 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004414 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4415 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004416 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004417 break;
4418 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004419 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004420 /* ignore uAPSD data */
4421 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4422
Johannes Berg77ee7c82013-02-15 00:48:33 +01004423 /* these are disallowed */
4424 if (params.sta_flags_mask &
4425 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4426 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004427 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004428 /* Only TDLS peers can be added */
4429 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4430 return -EINVAL;
4431 /* Can only add if TDLS ... */
4432 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4433 return -EOPNOTSUPP;
4434 /* ... with external setup is supported */
4435 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4436 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004437 /*
4438 * Older wpa_supplicant versions always mark the TDLS peer
4439 * as authorized, but it shouldn't yet be.
4440 */
4441 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004442 break;
4443 default:
4444 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004445 }
4446
Johannes Bergbdd90d52011-12-14 12:20:27 +01004447 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004448
Hila Gonene35e4d22012-06-27 17:19:42 +03004449 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004450
Johannes Berg5727ef12007-12-19 02:03:34 +01004451 if (params.vlan)
4452 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004453 return err;
4454}
4455
4456static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4457{
Johannes Berg4c476992010-10-04 21:36:35 +02004458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4459 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004460 struct station_del_parameters params;
4461
4462 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004463
4464 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004465 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004466
Johannes Berge80cf852009-05-11 14:43:13 +02004467 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004468 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004469 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004470 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4471 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004472
Johannes Berg4c476992010-10-04 21:36:35 +02004473 if (!rdev->ops->del_station)
4474 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004475
Jouni Malinen98856862014-10-20 13:20:45 +03004476 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4477 params.subtype =
4478 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4479 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4480 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4481 return -EINVAL;
4482 } else {
4483 /* Default to Deauthentication frame */
4484 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4485 }
4486
4487 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4488 params.reason_code =
4489 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4490 if (params.reason_code == 0)
4491 return -EINVAL; /* 0 is reserved */
4492 } else {
4493 /* Default to reason code 2 */
4494 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4495 }
4496
Jouni Malinen89c771e2014-10-10 20:52:40 +03004497 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004498}
4499
Eric W. Biederman15e47302012-09-07 20:12:54 +00004500static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004501 int flags, struct net_device *dev,
4502 u8 *dst, u8 *next_hop,
4503 struct mpath_info *pinfo)
4504{
4505 void *hdr;
4506 struct nlattr *pinfoattr;
4507
Henning Rogge1ef4c852014-11-04 16:14:58 +01004508 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004509 if (!hdr)
4510 return -1;
4511
David S. Miller9360ffd2012-03-29 04:41:26 -04004512 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4513 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4514 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4515 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4516 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004517
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004518 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4519 if (!pinfoattr)
4520 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004521 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4522 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4523 pinfo->frame_qlen))
4524 goto nla_put_failure;
4525 if (((pinfo->filled & MPATH_INFO_SN) &&
4526 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4527 ((pinfo->filled & MPATH_INFO_METRIC) &&
4528 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4529 pinfo->metric)) ||
4530 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4531 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4532 pinfo->exptime)) ||
4533 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4534 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4535 pinfo->flags)) ||
4536 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4537 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4538 pinfo->discovery_timeout)) ||
4539 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4540 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4541 pinfo->discovery_retries)))
4542 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543
4544 nla_nest_end(msg, pinfoattr);
4545
4546 return genlmsg_end(msg, hdr);
4547
4548 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004549 genlmsg_cancel(msg, hdr);
4550 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004551}
4552
4553static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004554 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004555{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004556 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004557 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004558 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004559 u8 dst[ETH_ALEN];
4560 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004561 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004562 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004563
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004564 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004565 if (err)
4566 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004567
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004568 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004569 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004570 goto out_err;
4571 }
4572
Johannes Berg97990a02013-04-19 01:02:55 +02004573 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004574 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004575 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004576 }
4577
Johannes Bergbba95fe2008-07-29 13:22:51 +02004578 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004579 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004580 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004581 if (err == -ENOENT)
4582 break;
4583 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004584 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004585
Eric W. Biederman15e47302012-09-07 20:12:54 +00004586 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004587 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004588 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004589 &pinfo) < 0)
4590 goto out;
4591
4592 path_idx++;
4593 }
4594
4595
4596 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004597 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004598 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004599 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004600 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004601 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004602}
4603
4604static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4605{
Johannes Berg4c476992010-10-04 21:36:35 +02004606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004607 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004608 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004609 struct mpath_info pinfo;
4610 struct sk_buff *msg;
4611 u8 *dst = NULL;
4612 u8 next_hop[ETH_ALEN];
4613
4614 memset(&pinfo, 0, sizeof(pinfo));
4615
4616 if (!info->attrs[NL80211_ATTR_MAC])
4617 return -EINVAL;
4618
4619 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4620
Johannes Berg4c476992010-10-04 21:36:35 +02004621 if (!rdev->ops->get_mpath)
4622 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004623
Johannes Berg4c476992010-10-04 21:36:35 +02004624 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4625 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004626
Hila Gonene35e4d22012-06-27 17:19:42 +03004627 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004628 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004629 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004630
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004631 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004632 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004633 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004634
Eric W. Biederman15e47302012-09-07 20:12:54 +00004635 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004636 dev, dst, next_hop, &pinfo) < 0) {
4637 nlmsg_free(msg);
4638 return -ENOBUFS;
4639 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004640
Johannes Berg4c476992010-10-04 21:36:35 +02004641 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004642}
4643
4644static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4645{
Johannes Berg4c476992010-10-04 21:36:35 +02004646 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4647 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004648 u8 *dst = NULL;
4649 u8 *next_hop = NULL;
4650
4651 if (!info->attrs[NL80211_ATTR_MAC])
4652 return -EINVAL;
4653
4654 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4655 return -EINVAL;
4656
4657 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4658 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4659
Johannes Berg4c476992010-10-04 21:36:35 +02004660 if (!rdev->ops->change_mpath)
4661 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004662
Johannes Berg4c476992010-10-04 21:36:35 +02004663 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4664 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004665
Hila Gonene35e4d22012-06-27 17:19:42 +03004666 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004667}
Johannes Berg4c476992010-10-04 21:36:35 +02004668
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004669static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4670{
Johannes Berg4c476992010-10-04 21:36:35 +02004671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4672 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004673 u8 *dst = NULL;
4674 u8 *next_hop = NULL;
4675
4676 if (!info->attrs[NL80211_ATTR_MAC])
4677 return -EINVAL;
4678
4679 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4680 return -EINVAL;
4681
4682 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4683 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4684
Johannes Berg4c476992010-10-04 21:36:35 +02004685 if (!rdev->ops->add_mpath)
4686 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004687
Johannes Berg4c476992010-10-04 21:36:35 +02004688 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4689 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004690
Hila Gonene35e4d22012-06-27 17:19:42 +03004691 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004692}
4693
4694static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4695{
Johannes Berg4c476992010-10-04 21:36:35 +02004696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4697 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004698 u8 *dst = NULL;
4699
4700 if (info->attrs[NL80211_ATTR_MAC])
4701 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4702
Johannes Berg4c476992010-10-04 21:36:35 +02004703 if (!rdev->ops->del_mpath)
4704 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004705
Hila Gonene35e4d22012-06-27 17:19:42 +03004706 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004707}
4708
Henning Rogge66be7d22014-09-12 08:58:49 +02004709static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4710{
4711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4712 int err;
4713 struct net_device *dev = info->user_ptr[1];
4714 struct mpath_info pinfo;
4715 struct sk_buff *msg;
4716 u8 *dst = NULL;
4717 u8 mpp[ETH_ALEN];
4718
4719 memset(&pinfo, 0, sizeof(pinfo));
4720
4721 if (!info->attrs[NL80211_ATTR_MAC])
4722 return -EINVAL;
4723
4724 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4725
4726 if (!rdev->ops->get_mpp)
4727 return -EOPNOTSUPP;
4728
4729 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4730 return -EOPNOTSUPP;
4731
4732 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4733 if (err)
4734 return err;
4735
4736 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4737 if (!msg)
4738 return -ENOMEM;
4739
4740 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4741 dev, dst, mpp, &pinfo) < 0) {
4742 nlmsg_free(msg);
4743 return -ENOBUFS;
4744 }
4745
4746 return genlmsg_reply(msg, info);
4747}
4748
4749static int nl80211_dump_mpp(struct sk_buff *skb,
4750 struct netlink_callback *cb)
4751{
4752 struct mpath_info pinfo;
4753 struct cfg80211_registered_device *rdev;
4754 struct wireless_dev *wdev;
4755 u8 dst[ETH_ALEN];
4756 u8 mpp[ETH_ALEN];
4757 int path_idx = cb->args[2];
4758 int err;
4759
4760 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4761 if (err)
4762 return err;
4763
4764 if (!rdev->ops->dump_mpp) {
4765 err = -EOPNOTSUPP;
4766 goto out_err;
4767 }
4768
4769 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4770 err = -EOPNOTSUPP;
4771 goto out_err;
4772 }
4773
4774 while (1) {
4775 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4776 mpp, &pinfo);
4777 if (err == -ENOENT)
4778 break;
4779 if (err)
4780 goto out_err;
4781
4782 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4783 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4784 wdev->netdev, dst, mpp,
4785 &pinfo) < 0)
4786 goto out;
4787
4788 path_idx++;
4789 }
4790
4791 out:
4792 cb->args[2] = path_idx;
4793 err = skb->len;
4794 out_err:
4795 nl80211_finish_wdev_dump(rdev);
4796 return err;
4797}
4798
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004799static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4800{
Johannes Berg4c476992010-10-04 21:36:35 +02004801 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4802 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004803 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004804 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004805 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004806
4807 memset(&params, 0, sizeof(params));
4808 /* default to not changing parameters */
4809 params.use_cts_prot = -1;
4810 params.use_short_preamble = -1;
4811 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004812 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004813 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004814 params.p2p_ctwindow = -1;
4815 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004816
4817 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4818 params.use_cts_prot =
4819 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4820 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4821 params.use_short_preamble =
4822 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4823 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4824 params.use_short_slot_time =
4825 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004826 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4827 params.basic_rates =
4828 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4829 params.basic_rates_len =
4830 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4831 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004832 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4833 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004834 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4835 params.ht_opmode =
4836 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004837
Johannes Berg53cabad2012-11-14 15:17:28 +01004838 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4839 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4840 return -EINVAL;
4841 params.p2p_ctwindow =
4842 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4843 if (params.p2p_ctwindow < 0)
4844 return -EINVAL;
4845 if (params.p2p_ctwindow != 0 &&
4846 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4847 return -EINVAL;
4848 }
4849
4850 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4851 u8 tmp;
4852
4853 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4854 return -EINVAL;
4855 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4856 if (tmp > 1)
4857 return -EINVAL;
4858 params.p2p_opp_ps = tmp;
4859 if (params.p2p_opp_ps &&
4860 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4861 return -EINVAL;
4862 }
4863
Johannes Berg4c476992010-10-04 21:36:35 +02004864 if (!rdev->ops->change_bss)
4865 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004866
Johannes Berg074ac8d2010-09-16 14:58:22 +02004867 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004868 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4869 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004870
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004871 wdev_lock(wdev);
4872 err = rdev_change_bss(rdev, dev, &params);
4873 wdev_unlock(wdev);
4874
4875 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004876}
4877
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004878static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004879 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4880 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4881 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4882 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4883 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4884 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004885 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004886};
4887
4888static int parse_reg_rule(struct nlattr *tb[],
4889 struct ieee80211_reg_rule *reg_rule)
4890{
4891 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4892 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4893
4894 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4895 return -EINVAL;
4896 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4897 return -EINVAL;
4898 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4899 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004900 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4901 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004902 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4903 return -EINVAL;
4904
4905 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4906
4907 freq_range->start_freq_khz =
4908 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4909 freq_range->end_freq_khz =
4910 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004911 freq_range->max_bandwidth_khz =
4912 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004913
4914 power_rule->max_eirp =
4915 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4916
4917 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4918 power_rule->max_antenna_gain =
4919 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4920
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004921 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4922 reg_rule->dfs_cac_ms =
4923 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4924
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004925 return 0;
4926}
4927
4928static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4929{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004930 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004931 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004932
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004933 /*
4934 * You should only get this when cfg80211 hasn't yet initialized
4935 * completely when built-in to the kernel right between the time
4936 * window between nl80211_init() and regulatory_init(), if that is
4937 * even possible.
4938 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004939 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004940 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004941
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004942 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4943 user_reg_hint_type =
4944 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4945 else
4946 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4947
4948 switch (user_reg_hint_type) {
4949 case NL80211_USER_REG_HINT_USER:
4950 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004951 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4952 return -EINVAL;
4953
4954 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4955 return regulatory_hint_user(data, user_reg_hint_type);
4956 case NL80211_USER_REG_HINT_INDOOR:
4957 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004958 default:
4959 return -EINVAL;
4960 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004961}
4962
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004963static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004964 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004965{
Johannes Berg4c476992010-10-04 21:36:35 +02004966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004967 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004968 struct wireless_dev *wdev = dev->ieee80211_ptr;
4969 struct mesh_config cur_params;
4970 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004971 void *hdr;
4972 struct nlattr *pinfoattr;
4973 struct sk_buff *msg;
4974
Johannes Berg29cbe682010-12-03 09:20:44 +01004975 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4976 return -EOPNOTSUPP;
4977
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004978 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004979 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004980
Johannes Berg29cbe682010-12-03 09:20:44 +01004981 wdev_lock(wdev);
4982 /* If not connected, get default parameters */
4983 if (!wdev->mesh_id_len)
4984 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4985 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004986 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004987 wdev_unlock(wdev);
4988
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004989 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004990 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004991
4992 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004993 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004994 if (!msg)
4995 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004996 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004997 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004998 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004999 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005000 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005001 if (!pinfoattr)
5002 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005003 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5004 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5005 cur_params.dot11MeshRetryTimeout) ||
5006 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5007 cur_params.dot11MeshConfirmTimeout) ||
5008 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5009 cur_params.dot11MeshHoldingTimeout) ||
5010 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5011 cur_params.dot11MeshMaxPeerLinks) ||
5012 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5013 cur_params.dot11MeshMaxRetries) ||
5014 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5015 cur_params.dot11MeshTTL) ||
5016 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5017 cur_params.element_ttl) ||
5018 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5019 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005020 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5021 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005022 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5023 cur_params.dot11MeshHWMPmaxPREQretries) ||
5024 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5025 cur_params.path_refresh_time) ||
5026 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5027 cur_params.min_discovery_timeout) ||
5028 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5029 cur_params.dot11MeshHWMPactivePathTimeout) ||
5030 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5031 cur_params.dot11MeshHWMPpreqMinInterval) ||
5032 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5033 cur_params.dot11MeshHWMPperrMinInterval) ||
5034 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5035 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5036 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5037 cur_params.dot11MeshHWMPRootMode) ||
5038 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5039 cur_params.dot11MeshHWMPRannInterval) ||
5040 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5041 cur_params.dot11MeshGateAnnouncementProtocol) ||
5042 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5043 cur_params.dot11MeshForwarding) ||
5044 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005045 cur_params.rssi_threshold) ||
5046 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005047 cur_params.ht_opmode) ||
5048 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5049 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5050 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005051 cur_params.dot11MeshHWMProotInterval) ||
5052 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005053 cur_params.dot11MeshHWMPconfirmationInterval) ||
5054 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5055 cur_params.power_mode) ||
5056 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005057 cur_params.dot11MeshAwakeWindowDuration) ||
5058 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5059 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005060 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005061 nla_nest_end(msg, pinfoattr);
5062 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005063 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005064
Johannes Berg3b858752009-03-12 09:55:09 +01005065 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005066 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005067 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005068 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005069 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005070}
5071
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005072static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005073 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5074 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5075 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5076 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5077 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5078 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005079 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005080 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005081 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005082 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5083 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5084 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5085 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5086 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005087 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005088 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005089 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005090 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005091 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005092 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005093 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5094 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005095 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5096 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005097 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005098 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5099 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005100 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005101};
5102
Javier Cardonac80d5452010-12-16 17:37:49 -08005103static const struct nla_policy
5104 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005105 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005106 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5107 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005108 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005109 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005110 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005111 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005112 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005113 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005114};
5115
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005116static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005117 struct mesh_config *cfg,
5118 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005119{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005120 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005121 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005122
Marco Porschea54fba2013-01-07 16:04:48 +01005123#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5124do { \
5125 if (tb[attr]) { \
5126 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5127 return -EINVAL; \
5128 cfg->param = fn(tb[attr]); \
5129 mask |= (1 << (attr - 1)); \
5130 } \
5131} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005132
5133
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005134 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005135 return -EINVAL;
5136 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005137 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005138 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005139 return -EINVAL;
5140
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005141 /* This makes sure that there aren't more than 32 mesh config
5142 * parameters (otherwise our bitfield scheme would not work.) */
5143 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5144
5145 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005146 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005147 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5148 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005149 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005150 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5151 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005152 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005153 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5154 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005155 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005156 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5157 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005158 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005159 mask, NL80211_MESHCONF_MAX_RETRIES,
5160 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005161 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005162 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005163 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005164 mask, NL80211_MESHCONF_ELEMENT_TTL,
5165 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005166 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005167 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5168 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005169 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5170 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005171 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5172 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005173 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005174 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5175 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005176 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005177 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5178 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005179 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005180 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5181 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005182 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5183 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005184 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5185 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005186 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005187 1, 65535, mask,
5188 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005189 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005190 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005191 1, 65535, mask,
5192 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005193 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005194 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005195 dot11MeshHWMPnetDiameterTraversalTime,
5196 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005197 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5198 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005199 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5200 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5201 nla_get_u8);
5202 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5203 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005204 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005205 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005206 dot11MeshGateAnnouncementProtocol, 0, 1,
5207 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005208 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005209 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005210 mask, NL80211_MESHCONF_FORWARDING,
5211 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005212 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005213 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005214 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005215 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005216 mask, NL80211_MESHCONF_HT_OPMODE,
5217 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005219 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005220 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5221 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005223 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5224 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005225 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005226 dot11MeshHWMPconfirmationInterval,
5227 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005228 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5229 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005230 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5231 NL80211_MESH_POWER_ACTIVE,
5232 NL80211_MESH_POWER_MAX,
5233 mask, NL80211_MESHCONF_POWER_MODE,
5234 nla_get_u32);
5235 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5236 0, 65535, mask,
5237 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5239 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5240 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005241 if (mask_out)
5242 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005243
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005244 return 0;
5245
5246#undef FILL_IN_MESH_PARAM_IF_SET
5247}
5248
Javier Cardonac80d5452010-12-16 17:37:49 -08005249static int nl80211_parse_mesh_setup(struct genl_info *info,
5250 struct mesh_setup *setup)
5251{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005253 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5254
5255 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5256 return -EINVAL;
5257 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5258 info->attrs[NL80211_ATTR_MESH_SETUP],
5259 nl80211_mesh_setup_params_policy))
5260 return -EINVAL;
5261
Javier Cardonad299a1f2012-03-31 11:31:33 -07005262 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5263 setup->sync_method =
5264 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5265 IEEE80211_SYNC_METHOD_VENDOR :
5266 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5267
Javier Cardonac80d5452010-12-16 17:37:49 -08005268 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5269 setup->path_sel_proto =
5270 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5271 IEEE80211_PATH_PROTOCOL_VENDOR :
5272 IEEE80211_PATH_PROTOCOL_HWMP;
5273
5274 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5275 setup->path_metric =
5276 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5277 IEEE80211_PATH_METRIC_VENDOR :
5278 IEEE80211_PATH_METRIC_AIRTIME;
5279
Javier Cardona581a8b02011-04-07 15:08:27 -07005280
5281 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005282 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005283 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005284 if (!is_valid_ie_attr(ieattr))
5285 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005286 setup->ie = nla_data(ieattr);
5287 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005288 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005289 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5290 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5291 return -EINVAL;
5292 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005293 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5294 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005295 if (setup->is_secure)
5296 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005297
Colleen Twitty6e16d902013-05-08 11:45:59 -07005298 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5299 if (!setup->user_mpm)
5300 return -EINVAL;
5301 setup->auth_id =
5302 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5303 }
5304
Javier Cardonac80d5452010-12-16 17:37:49 -08005305 return 0;
5306}
5307
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005308static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005309 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005310{
5311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5312 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005313 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005314 struct mesh_config cfg;
5315 u32 mask;
5316 int err;
5317
Johannes Berg29cbe682010-12-03 09:20:44 +01005318 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5319 return -EOPNOTSUPP;
5320
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005321 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005322 return -EOPNOTSUPP;
5323
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005324 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005325 if (err)
5326 return err;
5327
Johannes Berg29cbe682010-12-03 09:20:44 +01005328 wdev_lock(wdev);
5329 if (!wdev->mesh_id_len)
5330 err = -ENOLINK;
5331
5332 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005333 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005334
5335 wdev_unlock(wdev);
5336
5337 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005338}
5339
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005340static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5341 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005342{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005343 struct nlattr *nl_reg_rules;
5344 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005345
Johannes Berg458f4f92012-12-06 15:47:38 +01005346 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5347 (regdom->dfs_region &&
5348 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005349 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005350
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005351 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5352 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005353 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005354
Johannes Berg458f4f92012-12-06 15:47:38 +01005355 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005356 struct nlattr *nl_reg_rule;
5357 const struct ieee80211_reg_rule *reg_rule;
5358 const struct ieee80211_freq_range *freq_range;
5359 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005360 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005361
Johannes Berg458f4f92012-12-06 15:47:38 +01005362 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005363 freq_range = &reg_rule->freq_range;
5364 power_rule = &reg_rule->power_rule;
5365
5366 nl_reg_rule = nla_nest_start(msg, i);
5367 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005368 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005369
Janusz Dziedzic97524822014-01-30 09:52:20 +01005370 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5371 if (!max_bandwidth_khz)
5372 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5373 reg_rule);
5374
David S. Miller9360ffd2012-03-29 04:41:26 -04005375 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5376 reg_rule->flags) ||
5377 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5378 freq_range->start_freq_khz) ||
5379 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5380 freq_range->end_freq_khz) ||
5381 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005382 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005383 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5384 power_rule->max_antenna_gain) ||
5385 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005386 power_rule->max_eirp) ||
5387 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5388 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005389 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005390
5391 nla_nest_end(msg, nl_reg_rule);
5392 }
5393
5394 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005395 return 0;
5396
5397nla_put_failure:
5398 return -EMSGSIZE;
5399}
5400
5401static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5402{
5403 const struct ieee80211_regdomain *regdom = NULL;
5404 struct cfg80211_registered_device *rdev;
5405 struct wiphy *wiphy = NULL;
5406 struct sk_buff *msg;
5407 void *hdr;
5408
5409 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5410 if (!msg)
5411 return -ENOBUFS;
5412
5413 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5414 NL80211_CMD_GET_REG);
5415 if (!hdr)
5416 goto put_failure;
5417
5418 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005419 bool self_managed;
5420
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005421 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5422 if (IS_ERR(rdev)) {
5423 nlmsg_free(msg);
5424 return PTR_ERR(rdev);
5425 }
5426
5427 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005428 self_managed = wiphy->regulatory_flags &
5429 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005430 regdom = get_wiphy_regdom(wiphy);
5431
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005432 /* a self-managed-reg device must have a private regdom */
5433 if (WARN_ON(!regdom && self_managed)) {
5434 nlmsg_free(msg);
5435 return -EINVAL;
5436 }
5437
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005438 if (regdom &&
5439 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5440 goto nla_put_failure;
5441 }
5442
5443 if (!wiphy && reg_last_request_cell_base() &&
5444 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5445 NL80211_USER_REG_HINT_CELL_BASE))
5446 goto nla_put_failure;
5447
5448 rcu_read_lock();
5449
5450 if (!regdom)
5451 regdom = rcu_dereference(cfg80211_regdomain);
5452
5453 if (nl80211_put_regdom(regdom, msg))
5454 goto nla_put_failure_rcu;
5455
5456 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005457
5458 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005459 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005460
Johannes Berg458f4f92012-12-06 15:47:38 +01005461nla_put_failure_rcu:
5462 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005463nla_put_failure:
5464 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005465put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005466 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005467 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005468}
5469
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005470static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5471 u32 seq, int flags, struct wiphy *wiphy,
5472 const struct ieee80211_regdomain *regdom)
5473{
5474 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5475 NL80211_CMD_GET_REG);
5476
5477 if (!hdr)
5478 return -1;
5479
5480 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5481
5482 if (nl80211_put_regdom(regdom, msg))
5483 goto nla_put_failure;
5484
5485 if (!wiphy && reg_last_request_cell_base() &&
5486 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5487 NL80211_USER_REG_HINT_CELL_BASE))
5488 goto nla_put_failure;
5489
5490 if (wiphy &&
5491 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5492 goto nla_put_failure;
5493
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005494 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5495 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5496 goto nla_put_failure;
5497
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005498 return genlmsg_end(msg, hdr);
5499
5500nla_put_failure:
5501 genlmsg_cancel(msg, hdr);
5502 return -EMSGSIZE;
5503}
5504
5505static int nl80211_get_reg_dump(struct sk_buff *skb,
5506 struct netlink_callback *cb)
5507{
5508 const struct ieee80211_regdomain *regdom = NULL;
5509 struct cfg80211_registered_device *rdev;
5510 int err, reg_idx, start = cb->args[2];
5511
5512 rtnl_lock();
5513
5514 if (cfg80211_regdomain && start == 0) {
5515 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5516 NLM_F_MULTI, NULL,
5517 rtnl_dereference(cfg80211_regdomain));
5518 if (err < 0)
5519 goto out_err;
5520 }
5521
5522 /* the global regdom is idx 0 */
5523 reg_idx = 1;
5524 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5525 regdom = get_wiphy_regdom(&rdev->wiphy);
5526 if (!regdom)
5527 continue;
5528
5529 if (++reg_idx <= start)
5530 continue;
5531
5532 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5533 NLM_F_MULTI, &rdev->wiphy, regdom);
5534 if (err < 0) {
5535 reg_idx--;
5536 break;
5537 }
5538 }
5539
5540 cb->args[2] = reg_idx;
5541 err = skb->len;
5542out_err:
5543 rtnl_unlock();
5544 return err;
5545}
5546
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005547static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5548{
5549 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5550 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005551 char *alpha2;
5552 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005553 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005554 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005555 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005556
5557 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5558 return -EINVAL;
5559
5560 if (!info->attrs[NL80211_ATTR_REG_RULES])
5561 return -EINVAL;
5562
5563 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5564
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005565 if (info->attrs[NL80211_ATTR_DFS_REGION])
5566 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5567
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005568 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005569 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005570 num_rules++;
5571 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005572 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005573 }
5574
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005575 if (!reg_is_valid_request(alpha2))
5576 return -EINVAL;
5577
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005578 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005579 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005580
5581 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005582 if (!rd)
5583 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005584
5585 rd->n_reg_rules = num_rules;
5586 rd->alpha2[0] = alpha2[0];
5587 rd->alpha2[1] = alpha2[1];
5588
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005589 /*
5590 * Disable DFS master mode if the DFS region was
5591 * not supported or known on this kernel.
5592 */
5593 if (reg_supported_dfs_region(dfs_region))
5594 rd->dfs_region = dfs_region;
5595
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005596 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005597 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005598 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5599 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5600 reg_rule_policy);
5601 if (r)
5602 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005603 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5604 if (r)
5605 goto bad_reg;
5606
5607 rule_idx++;
5608
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005609 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5610 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005611 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005612 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005613 }
5614
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005615 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005616 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005617 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005618
Johannes Bergd2372b32008-10-24 20:32:20 +02005619 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005620 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005621 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005622}
5623
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005624static int validate_scan_freqs(struct nlattr *freqs)
5625{
5626 struct nlattr *attr1, *attr2;
5627 int n_channels = 0, tmp1, tmp2;
5628
5629 nla_for_each_nested(attr1, freqs, tmp1) {
5630 n_channels++;
5631 /*
5632 * Some hardware has a limited channel list for
5633 * scanning, and it is pretty much nonsensical
5634 * to scan for a channel twice, so disallow that
5635 * and don't require drivers to check that the
5636 * channel list they get isn't longer than what
5637 * they can scan, as long as they can scan all
5638 * the channels they registered at once.
5639 */
5640 nla_for_each_nested(attr2, freqs, tmp2)
5641 if (attr1 != attr2 &&
5642 nla_get_u32(attr1) == nla_get_u32(attr2))
5643 return 0;
5644 }
5645
5646 return n_channels;
5647}
5648
Johannes Bergad2b26a2014-06-12 21:39:05 +02005649static int nl80211_parse_random_mac(struct nlattr **attrs,
5650 u8 *mac_addr, u8 *mac_addr_mask)
5651{
5652 int i;
5653
5654 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5655 memset(mac_addr, 0, ETH_ALEN);
5656 memset(mac_addr_mask, 0, ETH_ALEN);
5657 mac_addr[0] = 0x2;
5658 mac_addr_mask[0] = 0x3;
5659
5660 return 0;
5661 }
5662
5663 /* need both or none */
5664 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5665 return -EINVAL;
5666
5667 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5668 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5669
5670 /* don't allow or configure an mcast address */
5671 if (!is_multicast_ether_addr(mac_addr_mask) ||
5672 is_multicast_ether_addr(mac_addr))
5673 return -EINVAL;
5674
5675 /*
5676 * allow users to pass a MAC address that has bits set outside
5677 * of the mask, but don't bother drivers with having to deal
5678 * with such bits
5679 */
5680 for (i = 0; i < ETH_ALEN; i++)
5681 mac_addr[i] &= mac_addr_mask[i];
5682
5683 return 0;
5684}
5685
Johannes Berg2a519312009-02-10 21:25:55 +01005686static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5687{
Johannes Berg4c476992010-10-04 21:36:35 +02005688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005689 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005690 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005691 struct nlattr *attr;
5692 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005693 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005694 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005695
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005696 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5697 return -EINVAL;
5698
Johannes Berg79c97e92009-07-07 03:56:12 +02005699 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005700
Johannes Berg4c476992010-10-04 21:36:35 +02005701 if (!rdev->ops->scan)
5702 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005703
Johannes Bergf9d15d12014-01-22 11:14:19 +02005704 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005705 err = -EBUSY;
5706 goto unlock;
5707 }
Johannes Berg2a519312009-02-10 21:25:55 +01005708
5709 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005710 n_channels = validate_scan_freqs(
5711 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005712 if (!n_channels) {
5713 err = -EINVAL;
5714 goto unlock;
5715 }
Johannes Berg2a519312009-02-10 21:25:55 +01005716 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005717 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005718 }
5719
5720 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5721 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5722 n_ssids++;
5723
Johannes Bergf9f47522013-03-19 15:04:07 +01005724 if (n_ssids > wiphy->max_scan_ssids) {
5725 err = -EINVAL;
5726 goto unlock;
5727 }
Johannes Berg2a519312009-02-10 21:25:55 +01005728
Jouni Malinen70692ad2009-02-16 19:39:13 +02005729 if (info->attrs[NL80211_ATTR_IE])
5730 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5731 else
5732 ie_len = 0;
5733
Johannes Bergf9f47522013-03-19 15:04:07 +01005734 if (ie_len > wiphy->max_scan_ie_len) {
5735 err = -EINVAL;
5736 goto unlock;
5737 }
Johannes Berg18a83652009-03-31 12:12:05 +02005738
Johannes Berg2a519312009-02-10 21:25:55 +01005739 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005740 + sizeof(*request->ssids) * n_ssids
5741 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005742 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005743 if (!request) {
5744 err = -ENOMEM;
5745 goto unlock;
5746 }
Johannes Berg2a519312009-02-10 21:25:55 +01005747
Johannes Berg2a519312009-02-10 21:25:55 +01005748 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005749 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005750 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005751 if (ie_len) {
5752 if (request->ssids)
5753 request->ie = (void *)(request->ssids + n_ssids);
5754 else
5755 request->ie = (void *)(request->channels + n_channels);
5756 }
Johannes Berg2a519312009-02-10 21:25:55 +01005757
Johannes Berg584991d2009-11-02 13:32:03 +01005758 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005759 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5760 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005761 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005762 struct ieee80211_channel *chan;
5763
5764 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5765
5766 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005767 err = -EINVAL;
5768 goto out_free;
5769 }
Johannes Berg584991d2009-11-02 13:32:03 +01005770
5771 /* ignore disabled channels */
5772 if (chan->flags & IEEE80211_CHAN_DISABLED)
5773 continue;
5774
5775 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005776 i++;
5777 }
5778 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005779 enum ieee80211_band band;
5780
Johannes Berg2a519312009-02-10 21:25:55 +01005781 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005782 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5783 int j;
5784 if (!wiphy->bands[band])
5785 continue;
5786 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005787 struct ieee80211_channel *chan;
5788
5789 chan = &wiphy->bands[band]->channels[j];
5790
5791 if (chan->flags & IEEE80211_CHAN_DISABLED)
5792 continue;
5793
5794 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005795 i++;
5796 }
5797 }
5798 }
5799
Johannes Berg584991d2009-11-02 13:32:03 +01005800 if (!i) {
5801 err = -EINVAL;
5802 goto out_free;
5803 }
5804
5805 request->n_channels = i;
5806
Johannes Berg2a519312009-02-10 21:25:55 +01005807 i = 0;
5808 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5809 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005810 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005811 err = -EINVAL;
5812 goto out_free;
5813 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005814 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005815 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005816 i++;
5817 }
5818 }
5819
Jouni Malinen70692ad2009-02-16 19:39:13 +02005820 if (info->attrs[NL80211_ATTR_IE]) {
5821 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005822 memcpy((void *)request->ie,
5823 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005824 request->ie_len);
5825 }
5826
Johannes Berg34850ab2011-07-18 18:08:35 +02005827 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005828 if (wiphy->bands[i])
5829 request->rates[i] =
5830 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005831
5832 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5833 nla_for_each_nested(attr,
5834 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5835 tmp) {
5836 enum ieee80211_band band = nla_type(attr);
5837
Dan Carpenter84404622011-07-29 11:52:18 +03005838 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005839 err = -EINVAL;
5840 goto out_free;
5841 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005842
5843 if (!wiphy->bands[band])
5844 continue;
5845
Johannes Berg34850ab2011-07-18 18:08:35 +02005846 err = ieee80211_get_ratemask(wiphy->bands[band],
5847 nla_data(attr),
5848 nla_len(attr),
5849 &request->rates[band]);
5850 if (err)
5851 goto out_free;
5852 }
5853 }
5854
Sam Leffler46856bb2012-10-11 21:03:32 -07005855 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005856 request->flags = nla_get_u32(
5857 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005858 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5859 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005860 err = -EOPNOTSUPP;
5861 goto out_free;
5862 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005863
5864 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5865 if (!(wiphy->features &
5866 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5867 err = -EOPNOTSUPP;
5868 goto out_free;
5869 }
5870
5871 if (wdev->current_bss) {
5872 err = -EOPNOTSUPP;
5873 goto out_free;
5874 }
5875
5876 err = nl80211_parse_random_mac(info->attrs,
5877 request->mac_addr,
5878 request->mac_addr_mask);
5879 if (err)
5880 goto out_free;
5881 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005882 }
Sam Lefflered4737712012-10-11 21:03:31 -07005883
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305884 request->no_cck =
5885 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5886
Johannes Bergfd014282012-06-18 19:17:03 +02005887 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005888 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005889 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005890
Johannes Berg79c97e92009-07-07 03:56:12 +02005891 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005892 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005893
Johannes Berg463d0182009-07-14 00:33:35 +02005894 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005895 nl80211_send_scan_start(rdev, wdev);
5896 if (wdev->netdev)
5897 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005898 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005899 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005900 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005901 kfree(request);
5902 }
Johannes Berg3b858752009-03-12 09:55:09 +01005903
Johannes Bergf9f47522013-03-19 15:04:07 +01005904 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005905 return err;
5906}
5907
Luciano Coelho256da022014-11-10 16:13:46 +02005908static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005909nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005910 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005911{
5912 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005913 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005914 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005915 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005916 enum ieee80211_band band;
5917 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005918 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005919 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005920
Luciano Coelho256da022014-11-10 16:13:46 +02005921 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5922 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005923
Luciano Coelho256da022014-11-10 16:13:46 +02005924 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5925 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005926
Luciano Coelho256da022014-11-10 16:13:46 +02005927 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005928 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005929 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005930
Luciano Coelho256da022014-11-10 16:13:46 +02005931 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005932 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005933 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005934 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005935 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005936 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005937 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005938 }
5939
Luciano Coelho256da022014-11-10 16:13:46 +02005940 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5941 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005942 tmp)
5943 n_ssids++;
5944
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005945 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005946 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005947
Johannes Bergea73cbc2014-01-24 10:53:53 +01005948 /*
5949 * First, count the number of 'real' matchsets. Due to an issue with
5950 * the old implementation, matchsets containing only the RSSI attribute
5951 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5952 * RSSI for all matchsets, rather than their own matchset for reporting
5953 * all APs with a strong RSSI. This is needed to be compatible with
5954 * older userspace that treated a matchset with only the RSSI as the
5955 * global RSSI for all other matchsets - if there are other matchsets.
5956 */
Luciano Coelho256da022014-11-10 16:13:46 +02005957 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005958 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005959 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005960 tmp) {
5961 struct nlattr *rssi;
5962
5963 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5964 nla_data(attr), nla_len(attr),
5965 nl80211_match_policy);
5966 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02005967 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005968 /* add other standalone attributes here */
5969 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5970 n_match_sets++;
5971 continue;
5972 }
5973 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5974 if (rssi)
5975 default_match_rssi = nla_get_s32(rssi);
5976 }
5977 }
5978
5979 /* However, if there's no other matchset, add the RSSI one */
5980 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5981 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005982
5983 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02005984 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005985
Luciano Coelho256da022014-11-10 16:13:46 +02005986 if (attrs[NL80211_ATTR_IE])
5987 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005988 else
5989 ie_len = 0;
5990
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005991 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02005992 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005993
Luciano Coelho807f8a82011-05-11 17:09:35 +03005994 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005995 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005996 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005997 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005998 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02005999 if (!request)
6000 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006001
6002 if (n_ssids)
6003 request->ssids = (void *)&request->channels[n_channels];
6004 request->n_ssids = n_ssids;
6005 if (ie_len) {
6006 if (request->ssids)
6007 request->ie = (void *)(request->ssids + n_ssids);
6008 else
6009 request->ie = (void *)(request->channels + n_channels);
6010 }
6011
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006012 if (n_match_sets) {
6013 if (request->ie)
6014 request->match_sets = (void *)(request->ie + ie_len);
6015 else if (request->ssids)
6016 request->match_sets =
6017 (void *)(request->ssids + n_ssids);
6018 else
6019 request->match_sets =
6020 (void *)(request->channels + n_channels);
6021 }
6022 request->n_match_sets = n_match_sets;
6023
Luciano Coelho807f8a82011-05-11 17:09:35 +03006024 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006025 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006026 /* user specified, bail out if channel not found */
6027 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006028 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006029 tmp) {
6030 struct ieee80211_channel *chan;
6031
6032 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6033
6034 if (!chan) {
6035 err = -EINVAL;
6036 goto out_free;
6037 }
6038
6039 /* ignore disabled channels */
6040 if (chan->flags & IEEE80211_CHAN_DISABLED)
6041 continue;
6042
6043 request->channels[i] = chan;
6044 i++;
6045 }
6046 } else {
6047 /* all channels */
6048 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6049 int j;
6050 if (!wiphy->bands[band])
6051 continue;
6052 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6053 struct ieee80211_channel *chan;
6054
6055 chan = &wiphy->bands[band]->channels[j];
6056
6057 if (chan->flags & IEEE80211_CHAN_DISABLED)
6058 continue;
6059
6060 request->channels[i] = chan;
6061 i++;
6062 }
6063 }
6064 }
6065
6066 if (!i) {
6067 err = -EINVAL;
6068 goto out_free;
6069 }
6070
6071 request->n_channels = i;
6072
6073 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006074 if (attrs[NL80211_ATTR_SCAN_SSIDS]) {
6075 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006076 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006077 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006078 err = -EINVAL;
6079 goto out_free;
6080 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006081 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006082 memcpy(request->ssids[i].ssid, nla_data(attr),
6083 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006084 i++;
6085 }
6086 }
6087
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006088 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006089 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006090 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006091 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006092 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006093 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006094
Johannes Bergae811e22014-01-24 10:17:47 +01006095 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6096 nla_data(attr), nla_len(attr),
6097 nl80211_match_policy);
6098 if (err)
6099 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006100 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006101 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006102 if (WARN_ON(i >= n_match_sets)) {
6103 /* this indicates a programming error,
6104 * the loop above should have verified
6105 * things properly
6106 */
6107 err = -EINVAL;
6108 goto out_free;
6109 }
6110
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006111 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6112 err = -EINVAL;
6113 goto out_free;
6114 }
6115 memcpy(request->match_sets[i].ssid.ssid,
6116 nla_data(ssid), nla_len(ssid));
6117 request->match_sets[i].ssid.ssid_len =
6118 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006119 /* special attribute - old implemenation w/a */
6120 request->match_sets[i].rssi_thold =
6121 default_match_rssi;
6122 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6123 if (rssi)
6124 request->match_sets[i].rssi_thold =
6125 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006126 }
6127 i++;
6128 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006129
6130 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006131 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006132 request->match_sets[0].rssi_thold = default_match_rssi;
6133
6134 request->min_rssi_thold = INT_MAX;
6135 for (i = 0; i < n_match_sets; i++)
6136 request->min_rssi_thold =
6137 min(request->match_sets[i].rssi_thold,
6138 request->min_rssi_thold);
6139 } else {
6140 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006141 }
6142
Johannes Berg9900e482014-02-04 21:01:25 +01006143 if (ie_len) {
6144 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006145 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006146 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006147 request->ie_len);
6148 }
6149
Luciano Coelho256da022014-11-10 16:13:46 +02006150 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006151 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006152 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006153 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6154 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006155 err = -EOPNOTSUPP;
6156 goto out_free;
6157 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006158
6159 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6160 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6161
6162 if (!wdev) /* must be net-detect */
6163 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6164
6165 if (!(wiphy->features & flg)) {
6166 err = -EOPNOTSUPP;
6167 goto out_free;
6168 }
6169
6170 if (wdev && wdev->current_bss) {
6171 err = -EOPNOTSUPP;
6172 goto out_free;
6173 }
6174
6175 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6176 request->mac_addr_mask);
6177 if (err)
6178 goto out_free;
6179 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006180 }
Sam Lefflered4737712012-10-11 21:03:31 -07006181
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006182 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006183 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006184
Luciano Coelho256da022014-11-10 16:13:46 +02006185 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006186
6187out_free:
6188 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006189 return ERR_PTR(err);
6190}
6191
6192static int nl80211_start_sched_scan(struct sk_buff *skb,
6193 struct genl_info *info)
6194{
6195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6196 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006197 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006198 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006199 int err;
6200
6201 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6202 !rdev->ops->sched_scan_start)
6203 return -EOPNOTSUPP;
6204
6205 if (rdev->sched_scan_req)
6206 return -EINPROGRESS;
6207
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006208 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6209 info->attrs);
6210
6211 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006212 if (err)
6213 goto out_err;
6214
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006215 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006216 if (err)
6217 goto out_free;
6218
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006219 sched_scan_req->dev = dev;
6220 sched_scan_req->wiphy = &rdev->wiphy;
6221
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006222 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6223 sched_scan_req->owner_nlportid = info->snd_portid;
6224
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006225 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006226
6227 nl80211_send_sched_scan(rdev, dev,
6228 NL80211_CMD_START_SCHED_SCAN);
6229 return 0;
6230
6231out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006232 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006233out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006234 return err;
6235}
6236
6237static int nl80211_stop_sched_scan(struct sk_buff *skb,
6238 struct genl_info *info)
6239{
6240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6241
6242 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6243 !rdev->ops->sched_scan_stop)
6244 return -EOPNOTSUPP;
6245
Johannes Berg5fe231e2013-05-08 21:45:15 +02006246 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006247}
6248
Simon Wunderlich04f39042013-02-08 18:16:19 +01006249static int nl80211_start_radar_detection(struct sk_buff *skb,
6250 struct genl_info *info)
6251{
6252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6253 struct net_device *dev = info->user_ptr[1];
6254 struct wireless_dev *wdev = dev->ieee80211_ptr;
6255 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006256 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006257 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006258 int err;
6259
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006260 dfs_region = reg_get_dfs_region(wdev->wiphy);
6261 if (dfs_region == NL80211_DFS_UNSET)
6262 return -EINVAL;
6263
Simon Wunderlich04f39042013-02-08 18:16:19 +01006264 err = nl80211_parse_chandef(rdev, info, &chandef);
6265 if (err)
6266 return err;
6267
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006268 if (netif_carrier_ok(dev))
6269 return -EBUSY;
6270
Simon Wunderlich04f39042013-02-08 18:16:19 +01006271 if (wdev->cac_started)
6272 return -EBUSY;
6273
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006274 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006275 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006276 if (err < 0)
6277 return err;
6278
6279 if (err == 0)
6280 return -EINVAL;
6281
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006282 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006283 return -EINVAL;
6284
6285 if (!rdev->ops->start_radar_detection)
6286 return -EOPNOTSUPP;
6287
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006288 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6289 if (WARN_ON(!cac_time_ms))
6290 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6291
6292 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6293 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006294 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006295 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006296 wdev->cac_started = true;
6297 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006298 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006299 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006300 return err;
6301}
6302
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006303static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6304{
6305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6306 struct net_device *dev = info->user_ptr[1];
6307 struct wireless_dev *wdev = dev->ieee80211_ptr;
6308 struct cfg80211_csa_settings params;
6309 /* csa_attrs is defined static to avoid waste of stack size - this
6310 * function is called under RTNL lock, so this should not be a problem.
6311 */
6312 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006313 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006314 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006315 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006316 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006317
6318 if (!rdev->ops->channel_switch ||
6319 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6320 return -EOPNOTSUPP;
6321
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006322 switch (dev->ieee80211_ptr->iftype) {
6323 case NL80211_IFTYPE_AP:
6324 case NL80211_IFTYPE_P2P_GO:
6325 need_new_beacon = true;
6326
6327 /* useless if AP is not running */
6328 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006329 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006330 break;
6331 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006332 if (!wdev->ssid_len)
6333 return -ENOTCONN;
6334 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006335 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006336 if (!wdev->mesh_id_len)
6337 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006338 break;
6339 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006340 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006341 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006342
6343 memset(&params, 0, sizeof(params));
6344
6345 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6346 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6347 return -EINVAL;
6348
6349 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006350 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006351 return -EINVAL;
6352
Luciano Coelho252e07c2014-10-08 09:48:34 +03006353 /* Even though the attribute is u32, the specification says
6354 * u8, so let's make sure we don't overflow.
6355 */
6356 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6357 if (cs_count > 255)
6358 return -EINVAL;
6359
6360 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006361
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006362 if (!need_new_beacon)
6363 goto skip_beacons;
6364
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006365 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6366 if (err)
6367 return err;
6368
6369 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6370 info->attrs[NL80211_ATTR_CSA_IES],
6371 nl80211_policy);
6372 if (err)
6373 return err;
6374
6375 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6376 if (err)
6377 return err;
6378
6379 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6380 return -EINVAL;
6381
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006382 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6383 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006384 return -EINVAL;
6385
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006386 params.n_counter_offsets_beacon = len / sizeof(u16);
6387 if (rdev->wiphy.max_num_csa_counters &&
6388 (params.n_counter_offsets_beacon >
6389 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006390 return -EINVAL;
6391
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006392 params.counter_offsets_beacon =
6393 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6394
6395 /* sanity checks - counters should fit and be the same */
6396 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6397 u16 offset = params.counter_offsets_beacon[i];
6398
6399 if (offset >= params.beacon_csa.tail_len)
6400 return -EINVAL;
6401
6402 if (params.beacon_csa.tail[offset] != params.count)
6403 return -EINVAL;
6404 }
6405
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006406 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006407 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6408 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006409 return -EINVAL;
6410
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006411 params.n_counter_offsets_presp = len / sizeof(u16);
6412 if (rdev->wiphy.max_num_csa_counters &&
6413 (params.n_counter_offsets_beacon >
6414 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006415 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006416
6417 params.counter_offsets_presp =
6418 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6419
6420 /* sanity checks - counters should fit and be the same */
6421 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6422 u16 offset = params.counter_offsets_presp[i];
6423
6424 if (offset >= params.beacon_csa.probe_resp_len)
6425 return -EINVAL;
6426
6427 if (params.beacon_csa.probe_resp[offset] !=
6428 params.count)
6429 return -EINVAL;
6430 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006431 }
6432
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006433skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006434 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6435 if (err)
6436 return err;
6437
Ilan Peer174e0cd2014-02-23 09:13:01 +02006438 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6439 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006440 return -EINVAL;
6441
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006442 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6443 &params.chandef,
6444 wdev->iftype);
6445 if (err < 0)
6446 return err;
6447
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006448 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006449 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006450
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006451 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6452 params.block_tx = true;
6453
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006454 wdev_lock(wdev);
6455 err = rdev_channel_switch(rdev, dev, &params);
6456 wdev_unlock(wdev);
6457
6458 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006459}
6460
Johannes Berg9720bb32011-06-21 09:45:33 +02006461static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6462 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006463 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006464 struct wireless_dev *wdev,
6465 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006466{
Johannes Berg48ab9052009-07-10 18:42:31 +02006467 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006468 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006469 void *hdr;
6470 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006471
6472 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006473
Eric W. Biederman15e47302012-09-07 20:12:54 +00006474 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006475 NL80211_CMD_NEW_SCAN_RESULTS);
6476 if (!hdr)
6477 return -1;
6478
Johannes Berg9720bb32011-06-21 09:45:33 +02006479 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6480
Johannes Berg97990a02013-04-19 01:02:55 +02006481 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6482 goto nla_put_failure;
6483 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006484 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6485 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006486 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6487 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006488
6489 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6490 if (!bss)
6491 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006492 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006493 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006494 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006495
6496 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006497 /* indicate whether we have probe response data or not */
6498 if (rcu_access_pointer(res->proberesp_ies) &&
6499 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6500 goto fail_unlock_rcu;
6501
6502 /* this pointer prefers to be pointed to probe response data
6503 * but is always valid
6504 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006505 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006506 if (ies) {
6507 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6508 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006509 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6510 ies->len, ies->data))
6511 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006512 }
Johannes Berg0e227082014-08-12 20:34:30 +02006513
6514 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006515 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006516 if (ies && ies->from_beacon) {
6517 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006518 goto fail_unlock_rcu;
6519 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6520 ies->len, ies->data))
6521 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006522 }
6523 rcu_read_unlock();
6524
David S. Miller9360ffd2012-03-29 04:41:26 -04006525 if (res->beacon_interval &&
6526 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6527 goto nla_put_failure;
6528 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6529 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006530 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006531 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6532 jiffies_to_msecs(jiffies - intbss->ts)))
6533 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006534
Johannes Berg77965c92009-02-18 18:45:06 +01006535 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006536 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006537 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6538 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006539 break;
6540 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006541 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6542 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006543 break;
6544 default:
6545 break;
6546 }
6547
Johannes Berg48ab9052009-07-10 18:42:31 +02006548 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006549 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006550 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006551 if (intbss == wdev->current_bss &&
6552 nla_put_u32(msg, NL80211_BSS_STATUS,
6553 NL80211_BSS_STATUS_ASSOCIATED))
6554 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006555 break;
6556 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006557 if (intbss == wdev->current_bss &&
6558 nla_put_u32(msg, NL80211_BSS_STATUS,
6559 NL80211_BSS_STATUS_IBSS_JOINED))
6560 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006561 break;
6562 default:
6563 break;
6564 }
6565
Johannes Berg2a519312009-02-10 21:25:55 +01006566 nla_nest_end(msg, bss);
6567
6568 return genlmsg_end(msg, hdr);
6569
Johannes Berg8cef2c92013-02-05 16:54:31 +01006570 fail_unlock_rcu:
6571 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006572 nla_put_failure:
6573 genlmsg_cancel(msg, hdr);
6574 return -EMSGSIZE;
6575}
6576
Johannes Berg97990a02013-04-19 01:02:55 +02006577static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006578{
Johannes Berg48ab9052009-07-10 18:42:31 +02006579 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006580 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006581 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006582 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006583 int err;
6584
Johannes Berg97990a02013-04-19 01:02:55 +02006585 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006586 if (err)
6587 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006588
Johannes Berg48ab9052009-07-10 18:42:31 +02006589 wdev_lock(wdev);
6590 spin_lock_bh(&rdev->bss_lock);
6591 cfg80211_bss_expire(rdev);
6592
Johannes Berg9720bb32011-06-21 09:45:33 +02006593 cb->seq = rdev->bss_generation;
6594
Johannes Berg48ab9052009-07-10 18:42:31 +02006595 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006596 if (++idx <= start)
6597 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006598 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006599 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006600 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006601 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006602 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006603 }
6604 }
6605
Johannes Berg48ab9052009-07-10 18:42:31 +02006606 spin_unlock_bh(&rdev->bss_lock);
6607 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006608
Johannes Berg97990a02013-04-19 01:02:55 +02006609 cb->args[2] = idx;
6610 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006611
Johannes Berg67748892010-10-04 21:14:06 +02006612 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006613}
6614
Eric W. Biederman15e47302012-09-07 20:12:54 +00006615static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006616 int flags, struct net_device *dev,
6617 bool allow_radio_stats,
6618 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006619{
6620 void *hdr;
6621 struct nlattr *infoattr;
6622
Johannes Berg11f78ac2014-11-14 16:43:50 +01006623 /* skip radio stats if userspace didn't request them */
6624 if (!survey->channel && !allow_radio_stats)
6625 return 0;
6626
Eric W. Biederman15e47302012-09-07 20:12:54 +00006627 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006628 NL80211_CMD_NEW_SURVEY_RESULTS);
6629 if (!hdr)
6630 return -ENOMEM;
6631
David S. Miller9360ffd2012-03-29 04:41:26 -04006632 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6633 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006634
6635 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6636 if (!infoattr)
6637 goto nla_put_failure;
6638
Johannes Berg11f78ac2014-11-14 16:43:50 +01006639 if (survey->channel &&
6640 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006641 survey->channel->center_freq))
6642 goto nla_put_failure;
6643
6644 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6645 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6646 goto nla_put_failure;
6647 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6648 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6649 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006650 if ((survey->filled & SURVEY_INFO_TIME) &&
6651 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6652 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006653 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006654 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6655 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6656 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006657 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006658 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6659 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6660 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006661 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006662 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6663 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6664 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006665 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006666 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6667 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6668 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006669 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006670 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6671 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6672 survey->time_scan))
6673 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006674
6675 nla_nest_end(msg, infoattr);
6676
6677 return genlmsg_end(msg, hdr);
6678
6679 nla_put_failure:
6680 genlmsg_cancel(msg, hdr);
6681 return -EMSGSIZE;
6682}
6683
Johannes Berg11f78ac2014-11-14 16:43:50 +01006684static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006685{
6686 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006687 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006688 struct wireless_dev *wdev;
6689 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006690 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006691 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006692
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006693 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006694 if (res)
6695 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006696
Johannes Berg11f78ac2014-11-14 16:43:50 +01006697 /* prepare_wdev_dump parsed the attributes */
6698 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6699
Johannes Berg97990a02013-04-19 01:02:55 +02006700 if (!wdev->netdev) {
6701 res = -EINVAL;
6702 goto out_err;
6703 }
6704
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006705 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006706 res = -EOPNOTSUPP;
6707 goto out_err;
6708 }
6709
6710 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006711 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006712 if (res == -ENOENT)
6713 break;
6714 if (res)
6715 goto out_err;
6716
Johannes Berg11f78ac2014-11-14 16:43:50 +01006717 /* don't send disabled channels, but do send non-channel data */
6718 if (survey.channel &&
6719 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006720 survey_idx++;
6721 continue;
6722 }
6723
Holger Schurig61fa7132009-11-11 12:25:40 +01006724 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006725 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006726 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006727 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006728 goto out;
6729 survey_idx++;
6730 }
6731
6732 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006733 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006734 res = skb->len;
6735 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006736 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006737 return res;
6738}
6739
Samuel Ortizb23aa672009-07-01 21:26:54 +02006740static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6741{
6742 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6743 NL80211_WPA_VERSION_2));
6744}
6745
Jouni Malinen636a5d32009-03-19 13:39:22 +02006746static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6747{
Johannes Berg4c476992010-10-04 21:36:35 +02006748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6749 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006750 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006751 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6752 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006753 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006754 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006755 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006756
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006757 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6758 return -EINVAL;
6759
6760 if (!info->attrs[NL80211_ATTR_MAC])
6761 return -EINVAL;
6762
Jouni Malinen17780922009-03-27 20:52:47 +02006763 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6764 return -EINVAL;
6765
Johannes Berg19957bb2009-07-02 17:20:43 +02006766 if (!info->attrs[NL80211_ATTR_SSID])
6767 return -EINVAL;
6768
6769 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6770 return -EINVAL;
6771
Johannes Bergfffd0932009-07-08 14:22:54 +02006772 err = nl80211_parse_key(info, &key);
6773 if (err)
6774 return err;
6775
6776 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006777 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6778 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006779 if (!key.p.key || !key.p.key_len)
6780 return -EINVAL;
6781 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6782 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6783 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6784 key.p.key_len != WLAN_KEY_LEN_WEP104))
6785 return -EINVAL;
6786 if (key.idx > 4)
6787 return -EINVAL;
6788 } else {
6789 key.p.key_len = 0;
6790 key.p.key = NULL;
6791 }
6792
Johannes Bergafea0b72010-08-10 09:46:42 +02006793 if (key.idx >= 0) {
6794 int i;
6795 bool ok = false;
6796 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6797 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6798 ok = true;
6799 break;
6800 }
6801 }
Johannes Berg4c476992010-10-04 21:36:35 +02006802 if (!ok)
6803 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006804 }
6805
Johannes Berg4c476992010-10-04 21:36:35 +02006806 if (!rdev->ops->auth)
6807 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006808
Johannes Berg074ac8d2010-09-16 14:58:22 +02006809 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006810 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6811 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006812
Johannes Berg19957bb2009-07-02 17:20:43 +02006813 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006814 chan = nl80211_get_valid_chan(&rdev->wiphy,
6815 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6816 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006817 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006818
Johannes Berg19957bb2009-07-02 17:20:43 +02006819 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6820 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6821
6822 if (info->attrs[NL80211_ATTR_IE]) {
6823 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6824 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6825 }
6826
6827 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006828 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006829 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006830
Jouni Malinene39e5b52012-09-30 19:29:39 +03006831 if (auth_type == NL80211_AUTHTYPE_SAE &&
6832 !info->attrs[NL80211_ATTR_SAE_DATA])
6833 return -EINVAL;
6834
6835 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6836 if (auth_type != NL80211_AUTHTYPE_SAE)
6837 return -EINVAL;
6838 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6839 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6840 /* need to include at least Auth Transaction and Status Code */
6841 if (sae_data_len < 4)
6842 return -EINVAL;
6843 }
6844
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006845 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6846
Johannes Berg95de8172012-01-20 13:55:25 +01006847 /*
6848 * Since we no longer track auth state, ignore
6849 * requests to only change local state.
6850 */
6851 if (local_state_change)
6852 return 0;
6853
Johannes Berg91bf9b22013-05-15 17:44:01 +02006854 wdev_lock(dev->ieee80211_ptr);
6855 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6856 ssid, ssid_len, ie, ie_len,
6857 key.p.key, key.p.key_len, key.idx,
6858 sae_data, sae_data_len);
6859 wdev_unlock(dev->ieee80211_ptr);
6860 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006861}
6862
Johannes Bergc0692b82010-08-27 14:26:53 +03006863static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6864 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006865 struct cfg80211_crypto_settings *settings,
6866 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006867{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006868 memset(settings, 0, sizeof(*settings));
6869
Samuel Ortizb23aa672009-07-01 21:26:54 +02006870 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6871
Johannes Bergc0692b82010-08-27 14:26:53 +03006872 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6873 u16 proto;
6874 proto = nla_get_u16(
6875 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6876 settings->control_port_ethertype = cpu_to_be16(proto);
6877 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6878 proto != ETH_P_PAE)
6879 return -EINVAL;
6880 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6881 settings->control_port_no_encrypt = true;
6882 } else
6883 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6884
Samuel Ortizb23aa672009-07-01 21:26:54 +02006885 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6886 void *data;
6887 int len, i;
6888
6889 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6890 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6891 settings->n_ciphers_pairwise = len / sizeof(u32);
6892
6893 if (len % sizeof(u32))
6894 return -EINVAL;
6895
Johannes Berg3dc27d22009-07-02 21:36:37 +02006896 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006897 return -EINVAL;
6898
6899 memcpy(settings->ciphers_pairwise, data, len);
6900
6901 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006902 if (!cfg80211_supported_cipher_suite(
6903 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006904 settings->ciphers_pairwise[i]))
6905 return -EINVAL;
6906 }
6907
6908 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6909 settings->cipher_group =
6910 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006911 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6912 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006913 return -EINVAL;
6914 }
6915
6916 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6917 settings->wpa_versions =
6918 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6919 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6920 return -EINVAL;
6921 }
6922
6923 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6924 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006925 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006926
6927 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6928 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6929 settings->n_akm_suites = len / sizeof(u32);
6930
6931 if (len % sizeof(u32))
6932 return -EINVAL;
6933
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006934 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6935 return -EINVAL;
6936
Samuel Ortizb23aa672009-07-01 21:26:54 +02006937 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006938 }
6939
6940 return 0;
6941}
6942
Jouni Malinen636a5d32009-03-19 13:39:22 +02006943static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6944{
Johannes Berg4c476992010-10-04 21:36:35 +02006945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6946 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006947 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006948 struct cfg80211_assoc_request req = {};
6949 const u8 *bssid, *ssid;
6950 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006951
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006952 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6953 return -EINVAL;
6954
6955 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006956 !info->attrs[NL80211_ATTR_SSID] ||
6957 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006958 return -EINVAL;
6959
Johannes Berg4c476992010-10-04 21:36:35 +02006960 if (!rdev->ops->assoc)
6961 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006962
Johannes Berg074ac8d2010-09-16 14:58:22 +02006963 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006964 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6965 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006966
Johannes Berg19957bb2009-07-02 17:20:43 +02006967 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006968
Jouni Malinen664834d2014-01-15 00:01:44 +02006969 chan = nl80211_get_valid_chan(&rdev->wiphy,
6970 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6971 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006972 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006973
Johannes Berg19957bb2009-07-02 17:20:43 +02006974 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6975 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006976
6977 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006978 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6979 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006980 }
6981
Jouni Malinendc6382c2009-05-06 22:09:37 +03006982 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006983 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006984 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006985 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006986 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006987 else if (mfp != NL80211_MFP_NO)
6988 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006989 }
6990
Johannes Berg3e5d7642009-07-07 14:37:26 +02006991 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006992 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006993
Ben Greear7e7c8922011-11-18 11:31:59 -08006994 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006995 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006996
6997 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006998 memcpy(&req.ht_capa_mask,
6999 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7000 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007001
7002 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007003 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007004 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007005 memcpy(&req.ht_capa,
7006 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7007 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007008 }
7009
Johannes Bergee2aca32013-02-21 17:36:01 +01007010 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007011 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007012
7013 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007014 memcpy(&req.vht_capa_mask,
7015 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7016 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007017
7018 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007019 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007020 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007021 memcpy(&req.vht_capa,
7022 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7023 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007024 }
7025
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007026 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7027 if (!(rdev->wiphy.features &
7028 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7029 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7030 return -EINVAL;
7031 req.flags |= ASSOC_REQ_USE_RRM;
7032 }
7033
Johannes Bergf62fab72013-02-21 20:09:09 +01007034 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007035 if (!err) {
7036 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007037 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7038 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007039 wdev_unlock(dev->ieee80211_ptr);
7040 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007041
Jouni Malinen636a5d32009-03-19 13:39:22 +02007042 return err;
7043}
7044
7045static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7046{
Johannes Berg4c476992010-10-04 21:36:35 +02007047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7048 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007049 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007050 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007051 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007052 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007053
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007054 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7055 return -EINVAL;
7056
7057 if (!info->attrs[NL80211_ATTR_MAC])
7058 return -EINVAL;
7059
7060 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7061 return -EINVAL;
7062
Johannes Berg4c476992010-10-04 21:36:35 +02007063 if (!rdev->ops->deauth)
7064 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007065
Johannes Berg074ac8d2010-09-16 14:58:22 +02007066 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007067 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7068 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007069
Johannes Berg19957bb2009-07-02 17:20:43 +02007070 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007071
Johannes Berg19957bb2009-07-02 17:20:43 +02007072 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7073 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007074 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007075 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007076 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007077
7078 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007079 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7080 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007081 }
7082
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007083 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7084
Johannes Berg91bf9b22013-05-15 17:44:01 +02007085 wdev_lock(dev->ieee80211_ptr);
7086 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7087 local_state_change);
7088 wdev_unlock(dev->ieee80211_ptr);
7089 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007090}
7091
7092static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7093{
Johannes Berg4c476992010-10-04 21:36:35 +02007094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7095 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007096 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007097 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007098 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007099 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007100
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007101 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7102 return -EINVAL;
7103
7104 if (!info->attrs[NL80211_ATTR_MAC])
7105 return -EINVAL;
7106
7107 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7108 return -EINVAL;
7109
Johannes Berg4c476992010-10-04 21:36:35 +02007110 if (!rdev->ops->disassoc)
7111 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007112
Johannes Berg074ac8d2010-09-16 14:58:22 +02007113 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007114 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7115 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007116
Johannes Berg19957bb2009-07-02 17:20:43 +02007117 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007118
Johannes Berg19957bb2009-07-02 17:20:43 +02007119 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7120 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007121 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007122 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007123 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007124
7125 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007126 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7127 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007128 }
7129
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007130 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7131
Johannes Berg91bf9b22013-05-15 17:44:01 +02007132 wdev_lock(dev->ieee80211_ptr);
7133 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7134 local_state_change);
7135 wdev_unlock(dev->ieee80211_ptr);
7136 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007137}
7138
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007139static bool
7140nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7141 int mcast_rate[IEEE80211_NUM_BANDS],
7142 int rateval)
7143{
7144 struct wiphy *wiphy = &rdev->wiphy;
7145 bool found = false;
7146 int band, i;
7147
7148 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7149 struct ieee80211_supported_band *sband;
7150
7151 sband = wiphy->bands[band];
7152 if (!sband)
7153 continue;
7154
7155 for (i = 0; i < sband->n_bitrates; i++) {
7156 if (sband->bitrates[i].bitrate == rateval) {
7157 mcast_rate[band] = i + 1;
7158 found = true;
7159 break;
7160 }
7161 }
7162 }
7163
7164 return found;
7165}
7166
Johannes Berg04a773a2009-04-19 21:24:32 +02007167static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7168{
Johannes Berg4c476992010-10-04 21:36:35 +02007169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7170 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007171 struct cfg80211_ibss_params ibss;
7172 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007173 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007174 int err;
7175
Johannes Berg8e30bc52009-04-22 17:45:38 +02007176 memset(&ibss, 0, sizeof(ibss));
7177
Johannes Berg04a773a2009-04-19 21:24:32 +02007178 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7179 return -EINVAL;
7180
Johannes Berg683b6d32012-11-08 21:25:48 +01007181 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007182 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7183 return -EINVAL;
7184
Johannes Berg8e30bc52009-04-22 17:45:38 +02007185 ibss.beacon_interval = 100;
7186
7187 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7188 ibss.beacon_interval =
7189 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7190 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7191 return -EINVAL;
7192 }
7193
Johannes Berg4c476992010-10-04 21:36:35 +02007194 if (!rdev->ops->join_ibss)
7195 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007196
Johannes Berg4c476992010-10-04 21:36:35 +02007197 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7198 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007199
Johannes Berg79c97e92009-07-07 03:56:12 +02007200 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007201
Johannes Berg39193492011-09-16 13:45:25 +02007202 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007203 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007204
7205 if (!is_valid_ether_addr(ibss.bssid))
7206 return -EINVAL;
7207 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007208 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7209 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7210
7211 if (info->attrs[NL80211_ATTR_IE]) {
7212 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7213 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7214 }
7215
Johannes Berg683b6d32012-11-08 21:25:48 +01007216 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7217 if (err)
7218 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007219
Ilan Peer174e0cd2014-02-23 09:13:01 +02007220 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7221 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007222 return -EINVAL;
7223
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007224 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007225 case NL80211_CHAN_WIDTH_5:
7226 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007227 case NL80211_CHAN_WIDTH_20_NOHT:
7228 break;
7229 case NL80211_CHAN_WIDTH_20:
7230 case NL80211_CHAN_WIDTH_40:
7231 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
7232 break;
7233 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007234 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007235 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007236
Johannes Berg04a773a2009-04-19 21:24:32 +02007237 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007238 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007239
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007240 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7241 u8 *rates =
7242 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7243 int n_rates =
7244 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7245 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007246 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007247
Johannes Berg34850ab2011-07-18 18:08:35 +02007248 err = ieee80211_get_ratemask(sband, rates, n_rates,
7249 &ibss.basic_rates);
7250 if (err)
7251 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007252 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007253
Simon Wunderlich803768f2013-06-28 10:39:58 +02007254 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7255 memcpy(&ibss.ht_capa_mask,
7256 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7257 sizeof(ibss.ht_capa_mask));
7258
7259 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7260 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7261 return -EINVAL;
7262 memcpy(&ibss.ht_capa,
7263 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7264 sizeof(ibss.ht_capa));
7265 }
7266
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007267 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7268 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7269 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7270 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007271
Johannes Berg4c476992010-10-04 21:36:35 +02007272 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307273 bool no_ht = false;
7274
Johannes Berg4c476992010-10-04 21:36:35 +02007275 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307276 info->attrs[NL80211_ATTR_KEYS],
7277 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007278 if (IS_ERR(connkeys))
7279 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307280
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007281 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7282 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307283 kfree(connkeys);
7284 return -EINVAL;
7285 }
Johannes Berg4c476992010-10-04 21:36:35 +02007286 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007287
Antonio Quartulli267335d2012-01-31 20:25:47 +01007288 ibss.control_port =
7289 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7290
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007291 ibss.userspace_handles_dfs =
7292 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7293
Johannes Berg4c476992010-10-04 21:36:35 +02007294 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007295 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007296 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007297 return err;
7298}
7299
7300static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7301{
Johannes Berg4c476992010-10-04 21:36:35 +02007302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7303 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007304
Johannes Berg4c476992010-10-04 21:36:35 +02007305 if (!rdev->ops->leave_ibss)
7306 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007307
Johannes Berg4c476992010-10-04 21:36:35 +02007308 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7309 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007310
Johannes Berg4c476992010-10-04 21:36:35 +02007311 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007312}
7313
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007314static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7315{
7316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7317 struct net_device *dev = info->user_ptr[1];
7318 int mcast_rate[IEEE80211_NUM_BANDS];
7319 u32 nla_rate;
7320 int err;
7321
7322 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7323 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7324 return -EOPNOTSUPP;
7325
7326 if (!rdev->ops->set_mcast_rate)
7327 return -EOPNOTSUPP;
7328
7329 memset(mcast_rate, 0, sizeof(mcast_rate));
7330
7331 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7332 return -EINVAL;
7333
7334 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7335 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7336 return -EINVAL;
7337
7338 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7339
7340 return err;
7341}
7342
Johannes Bergad7e7182013-11-13 13:37:47 +01007343static struct sk_buff *
7344__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7345 int approxlen, u32 portid, u32 seq,
7346 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007347 enum nl80211_attrs attr,
7348 const struct nl80211_vendor_cmd_info *info,
7349 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007350{
7351 struct sk_buff *skb;
7352 void *hdr;
7353 struct nlattr *data;
7354
7355 skb = nlmsg_new(approxlen + 100, gfp);
7356 if (!skb)
7357 return NULL;
7358
7359 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7360 if (!hdr) {
7361 kfree_skb(skb);
7362 return NULL;
7363 }
7364
7365 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7366 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007367
7368 if (info) {
7369 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7370 info->vendor_id))
7371 goto nla_put_failure;
7372 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7373 info->subcmd))
7374 goto nla_put_failure;
7375 }
7376
Johannes Bergad7e7182013-11-13 13:37:47 +01007377 data = nla_nest_start(skb, attr);
7378
7379 ((void **)skb->cb)[0] = rdev;
7380 ((void **)skb->cb)[1] = hdr;
7381 ((void **)skb->cb)[2] = data;
7382
7383 return skb;
7384
7385 nla_put_failure:
7386 kfree_skb(skb);
7387 return NULL;
7388}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007389
Johannes Berge03ad6e2014-01-01 17:22:30 +01007390struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7391 enum nl80211_commands cmd,
7392 enum nl80211_attrs attr,
7393 int vendor_event_idx,
7394 int approxlen, gfp_t gfp)
7395{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007396 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007397 const struct nl80211_vendor_cmd_info *info;
7398
7399 switch (cmd) {
7400 case NL80211_CMD_TESTMODE:
7401 if (WARN_ON(vendor_event_idx != -1))
7402 return NULL;
7403 info = NULL;
7404 break;
7405 case NL80211_CMD_VENDOR:
7406 if (WARN_ON(vendor_event_idx < 0 ||
7407 vendor_event_idx >= wiphy->n_vendor_events))
7408 return NULL;
7409 info = &wiphy->vendor_events[vendor_event_idx];
7410 break;
7411 default:
7412 WARN_ON(1);
7413 return NULL;
7414 }
7415
7416 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7417 cmd, attr, info, gfp);
7418}
7419EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7420
7421void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7422{
7423 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7424 void *hdr = ((void **)skb->cb)[1];
7425 struct nlattr *data = ((void **)skb->cb)[2];
7426 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7427
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007428 /* clear CB data for netlink core to own from now on */
7429 memset(skb->cb, 0, sizeof(skb->cb));
7430
Johannes Berge03ad6e2014-01-01 17:22:30 +01007431 nla_nest_end(skb, data);
7432 genlmsg_end(skb, hdr);
7433
7434 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7435 mcgrp = NL80211_MCGRP_VENDOR;
7436
7437 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7438 mcgrp, gfp);
7439}
7440EXPORT_SYMBOL(__cfg80211_send_event_skb);
7441
Johannes Bergaff89a92009-07-01 21:26:51 +02007442#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007443static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7444{
Johannes Berg4c476992010-10-04 21:36:35 +02007445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007446 struct wireless_dev *wdev =
7447 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007448 int err;
7449
David Spinadelfc73f112013-07-31 18:04:15 +03007450 if (!rdev->ops->testmode_cmd)
7451 return -EOPNOTSUPP;
7452
7453 if (IS_ERR(wdev)) {
7454 err = PTR_ERR(wdev);
7455 if (err != -EINVAL)
7456 return err;
7457 wdev = NULL;
7458 } else if (wdev->wiphy != &rdev->wiphy) {
7459 return -EINVAL;
7460 }
7461
Johannes Bergaff89a92009-07-01 21:26:51 +02007462 if (!info->attrs[NL80211_ATTR_TESTDATA])
7463 return -EINVAL;
7464
Johannes Bergad7e7182013-11-13 13:37:47 +01007465 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007466 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007467 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7468 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007469 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007470
Johannes Bergaff89a92009-07-01 21:26:51 +02007471 return err;
7472}
7473
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007474static int nl80211_testmode_dump(struct sk_buff *skb,
7475 struct netlink_callback *cb)
7476{
Johannes Berg00918d32011-12-13 17:22:05 +01007477 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007478 int err;
7479 long phy_idx;
7480 void *data = NULL;
7481 int data_len = 0;
7482
Johannes Berg5fe231e2013-05-08 21:45:15 +02007483 rtnl_lock();
7484
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007485 if (cb->args[0]) {
7486 /*
7487 * 0 is a valid index, but not valid for args[0],
7488 * so we need to offset by 1.
7489 */
7490 phy_idx = cb->args[0] - 1;
7491 } else {
7492 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7493 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7494 nl80211_policy);
7495 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007496 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007497
Johannes Berg2bd7e352012-06-15 14:23:16 +02007498 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7499 nl80211_fam.attrbuf);
7500 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007501 err = PTR_ERR(rdev);
7502 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007503 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007504 phy_idx = rdev->wiphy_idx;
7505 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007506
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007507 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7508 cb->args[1] =
7509 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7510 }
7511
7512 if (cb->args[1]) {
7513 data = nla_data((void *)cb->args[1]);
7514 data_len = nla_len((void *)cb->args[1]);
7515 }
7516
Johannes Berg00918d32011-12-13 17:22:05 +01007517 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7518 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007519 err = -ENOENT;
7520 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007521 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007522
Johannes Berg00918d32011-12-13 17:22:05 +01007523 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007524 err = -EOPNOTSUPP;
7525 goto out_err;
7526 }
7527
7528 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007529 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007530 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7531 NL80211_CMD_TESTMODE);
7532 struct nlattr *tmdata;
7533
Dan Carpentercb35fba2013-08-14 14:50:01 +03007534 if (!hdr)
7535 break;
7536
David S. Miller9360ffd2012-03-29 04:41:26 -04007537 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007538 genlmsg_cancel(skb, hdr);
7539 break;
7540 }
7541
7542 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7543 if (!tmdata) {
7544 genlmsg_cancel(skb, hdr);
7545 break;
7546 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007547 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007548 nla_nest_end(skb, tmdata);
7549
7550 if (err == -ENOBUFS || err == -ENOENT) {
7551 genlmsg_cancel(skb, hdr);
7552 break;
7553 } else if (err) {
7554 genlmsg_cancel(skb, hdr);
7555 goto out_err;
7556 }
7557
7558 genlmsg_end(skb, hdr);
7559 }
7560
7561 err = skb->len;
7562 /* see above */
7563 cb->args[0] = phy_idx + 1;
7564 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007565 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007566 return err;
7567}
Johannes Bergaff89a92009-07-01 21:26:51 +02007568#endif
7569
Samuel Ortizb23aa672009-07-01 21:26:54 +02007570static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7571{
Johannes Berg4c476992010-10-04 21:36:35 +02007572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7573 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007574 struct cfg80211_connect_params connect;
7575 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007576 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007577 int err;
7578
7579 memset(&connect, 0, sizeof(connect));
7580
7581 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7582 return -EINVAL;
7583
7584 if (!info->attrs[NL80211_ATTR_SSID] ||
7585 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7586 return -EINVAL;
7587
7588 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7589 connect.auth_type =
7590 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007591 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7592 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007593 return -EINVAL;
7594 } else
7595 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7596
7597 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7598
Johannes Bergc0692b82010-08-27 14:26:53 +03007599 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007600 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007601 if (err)
7602 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007603
Johannes Berg074ac8d2010-09-16 14:58:22 +02007604 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007605 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7606 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007607
Johannes Berg79c97e92009-07-07 03:56:12 +02007608 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007609
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307610 connect.bg_scan_period = -1;
7611 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7612 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7613 connect.bg_scan_period =
7614 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7615 }
7616
Samuel Ortizb23aa672009-07-01 21:26:54 +02007617 if (info->attrs[NL80211_ATTR_MAC])
7618 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007619 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7620 connect.bssid_hint =
7621 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007622 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7623 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7624
7625 if (info->attrs[NL80211_ATTR_IE]) {
7626 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7627 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7628 }
7629
Jouni Malinencee00a92013-01-15 17:15:57 +02007630 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7631 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7632 if (connect.mfp != NL80211_MFP_REQUIRED &&
7633 connect.mfp != NL80211_MFP_NO)
7634 return -EINVAL;
7635 } else {
7636 connect.mfp = NL80211_MFP_NO;
7637 }
7638
Samuel Ortizb23aa672009-07-01 21:26:54 +02007639 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007640 connect.channel = nl80211_get_valid_chan(
7641 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7642 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007643 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007644 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007645 connect.channel_hint = nl80211_get_valid_chan(
7646 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7647 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007648 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007649 }
7650
Johannes Bergfffd0932009-07-08 14:22:54 +02007651 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7652 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307653 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007654 if (IS_ERR(connkeys))
7655 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007656 }
7657
Ben Greear7e7c8922011-11-18 11:31:59 -08007658 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7659 connect.flags |= ASSOC_REQ_DISABLE_HT;
7660
7661 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7662 memcpy(&connect.ht_capa_mask,
7663 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7664 sizeof(connect.ht_capa_mask));
7665
7666 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007667 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007668 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007669 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007670 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007671 memcpy(&connect.ht_capa,
7672 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7673 sizeof(connect.ht_capa));
7674 }
7675
Johannes Bergee2aca32013-02-21 17:36:01 +01007676 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7677 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7678
7679 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7680 memcpy(&connect.vht_capa_mask,
7681 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7682 sizeof(connect.vht_capa_mask));
7683
7684 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7685 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007686 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007687 return -EINVAL;
7688 }
7689 memcpy(&connect.vht_capa,
7690 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7691 sizeof(connect.vht_capa));
7692 }
7693
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007694 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7695 if (!(rdev->wiphy.features &
7696 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7697 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7698 return -EINVAL;
7699 connect.flags |= ASSOC_REQ_USE_RRM;
7700 }
7701
Johannes Berg83739b02013-05-15 17:44:01 +02007702 wdev_lock(dev->ieee80211_ptr);
7703 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7704 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007705 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007706 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007707 return err;
7708}
7709
7710static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7711{
Johannes Berg4c476992010-10-04 21:36:35 +02007712 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7713 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007714 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007715 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007716
7717 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7718 reason = WLAN_REASON_DEAUTH_LEAVING;
7719 else
7720 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7721
7722 if (reason == 0)
7723 return -EINVAL;
7724
Johannes Berg074ac8d2010-09-16 14:58:22 +02007725 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007726 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7727 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007728
Johannes Berg83739b02013-05-15 17:44:01 +02007729 wdev_lock(dev->ieee80211_ptr);
7730 ret = cfg80211_disconnect(rdev, dev, reason, true);
7731 wdev_unlock(dev->ieee80211_ptr);
7732 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007733}
7734
Johannes Berg463d0182009-07-14 00:33:35 +02007735static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7736{
Johannes Berg4c476992010-10-04 21:36:35 +02007737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007738 struct net *net;
7739 int err;
7740 u32 pid;
7741
7742 if (!info->attrs[NL80211_ATTR_PID])
7743 return -EINVAL;
7744
7745 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7746
Johannes Berg463d0182009-07-14 00:33:35 +02007747 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007748 if (IS_ERR(net))
7749 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007750
7751 err = 0;
7752
7753 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007754 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7755 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007756
Johannes Berg463d0182009-07-14 00:33:35 +02007757 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007758 return err;
7759}
7760
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007761static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7762{
Johannes Berg4c476992010-10-04 21:36:35 +02007763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007764 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7765 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007766 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007767 struct cfg80211_pmksa pmksa;
7768
7769 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7770
7771 if (!info->attrs[NL80211_ATTR_MAC])
7772 return -EINVAL;
7773
7774 if (!info->attrs[NL80211_ATTR_PMKID])
7775 return -EINVAL;
7776
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007777 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7778 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7779
Johannes Berg074ac8d2010-09-16 14:58:22 +02007780 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007781 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7782 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007783
7784 switch (info->genlhdr->cmd) {
7785 case NL80211_CMD_SET_PMKSA:
7786 rdev_ops = rdev->ops->set_pmksa;
7787 break;
7788 case NL80211_CMD_DEL_PMKSA:
7789 rdev_ops = rdev->ops->del_pmksa;
7790 break;
7791 default:
7792 WARN_ON(1);
7793 break;
7794 }
7795
Johannes Berg4c476992010-10-04 21:36:35 +02007796 if (!rdev_ops)
7797 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007798
Johannes Berg4c476992010-10-04 21:36:35 +02007799 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007800}
7801
7802static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7803{
Johannes Berg4c476992010-10-04 21:36:35 +02007804 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7805 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007806
Johannes Berg074ac8d2010-09-16 14:58:22 +02007807 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007808 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7809 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007810
Johannes Berg4c476992010-10-04 21:36:35 +02007811 if (!rdev->ops->flush_pmksa)
7812 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007813
Hila Gonene35e4d22012-06-27 17:19:42 +03007814 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007815}
7816
Arik Nemtsov109086c2011-09-28 14:12:50 +03007817static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7818{
7819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7820 struct net_device *dev = info->user_ptr[1];
7821 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307822 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007823 u16 status_code;
7824 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007825 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007826
7827 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7828 !rdev->ops->tdls_mgmt)
7829 return -EOPNOTSUPP;
7830
7831 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7832 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7833 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7834 !info->attrs[NL80211_ATTR_IE] ||
7835 !info->attrs[NL80211_ATTR_MAC])
7836 return -EINVAL;
7837
7838 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7839 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7840 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7841 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007842 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307843 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7844 peer_capability =
7845 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007846
Hila Gonene35e4d22012-06-27 17:19:42 +03007847 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307848 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007849 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007850 nla_data(info->attrs[NL80211_ATTR_IE]),
7851 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007852}
7853
7854static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7855{
7856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7857 struct net_device *dev = info->user_ptr[1];
7858 enum nl80211_tdls_operation operation;
7859 u8 *peer;
7860
7861 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7862 !rdev->ops->tdls_oper)
7863 return -EOPNOTSUPP;
7864
7865 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7866 !info->attrs[NL80211_ATTR_MAC])
7867 return -EINVAL;
7868
7869 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7870 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7871
Hila Gonene35e4d22012-06-27 17:19:42 +03007872 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007873}
7874
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007875static int nl80211_remain_on_channel(struct sk_buff *skb,
7876 struct genl_info *info)
7877{
Johannes Berg4c476992010-10-04 21:36:35 +02007878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007879 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007880 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007881 struct sk_buff *msg;
7882 void *hdr;
7883 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007884 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007885 int err;
7886
7887 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7888 !info->attrs[NL80211_ATTR_DURATION])
7889 return -EINVAL;
7890
7891 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7892
Johannes Berg7c4ef712011-11-18 15:33:48 +01007893 if (!rdev->ops->remain_on_channel ||
7894 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007895 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007896
Johannes Bergebf348f2012-06-01 12:50:54 +02007897 /*
7898 * We should be on that channel for at least a minimum amount of
7899 * time (10ms) but no longer than the driver supports.
7900 */
7901 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7902 duration > rdev->wiphy.max_remain_on_channel_duration)
7903 return -EINVAL;
7904
Johannes Berg683b6d32012-11-08 21:25:48 +01007905 err = nl80211_parse_chandef(rdev, info, &chandef);
7906 if (err)
7907 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007908
7909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007910 if (!msg)
7911 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007912
Eric W. Biederman15e47302012-09-07 20:12:54 +00007913 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007914 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007915 if (!hdr) {
7916 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007917 goto free_msg;
7918 }
7919
Johannes Berg683b6d32012-11-08 21:25:48 +01007920 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7921 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007922
7923 if (err)
7924 goto free_msg;
7925
David S. Miller9360ffd2012-03-29 04:41:26 -04007926 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7927 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007928
7929 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007930
7931 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007932
7933 nla_put_failure:
7934 err = -ENOBUFS;
7935 free_msg:
7936 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007937 return err;
7938}
7939
7940static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7941 struct genl_info *info)
7942{
Johannes Berg4c476992010-10-04 21:36:35 +02007943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007944 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007945 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007946
7947 if (!info->attrs[NL80211_ATTR_COOKIE])
7948 return -EINVAL;
7949
Johannes Berg4c476992010-10-04 21:36:35 +02007950 if (!rdev->ops->cancel_remain_on_channel)
7951 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007952
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007953 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7954
Hila Gonene35e4d22012-06-27 17:19:42 +03007955 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007956}
7957
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007958static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7959 u8 *rates, u8 rates_len)
7960{
7961 u8 i;
7962 u32 mask = 0;
7963
7964 for (i = 0; i < rates_len; i++) {
7965 int rate = (rates[i] & 0x7f) * 5;
7966 int ridx;
7967 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7968 struct ieee80211_rate *srate =
7969 &sband->bitrates[ridx];
7970 if (rate == srate->bitrate) {
7971 mask |= 1 << ridx;
7972 break;
7973 }
7974 }
7975 if (ridx == sband->n_bitrates)
7976 return 0; /* rate not found */
7977 }
7978
7979 return mask;
7980}
7981
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007982static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7983 u8 *rates, u8 rates_len,
7984 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7985{
7986 u8 i;
7987
7988 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7989
7990 for (i = 0; i < rates_len; i++) {
7991 int ridx, rbit;
7992
7993 ridx = rates[i] / 8;
7994 rbit = BIT(rates[i] % 8);
7995
7996 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007997 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007998 return false;
7999
8000 /* check availability */
8001 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8002 mcs[ridx] |= rbit;
8003 else
8004 return false;
8005 }
8006
8007 return true;
8008}
8009
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008010static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8011{
8012 u16 mcs_mask = 0;
8013
8014 switch (vht_mcs_map) {
8015 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8016 break;
8017 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8018 mcs_mask = 0x00FF;
8019 break;
8020 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8021 mcs_mask = 0x01FF;
8022 break;
8023 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8024 mcs_mask = 0x03FF;
8025 break;
8026 default:
8027 break;
8028 }
8029
8030 return mcs_mask;
8031}
8032
8033static void vht_build_mcs_mask(u16 vht_mcs_map,
8034 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8035{
8036 u8 nss;
8037
8038 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8039 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8040 vht_mcs_map >>= 2;
8041 }
8042}
8043
8044static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8045 struct nl80211_txrate_vht *txrate,
8046 u16 mcs[NL80211_VHT_NSS_MAX])
8047{
8048 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8049 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8050 u8 i;
8051
8052 if (!sband->vht_cap.vht_supported)
8053 return false;
8054
8055 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8056
8057 /* Build vht_mcs_mask from VHT capabilities */
8058 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8059
8060 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8061 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8062 mcs[i] = txrate->mcs[i];
8063 else
8064 return false;
8065 }
8066
8067 return true;
8068}
8069
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008070static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008071 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8072 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008073 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8074 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008075 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008076 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008077};
8078
8079static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8080 struct genl_info *info)
8081{
8082 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008083 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008084 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008085 int rem, i;
8086 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008087 struct nlattr *tx_rates;
8088 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008089 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008090
Johannes Berg4c476992010-10-04 21:36:35 +02008091 if (!rdev->ops->set_bitrate_mask)
8092 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008093
8094 memset(&mask, 0, sizeof(mask));
8095 /* Default to all rates enabled */
8096 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8097 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008098
8099 if (!sband)
8100 continue;
8101
8102 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008103 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008104 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008105 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008106
8107 if (!sband->vht_cap.vht_supported)
8108 continue;
8109
8110 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8111 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008112 }
8113
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008114 /* if no rates are given set it back to the defaults */
8115 if (!info->attrs[NL80211_ATTR_TX_RATES])
8116 goto out;
8117
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008118 /*
8119 * The nested attribute uses enum nl80211_band as the index. This maps
8120 * directly to the enum ieee80211_band values used in cfg80211.
8121 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008122 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008123 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008124 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008125 int err;
8126
Johannes Berg4c476992010-10-04 21:36:35 +02008127 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8128 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008129 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008130 if (sband == NULL)
8131 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008132 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8133 nla_len(tx_rates), nl80211_txattr_policy);
8134 if (err)
8135 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008136 if (tb[NL80211_TXRATE_LEGACY]) {
8137 mask.control[band].legacy = rateset_to_mask(
8138 sband,
8139 nla_data(tb[NL80211_TXRATE_LEGACY]),
8140 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308141 if ((mask.control[band].legacy == 0) &&
8142 nla_len(tb[NL80211_TXRATE_LEGACY]))
8143 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008144 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008145 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008146 if (!ht_rateset_to_mask(
8147 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008148 nla_data(tb[NL80211_TXRATE_HT]),
8149 nla_len(tb[NL80211_TXRATE_HT]),
8150 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008151 return -EINVAL;
8152 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008153 if (tb[NL80211_TXRATE_VHT]) {
8154 if (!vht_set_mcs_mask(
8155 sband,
8156 nla_data(tb[NL80211_TXRATE_VHT]),
8157 mask.control[band].vht_mcs))
8158 return -EINVAL;
8159 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008160 if (tb[NL80211_TXRATE_GI]) {
8161 mask.control[band].gi =
8162 nla_get_u8(tb[NL80211_TXRATE_GI]);
8163 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8164 return -EINVAL;
8165 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008166
8167 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008168 /* don't allow empty legacy rates if HT or VHT
8169 * are not even supported.
8170 */
8171 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8172 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008173 return -EINVAL;
8174
8175 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008176 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008177 goto out;
8178
8179 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8180 if (mask.control[band].vht_mcs[i])
8181 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008182
8183 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008184 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008185 }
8186 }
8187
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008188out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008189 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008190}
8191
Johannes Berg2e161f72010-08-12 15:38:38 +02008192static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008193{
Johannes Berg4c476992010-10-04 21:36:35 +02008194 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008195 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008196 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008197
8198 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8199 return -EINVAL;
8200
Johannes Berg2e161f72010-08-12 15:38:38 +02008201 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8202 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008203
Johannes Berg71bbc992012-06-15 15:30:18 +02008204 switch (wdev->iftype) {
8205 case NL80211_IFTYPE_STATION:
8206 case NL80211_IFTYPE_ADHOC:
8207 case NL80211_IFTYPE_P2P_CLIENT:
8208 case NL80211_IFTYPE_AP:
8209 case NL80211_IFTYPE_AP_VLAN:
8210 case NL80211_IFTYPE_MESH_POINT:
8211 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008212 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008213 break;
8214 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008215 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008216 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008217
8218 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008219 if (!rdev->ops->mgmt_tx)
8220 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008221
Eric W. Biederman15e47302012-09-07 20:12:54 +00008222 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008223 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8224 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008225}
8226
Johannes Berg2e161f72010-08-12 15:38:38 +02008227static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008228{
Johannes Berg4c476992010-10-04 21:36:35 +02008229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008230 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008231 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008232 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008233 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008234 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008235 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008236 struct cfg80211_mgmt_tx_params params = {
8237 .dont_wait_for_ack =
8238 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8239 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008240
Johannes Berg683b6d32012-11-08 21:25:48 +01008241 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008242 return -EINVAL;
8243
Johannes Berg4c476992010-10-04 21:36:35 +02008244 if (!rdev->ops->mgmt_tx)
8245 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008246
Johannes Berg71bbc992012-06-15 15:30:18 +02008247 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008248 case NL80211_IFTYPE_P2P_DEVICE:
8249 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8250 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008251 case NL80211_IFTYPE_STATION:
8252 case NL80211_IFTYPE_ADHOC:
8253 case NL80211_IFTYPE_P2P_CLIENT:
8254 case NL80211_IFTYPE_AP:
8255 case NL80211_IFTYPE_AP_VLAN:
8256 case NL80211_IFTYPE_MESH_POINT:
8257 case NL80211_IFTYPE_P2P_GO:
8258 break;
8259 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008260 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008261 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008262
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008263 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008264 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008265 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008266 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008267
8268 /*
8269 * We should wait on the channel for at least a minimum amount
8270 * of time (10ms) but no longer than the driver supports.
8271 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008272 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8273 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008274 return -EINVAL;
8275
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008276 }
8277
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008278 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008279
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008280 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008281 return -EINVAL;
8282
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008283 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308284
Antonio Quartulliea141b752013-06-11 14:20:03 +02008285 /* get the channel if any has been specified, otherwise pass NULL to
8286 * the driver. The latter will use the current one
8287 */
8288 chandef.chan = NULL;
8289 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8290 err = nl80211_parse_chandef(rdev, info, &chandef);
8291 if (err)
8292 return err;
8293 }
8294
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008295 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008296 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008297
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008298 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8299 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8300
8301 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8302 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8303 int i;
8304
8305 if (len % sizeof(u16))
8306 return -EINVAL;
8307
8308 params.n_csa_offsets = len / sizeof(u16);
8309 params.csa_offsets =
8310 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8311
8312 /* check that all the offsets fit the frame */
8313 for (i = 0; i < params.n_csa_offsets; i++) {
8314 if (params.csa_offsets[i] >= params.len)
8315 return -EINVAL;
8316 }
8317 }
8318
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008319 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008320 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8321 if (!msg)
8322 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008323
Eric W. Biederman15e47302012-09-07 20:12:54 +00008324 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008325 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008326 if (!hdr) {
8327 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008328 goto free_msg;
8329 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008330 }
Johannes Berge247bd902011-11-04 11:18:21 +01008331
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008332 params.chan = chandef.chan;
8333 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008334 if (err)
8335 goto free_msg;
8336
Johannes Berge247bd902011-11-04 11:18:21 +01008337 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008338 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8339 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008340
Johannes Berge247bd902011-11-04 11:18:21 +01008341 genlmsg_end(msg, hdr);
8342 return genlmsg_reply(msg, info);
8343 }
8344
8345 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008346
8347 nla_put_failure:
8348 err = -ENOBUFS;
8349 free_msg:
8350 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008351 return err;
8352}
8353
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008354static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8355{
8356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008357 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008358 u64 cookie;
8359
8360 if (!info->attrs[NL80211_ATTR_COOKIE])
8361 return -EINVAL;
8362
8363 if (!rdev->ops->mgmt_tx_cancel_wait)
8364 return -EOPNOTSUPP;
8365
Johannes Berg71bbc992012-06-15 15:30:18 +02008366 switch (wdev->iftype) {
8367 case NL80211_IFTYPE_STATION:
8368 case NL80211_IFTYPE_ADHOC:
8369 case NL80211_IFTYPE_P2P_CLIENT:
8370 case NL80211_IFTYPE_AP:
8371 case NL80211_IFTYPE_AP_VLAN:
8372 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008373 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008374 break;
8375 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008376 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008377 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008378
8379 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8380
Hila Gonene35e4d22012-06-27 17:19:42 +03008381 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008382}
8383
Kalle Valoffb9eb32010-02-17 17:58:10 +02008384static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8385{
Johannes Berg4c476992010-10-04 21:36:35 +02008386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008387 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 u8 ps_state;
8390 bool state;
8391 int err;
8392
Johannes Berg4c476992010-10-04 21:36:35 +02008393 if (!info->attrs[NL80211_ATTR_PS_STATE])
8394 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008395
8396 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8397
Johannes Berg4c476992010-10-04 21:36:35 +02008398 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8399 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008400
8401 wdev = dev->ieee80211_ptr;
8402
Johannes Berg4c476992010-10-04 21:36:35 +02008403 if (!rdev->ops->set_power_mgmt)
8404 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008405
8406 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8407
8408 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008409 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008410
Hila Gonene35e4d22012-06-27 17:19:42 +03008411 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008412 if (!err)
8413 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008414 return err;
8415}
8416
8417static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8418{
Johannes Berg4c476992010-10-04 21:36:35 +02008419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008420 enum nl80211_ps_state ps_state;
8421 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008422 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008423 struct sk_buff *msg;
8424 void *hdr;
8425 int err;
8426
Kalle Valoffb9eb32010-02-17 17:58:10 +02008427 wdev = dev->ieee80211_ptr;
8428
Johannes Berg4c476992010-10-04 21:36:35 +02008429 if (!rdev->ops->set_power_mgmt)
8430 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008431
8432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008433 if (!msg)
8434 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008435
Eric W. Biederman15e47302012-09-07 20:12:54 +00008436 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008437 NL80211_CMD_GET_POWER_SAVE);
8438 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008439 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008440 goto free_msg;
8441 }
8442
8443 if (wdev->ps)
8444 ps_state = NL80211_PS_ENABLED;
8445 else
8446 ps_state = NL80211_PS_DISABLED;
8447
David S. Miller9360ffd2012-03-29 04:41:26 -04008448 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8449 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008450
8451 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008452 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008453
Johannes Berg4c476992010-10-04 21:36:35 +02008454 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008455 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008456 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008457 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008458 return err;
8459}
8460
Johannes Berg94e860f2014-01-20 23:58:15 +01008461static const struct nla_policy
8462nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008463 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8464 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8465 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008466 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8467 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8468 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008469};
8470
Thomas Pedersen84f10702012-07-12 16:17:33 -07008471static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008472 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008473{
8474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008475 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008476 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008477
Johannes Bergd9d8b012012-11-26 12:51:52 +01008478 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008479 return -EINVAL;
8480
Thomas Pedersen84f10702012-07-12 16:17:33 -07008481 if (!rdev->ops->set_cqm_txe_config)
8482 return -EOPNOTSUPP;
8483
8484 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8485 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8486 return -EOPNOTSUPP;
8487
Hila Gonene35e4d22012-06-27 17:19:42 +03008488 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008489}
8490
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008491static int nl80211_set_cqm_rssi(struct genl_info *info,
8492 s32 threshold, u32 hysteresis)
8493{
Johannes Berg4c476992010-10-04 21:36:35 +02008494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008495 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008496 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008497
8498 if (threshold > 0)
8499 return -EINVAL;
8500
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008501 /* disabling - hysteresis should also be zero then */
8502 if (threshold == 0)
8503 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008504
Johannes Berg4c476992010-10-04 21:36:35 +02008505 if (!rdev->ops->set_cqm_rssi_config)
8506 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008507
Johannes Berg074ac8d2010-09-16 14:58:22 +02008508 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008509 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8510 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008511
Hila Gonene35e4d22012-06-27 17:19:42 +03008512 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008513}
8514
8515static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8516{
8517 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8518 struct nlattr *cqm;
8519 int err;
8520
8521 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008522 if (!cqm)
8523 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008524
8525 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8526 nl80211_attr_cqm_policy);
8527 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008528 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008529
8530 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8531 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008532 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8533 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008534
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008535 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8536 }
8537
8538 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8539 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8540 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8541 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8542 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8543 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8544
8545 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8546 }
8547
8548 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008549}
8550
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008551static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8552{
8553 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8554 struct net_device *dev = info->user_ptr[1];
8555 struct ocb_setup setup = {};
8556 int err;
8557
8558 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8559 if (err)
8560 return err;
8561
8562 return cfg80211_join_ocb(rdev, dev, &setup);
8563}
8564
8565static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8566{
8567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8568 struct net_device *dev = info->user_ptr[1];
8569
8570 return cfg80211_leave_ocb(rdev, dev);
8571}
8572
Johannes Berg29cbe682010-12-03 09:20:44 +01008573static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8574{
8575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8576 struct net_device *dev = info->user_ptr[1];
8577 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008578 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008579 int err;
8580
8581 /* start with default */
8582 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008583 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008584
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008585 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008586 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008587 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008588 if (err)
8589 return err;
8590 }
8591
8592 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8593 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8594 return -EINVAL;
8595
Javier Cardonac80d5452010-12-16 17:37:49 -08008596 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8597 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8598
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008599 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8600 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8601 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8602 return -EINVAL;
8603
Marco Porsch9bdbf042013-01-07 16:04:51 +01008604 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8605 setup.beacon_interval =
8606 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8607 if (setup.beacon_interval < 10 ||
8608 setup.beacon_interval > 10000)
8609 return -EINVAL;
8610 }
8611
8612 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8613 setup.dtim_period =
8614 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8615 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8616 return -EINVAL;
8617 }
8618
Javier Cardonac80d5452010-12-16 17:37:49 -08008619 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8620 /* parse additional setup parameters if given */
8621 err = nl80211_parse_mesh_setup(info, &setup);
8622 if (err)
8623 return err;
8624 }
8625
Thomas Pedersend37bb182013-03-04 13:06:13 -08008626 if (setup.user_mpm)
8627 cfg.auto_open_plinks = false;
8628
Johannes Bergcc1d2802012-05-16 23:50:20 +02008629 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008630 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8631 if (err)
8632 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008633 } else {
8634 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008635 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008636 }
8637
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008638 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8639 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8640 int n_rates =
8641 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8642 struct ieee80211_supported_band *sband;
8643
8644 if (!setup.chandef.chan)
8645 return -EINVAL;
8646
8647 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8648
8649 err = ieee80211_get_ratemask(sband, rates, n_rates,
8650 &setup.basic_rates);
8651 if (err)
8652 return err;
8653 }
8654
Javier Cardonac80d5452010-12-16 17:37:49 -08008655 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008656}
8657
8658static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8659{
8660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8661 struct net_device *dev = info->user_ptr[1];
8662
8663 return cfg80211_leave_mesh(rdev, dev);
8664}
8665
Johannes Bergdfb89c52012-06-27 09:23:48 +02008666#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008667static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8668 struct cfg80211_registered_device *rdev)
8669{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008670 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008671 struct nlattr *nl_pats, *nl_pat;
8672 int i, pat_len;
8673
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008674 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008675 return 0;
8676
8677 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8678 if (!nl_pats)
8679 return -ENOBUFS;
8680
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008681 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008682 nl_pat = nla_nest_start(msg, i + 1);
8683 if (!nl_pat)
8684 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008685 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008686 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008687 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008688 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8689 wowlan->patterns[i].pattern) ||
8690 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008691 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008692 return -ENOBUFS;
8693 nla_nest_end(msg, nl_pat);
8694 }
8695 nla_nest_end(msg, nl_pats);
8696
8697 return 0;
8698}
8699
Johannes Berg2a0e0472013-01-23 22:57:40 +01008700static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8701 struct cfg80211_wowlan_tcp *tcp)
8702{
8703 struct nlattr *nl_tcp;
8704
8705 if (!tcp)
8706 return 0;
8707
8708 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8709 if (!nl_tcp)
8710 return -ENOBUFS;
8711
8712 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8713 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8714 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8715 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8716 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8717 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8718 tcp->payload_len, tcp->payload) ||
8719 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8720 tcp->data_interval) ||
8721 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8722 tcp->wake_len, tcp->wake_data) ||
8723 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8724 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8725 return -ENOBUFS;
8726
8727 if (tcp->payload_seq.len &&
8728 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8729 sizeof(tcp->payload_seq), &tcp->payload_seq))
8730 return -ENOBUFS;
8731
8732 if (tcp->payload_tok.len &&
8733 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8734 sizeof(tcp->payload_tok) + tcp->tokens_size,
8735 &tcp->payload_tok))
8736 return -ENOBUFS;
8737
Johannes Berge248ad32013-05-16 10:24:28 +02008738 nla_nest_end(msg, nl_tcp);
8739
Johannes Berg2a0e0472013-01-23 22:57:40 +01008740 return 0;
8741}
8742
Johannes Bergff1b6e62011-05-04 15:37:28 +02008743static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8744{
8745 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8746 struct sk_buff *msg;
8747 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008748 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008749
Johannes Berg964dc9e2013-06-03 17:25:34 +02008750 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008751 return -EOPNOTSUPP;
8752
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008753 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008754 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008755 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8756 rdev->wiphy.wowlan_config->tcp->payload_len +
8757 rdev->wiphy.wowlan_config->tcp->wake_len +
8758 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008759 }
8760
8761 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008762 if (!msg)
8763 return -ENOMEM;
8764
Eric W. Biederman15e47302012-09-07 20:12:54 +00008765 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008766 NL80211_CMD_GET_WOWLAN);
8767 if (!hdr)
8768 goto nla_put_failure;
8769
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008770 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008771 struct nlattr *nl_wowlan;
8772
8773 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8774 if (!nl_wowlan)
8775 goto nla_put_failure;
8776
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008777 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008778 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008779 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008780 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008781 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008782 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008783 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008784 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008785 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008786 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008787 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008788 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008789 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008790 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8791 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008792
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008793 if (nl80211_send_wowlan_patterns(msg, rdev))
8794 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008795
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008796 if (nl80211_send_wowlan_tcp(msg,
8797 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008798 goto nla_put_failure;
8799
Johannes Bergff1b6e62011-05-04 15:37:28 +02008800 nla_nest_end(msg, nl_wowlan);
8801 }
8802
8803 genlmsg_end(msg, hdr);
8804 return genlmsg_reply(msg, info);
8805
8806nla_put_failure:
8807 nlmsg_free(msg);
8808 return -ENOBUFS;
8809}
8810
Johannes Berg2a0e0472013-01-23 22:57:40 +01008811static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8812 struct nlattr *attr,
8813 struct cfg80211_wowlan *trig)
8814{
8815 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8816 struct cfg80211_wowlan_tcp *cfg;
8817 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8818 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8819 u32 size;
8820 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8821 int err, port;
8822
Johannes Berg964dc9e2013-06-03 17:25:34 +02008823 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008824 return -EINVAL;
8825
8826 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8827 nla_data(attr), nla_len(attr),
8828 nl80211_wowlan_tcp_policy);
8829 if (err)
8830 return err;
8831
8832 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8833 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8834 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8835 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8836 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8837 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8838 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8839 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8840 return -EINVAL;
8841
8842 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008843 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008844 return -EINVAL;
8845
8846 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008847 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008848 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008849 return -EINVAL;
8850
8851 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008852 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008853 return -EINVAL;
8854
8855 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8856 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8857 return -EINVAL;
8858
8859 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8860 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8861
8862 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8863 tokens_size = tokln - sizeof(*tok);
8864
8865 if (!tok->len || tokens_size % tok->len)
8866 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008867 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008868 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008869 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008870 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008871 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008872 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008873 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008874 return -EINVAL;
8875 if (tok->offset + tok->len > data_size)
8876 return -EINVAL;
8877 }
8878
8879 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8880 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008881 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008882 return -EINVAL;
8883 if (seq->len == 0 || seq->len > 4)
8884 return -EINVAL;
8885 if (seq->len + seq->offset > data_size)
8886 return -EINVAL;
8887 }
8888
8889 size = sizeof(*cfg);
8890 size += data_size;
8891 size += wake_size + wake_mask_size;
8892 size += tokens_size;
8893
8894 cfg = kzalloc(size, GFP_KERNEL);
8895 if (!cfg)
8896 return -ENOMEM;
8897 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8898 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8899 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8900 ETH_ALEN);
8901 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8902 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8903 else
8904 port = 0;
8905#ifdef CONFIG_INET
8906 /* allocate a socket and port for it and use it */
8907 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8908 IPPROTO_TCP, &cfg->sock, 1);
8909 if (err) {
8910 kfree(cfg);
8911 return err;
8912 }
8913 if (inet_csk_get_port(cfg->sock->sk, port)) {
8914 sock_release(cfg->sock);
8915 kfree(cfg);
8916 return -EADDRINUSE;
8917 }
8918 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8919#else
8920 if (!port) {
8921 kfree(cfg);
8922 return -EINVAL;
8923 }
8924 cfg->src_port = port;
8925#endif
8926
8927 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8928 cfg->payload_len = data_size;
8929 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8930 memcpy((void *)cfg->payload,
8931 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8932 data_size);
8933 if (seq)
8934 cfg->payload_seq = *seq;
8935 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8936 cfg->wake_len = wake_size;
8937 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8938 memcpy((void *)cfg->wake_data,
8939 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8940 wake_size);
8941 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8942 data_size + wake_size;
8943 memcpy((void *)cfg->wake_mask,
8944 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8945 wake_mask_size);
8946 if (tok) {
8947 cfg->tokens_size = tokens_size;
8948 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8949 }
8950
8951 trig->tcp = cfg;
8952
8953 return 0;
8954}
8955
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008956static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
8957 const struct wiphy_wowlan_support *wowlan,
8958 struct nlattr *attr,
8959 struct cfg80211_wowlan *trig)
8960{
8961 struct nlattr **tb;
8962 int err;
8963
8964 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
8965 if (!tb)
8966 return -ENOMEM;
8967
8968 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
8969 err = -EOPNOTSUPP;
8970 goto out;
8971 }
8972
8973 err = nla_parse(tb, NL80211_ATTR_MAX,
8974 nla_data(attr), nla_len(attr),
8975 nl80211_policy);
8976 if (err)
8977 goto out;
8978
Johannes Bergad2b26a2014-06-12 21:39:05 +02008979 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008980 err = PTR_ERR_OR_ZERO(trig->nd_config);
8981 if (err)
8982 trig->nd_config = NULL;
8983
8984out:
8985 kfree(tb);
8986 return err;
8987}
8988
Johannes Bergff1b6e62011-05-04 15:37:28 +02008989static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8990{
8991 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8992 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008993 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008994 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008995 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008996 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008997 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008998
Johannes Berg964dc9e2013-06-03 17:25:34 +02008999 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009000 return -EOPNOTSUPP;
9001
Johannes Bergae33bd82012-07-12 16:25:02 +02009002 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9003 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009004 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009005 goto set_wakeup;
9006 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009007
9008 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9009 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9010 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9011 nl80211_wowlan_policy);
9012 if (err)
9013 return err;
9014
9015 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9016 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9017 return -EINVAL;
9018 new_triggers.any = true;
9019 }
9020
9021 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9022 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9023 return -EINVAL;
9024 new_triggers.disconnect = true;
9025 }
9026
9027 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9028 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9029 return -EINVAL;
9030 new_triggers.magic_pkt = true;
9031 }
9032
Johannes Berg77dbbb12011-07-13 10:48:55 +02009033 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9034 return -EINVAL;
9035
9036 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9037 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9038 return -EINVAL;
9039 new_triggers.gtk_rekey_failure = true;
9040 }
9041
9042 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9043 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9044 return -EINVAL;
9045 new_triggers.eap_identity_req = true;
9046 }
9047
9048 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9049 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9050 return -EINVAL;
9051 new_triggers.four_way_handshake = true;
9052 }
9053
9054 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9055 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9056 return -EINVAL;
9057 new_triggers.rfkill_release = true;
9058 }
9059
Johannes Bergff1b6e62011-05-04 15:37:28 +02009060 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9061 struct nlattr *pat;
9062 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009063 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009064 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009065
9066 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9067 rem)
9068 n_patterns++;
9069 if (n_patterns > wowlan->n_patterns)
9070 return -EINVAL;
9071
9072 new_triggers.patterns = kcalloc(n_patterns,
9073 sizeof(new_triggers.patterns[0]),
9074 GFP_KERNEL);
9075 if (!new_triggers.patterns)
9076 return -ENOMEM;
9077
9078 new_triggers.n_patterns = n_patterns;
9079 i = 0;
9080
9081 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9082 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009083 u8 *mask_pat;
9084
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009085 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9086 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009087 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009088 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9089 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009090 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009091 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009092 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009093 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009094 goto error;
9095 if (pat_len > wowlan->pattern_max_len ||
9096 pat_len < wowlan->pattern_min_len)
9097 goto error;
9098
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009099 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009100 pkt_offset = 0;
9101 else
9102 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009103 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009104 if (pkt_offset > wowlan->max_pkt_offset)
9105 goto error;
9106 new_triggers.patterns[i].pkt_offset = pkt_offset;
9107
Johannes Berg922bd802014-05-19 17:59:50 +02009108 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9109 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009110 err = -ENOMEM;
9111 goto error;
9112 }
Johannes Berg922bd802014-05-19 17:59:50 +02009113 new_triggers.patterns[i].mask = mask_pat;
9114 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009115 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009116 mask_pat += mask_len;
9117 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009118 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009119 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009120 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009121 pat_len);
9122 i++;
9123 }
9124 }
9125
Johannes Berg2a0e0472013-01-23 22:57:40 +01009126 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
9127 err = nl80211_parse_wowlan_tcp(
9128 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9129 &new_triggers);
9130 if (err)
9131 goto error;
9132 }
9133
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009134 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
9135 err = nl80211_parse_wowlan_nd(
9136 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9137 &new_triggers);
9138 if (err)
9139 goto error;
9140 }
9141
Johannes Bergae33bd82012-07-12 16:25:02 +02009142 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9143 if (!ntrig) {
9144 err = -ENOMEM;
9145 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009146 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009147 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009148 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009149
Johannes Bergae33bd82012-07-12 16:25:02 +02009150 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009151 if (rdev->ops->set_wakeup &&
9152 prev_enabled != !!rdev->wiphy.wowlan_config)
9153 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009154
Johannes Bergff1b6e62011-05-04 15:37:28 +02009155 return 0;
9156 error:
9157 for (i = 0; i < new_triggers.n_patterns; i++)
9158 kfree(new_triggers.patterns[i].mask);
9159 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009160 if (new_triggers.tcp && new_triggers.tcp->sock)
9161 sock_release(new_triggers.tcp->sock);
9162 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009163 return err;
9164}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009165#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009166
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009167static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9168 struct cfg80211_registered_device *rdev)
9169{
9170 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9171 int i, j, pat_len;
9172 struct cfg80211_coalesce_rules *rule;
9173
9174 if (!rdev->coalesce->n_rules)
9175 return 0;
9176
9177 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9178 if (!nl_rules)
9179 return -ENOBUFS;
9180
9181 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9182 nl_rule = nla_nest_start(msg, i + 1);
9183 if (!nl_rule)
9184 return -ENOBUFS;
9185
9186 rule = &rdev->coalesce->rules[i];
9187 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9188 rule->delay))
9189 return -ENOBUFS;
9190
9191 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9192 rule->condition))
9193 return -ENOBUFS;
9194
9195 nl_pats = nla_nest_start(msg,
9196 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9197 if (!nl_pats)
9198 return -ENOBUFS;
9199
9200 for (j = 0; j < rule->n_patterns; j++) {
9201 nl_pat = nla_nest_start(msg, j + 1);
9202 if (!nl_pat)
9203 return -ENOBUFS;
9204 pat_len = rule->patterns[j].pattern_len;
9205 if (nla_put(msg, NL80211_PKTPAT_MASK,
9206 DIV_ROUND_UP(pat_len, 8),
9207 rule->patterns[j].mask) ||
9208 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9209 rule->patterns[j].pattern) ||
9210 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9211 rule->patterns[j].pkt_offset))
9212 return -ENOBUFS;
9213 nla_nest_end(msg, nl_pat);
9214 }
9215 nla_nest_end(msg, nl_pats);
9216 nla_nest_end(msg, nl_rule);
9217 }
9218 nla_nest_end(msg, nl_rules);
9219
9220 return 0;
9221}
9222
9223static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9224{
9225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9226 struct sk_buff *msg;
9227 void *hdr;
9228
9229 if (!rdev->wiphy.coalesce)
9230 return -EOPNOTSUPP;
9231
9232 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9233 if (!msg)
9234 return -ENOMEM;
9235
9236 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9237 NL80211_CMD_GET_COALESCE);
9238 if (!hdr)
9239 goto nla_put_failure;
9240
9241 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9242 goto nla_put_failure;
9243
9244 genlmsg_end(msg, hdr);
9245 return genlmsg_reply(msg, info);
9246
9247nla_put_failure:
9248 nlmsg_free(msg);
9249 return -ENOBUFS;
9250}
9251
9252void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9253{
9254 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9255 int i, j;
9256 struct cfg80211_coalesce_rules *rule;
9257
9258 if (!coalesce)
9259 return;
9260
9261 for (i = 0; i < coalesce->n_rules; i++) {
9262 rule = &coalesce->rules[i];
9263 for (j = 0; j < rule->n_patterns; j++)
9264 kfree(rule->patterns[j].mask);
9265 kfree(rule->patterns);
9266 }
9267 kfree(coalesce->rules);
9268 kfree(coalesce);
9269 rdev->coalesce = NULL;
9270}
9271
9272static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9273 struct nlattr *rule,
9274 struct cfg80211_coalesce_rules *new_rule)
9275{
9276 int err, i;
9277 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9278 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9279 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9280 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9281
9282 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9283 nla_len(rule), nl80211_coalesce_policy);
9284 if (err)
9285 return err;
9286
9287 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9288 new_rule->delay =
9289 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9290 if (new_rule->delay > coalesce->max_delay)
9291 return -EINVAL;
9292
9293 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9294 new_rule->condition =
9295 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9296 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9297 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9298 return -EINVAL;
9299
9300 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9301 return -EINVAL;
9302
9303 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9304 rem)
9305 n_patterns++;
9306 if (n_patterns > coalesce->n_patterns)
9307 return -EINVAL;
9308
9309 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9310 GFP_KERNEL);
9311 if (!new_rule->patterns)
9312 return -ENOMEM;
9313
9314 new_rule->n_patterns = n_patterns;
9315 i = 0;
9316
9317 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9318 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009319 u8 *mask_pat;
9320
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009321 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9322 nla_len(pat), NULL);
9323 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9324 !pat_tb[NL80211_PKTPAT_PATTERN])
9325 return -EINVAL;
9326 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9327 mask_len = DIV_ROUND_UP(pat_len, 8);
9328 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9329 return -EINVAL;
9330 if (pat_len > coalesce->pattern_max_len ||
9331 pat_len < coalesce->pattern_min_len)
9332 return -EINVAL;
9333
9334 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9335 pkt_offset = 0;
9336 else
9337 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9338 if (pkt_offset > coalesce->max_pkt_offset)
9339 return -EINVAL;
9340 new_rule->patterns[i].pkt_offset = pkt_offset;
9341
Johannes Berg922bd802014-05-19 17:59:50 +02009342 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9343 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009344 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009345
9346 new_rule->patterns[i].mask = mask_pat;
9347 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9348 mask_len);
9349
9350 mask_pat += mask_len;
9351 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009352 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009353 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9354 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009355 i++;
9356 }
9357
9358 return 0;
9359}
9360
9361static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9362{
9363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9364 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9365 struct cfg80211_coalesce new_coalesce = {};
9366 struct cfg80211_coalesce *n_coalesce;
9367 int err, rem_rule, n_rules = 0, i, j;
9368 struct nlattr *rule;
9369 struct cfg80211_coalesce_rules *tmp_rule;
9370
9371 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9372 return -EOPNOTSUPP;
9373
9374 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9375 cfg80211_rdev_free_coalesce(rdev);
9376 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9377 return 0;
9378 }
9379
9380 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9381 rem_rule)
9382 n_rules++;
9383 if (n_rules > coalesce->n_rules)
9384 return -EINVAL;
9385
9386 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9387 GFP_KERNEL);
9388 if (!new_coalesce.rules)
9389 return -ENOMEM;
9390
9391 new_coalesce.n_rules = n_rules;
9392 i = 0;
9393
9394 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9395 rem_rule) {
9396 err = nl80211_parse_coalesce_rule(rdev, rule,
9397 &new_coalesce.rules[i]);
9398 if (err)
9399 goto error;
9400
9401 i++;
9402 }
9403
9404 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9405 if (err)
9406 goto error;
9407
9408 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9409 if (!n_coalesce) {
9410 err = -ENOMEM;
9411 goto error;
9412 }
9413 cfg80211_rdev_free_coalesce(rdev);
9414 rdev->coalesce = n_coalesce;
9415
9416 return 0;
9417error:
9418 for (i = 0; i < new_coalesce.n_rules; i++) {
9419 tmp_rule = &new_coalesce.rules[i];
9420 for (j = 0; j < tmp_rule->n_patterns; j++)
9421 kfree(tmp_rule->patterns[j].mask);
9422 kfree(tmp_rule->patterns);
9423 }
9424 kfree(new_coalesce.rules);
9425
9426 return err;
9427}
9428
Johannes Berge5497d72011-07-05 16:35:40 +02009429static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9430{
9431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9432 struct net_device *dev = info->user_ptr[1];
9433 struct wireless_dev *wdev = dev->ieee80211_ptr;
9434 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9435 struct cfg80211_gtk_rekey_data rekey_data;
9436 int err;
9437
9438 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9439 return -EINVAL;
9440
9441 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9442 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9443 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9444 nl80211_rekey_policy);
9445 if (err)
9446 return err;
9447
9448 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9449 return -ERANGE;
9450 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9451 return -ERANGE;
9452 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9453 return -ERANGE;
9454
Johannes Berg78f686c2014-09-10 22:28:06 +03009455 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9456 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9457 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009458
9459 wdev_lock(wdev);
9460 if (!wdev->current_bss) {
9461 err = -ENOTCONN;
9462 goto out;
9463 }
9464
9465 if (!rdev->ops->set_rekey_data) {
9466 err = -EOPNOTSUPP;
9467 goto out;
9468 }
9469
Hila Gonene35e4d22012-06-27 17:19:42 +03009470 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009471 out:
9472 wdev_unlock(wdev);
9473 return err;
9474}
9475
Johannes Berg28946da2011-11-04 11:18:12 +01009476static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9477 struct genl_info *info)
9478{
9479 struct net_device *dev = info->user_ptr[1];
9480 struct wireless_dev *wdev = dev->ieee80211_ptr;
9481
9482 if (wdev->iftype != NL80211_IFTYPE_AP &&
9483 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9484 return -EINVAL;
9485
Eric W. Biederman15e47302012-09-07 20:12:54 +00009486 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009487 return -EBUSY;
9488
Eric W. Biederman15e47302012-09-07 20:12:54 +00009489 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009490 return 0;
9491}
9492
Johannes Berg7f6cf312011-11-04 11:18:15 +01009493static int nl80211_probe_client(struct sk_buff *skb,
9494 struct genl_info *info)
9495{
9496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9497 struct net_device *dev = info->user_ptr[1];
9498 struct wireless_dev *wdev = dev->ieee80211_ptr;
9499 struct sk_buff *msg;
9500 void *hdr;
9501 const u8 *addr;
9502 u64 cookie;
9503 int err;
9504
9505 if (wdev->iftype != NL80211_IFTYPE_AP &&
9506 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9507 return -EOPNOTSUPP;
9508
9509 if (!info->attrs[NL80211_ATTR_MAC])
9510 return -EINVAL;
9511
9512 if (!rdev->ops->probe_client)
9513 return -EOPNOTSUPP;
9514
9515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9516 if (!msg)
9517 return -ENOMEM;
9518
Eric W. Biederman15e47302012-09-07 20:12:54 +00009519 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009520 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009521 if (!hdr) {
9522 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009523 goto free_msg;
9524 }
9525
9526 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9527
Hila Gonene35e4d22012-06-27 17:19:42 +03009528 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009529 if (err)
9530 goto free_msg;
9531
David S. Miller9360ffd2012-03-29 04:41:26 -04009532 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9533 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009534
9535 genlmsg_end(msg, hdr);
9536
9537 return genlmsg_reply(msg, info);
9538
9539 nla_put_failure:
9540 err = -ENOBUFS;
9541 free_msg:
9542 nlmsg_free(msg);
9543 return err;
9544}
9545
Johannes Berg5e760232011-11-04 11:18:17 +01009546static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9547{
9548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009549 struct cfg80211_beacon_registration *reg, *nreg;
9550 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009551
9552 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9553 return -EOPNOTSUPP;
9554
Ben Greear37c73b52012-10-26 14:49:25 -07009555 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9556 if (!nreg)
9557 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009558
Ben Greear37c73b52012-10-26 14:49:25 -07009559 /* First, check if already registered. */
9560 spin_lock_bh(&rdev->beacon_registrations_lock);
9561 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9562 if (reg->nlportid == info->snd_portid) {
9563 rv = -EALREADY;
9564 goto out_err;
9565 }
9566 }
9567 /* Add it to the list */
9568 nreg->nlportid = info->snd_portid;
9569 list_add(&nreg->list, &rdev->beacon_registrations);
9570
9571 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009572
9573 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009574out_err:
9575 spin_unlock_bh(&rdev->beacon_registrations_lock);
9576 kfree(nreg);
9577 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009578}
9579
Johannes Berg98104fde2012-06-16 00:19:54 +02009580static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9581{
9582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9583 struct wireless_dev *wdev = info->user_ptr[1];
9584 int err;
9585
9586 if (!rdev->ops->start_p2p_device)
9587 return -EOPNOTSUPP;
9588
9589 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9590 return -EOPNOTSUPP;
9591
9592 if (wdev->p2p_started)
9593 return 0;
9594
Luciano Coelhob6a55012014-02-27 11:07:21 +02009595 if (rfkill_blocked(rdev->rfkill))
9596 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009597
Johannes Bergeeb126e2012-10-23 15:16:50 +02009598 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009599 if (err)
9600 return err;
9601
9602 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009603 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009604
9605 return 0;
9606}
9607
9608static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9609{
9610 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9611 struct wireless_dev *wdev = info->user_ptr[1];
9612
9613 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9614 return -EOPNOTSUPP;
9615
9616 if (!rdev->ops->stop_p2p_device)
9617 return -EOPNOTSUPP;
9618
Johannes Bergf9f47522013-03-19 15:04:07 +01009619 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009620
9621 return 0;
9622}
9623
Johannes Berg3713b4e2013-02-14 16:19:38 +01009624static int nl80211_get_protocol_features(struct sk_buff *skb,
9625 struct genl_info *info)
9626{
9627 void *hdr;
9628 struct sk_buff *msg;
9629
9630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9631 if (!msg)
9632 return -ENOMEM;
9633
9634 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9635 NL80211_CMD_GET_PROTOCOL_FEATURES);
9636 if (!hdr)
9637 goto nla_put_failure;
9638
9639 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9640 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9641 goto nla_put_failure;
9642
9643 genlmsg_end(msg, hdr);
9644 return genlmsg_reply(msg, info);
9645
9646 nla_put_failure:
9647 kfree_skb(msg);
9648 return -ENOBUFS;
9649}
9650
Jouni Malinen355199e2013-02-27 17:14:27 +02009651static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9652{
9653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9654 struct cfg80211_update_ft_ies_params ft_params;
9655 struct net_device *dev = info->user_ptr[1];
9656
9657 if (!rdev->ops->update_ft_ies)
9658 return -EOPNOTSUPP;
9659
9660 if (!info->attrs[NL80211_ATTR_MDID] ||
9661 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9662 return -EINVAL;
9663
9664 memset(&ft_params, 0, sizeof(ft_params));
9665 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9666 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9667 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9668
9669 return rdev_update_ft_ies(rdev, dev, &ft_params);
9670}
9671
Arend van Spriel5de17982013-04-18 15:49:00 +02009672static int nl80211_crit_protocol_start(struct sk_buff *skb,
9673 struct genl_info *info)
9674{
9675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9676 struct wireless_dev *wdev = info->user_ptr[1];
9677 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9678 u16 duration;
9679 int ret;
9680
9681 if (!rdev->ops->crit_proto_start)
9682 return -EOPNOTSUPP;
9683
9684 if (WARN_ON(!rdev->ops->crit_proto_stop))
9685 return -EINVAL;
9686
9687 if (rdev->crit_proto_nlportid)
9688 return -EBUSY;
9689
9690 /* determine protocol if provided */
9691 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9692 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9693
9694 if (proto >= NUM_NL80211_CRIT_PROTO)
9695 return -EINVAL;
9696
9697 /* timeout must be provided */
9698 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9699 return -EINVAL;
9700
9701 duration =
9702 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9703
9704 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9705 return -ERANGE;
9706
9707 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9708 if (!ret)
9709 rdev->crit_proto_nlportid = info->snd_portid;
9710
9711 return ret;
9712}
9713
9714static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9715 struct genl_info *info)
9716{
9717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9718 struct wireless_dev *wdev = info->user_ptr[1];
9719
9720 if (!rdev->ops->crit_proto_stop)
9721 return -EOPNOTSUPP;
9722
9723 if (rdev->crit_proto_nlportid) {
9724 rdev->crit_proto_nlportid = 0;
9725 rdev_crit_proto_stop(rdev, wdev);
9726 }
9727 return 0;
9728}
9729
Johannes Bergad7e7182013-11-13 13:37:47 +01009730static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9731{
9732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9733 struct wireless_dev *wdev =
9734 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9735 int i, err;
9736 u32 vid, subcmd;
9737
9738 if (!rdev->wiphy.vendor_commands)
9739 return -EOPNOTSUPP;
9740
9741 if (IS_ERR(wdev)) {
9742 err = PTR_ERR(wdev);
9743 if (err != -EINVAL)
9744 return err;
9745 wdev = NULL;
9746 } else if (wdev->wiphy != &rdev->wiphy) {
9747 return -EINVAL;
9748 }
9749
9750 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9751 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9752 return -EINVAL;
9753
9754 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9755 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9756 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9757 const struct wiphy_vendor_command *vcmd;
9758 void *data = NULL;
9759 int len = 0;
9760
9761 vcmd = &rdev->wiphy.vendor_commands[i];
9762
9763 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9764 continue;
9765
9766 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9767 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9768 if (!wdev)
9769 return -EINVAL;
9770 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9771 !wdev->netdev)
9772 return -EINVAL;
9773
9774 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9775 if (wdev->netdev &&
9776 !netif_running(wdev->netdev))
9777 return -ENETDOWN;
9778 if (!wdev->netdev && !wdev->p2p_started)
9779 return -ENETDOWN;
9780 }
9781 } else {
9782 wdev = NULL;
9783 }
9784
9785 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9786 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9787 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9788 }
9789
9790 rdev->cur_cmd_info = info;
9791 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9792 data, len);
9793 rdev->cur_cmd_info = NULL;
9794 return err;
9795 }
9796
9797 return -EOPNOTSUPP;
9798}
9799
9800struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9801 enum nl80211_commands cmd,
9802 enum nl80211_attrs attr,
9803 int approxlen)
9804{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009805 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009806
9807 if (WARN_ON(!rdev->cur_cmd_info))
9808 return NULL;
9809
9810 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9811 rdev->cur_cmd_info->snd_portid,
9812 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009813 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009814}
9815EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9816
9817int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9818{
9819 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9820 void *hdr = ((void **)skb->cb)[1];
9821 struct nlattr *data = ((void **)skb->cb)[2];
9822
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009823 /* clear CB data for netlink core to own from now on */
9824 memset(skb->cb, 0, sizeof(skb->cb));
9825
Johannes Bergad7e7182013-11-13 13:37:47 +01009826 if (WARN_ON(!rdev->cur_cmd_info)) {
9827 kfree_skb(skb);
9828 return -EINVAL;
9829 }
9830
9831 nla_nest_end(skb, data);
9832 genlmsg_end(skb, hdr);
9833 return genlmsg_reply(skb, rdev->cur_cmd_info);
9834}
9835EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9836
9837
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009838static int nl80211_set_qos_map(struct sk_buff *skb,
9839 struct genl_info *info)
9840{
9841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9842 struct cfg80211_qos_map *qos_map = NULL;
9843 struct net_device *dev = info->user_ptr[1];
9844 u8 *pos, len, num_des, des_len, des;
9845 int ret;
9846
9847 if (!rdev->ops->set_qos_map)
9848 return -EOPNOTSUPP;
9849
9850 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9851 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9852 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9853
9854 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9855 len > IEEE80211_QOS_MAP_LEN_MAX)
9856 return -EINVAL;
9857
9858 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9859 if (!qos_map)
9860 return -ENOMEM;
9861
9862 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9863 if (num_des) {
9864 des_len = num_des *
9865 sizeof(struct cfg80211_dscp_exception);
9866 memcpy(qos_map->dscp_exception, pos, des_len);
9867 qos_map->num_des = num_des;
9868 for (des = 0; des < num_des; des++) {
9869 if (qos_map->dscp_exception[des].up > 7) {
9870 kfree(qos_map);
9871 return -EINVAL;
9872 }
9873 }
9874 pos += des_len;
9875 }
9876 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9877 }
9878
9879 wdev_lock(dev->ieee80211_ptr);
9880 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9881 if (!ret)
9882 ret = rdev_set_qos_map(rdev, dev, qos_map);
9883 wdev_unlock(dev->ieee80211_ptr);
9884
9885 kfree(qos_map);
9886 return ret;
9887}
9888
Johannes Berg960d01a2014-09-09 22:55:35 +03009889static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9890{
9891 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9892 struct net_device *dev = info->user_ptr[1];
9893 struct wireless_dev *wdev = dev->ieee80211_ptr;
9894 const u8 *peer;
9895 u8 tsid, up;
9896 u16 admitted_time = 0;
9897 int err;
9898
Johannes Berg723e73a2014-10-22 09:25:06 +02009899 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009900 return -EOPNOTSUPP;
9901
9902 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9903 !info->attrs[NL80211_ATTR_USER_PRIO])
9904 return -EINVAL;
9905
9906 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9907 if (tsid >= IEEE80211_NUM_TIDS)
9908 return -EINVAL;
9909
9910 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9911 if (up >= IEEE80211_NUM_UPS)
9912 return -EINVAL;
9913
9914 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009915 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009916 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009917 * need more attributes for that (e.g. BA session requirement);
9918 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009919 */
9920 return -EINVAL;
9921 }
9922
9923 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9924
9925 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9926 admitted_time =
9927 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9928 if (!admitted_time)
9929 return -EINVAL;
9930 }
9931
9932 wdev_lock(wdev);
9933 switch (wdev->iftype) {
9934 case NL80211_IFTYPE_STATION:
9935 case NL80211_IFTYPE_P2P_CLIENT:
9936 if (wdev->current_bss)
9937 break;
9938 err = -ENOTCONN;
9939 goto out;
9940 default:
9941 err = -EOPNOTSUPP;
9942 goto out;
9943 }
9944
9945 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9946
9947 out:
9948 wdev_unlock(wdev);
9949 return err;
9950}
9951
9952static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9953{
9954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9955 struct net_device *dev = info->user_ptr[1];
9956 struct wireless_dev *wdev = dev->ieee80211_ptr;
9957 const u8 *peer;
9958 u8 tsid;
9959 int err;
9960
9961 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9962 return -EINVAL;
9963
9964 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9965 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9966
9967 wdev_lock(wdev);
9968 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9969 wdev_unlock(wdev);
9970
9971 return err;
9972}
9973
Arik Nemtsov1057d352014-11-19 12:54:26 +02009974static int nl80211_tdls_channel_switch(struct sk_buff *skb,
9975 struct genl_info *info)
9976{
9977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9978 struct net_device *dev = info->user_ptr[1];
9979 struct wireless_dev *wdev = dev->ieee80211_ptr;
9980 struct cfg80211_chan_def chandef = {};
9981 const u8 *addr;
9982 u8 oper_class;
9983 int err;
9984
9985 if (!rdev->ops->tdls_channel_switch ||
9986 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9987 return -EOPNOTSUPP;
9988
9989 switch (dev->ieee80211_ptr->iftype) {
9990 case NL80211_IFTYPE_STATION:
9991 case NL80211_IFTYPE_P2P_CLIENT:
9992 break;
9993 default:
9994 return -EOPNOTSUPP;
9995 }
9996
9997 if (!info->attrs[NL80211_ATTR_MAC] ||
9998 !info->attrs[NL80211_ATTR_OPER_CLASS])
9999 return -EINVAL;
10000
10001 err = nl80211_parse_chandef(rdev, info, &chandef);
10002 if (err)
10003 return err;
10004
10005 /*
10006 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10007 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10008 * specification is not defined for them.
10009 */
10010 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10011 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10012 chandef.width != NL80211_CHAN_WIDTH_20)
10013 return -EINVAL;
10014
10015 /* we will be active on the TDLS link */
10016 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
10017 return -EINVAL;
10018
10019 /* don't allow switching to DFS channels */
10020 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10021 return -EINVAL;
10022
10023 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10024 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10025
10026 wdev_lock(wdev);
10027 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10028 wdev_unlock(wdev);
10029
10030 return err;
10031}
10032
10033static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10034 struct genl_info *info)
10035{
10036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10037 struct net_device *dev = info->user_ptr[1];
10038 struct wireless_dev *wdev = dev->ieee80211_ptr;
10039 const u8 *addr;
10040
10041 if (!rdev->ops->tdls_channel_switch ||
10042 !rdev->ops->tdls_cancel_channel_switch ||
10043 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10044 return -EOPNOTSUPP;
10045
10046 switch (dev->ieee80211_ptr->iftype) {
10047 case NL80211_IFTYPE_STATION:
10048 case NL80211_IFTYPE_P2P_CLIENT:
10049 break;
10050 default:
10051 return -EOPNOTSUPP;
10052 }
10053
10054 if (!info->attrs[NL80211_ATTR_MAC])
10055 return -EINVAL;
10056
10057 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10058
10059 wdev_lock(wdev);
10060 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10061 wdev_unlock(wdev);
10062
10063 return 0;
10064}
10065
Johannes Berg4c476992010-10-04 21:36:35 +020010066#define NL80211_FLAG_NEED_WIPHY 0x01
10067#define NL80211_FLAG_NEED_NETDEV 0x02
10068#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010069#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10070#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10071 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010072#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010073/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010074#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10075 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010076#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010077
Johannes Bergf84f7712013-11-14 17:14:45 +010010078static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010079 struct genl_info *info)
10080{
10081 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010082 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010083 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010084 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10085
10086 if (rtnl)
10087 rtnl_lock();
10088
10089 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010090 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010091 if (IS_ERR(rdev)) {
10092 if (rtnl)
10093 rtnl_unlock();
10094 return PTR_ERR(rdev);
10095 }
10096 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010097 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10098 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010099 ASSERT_RTNL();
10100
Johannes Berg89a54e42012-06-15 14:33:17 +020010101 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10102 info->attrs);
10103 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010104 if (rtnl)
10105 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010106 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010107 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010108
Johannes Berg89a54e42012-06-15 14:33:17 +020010109 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010110 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010111
Johannes Berg1bf614e2012-06-15 15:23:36 +020010112 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10113 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010114 if (rtnl)
10115 rtnl_unlock();
10116 return -EINVAL;
10117 }
10118
10119 info->user_ptr[1] = dev;
10120 } else {
10121 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010122 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010123
Johannes Berg1bf614e2012-06-15 15:23:36 +020010124 if (dev) {
10125 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10126 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010127 if (rtnl)
10128 rtnl_unlock();
10129 return -ENETDOWN;
10130 }
10131
10132 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010133 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10134 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010135 if (rtnl)
10136 rtnl_unlock();
10137 return -ENETDOWN;
10138 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010139 }
10140
Johannes Berg4c476992010-10-04 21:36:35 +020010141 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010142 }
10143
10144 return 0;
10145}
10146
Johannes Bergf84f7712013-11-14 17:14:45 +010010147static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010148 struct genl_info *info)
10149{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010150 if (info->user_ptr[1]) {
10151 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10152 struct wireless_dev *wdev = info->user_ptr[1];
10153
10154 if (wdev->netdev)
10155 dev_put(wdev->netdev);
10156 } else {
10157 dev_put(info->user_ptr[1]);
10158 }
10159 }
Johannes Berg5393b912014-09-10 15:00:16 +030010160
Johannes Berg4c476992010-10-04 21:36:35 +020010161 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10162 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010163
10164 /* If needed, clear the netlink message payload from the SKB
10165 * as it might contain key data that shouldn't stick around on
10166 * the heap after the SKB is freed. The netlink message header
10167 * is still needed for further processing, so leave it intact.
10168 */
10169 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10170 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10171
10172 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10173 }
Johannes Berg4c476992010-10-04 21:36:35 +020010174}
10175
Johannes Berg4534de82013-11-14 17:14:46 +010010176static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010177 {
10178 .cmd = NL80211_CMD_GET_WIPHY,
10179 .doit = nl80211_get_wiphy,
10180 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010181 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010182 .policy = nl80211_policy,
10183 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010184 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10185 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010186 },
10187 {
10188 .cmd = NL80211_CMD_SET_WIPHY,
10189 .doit = nl80211_set_wiphy,
10190 .policy = nl80211_policy,
10191 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010192 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010193 },
10194 {
10195 .cmd = NL80211_CMD_GET_INTERFACE,
10196 .doit = nl80211_get_interface,
10197 .dumpit = nl80211_dump_interface,
10198 .policy = nl80211_policy,
10199 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010200 .internal_flags = NL80211_FLAG_NEED_WDEV |
10201 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010202 },
10203 {
10204 .cmd = NL80211_CMD_SET_INTERFACE,
10205 .doit = nl80211_set_interface,
10206 .policy = nl80211_policy,
10207 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010208 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10209 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010210 },
10211 {
10212 .cmd = NL80211_CMD_NEW_INTERFACE,
10213 .doit = nl80211_new_interface,
10214 .policy = nl80211_policy,
10215 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010216 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10217 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010218 },
10219 {
10220 .cmd = NL80211_CMD_DEL_INTERFACE,
10221 .doit = nl80211_del_interface,
10222 .policy = nl80211_policy,
10223 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010224 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010225 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010226 },
Johannes Berg41ade002007-12-19 02:03:29 +010010227 {
10228 .cmd = NL80211_CMD_GET_KEY,
10229 .doit = nl80211_get_key,
10230 .policy = nl80211_policy,
10231 .flags = GENL_ADMIN_PERM,
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 Berg41ade002007-12-19 02:03:29 +010010234 },
10235 {
10236 .cmd = NL80211_CMD_SET_KEY,
10237 .doit = nl80211_set_key,
10238 .policy = nl80211_policy,
10239 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010240 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010241 NL80211_FLAG_NEED_RTNL |
10242 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010243 },
10244 {
10245 .cmd = NL80211_CMD_NEW_KEY,
10246 .doit = nl80211_new_key,
10247 .policy = nl80211_policy,
10248 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010250 NL80211_FLAG_NEED_RTNL |
10251 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010252 },
10253 {
10254 .cmd = NL80211_CMD_DEL_KEY,
10255 .doit = nl80211_del_key,
10256 .policy = nl80211_policy,
10257 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010258 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010259 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010260 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010261 {
10262 .cmd = NL80211_CMD_SET_BEACON,
10263 .policy = nl80211_policy,
10264 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010265 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010266 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010267 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010268 },
10269 {
Johannes Berg88600202012-02-13 15:17:18 +010010270 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010271 .policy = nl80211_policy,
10272 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010273 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010275 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010276 },
10277 {
Johannes Berg88600202012-02-13 15:17:18 +010010278 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010279 .policy = nl80211_policy,
10280 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010281 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010282 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010283 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010284 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010285 {
10286 .cmd = NL80211_CMD_GET_STATION,
10287 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010288 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010289 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010290 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10291 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010292 },
10293 {
10294 .cmd = NL80211_CMD_SET_STATION,
10295 .doit = nl80211_set_station,
10296 .policy = nl80211_policy,
10297 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010298 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010299 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010300 },
10301 {
10302 .cmd = NL80211_CMD_NEW_STATION,
10303 .doit = nl80211_new_station,
10304 .policy = nl80211_policy,
10305 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010307 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010308 },
10309 {
10310 .cmd = NL80211_CMD_DEL_STATION,
10311 .doit = nl80211_del_station,
10312 .policy = nl80211_policy,
10313 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010315 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010316 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010317 {
10318 .cmd = NL80211_CMD_GET_MPATH,
10319 .doit = nl80211_get_mpath,
10320 .dumpit = nl80211_dump_mpath,
10321 .policy = nl80211_policy,
10322 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010323 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010324 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010325 },
10326 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010327 .cmd = NL80211_CMD_GET_MPP,
10328 .doit = nl80211_get_mpp,
10329 .dumpit = nl80211_dump_mpp,
10330 .policy = nl80211_policy,
10331 .flags = GENL_ADMIN_PERM,
10332 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10333 NL80211_FLAG_NEED_RTNL,
10334 },
10335 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010336 .cmd = NL80211_CMD_SET_MPATH,
10337 .doit = nl80211_set_mpath,
10338 .policy = nl80211_policy,
10339 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010340 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010341 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010342 },
10343 {
10344 .cmd = NL80211_CMD_NEW_MPATH,
10345 .doit = nl80211_new_mpath,
10346 .policy = nl80211_policy,
10347 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010348 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010349 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010350 },
10351 {
10352 .cmd = NL80211_CMD_DEL_MPATH,
10353 .doit = nl80211_del_mpath,
10354 .policy = nl80211_policy,
10355 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010356 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010357 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010358 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010359 {
10360 .cmd = NL80211_CMD_SET_BSS,
10361 .doit = nl80211_set_bss,
10362 .policy = nl80211_policy,
10363 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010364 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010365 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010366 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010367 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010368 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010369 .doit = nl80211_get_reg_do,
10370 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010371 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010372 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010373 /* can be retrieved by unprivileged users */
10374 },
10375 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010376 .cmd = NL80211_CMD_SET_REG,
10377 .doit = nl80211_set_reg,
10378 .policy = nl80211_policy,
10379 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010380 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010381 },
10382 {
10383 .cmd = NL80211_CMD_REQ_SET_REG,
10384 .doit = nl80211_req_set_reg,
10385 .policy = nl80211_policy,
10386 .flags = GENL_ADMIN_PERM,
10387 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010388 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010389 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10390 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010391 .policy = nl80211_policy,
10392 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010393 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010394 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010395 },
10396 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010397 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10398 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010399 .policy = nl80211_policy,
10400 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010401 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010402 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010403 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010404 {
Johannes Berg2a519312009-02-10 21:25:55 +010010405 .cmd = NL80211_CMD_TRIGGER_SCAN,
10406 .doit = nl80211_trigger_scan,
10407 .policy = nl80211_policy,
10408 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010409 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010410 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010411 },
10412 {
10413 .cmd = NL80211_CMD_GET_SCAN,
10414 .policy = nl80211_policy,
10415 .dumpit = nl80211_dump_scan,
10416 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010417 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010418 .cmd = NL80211_CMD_START_SCHED_SCAN,
10419 .doit = nl80211_start_sched_scan,
10420 .policy = nl80211_policy,
10421 .flags = GENL_ADMIN_PERM,
10422 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10423 NL80211_FLAG_NEED_RTNL,
10424 },
10425 {
10426 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10427 .doit = nl80211_stop_sched_scan,
10428 .policy = nl80211_policy,
10429 .flags = GENL_ADMIN_PERM,
10430 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10431 NL80211_FLAG_NEED_RTNL,
10432 },
10433 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010434 .cmd = NL80211_CMD_AUTHENTICATE,
10435 .doit = nl80211_authenticate,
10436 .policy = nl80211_policy,
10437 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010438 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010439 NL80211_FLAG_NEED_RTNL |
10440 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010441 },
10442 {
10443 .cmd = NL80211_CMD_ASSOCIATE,
10444 .doit = nl80211_associate,
10445 .policy = nl80211_policy,
10446 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010448 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010449 },
10450 {
10451 .cmd = NL80211_CMD_DEAUTHENTICATE,
10452 .doit = nl80211_deauthenticate,
10453 .policy = nl80211_policy,
10454 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010455 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010456 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010457 },
10458 {
10459 .cmd = NL80211_CMD_DISASSOCIATE,
10460 .doit = nl80211_disassociate,
10461 .policy = nl80211_policy,
10462 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010463 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010464 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010465 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010466 {
10467 .cmd = NL80211_CMD_JOIN_IBSS,
10468 .doit = nl80211_join_ibss,
10469 .policy = nl80211_policy,
10470 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010471 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010472 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010473 },
10474 {
10475 .cmd = NL80211_CMD_LEAVE_IBSS,
10476 .doit = nl80211_leave_ibss,
10477 .policy = nl80211_policy,
10478 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010479 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010480 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010481 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010482#ifdef CONFIG_NL80211_TESTMODE
10483 {
10484 .cmd = NL80211_CMD_TESTMODE,
10485 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010486 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010487 .policy = nl80211_policy,
10488 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010489 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10490 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010491 },
10492#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010493 {
10494 .cmd = NL80211_CMD_CONNECT,
10495 .doit = nl80211_connect,
10496 .policy = nl80211_policy,
10497 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010498 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010499 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010500 },
10501 {
10502 .cmd = NL80211_CMD_DISCONNECT,
10503 .doit = nl80211_disconnect,
10504 .policy = nl80211_policy,
10505 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010506 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010507 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010508 },
Johannes Berg463d0182009-07-14 00:33:35 +020010509 {
10510 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10511 .doit = nl80211_wiphy_netns,
10512 .policy = nl80211_policy,
10513 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010514 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10515 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010516 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010517 {
10518 .cmd = NL80211_CMD_GET_SURVEY,
10519 .policy = nl80211_policy,
10520 .dumpit = nl80211_dump_survey,
10521 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010522 {
10523 .cmd = NL80211_CMD_SET_PMKSA,
10524 .doit = nl80211_setdel_pmksa,
10525 .policy = nl80211_policy,
10526 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010527 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010528 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010529 },
10530 {
10531 .cmd = NL80211_CMD_DEL_PMKSA,
10532 .doit = nl80211_setdel_pmksa,
10533 .policy = nl80211_policy,
10534 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010535 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010536 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010537 },
10538 {
10539 .cmd = NL80211_CMD_FLUSH_PMKSA,
10540 .doit = nl80211_flush_pmksa,
10541 .policy = nl80211_policy,
10542 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010543 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010544 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010545 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010546 {
10547 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10548 .doit = nl80211_remain_on_channel,
10549 .policy = nl80211_policy,
10550 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010551 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010552 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010553 },
10554 {
10555 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10556 .doit = nl80211_cancel_remain_on_channel,
10557 .policy = nl80211_policy,
10558 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010559 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010560 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010561 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010562 {
10563 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10564 .doit = nl80211_set_tx_bitrate_mask,
10565 .policy = nl80211_policy,
10566 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010567 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10568 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010569 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010570 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010571 .cmd = NL80211_CMD_REGISTER_FRAME,
10572 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010573 .policy = nl80211_policy,
10574 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010575 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010576 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010577 },
10578 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010579 .cmd = NL80211_CMD_FRAME,
10580 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010581 .policy = nl80211_policy,
10582 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010583 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010584 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010585 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010586 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010587 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10588 .doit = nl80211_tx_mgmt_cancel_wait,
10589 .policy = nl80211_policy,
10590 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010591 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010592 NL80211_FLAG_NEED_RTNL,
10593 },
10594 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010595 .cmd = NL80211_CMD_SET_POWER_SAVE,
10596 .doit = nl80211_set_power_save,
10597 .policy = nl80211_policy,
10598 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010599 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10600 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010601 },
10602 {
10603 .cmd = NL80211_CMD_GET_POWER_SAVE,
10604 .doit = nl80211_get_power_save,
10605 .policy = nl80211_policy,
10606 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010607 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10608 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010609 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010610 {
10611 .cmd = NL80211_CMD_SET_CQM,
10612 .doit = nl80211_set_cqm,
10613 .policy = nl80211_policy,
10614 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010615 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10616 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010617 },
Johannes Bergf444de02010-05-05 15:25:02 +020010618 {
10619 .cmd = NL80211_CMD_SET_CHANNEL,
10620 .doit = nl80211_set_channel,
10621 .policy = nl80211_policy,
10622 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010623 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10624 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010625 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010626 {
10627 .cmd = NL80211_CMD_SET_WDS_PEER,
10628 .doit = nl80211_set_wds_peer,
10629 .policy = nl80211_policy,
10630 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010631 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10632 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010633 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010634 {
10635 .cmd = NL80211_CMD_JOIN_MESH,
10636 .doit = nl80211_join_mesh,
10637 .policy = nl80211_policy,
10638 .flags = GENL_ADMIN_PERM,
10639 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10640 NL80211_FLAG_NEED_RTNL,
10641 },
10642 {
10643 .cmd = NL80211_CMD_LEAVE_MESH,
10644 .doit = nl80211_leave_mesh,
10645 .policy = nl80211_policy,
10646 .flags = GENL_ADMIN_PERM,
10647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10648 NL80211_FLAG_NEED_RTNL,
10649 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010650 {
10651 .cmd = NL80211_CMD_JOIN_OCB,
10652 .doit = nl80211_join_ocb,
10653 .policy = nl80211_policy,
10654 .flags = GENL_ADMIN_PERM,
10655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10656 NL80211_FLAG_NEED_RTNL,
10657 },
10658 {
10659 .cmd = NL80211_CMD_LEAVE_OCB,
10660 .doit = nl80211_leave_ocb,
10661 .policy = nl80211_policy,
10662 .flags = GENL_ADMIN_PERM,
10663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10664 NL80211_FLAG_NEED_RTNL,
10665 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010666#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010667 {
10668 .cmd = NL80211_CMD_GET_WOWLAN,
10669 .doit = nl80211_get_wowlan,
10670 .policy = nl80211_policy,
10671 /* can be retrieved by unprivileged users */
10672 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10673 NL80211_FLAG_NEED_RTNL,
10674 },
10675 {
10676 .cmd = NL80211_CMD_SET_WOWLAN,
10677 .doit = nl80211_set_wowlan,
10678 .policy = nl80211_policy,
10679 .flags = GENL_ADMIN_PERM,
10680 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10681 NL80211_FLAG_NEED_RTNL,
10682 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010683#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010684 {
10685 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10686 .doit = nl80211_set_rekey_data,
10687 .policy = nl80211_policy,
10688 .flags = GENL_ADMIN_PERM,
10689 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010690 NL80211_FLAG_NEED_RTNL |
10691 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010692 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010693 {
10694 .cmd = NL80211_CMD_TDLS_MGMT,
10695 .doit = nl80211_tdls_mgmt,
10696 .policy = nl80211_policy,
10697 .flags = GENL_ADMIN_PERM,
10698 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10699 NL80211_FLAG_NEED_RTNL,
10700 },
10701 {
10702 .cmd = NL80211_CMD_TDLS_OPER,
10703 .doit = nl80211_tdls_oper,
10704 .policy = nl80211_policy,
10705 .flags = GENL_ADMIN_PERM,
10706 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10707 NL80211_FLAG_NEED_RTNL,
10708 },
Johannes Berg28946da2011-11-04 11:18:12 +010010709 {
10710 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10711 .doit = nl80211_register_unexpected_frame,
10712 .policy = nl80211_policy,
10713 .flags = GENL_ADMIN_PERM,
10714 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10715 NL80211_FLAG_NEED_RTNL,
10716 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010717 {
10718 .cmd = NL80211_CMD_PROBE_CLIENT,
10719 .doit = nl80211_probe_client,
10720 .policy = nl80211_policy,
10721 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010723 NL80211_FLAG_NEED_RTNL,
10724 },
Johannes Berg5e760232011-11-04 11:18:17 +010010725 {
10726 .cmd = NL80211_CMD_REGISTER_BEACONS,
10727 .doit = nl80211_register_beacons,
10728 .policy = nl80211_policy,
10729 .flags = GENL_ADMIN_PERM,
10730 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10731 NL80211_FLAG_NEED_RTNL,
10732 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010733 {
10734 .cmd = NL80211_CMD_SET_NOACK_MAP,
10735 .doit = nl80211_set_noack_map,
10736 .policy = nl80211_policy,
10737 .flags = GENL_ADMIN_PERM,
10738 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10739 NL80211_FLAG_NEED_RTNL,
10740 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010741 {
10742 .cmd = NL80211_CMD_START_P2P_DEVICE,
10743 .doit = nl80211_start_p2p_device,
10744 .policy = nl80211_policy,
10745 .flags = GENL_ADMIN_PERM,
10746 .internal_flags = NL80211_FLAG_NEED_WDEV |
10747 NL80211_FLAG_NEED_RTNL,
10748 },
10749 {
10750 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10751 .doit = nl80211_stop_p2p_device,
10752 .policy = nl80211_policy,
10753 .flags = GENL_ADMIN_PERM,
10754 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10755 NL80211_FLAG_NEED_RTNL,
10756 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010757 {
10758 .cmd = NL80211_CMD_SET_MCAST_RATE,
10759 .doit = nl80211_set_mcast_rate,
10760 .policy = nl80211_policy,
10761 .flags = GENL_ADMIN_PERM,
10762 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10763 NL80211_FLAG_NEED_RTNL,
10764 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010765 {
10766 .cmd = NL80211_CMD_SET_MAC_ACL,
10767 .doit = nl80211_set_mac_acl,
10768 .policy = nl80211_policy,
10769 .flags = GENL_ADMIN_PERM,
10770 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10771 NL80211_FLAG_NEED_RTNL,
10772 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010773 {
10774 .cmd = NL80211_CMD_RADAR_DETECT,
10775 .doit = nl80211_start_radar_detection,
10776 .policy = nl80211_policy,
10777 .flags = GENL_ADMIN_PERM,
10778 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10779 NL80211_FLAG_NEED_RTNL,
10780 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010781 {
10782 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10783 .doit = nl80211_get_protocol_features,
10784 .policy = nl80211_policy,
10785 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010786 {
10787 .cmd = NL80211_CMD_UPDATE_FT_IES,
10788 .doit = nl80211_update_ft_ies,
10789 .policy = nl80211_policy,
10790 .flags = GENL_ADMIN_PERM,
10791 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10792 NL80211_FLAG_NEED_RTNL,
10793 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010794 {
10795 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10796 .doit = nl80211_crit_protocol_start,
10797 .policy = nl80211_policy,
10798 .flags = GENL_ADMIN_PERM,
10799 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10800 NL80211_FLAG_NEED_RTNL,
10801 },
10802 {
10803 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10804 .doit = nl80211_crit_protocol_stop,
10805 .policy = nl80211_policy,
10806 .flags = GENL_ADMIN_PERM,
10807 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10808 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010809 },
10810 {
10811 .cmd = NL80211_CMD_GET_COALESCE,
10812 .doit = nl80211_get_coalesce,
10813 .policy = nl80211_policy,
10814 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10815 NL80211_FLAG_NEED_RTNL,
10816 },
10817 {
10818 .cmd = NL80211_CMD_SET_COALESCE,
10819 .doit = nl80211_set_coalesce,
10820 .policy = nl80211_policy,
10821 .flags = GENL_ADMIN_PERM,
10822 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10823 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010824 },
10825 {
10826 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10827 .doit = nl80211_channel_switch,
10828 .policy = nl80211_policy,
10829 .flags = GENL_ADMIN_PERM,
10830 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10831 NL80211_FLAG_NEED_RTNL,
10832 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010833 {
10834 .cmd = NL80211_CMD_VENDOR,
10835 .doit = nl80211_vendor_cmd,
10836 .policy = nl80211_policy,
10837 .flags = GENL_ADMIN_PERM,
10838 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10839 NL80211_FLAG_NEED_RTNL,
10840 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010841 {
10842 .cmd = NL80211_CMD_SET_QOS_MAP,
10843 .doit = nl80211_set_qos_map,
10844 .policy = nl80211_policy,
10845 .flags = GENL_ADMIN_PERM,
10846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10847 NL80211_FLAG_NEED_RTNL,
10848 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010849 {
10850 .cmd = NL80211_CMD_ADD_TX_TS,
10851 .doit = nl80211_add_tx_ts,
10852 .policy = nl80211_policy,
10853 .flags = GENL_ADMIN_PERM,
10854 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10855 NL80211_FLAG_NEED_RTNL,
10856 },
10857 {
10858 .cmd = NL80211_CMD_DEL_TX_TS,
10859 .doit = nl80211_del_tx_ts,
10860 .policy = nl80211_policy,
10861 .flags = GENL_ADMIN_PERM,
10862 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10863 NL80211_FLAG_NEED_RTNL,
10864 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020010865 {
10866 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
10867 .doit = nl80211_tdls_channel_switch,
10868 .policy = nl80211_policy,
10869 .flags = GENL_ADMIN_PERM,
10870 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10871 NL80211_FLAG_NEED_RTNL,
10872 },
10873 {
10874 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
10875 .doit = nl80211_tdls_cancel_channel_switch,
10876 .policy = nl80211_policy,
10877 .flags = GENL_ADMIN_PERM,
10878 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10879 NL80211_FLAG_NEED_RTNL,
10880 },
Johannes Berg55682962007-09-20 13:09:35 -040010881};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010882
Johannes Berg55682962007-09-20 13:09:35 -040010883/* notification functions */
10884
Johannes Berg3bb20552014-05-26 13:52:25 +020010885void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10886 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010887{
10888 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010889 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010890
Johannes Berg3bb20552014-05-26 13:52:25 +020010891 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10892 cmd != NL80211_CMD_DEL_WIPHY);
10893
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010894 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010895 if (!msg)
10896 return;
10897
Johannes Berg3bb20552014-05-26 13:52:25 +020010898 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010899 nlmsg_free(msg);
10900 return;
10901 }
10902
Johannes Berg68eb5502013-11-19 15:19:38 +010010903 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010904 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010905}
10906
Johannes Berg362a4152009-05-24 16:43:15 +020010907static int nl80211_add_scan_req(struct sk_buff *msg,
10908 struct cfg80211_registered_device *rdev)
10909{
10910 struct cfg80211_scan_request *req = rdev->scan_req;
10911 struct nlattr *nest;
10912 int i;
10913
10914 if (WARN_ON(!req))
10915 return 0;
10916
10917 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10918 if (!nest)
10919 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010920 for (i = 0; i < req->n_ssids; i++) {
10921 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10922 goto nla_put_failure;
10923 }
Johannes Berg362a4152009-05-24 16:43:15 +020010924 nla_nest_end(msg, nest);
10925
10926 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10927 if (!nest)
10928 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010929 for (i = 0; i < req->n_channels; i++) {
10930 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10931 goto nla_put_failure;
10932 }
Johannes Berg362a4152009-05-24 16:43:15 +020010933 nla_nest_end(msg, nest);
10934
David S. Miller9360ffd2012-03-29 04:41:26 -040010935 if (req->ie &&
10936 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10937 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010938
Johannes Bergae917c92013-10-25 11:05:22 +020010939 if (req->flags &&
10940 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10941 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010942
Johannes Berg362a4152009-05-24 16:43:15 +020010943 return 0;
10944 nla_put_failure:
10945 return -ENOBUFS;
10946}
10947
Johannes Berga538e2d2009-06-16 19:56:42 +020010948static int nl80211_send_scan_msg(struct sk_buff *msg,
10949 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010950 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010951 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010952 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010953{
10954 void *hdr;
10955
Eric W. Biederman15e47302012-09-07 20:12:54 +000010956 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010957 if (!hdr)
10958 return -1;
10959
David S. Miller9360ffd2012-03-29 04:41:26 -040010960 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010961 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10962 wdev->netdev->ifindex)) ||
10963 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010964 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010965
Johannes Berg362a4152009-05-24 16:43:15 +020010966 /* ignore errors and send incomplete event anyway */
10967 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010968
10969 return genlmsg_end(msg, hdr);
10970
10971 nla_put_failure:
10972 genlmsg_cancel(msg, hdr);
10973 return -EMSGSIZE;
10974}
10975
Luciano Coelho807f8a82011-05-11 17:09:35 +030010976static int
10977nl80211_send_sched_scan_msg(struct sk_buff *msg,
10978 struct cfg80211_registered_device *rdev,
10979 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010980 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010981{
10982 void *hdr;
10983
Eric W. Biederman15e47302012-09-07 20:12:54 +000010984 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010985 if (!hdr)
10986 return -1;
10987
David S. Miller9360ffd2012-03-29 04:41:26 -040010988 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10989 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10990 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010991
10992 return genlmsg_end(msg, hdr);
10993
10994 nla_put_failure:
10995 genlmsg_cancel(msg, hdr);
10996 return -EMSGSIZE;
10997}
10998
Johannes Berga538e2d2009-06-16 19:56:42 +020010999void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011000 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011001{
11002 struct sk_buff *msg;
11003
Thomas Graf58050fc2012-06-28 03:57:45 +000011004 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011005 if (!msg)
11006 return;
11007
Johannes Bergfd014282012-06-18 19:17:03 +020011008 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011009 NL80211_CMD_TRIGGER_SCAN) < 0) {
11010 nlmsg_free(msg);
11011 return;
11012 }
11013
Johannes Berg68eb5502013-11-19 15:19:38 +010011014 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011015 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011016}
11017
Johannes Bergf9d15d12014-01-22 11:14:19 +020011018struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11019 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011020{
11021 struct sk_buff *msg;
11022
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011023 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011024 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011025 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011026
Johannes Bergfd014282012-06-18 19:17:03 +020011027 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011028 aborted ? NL80211_CMD_SCAN_ABORTED :
11029 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011030 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011031 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011032 }
11033
Johannes Bergf9d15d12014-01-22 11:14:19 +020011034 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011035}
11036
Johannes Bergf9d15d12014-01-22 11:14:19 +020011037void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11038 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011039{
Johannes Berg2a519312009-02-10 21:25:55 +010011040 if (!msg)
11041 return;
11042
Johannes Berg68eb5502013-11-19 15:19:38 +010011043 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011044 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011045}
11046
Luciano Coelho807f8a82011-05-11 17:09:35 +030011047void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11048 struct net_device *netdev)
11049{
11050 struct sk_buff *msg;
11051
11052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11053 if (!msg)
11054 return;
11055
11056 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11057 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11058 nlmsg_free(msg);
11059 return;
11060 }
11061
Johannes Berg68eb5502013-11-19 15:19:38 +010011062 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011063 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011064}
11065
11066void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11067 struct net_device *netdev, u32 cmd)
11068{
11069 struct sk_buff *msg;
11070
Thomas Graf58050fc2012-06-28 03:57:45 +000011071 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011072 if (!msg)
11073 return;
11074
11075 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11076 nlmsg_free(msg);
11077 return;
11078 }
11079
Johannes Berg68eb5502013-11-19 15:19:38 +010011080 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011081 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011082}
11083
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011084static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11085 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011086{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011087 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011088 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11089 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011090
David S. Miller9360ffd2012-03-29 04:41:26 -040011091 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11092 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11093 NL80211_REGDOM_TYPE_WORLD))
11094 goto nla_put_failure;
11095 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11096 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11097 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11098 goto nla_put_failure;
11099 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11100 request->intersect) {
11101 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11102 NL80211_REGDOM_TYPE_INTERSECTION))
11103 goto nla_put_failure;
11104 } else {
11105 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11106 NL80211_REGDOM_TYPE_COUNTRY) ||
11107 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11108 request->alpha2))
11109 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011110 }
11111
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011112 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11113 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11114
11115 if (wiphy &&
11116 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11117 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011118
11119 if (wiphy &&
11120 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11121 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11122 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011123 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011124
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011125 return true;
11126
11127nla_put_failure:
11128 return false;
11129}
11130
11131/*
11132 * This can happen on global regulatory changes or device specific settings
11133 * based on custom regulatory domains.
11134 */
11135void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11136 struct regulatory_request *request)
11137{
11138 struct sk_buff *msg;
11139 void *hdr;
11140
11141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11142 if (!msg)
11143 return;
11144
11145 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11146 if (!hdr) {
11147 nlmsg_free(msg);
11148 return;
11149 }
11150
11151 if (nl80211_reg_change_event_fill(msg, request) == false)
11152 goto nla_put_failure;
11153
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011154 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011155
Johannes Bergbc43b282009-07-25 10:54:13 +020011156 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011157 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011158 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011159 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011160
11161 return;
11162
11163nla_put_failure:
11164 genlmsg_cancel(msg, hdr);
11165 nlmsg_free(msg);
11166}
11167
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011168static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11169 struct net_device *netdev,
11170 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011171 enum nl80211_commands cmd, gfp_t gfp,
11172 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011173{
11174 struct sk_buff *msg;
11175 void *hdr;
11176
Johannes Berge6d6e342009-07-01 21:26:47 +020011177 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011178 if (!msg)
11179 return;
11180
11181 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11182 if (!hdr) {
11183 nlmsg_free(msg);
11184 return;
11185 }
11186
David S. Miller9360ffd2012-03-29 04:41:26 -040011187 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11188 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11189 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11190 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011191
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011192 if (uapsd_queues >= 0) {
11193 struct nlattr *nla_wmm =
11194 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11195 if (!nla_wmm)
11196 goto nla_put_failure;
11197
11198 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11199 uapsd_queues))
11200 goto nla_put_failure;
11201
11202 nla_nest_end(msg, nla_wmm);
11203 }
11204
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011205 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011206
Johannes Berg68eb5502013-11-19 15:19:38 +010011207 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011208 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011209 return;
11210
11211 nla_put_failure:
11212 genlmsg_cancel(msg, hdr);
11213 nlmsg_free(msg);
11214}
11215
11216void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011217 struct net_device *netdev, const u8 *buf,
11218 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011219{
11220 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011221 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011222}
11223
11224void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11225 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011226 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011227{
Johannes Berge6d6e342009-07-01 21:26:47 +020011228 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011229 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011230}
11231
Jouni Malinen53b46b82009-03-27 20:53:56 +020011232void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011233 struct net_device *netdev, const u8 *buf,
11234 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011235{
11236 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011237 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011238}
11239
Jouni Malinen53b46b82009-03-27 20:53:56 +020011240void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11241 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011242 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011243{
11244 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011245 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011246}
11247
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011248void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11249 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011250{
Johannes Berg947add32013-02-22 22:05:20 +010011251 struct wireless_dev *wdev = dev->ieee80211_ptr;
11252 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011253 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011254 const struct ieee80211_mgmt *mgmt = (void *)buf;
11255 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011256
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011257 if (WARN_ON(len < 2))
11258 return;
11259
11260 if (ieee80211_is_deauth(mgmt->frame_control))
11261 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11262 else
11263 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11264
11265 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011266 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011267}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011268EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011269
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011270static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11271 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011272 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011273{
11274 struct sk_buff *msg;
11275 void *hdr;
11276
Johannes Berge6d6e342009-07-01 21:26:47 +020011277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011278 if (!msg)
11279 return;
11280
11281 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11282 if (!hdr) {
11283 nlmsg_free(msg);
11284 return;
11285 }
11286
David S. Miller9360ffd2012-03-29 04:41:26 -040011287 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11288 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11289 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11290 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11291 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011292
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011293 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011294
Johannes Berg68eb5502013-11-19 15:19:38 +010011295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011296 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011297 return;
11298
11299 nla_put_failure:
11300 genlmsg_cancel(msg, hdr);
11301 nlmsg_free(msg);
11302}
11303
11304void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011305 struct net_device *netdev, const u8 *addr,
11306 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011307{
11308 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011309 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011310}
11311
11312void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011313 struct net_device *netdev, const u8 *addr,
11314 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011315{
Johannes Berge6d6e342009-07-01 21:26:47 +020011316 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11317 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011318}
11319
Samuel Ortizb23aa672009-07-01 21:26:54 +020011320void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11321 struct net_device *netdev, const u8 *bssid,
11322 const u8 *req_ie, size_t req_ie_len,
11323 const u8 *resp_ie, size_t resp_ie_len,
11324 u16 status, gfp_t gfp)
11325{
11326 struct sk_buff *msg;
11327 void *hdr;
11328
Thomas Graf58050fc2012-06-28 03:57:45 +000011329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011330 if (!msg)
11331 return;
11332
11333 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11334 if (!hdr) {
11335 nlmsg_free(msg);
11336 return;
11337 }
11338
David S. Miller9360ffd2012-03-29 04:41:26 -040011339 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11340 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11341 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11342 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11343 (req_ie &&
11344 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11345 (resp_ie &&
11346 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11347 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011348
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011349 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011350
Johannes Berg68eb5502013-11-19 15:19:38 +010011351 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011352 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011353 return;
11354
11355 nla_put_failure:
11356 genlmsg_cancel(msg, hdr);
11357 nlmsg_free(msg);
11358
11359}
11360
11361void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11362 struct net_device *netdev, const u8 *bssid,
11363 const u8 *req_ie, size_t req_ie_len,
11364 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11365{
11366 struct sk_buff *msg;
11367 void *hdr;
11368
Thomas Graf58050fc2012-06-28 03:57:45 +000011369 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011370 if (!msg)
11371 return;
11372
11373 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11374 if (!hdr) {
11375 nlmsg_free(msg);
11376 return;
11377 }
11378
David S. Miller9360ffd2012-03-29 04:41:26 -040011379 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11380 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11381 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11382 (req_ie &&
11383 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11384 (resp_ie &&
11385 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11386 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011387
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011388 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011389
Johannes Berg68eb5502013-11-19 15:19:38 +010011390 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011391 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011392 return;
11393
11394 nla_put_failure:
11395 genlmsg_cancel(msg, hdr);
11396 nlmsg_free(msg);
11397
11398}
11399
11400void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11401 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011402 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011403{
11404 struct sk_buff *msg;
11405 void *hdr;
11406
Thomas Graf58050fc2012-06-28 03:57:45 +000011407 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011408 if (!msg)
11409 return;
11410
11411 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11412 if (!hdr) {
11413 nlmsg_free(msg);
11414 return;
11415 }
11416
David S. Miller9360ffd2012-03-29 04:41:26 -040011417 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11418 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11419 (from_ap && reason &&
11420 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11421 (from_ap &&
11422 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11423 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11424 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011425
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011426 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +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_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011430 return;
11431
11432 nla_put_failure:
11433 genlmsg_cancel(msg, hdr);
11434 nlmsg_free(msg);
11435
11436}
11437
Johannes Berg04a773a2009-04-19 21:24:32 +020011438void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11439 struct net_device *netdev, const u8 *bssid,
11440 gfp_t gfp)
11441{
11442 struct sk_buff *msg;
11443 void *hdr;
11444
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011445 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011446 if (!msg)
11447 return;
11448
11449 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11450 if (!hdr) {
11451 nlmsg_free(msg);
11452 return;
11453 }
11454
David S. Miller9360ffd2012-03-29 04:41:26 -040011455 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11456 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11457 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11458 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011459
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011460 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011461
Johannes Berg68eb5502013-11-19 15:19:38 +010011462 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011463 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011464 return;
11465
11466 nla_put_failure:
11467 genlmsg_cancel(msg, hdr);
11468 nlmsg_free(msg);
11469}
11470
Johannes Berg947add32013-02-22 22:05:20 +010011471void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11472 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011473{
Johannes Berg947add32013-02-22 22:05:20 +010011474 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011475 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011476 struct sk_buff *msg;
11477 void *hdr;
11478
Johannes Berg947add32013-02-22 22:05:20 +010011479 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11480 return;
11481
11482 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11483
Javier Cardonac93b5e72011-04-07 15:08:34 -070011484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11485 if (!msg)
11486 return;
11487
11488 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11489 if (!hdr) {
11490 nlmsg_free(msg);
11491 return;
11492 }
11493
David S. Miller9360ffd2012-03-29 04:41:26 -040011494 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011495 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11496 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011497 (ie_len && ie &&
11498 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11499 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011500
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011501 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011502
Johannes Berg68eb5502013-11-19 15:19:38 +010011503 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011504 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011505 return;
11506
11507 nla_put_failure:
11508 genlmsg_cancel(msg, hdr);
11509 nlmsg_free(msg);
11510}
Johannes Berg947add32013-02-22 22:05:20 +010011511EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011512
Jouni Malinena3b8b052009-03-27 21:59:49 +020011513void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11514 struct net_device *netdev, const u8 *addr,
11515 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011516 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011517{
11518 struct sk_buff *msg;
11519 void *hdr;
11520
Johannes Berge6d6e342009-07-01 21:26:47 +020011521 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011522 if (!msg)
11523 return;
11524
11525 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11526 if (!hdr) {
11527 nlmsg_free(msg);
11528 return;
11529 }
11530
David S. Miller9360ffd2012-03-29 04:41:26 -040011531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11532 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11533 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11534 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11535 (key_id != -1 &&
11536 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11537 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11538 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011539
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011540 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011541
Johannes Berg68eb5502013-11-19 15:19:38 +010011542 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011543 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011544 return;
11545
11546 nla_put_failure:
11547 genlmsg_cancel(msg, hdr);
11548 nlmsg_free(msg);
11549}
11550
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011551void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11552 struct ieee80211_channel *channel_before,
11553 struct ieee80211_channel *channel_after)
11554{
11555 struct sk_buff *msg;
11556 void *hdr;
11557 struct nlattr *nl_freq;
11558
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011560 if (!msg)
11561 return;
11562
11563 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11564 if (!hdr) {
11565 nlmsg_free(msg);
11566 return;
11567 }
11568
11569 /*
11570 * Since we are applying the beacon hint to a wiphy we know its
11571 * wiphy_idx is valid
11572 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011573 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11574 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011575
11576 /* Before */
11577 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11578 if (!nl_freq)
11579 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011580 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011581 goto nla_put_failure;
11582 nla_nest_end(msg, nl_freq);
11583
11584 /* After */
11585 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11586 if (!nl_freq)
11587 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011588 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011589 goto nla_put_failure;
11590 nla_nest_end(msg, nl_freq);
11591
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011592 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011593
Johannes Berg463d0182009-07-14 00:33:35 +020011594 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011595 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011596 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011597 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011598
11599 return;
11600
11601nla_put_failure:
11602 genlmsg_cancel(msg, hdr);
11603 nlmsg_free(msg);
11604}
11605
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011606static void nl80211_send_remain_on_chan_event(
11607 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011608 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011609 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011610 unsigned int duration, gfp_t gfp)
11611{
11612 struct sk_buff *msg;
11613 void *hdr;
11614
11615 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11616 if (!msg)
11617 return;
11618
11619 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11620 if (!hdr) {
11621 nlmsg_free(msg);
11622 return;
11623 }
11624
David S. Miller9360ffd2012-03-29 04:41:26 -040011625 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011626 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11627 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011628 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011629 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011630 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11631 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011632 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11633 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011634
David S. Miller9360ffd2012-03-29 04:41:26 -040011635 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11636 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11637 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011638
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011639 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011640
Johannes Berg68eb5502013-11-19 15:19:38 +010011641 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011642 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011643 return;
11644
11645 nla_put_failure:
11646 genlmsg_cancel(msg, hdr);
11647 nlmsg_free(msg);
11648}
11649
Johannes Berg947add32013-02-22 22:05:20 +010011650void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11651 struct ieee80211_channel *chan,
11652 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011653{
Johannes Berg947add32013-02-22 22:05:20 +010011654 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011655 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011656
11657 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011658 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011659 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011660 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011661}
Johannes Berg947add32013-02-22 22:05:20 +010011662EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011663
Johannes Berg947add32013-02-22 22:05:20 +010011664void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11665 struct ieee80211_channel *chan,
11666 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011667{
Johannes Berg947add32013-02-22 22:05:20 +010011668 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011669 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011670
11671 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011672 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011673 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011674}
Johannes Berg947add32013-02-22 22:05:20 +010011675EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011676
Johannes Berg947add32013-02-22 22:05:20 +010011677void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11678 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011679{
Johannes Berg947add32013-02-22 22:05:20 +010011680 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011681 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011682 struct sk_buff *msg;
11683
Johannes Berg947add32013-02-22 22:05:20 +010011684 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11685
Thomas Graf58050fc2012-06-28 03:57:45 +000011686 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011687 if (!msg)
11688 return;
11689
John W. Linville66266b32012-03-15 13:25:41 -040011690 if (nl80211_send_station(msg, 0, 0, 0,
11691 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011692 nlmsg_free(msg);
11693 return;
11694 }
11695
Johannes Berg68eb5502013-11-19 15:19:38 +010011696 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011697 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011698}
Johannes Berg947add32013-02-22 22:05:20 +010011699EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011700
Johannes Berg947add32013-02-22 22:05:20 +010011701void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011702{
Johannes Berg947add32013-02-22 22:05:20 +010011703 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011704 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011705 struct sk_buff *msg;
11706 void *hdr;
11707
Johannes Berg947add32013-02-22 22:05:20 +010011708 trace_cfg80211_del_sta(dev, mac_addr);
11709
Thomas Graf58050fc2012-06-28 03:57:45 +000011710 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011711 if (!msg)
11712 return;
11713
11714 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11715 if (!hdr) {
11716 nlmsg_free(msg);
11717 return;
11718 }
11719
David S. Miller9360ffd2012-03-29 04:41:26 -040011720 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11721 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11722 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011723
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011724 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011725
Johannes Berg68eb5502013-11-19 15:19:38 +010011726 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011727 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011728 return;
11729
11730 nla_put_failure:
11731 genlmsg_cancel(msg, hdr);
11732 nlmsg_free(msg);
11733}
Johannes Berg947add32013-02-22 22:05:20 +010011734EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011735
Johannes Berg947add32013-02-22 22:05:20 +010011736void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11737 enum nl80211_connect_failed_reason reason,
11738 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011739{
Johannes Berg947add32013-02-22 22:05:20 +010011740 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011741 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011742 struct sk_buff *msg;
11743 void *hdr;
11744
11745 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11746 if (!msg)
11747 return;
11748
11749 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11750 if (!hdr) {
11751 nlmsg_free(msg);
11752 return;
11753 }
11754
11755 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11756 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11757 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11758 goto nla_put_failure;
11759
11760 genlmsg_end(msg, hdr);
11761
Johannes Berg68eb5502013-11-19 15:19:38 +010011762 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011763 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011764 return;
11765
11766 nla_put_failure:
11767 genlmsg_cancel(msg, hdr);
11768 nlmsg_free(msg);
11769}
Johannes Berg947add32013-02-22 22:05:20 +010011770EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011771
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011772static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11773 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011774{
11775 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011776 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011777 struct sk_buff *msg;
11778 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011779 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011780
Eric W. Biederman15e47302012-09-07 20:12:54 +000011781 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011782 return false;
11783
11784 msg = nlmsg_new(100, gfp);
11785 if (!msg)
11786 return true;
11787
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011788 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011789 if (!hdr) {
11790 nlmsg_free(msg);
11791 return true;
11792 }
11793
David S. Miller9360ffd2012-03-29 04:41:26 -040011794 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11795 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11796 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11797 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011798
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011799 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011800 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011801 return true;
11802
11803 nla_put_failure:
11804 genlmsg_cancel(msg, hdr);
11805 nlmsg_free(msg);
11806 return true;
11807}
11808
Johannes Berg947add32013-02-22 22:05:20 +010011809bool cfg80211_rx_spurious_frame(struct net_device *dev,
11810 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011811{
Johannes Berg947add32013-02-22 22:05:20 +010011812 struct wireless_dev *wdev = dev->ieee80211_ptr;
11813 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011814
Johannes Berg947add32013-02-22 22:05:20 +010011815 trace_cfg80211_rx_spurious_frame(dev, addr);
11816
11817 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11818 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11819 trace_cfg80211_return_bool(false);
11820 return false;
11821 }
11822 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11823 addr, gfp);
11824 trace_cfg80211_return_bool(ret);
11825 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011826}
Johannes Berg947add32013-02-22 22:05:20 +010011827EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11828
11829bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11830 const u8 *addr, gfp_t gfp)
11831{
11832 struct wireless_dev *wdev = dev->ieee80211_ptr;
11833 bool ret;
11834
11835 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11836
11837 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11838 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11839 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11840 trace_cfg80211_return_bool(false);
11841 return false;
11842 }
11843 ret = __nl80211_unexpected_frame(dev,
11844 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11845 addr, gfp);
11846 trace_cfg80211_return_bool(ret);
11847 return ret;
11848}
11849EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011850
Johannes Berg2e161f72010-08-12 15:38:38 +020011851int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011852 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011853 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011854 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011855{
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;
Jouni Malinen026331c2010-02-15 12:53:10 +020011859
11860 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11861 if (!msg)
11862 return -ENOMEM;
11863
Johannes Berg2e161f72010-08-12 15:38:38 +020011864 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011865 if (!hdr) {
11866 nlmsg_free(msg);
11867 return -ENOMEM;
11868 }
11869
David S. Miller9360ffd2012-03-29 04:41:26 -040011870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011871 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11872 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011873 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011874 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11875 (sig_dbm &&
11876 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011877 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11878 (flags &&
11879 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011880 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011881
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011882 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011883
Eric W. Biederman15e47302012-09-07 20:12:54 +000011884 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011885
11886 nla_put_failure:
11887 genlmsg_cancel(msg, hdr);
11888 nlmsg_free(msg);
11889 return -ENOBUFS;
11890}
11891
Johannes Berg947add32013-02-22 22:05:20 +010011892void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11893 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011894{
Johannes Berg947add32013-02-22 22:05:20 +010011895 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011896 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011897 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011898 struct sk_buff *msg;
11899 void *hdr;
11900
Johannes Berg947add32013-02-22 22:05:20 +010011901 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11902
Jouni Malinen026331c2010-02-15 12:53:10 +020011903 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11904 if (!msg)
11905 return;
11906
Johannes Berg2e161f72010-08-12 15:38:38 +020011907 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011908 if (!hdr) {
11909 nlmsg_free(msg);
11910 return;
11911 }
11912
David S. Miller9360ffd2012-03-29 04:41:26 -040011913 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011914 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11915 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011916 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011917 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11918 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11919 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11920 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011921
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011922 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011923
Johannes Berg68eb5502013-11-19 15:19:38 +010011924 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011925 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011926 return;
11927
11928 nla_put_failure:
11929 genlmsg_cancel(msg, hdr);
11930 nlmsg_free(msg);
11931}
Johannes Berg947add32013-02-22 22:05:20 +010011932EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011933
Johannes Berg5b97f492014-11-26 12:37:43 +010011934static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
11935 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011936{
Johannes Berg947add32013-02-22 22:05:20 +010011937 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010011938 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
11939 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11940 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011941
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011942 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010011943 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011944
Johannes Berg5b97f492014-11-26 12:37:43 +010011945 cb = (void **)msg->cb;
11946
11947 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11948 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011949 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010011950 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011951 }
11952
David S. Miller9360ffd2012-03-29 04:41:26 -040011953 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011954 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011955 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011956
Johannes Berg5b97f492014-11-26 12:37:43 +010011957 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011958 goto nla_put_failure;
11959
Johannes Berg5b97f492014-11-26 12:37:43 +010011960 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
11961 if (!cb[1])
11962 goto nla_put_failure;
11963
11964 cb[2] = rdev;
11965
11966 return msg;
11967 nla_put_failure:
11968 nlmsg_free(msg);
11969 return NULL;
11970}
11971
11972static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
11973{
11974 void **cb = (void **)msg->cb;
11975 struct cfg80211_registered_device *rdev = cb[2];
11976
11977 nla_nest_end(msg, cb[1]);
11978 genlmsg_end(msg, cb[0]);
11979
11980 memset(msg->cb, 0, sizeof(msg->cb));
11981
11982 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11983 NL80211_MCGRP_MLME, gfp);
11984}
11985
11986void cfg80211_cqm_rssi_notify(struct net_device *dev,
11987 enum nl80211_cqm_rssi_threshold_event rssi_event,
11988 gfp_t gfp)
11989{
11990 struct sk_buff *msg;
11991
11992 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11993
Johannes Berg98f03342014-11-26 12:42:02 +010011994 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
11995 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
11996 return;
11997
Johannes Berg5b97f492014-11-26 12:37:43 +010011998 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
11999 if (!msg)
12000 return;
12001
David S. Miller9360ffd2012-03-29 04:41:26 -040012002 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12003 rssi_event))
12004 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012005
Johannes Berg5b97f492014-11-26 12:37:43 +010012006 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012007
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012008 return;
12009
12010 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012011 nlmsg_free(msg);
12012}
Johannes Berg947add32013-02-22 22:05:20 +010012013EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012014
Johannes Berg5b97f492014-11-26 12:37:43 +010012015void cfg80211_cqm_txe_notify(struct net_device *dev,
12016 const u8 *peer, u32 num_packets,
12017 u32 rate, u32 intvl, gfp_t gfp)
12018{
12019 struct sk_buff *msg;
12020
12021 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12022 if (!msg)
12023 return;
12024
12025 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12026 goto nla_put_failure;
12027
12028 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12029 goto nla_put_failure;
12030
12031 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
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_txe_notify);
12041
12042void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12043 const u8 *peer, u32 num_packets, gfp_t gfp)
12044{
12045 struct sk_buff *msg;
12046
12047 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12048
12049 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12050 if (!msg)
12051 return;
12052
12053 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12054 goto nla_put_failure;
12055
12056 cfg80211_send_cqm(msg, gfp);
12057 return;
12058
12059 nla_put_failure:
12060 nlmsg_free(msg);
12061}
12062EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12063
Johannes Berg98f03342014-11-26 12:42:02 +010012064void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12065{
12066 struct sk_buff *msg;
12067
12068 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12069 if (!msg)
12070 return;
12071
12072 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12073 goto nla_put_failure;
12074
12075 cfg80211_send_cqm(msg, gfp);
12076 return;
12077
12078 nla_put_failure:
12079 nlmsg_free(msg);
12080}
12081EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12082
Johannes Berg947add32013-02-22 22:05:20 +010012083static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12084 struct net_device *netdev, const u8 *bssid,
12085 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012086{
12087 struct sk_buff *msg;
12088 struct nlattr *rekey_attr;
12089 void *hdr;
12090
Thomas Graf58050fc2012-06-28 03:57:45 +000012091 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012092 if (!msg)
12093 return;
12094
12095 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12096 if (!hdr) {
12097 nlmsg_free(msg);
12098 return;
12099 }
12100
David S. Miller9360ffd2012-03-29 04:41:26 -040012101 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12102 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12103 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12104 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012105
12106 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12107 if (!rekey_attr)
12108 goto nla_put_failure;
12109
David S. Miller9360ffd2012-03-29 04:41:26 -040012110 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12111 NL80211_REPLAY_CTR_LEN, replay_ctr))
12112 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012113
12114 nla_nest_end(msg, rekey_attr);
12115
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012116 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012117
Johannes Berg68eb5502013-11-19 15:19:38 +010012118 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012119 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012120 return;
12121
12122 nla_put_failure:
12123 genlmsg_cancel(msg, hdr);
12124 nlmsg_free(msg);
12125}
12126
Johannes Berg947add32013-02-22 22:05:20 +010012127void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12128 const u8 *replay_ctr, gfp_t gfp)
12129{
12130 struct wireless_dev *wdev = dev->ieee80211_ptr;
12131 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012132 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012133
12134 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12135 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12136}
12137EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12138
12139static void
12140nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12141 struct net_device *netdev, int index,
12142 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012143{
12144 struct sk_buff *msg;
12145 struct nlattr *attr;
12146 void *hdr;
12147
Thomas Graf58050fc2012-06-28 03:57:45 +000012148 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012149 if (!msg)
12150 return;
12151
12152 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12153 if (!hdr) {
12154 nlmsg_free(msg);
12155 return;
12156 }
12157
David S. Miller9360ffd2012-03-29 04:41:26 -040012158 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12159 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12160 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012161
12162 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12163 if (!attr)
12164 goto nla_put_failure;
12165
David S. Miller9360ffd2012-03-29 04:41:26 -040012166 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12167 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12168 (preauth &&
12169 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12170 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012171
12172 nla_nest_end(msg, attr);
12173
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012174 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012175
Johannes Berg68eb5502013-11-19 15:19:38 +010012176 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012177 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012178 return;
12179
12180 nla_put_failure:
12181 genlmsg_cancel(msg, hdr);
12182 nlmsg_free(msg);
12183}
12184
Johannes Berg947add32013-02-22 22:05:20 +010012185void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12186 const u8 *bssid, bool preauth, gfp_t gfp)
12187{
12188 struct wireless_dev *wdev = dev->ieee80211_ptr;
12189 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012190 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012191
12192 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12193 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12194}
12195EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12196
12197static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12198 struct net_device *netdev,
12199 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012200 gfp_t gfp,
12201 enum nl80211_commands notif,
12202 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012203{
12204 struct sk_buff *msg;
12205 void *hdr;
12206
Thomas Graf58050fc2012-06-28 03:57:45 +000012207 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012208 if (!msg)
12209 return;
12210
Luciano Coelhof8d75522014-11-07 14:31:35 +020012211 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012212 if (!hdr) {
12213 nlmsg_free(msg);
12214 return;
12215 }
12216
Johannes Berg683b6d32012-11-08 21:25:48 +010012217 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12218 goto nla_put_failure;
12219
12220 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012221 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012222
Luciano Coelhof8d75522014-11-07 14:31:35 +020012223 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12224 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12225 goto nla_put_failure;
12226
Thomas Pedersen53145262012-04-06 13:35:47 -070012227 genlmsg_end(msg, hdr);
12228
Johannes Berg68eb5502013-11-19 15:19:38 +010012229 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012230 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012231 return;
12232
12233 nla_put_failure:
12234 genlmsg_cancel(msg, hdr);
12235 nlmsg_free(msg);
12236}
12237
Johannes Berg947add32013-02-22 22:05:20 +010012238void cfg80211_ch_switch_notify(struct net_device *dev,
12239 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012240{
Johannes Berg947add32013-02-22 22:05:20 +010012241 struct wireless_dev *wdev = dev->ieee80211_ptr;
12242 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012243 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012244
Simon Wunderliche487eae2013-11-21 18:19:51 +010012245 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012246
Simon Wunderliche487eae2013-11-21 18:19:51 +010012247 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012248
Michal Kazior9e0e2962014-01-29 14:22:27 +010012249 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012250 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012251 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12252 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012253}
12254EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12255
Luciano Coelhof8d75522014-11-07 14:31:35 +020012256void cfg80211_ch_switch_started_notify(struct net_device *dev,
12257 struct cfg80211_chan_def *chandef,
12258 u8 count)
12259{
12260 struct wireless_dev *wdev = dev->ieee80211_ptr;
12261 struct wiphy *wiphy = wdev->wiphy;
12262 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12263
12264 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12265
12266 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12267 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12268}
12269EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12270
Thomas Pedersen84f10702012-07-12 16:17:33 -070012271void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012272nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012273 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012274 enum nl80211_radar_event event,
12275 struct net_device *netdev, gfp_t gfp)
12276{
12277 struct sk_buff *msg;
12278 void *hdr;
12279
12280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12281 if (!msg)
12282 return;
12283
12284 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12285 if (!hdr) {
12286 nlmsg_free(msg);
12287 return;
12288 }
12289
12290 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12291 goto nla_put_failure;
12292
12293 /* NOP and radar events don't need a netdev parameter */
12294 if (netdev) {
12295 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12296
12297 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12298 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12299 goto nla_put_failure;
12300 }
12301
12302 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12303 goto nla_put_failure;
12304
12305 if (nl80211_send_chandef(msg, chandef))
12306 goto nla_put_failure;
12307
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012308 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012309
Johannes Berg68eb5502013-11-19 15:19:38 +010012310 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012311 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012312 return;
12313
12314 nla_put_failure:
12315 genlmsg_cancel(msg, hdr);
12316 nlmsg_free(msg);
12317}
12318
Johannes Berg7f6cf312011-11-04 11:18:15 +010012319void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12320 u64 cookie, bool acked, gfp_t gfp)
12321{
12322 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012323 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012324 struct sk_buff *msg;
12325 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012326
Beni Lev4ee3e062012-08-27 12:49:39 +030012327 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12328
Thomas Graf58050fc2012-06-28 03:57:45 +000012329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012330
Johannes Berg7f6cf312011-11-04 11:18:15 +010012331 if (!msg)
12332 return;
12333
12334 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12335 if (!hdr) {
12336 nlmsg_free(msg);
12337 return;
12338 }
12339
David S. Miller9360ffd2012-03-29 04:41:26 -040012340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12341 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12342 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12343 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12344 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12345 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012346
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012347 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012348
Johannes Berg68eb5502013-11-19 15:19:38 +010012349 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012350 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012351 return;
12352
12353 nla_put_failure:
12354 genlmsg_cancel(msg, hdr);
12355 nlmsg_free(msg);
12356}
12357EXPORT_SYMBOL(cfg80211_probe_status);
12358
Johannes Berg5e760232011-11-04 11:18:17 +010012359void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12360 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012361 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012362{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012363 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012364 struct sk_buff *msg;
12365 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012366 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012367
Beni Lev4ee3e062012-08-27 12:49:39 +030012368 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12369
Ben Greear37c73b52012-10-26 14:49:25 -070012370 spin_lock_bh(&rdev->beacon_registrations_lock);
12371 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12372 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12373 if (!msg) {
12374 spin_unlock_bh(&rdev->beacon_registrations_lock);
12375 return;
12376 }
Johannes Berg5e760232011-11-04 11:18:17 +010012377
Ben Greear37c73b52012-10-26 14:49:25 -070012378 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12379 if (!hdr)
12380 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012381
Ben Greear37c73b52012-10-26 14:49:25 -070012382 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12383 (freq &&
12384 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12385 (sig_dbm &&
12386 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12387 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12388 goto nla_put_failure;
12389
12390 genlmsg_end(msg, hdr);
12391
12392 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012393 }
Ben Greear37c73b52012-10-26 14:49:25 -070012394 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012395 return;
12396
12397 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012398 spin_unlock_bh(&rdev->beacon_registrations_lock);
12399 if (hdr)
12400 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012401 nlmsg_free(msg);
12402}
12403EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12404
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012405#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012406static int cfg80211_net_detect_results(struct sk_buff *msg,
12407 struct cfg80211_wowlan_wakeup *wakeup)
12408{
12409 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12410 struct nlattr *nl_results, *nl_match, *nl_freqs;
12411 int i, j;
12412
12413 nl_results = nla_nest_start(
12414 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12415 if (!nl_results)
12416 return -EMSGSIZE;
12417
12418 for (i = 0; i < nd->n_matches; i++) {
12419 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12420
12421 nl_match = nla_nest_start(msg, i);
12422 if (!nl_match)
12423 break;
12424
12425 /* The SSID attribute is optional in nl80211, but for
12426 * simplicity reasons it's always present in the
12427 * cfg80211 structure. If a driver can't pass the
12428 * SSID, that needs to be changed. A zero length SSID
12429 * is still a valid SSID (wildcard), so it cannot be
12430 * used for this purpose.
12431 */
12432 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12433 match->ssid.ssid)) {
12434 nla_nest_cancel(msg, nl_match);
12435 goto out;
12436 }
12437
12438 if (match->n_channels) {
12439 nl_freqs = nla_nest_start(
12440 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12441 if (!nl_freqs) {
12442 nla_nest_cancel(msg, nl_match);
12443 goto out;
12444 }
12445
12446 for (j = 0; j < match->n_channels; j++) {
12447 if (nla_put_u32(msg,
12448 NL80211_ATTR_WIPHY_FREQ,
12449 match->channels[j])) {
12450 nla_nest_cancel(msg, nl_freqs);
12451 nla_nest_cancel(msg, nl_match);
12452 goto out;
12453 }
12454 }
12455
12456 nla_nest_end(msg, nl_freqs);
12457 }
12458
12459 nla_nest_end(msg, nl_match);
12460 }
12461
12462out:
12463 nla_nest_end(msg, nl_results);
12464 return 0;
12465}
12466
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012467void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12468 struct cfg80211_wowlan_wakeup *wakeup,
12469 gfp_t gfp)
12470{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012471 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012472 struct sk_buff *msg;
12473 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012474 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012475
12476 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12477
12478 if (wakeup)
12479 size += wakeup->packet_present_len;
12480
12481 msg = nlmsg_new(size, gfp);
12482 if (!msg)
12483 return;
12484
12485 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12486 if (!hdr)
12487 goto free_msg;
12488
12489 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12490 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12491 goto free_msg;
12492
12493 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12494 wdev->netdev->ifindex))
12495 goto free_msg;
12496
12497 if (wakeup) {
12498 struct nlattr *reasons;
12499
12500 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012501 if (!reasons)
12502 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012503
12504 if (wakeup->disconnect &&
12505 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12506 goto free_msg;
12507 if (wakeup->magic_pkt &&
12508 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12509 goto free_msg;
12510 if (wakeup->gtk_rekey_failure &&
12511 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12512 goto free_msg;
12513 if (wakeup->eap_identity_req &&
12514 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12515 goto free_msg;
12516 if (wakeup->four_way_handshake &&
12517 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12518 goto free_msg;
12519 if (wakeup->rfkill_release &&
12520 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12521 goto free_msg;
12522
12523 if (wakeup->pattern_idx >= 0 &&
12524 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12525 wakeup->pattern_idx))
12526 goto free_msg;
12527
Johannes Bergae917c92013-10-25 11:05:22 +020012528 if (wakeup->tcp_match &&
12529 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12530 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012531
Johannes Bergae917c92013-10-25 11:05:22 +020012532 if (wakeup->tcp_connlost &&
12533 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12534 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012535
Johannes Bergae917c92013-10-25 11:05:22 +020012536 if (wakeup->tcp_nomoretokens &&
12537 nla_put_flag(msg,
12538 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12539 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012540
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012541 if (wakeup->packet) {
12542 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12543 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12544
12545 if (!wakeup->packet_80211) {
12546 pkt_attr =
12547 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12548 len_attr =
12549 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12550 }
12551
12552 if (wakeup->packet_len &&
12553 nla_put_u32(msg, len_attr, wakeup->packet_len))
12554 goto free_msg;
12555
12556 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12557 wakeup->packet))
12558 goto free_msg;
12559 }
12560
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012561 if (wakeup->net_detect &&
12562 cfg80211_net_detect_results(msg, wakeup))
12563 goto free_msg;
12564
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012565 nla_nest_end(msg, reasons);
12566 }
12567
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012568 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012569
Johannes Berg68eb5502013-11-19 15:19:38 +010012570 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012571 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012572 return;
12573
12574 free_msg:
12575 nlmsg_free(msg);
12576}
12577EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12578#endif
12579
Jouni Malinen3475b092012-11-16 22:49:57 +020012580void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12581 enum nl80211_tdls_operation oper,
12582 u16 reason_code, gfp_t gfp)
12583{
12584 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012585 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012586 struct sk_buff *msg;
12587 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012588
12589 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12590 reason_code);
12591
12592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12593 if (!msg)
12594 return;
12595
12596 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12597 if (!hdr) {
12598 nlmsg_free(msg);
12599 return;
12600 }
12601
12602 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12603 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12604 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12605 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12606 (reason_code > 0 &&
12607 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12608 goto nla_put_failure;
12609
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012610 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012611
Johannes Berg68eb5502013-11-19 15:19:38 +010012612 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012613 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012614 return;
12615
12616 nla_put_failure:
12617 genlmsg_cancel(msg, hdr);
12618 nlmsg_free(msg);
12619}
12620EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12621
Jouni Malinen026331c2010-02-15 12:53:10 +020012622static int nl80211_netlink_notify(struct notifier_block * nb,
12623 unsigned long state,
12624 void *_notify)
12625{
12626 struct netlink_notify *notify = _notify;
12627 struct cfg80211_registered_device *rdev;
12628 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012629 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012630
12631 if (state != NETLINK_URELEASE)
12632 return NOTIFY_DONE;
12633
12634 rcu_read_lock();
12635
Johannes Berg5e760232011-11-04 11:18:17 +010012636 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012637 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012638 bool schedule_scan_stop = false;
12639 struct cfg80211_sched_scan_request *sched_scan_req =
12640 rcu_dereference(rdev->sched_scan_req);
12641
12642 if (sched_scan_req && notify->portid &&
12643 sched_scan_req->owner_nlportid == notify->portid)
12644 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012645
12646 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012647 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012648
Johannes Berg78f22b62014-03-24 17:57:27 +010012649 if (wdev->owner_nlportid == notify->portid)
12650 schedule_destroy_work = true;
12651 }
12652
Ben Greear37c73b52012-10-26 14:49:25 -070012653 spin_lock_bh(&rdev->beacon_registrations_lock);
12654 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12655 list) {
12656 if (reg->nlportid == notify->portid) {
12657 list_del(&reg->list);
12658 kfree(reg);
12659 break;
12660 }
12661 }
12662 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012663
12664 if (schedule_destroy_work) {
12665 struct cfg80211_iface_destroy *destroy;
12666
12667 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12668 if (destroy) {
12669 destroy->nlportid = notify->portid;
12670 spin_lock(&rdev->destroy_list_lock);
12671 list_add(&destroy->list, &rdev->destroy_list);
12672 spin_unlock(&rdev->destroy_list_lock);
12673 schedule_work(&rdev->destroy_work);
12674 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012675 } else if (schedule_scan_stop) {
12676 sched_scan_req->owner_nlportid = 0;
12677
12678 if (rdev->ops->sched_scan_stop &&
12679 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12680 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012681 }
Johannes Berg5e760232011-11-04 11:18:17 +010012682 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012683
12684 rcu_read_unlock();
12685
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012686 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012687}
12688
12689static struct notifier_block nl80211_netlink_notifier = {
12690 .notifier_call = nl80211_netlink_notify,
12691};
12692
Jouni Malinen355199e2013-02-27 17:14:27 +020012693void cfg80211_ft_event(struct net_device *netdev,
12694 struct cfg80211_ft_event_params *ft_event)
12695{
12696 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012697 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012698 struct sk_buff *msg;
12699 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012700
12701 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12702
12703 if (!ft_event->target_ap)
12704 return;
12705
12706 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12707 if (!msg)
12708 return;
12709
12710 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012711 if (!hdr)
12712 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012713
Johannes Bergae917c92013-10-25 11:05:22 +020012714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12716 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12717 goto out;
12718
12719 if (ft_event->ies &&
12720 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12721 goto out;
12722 if (ft_event->ric_ies &&
12723 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12724 ft_event->ric_ies))
12725 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012726
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012727 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012728
Johannes Berg68eb5502013-11-19 15:19:38 +010012729 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012730 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012731 return;
12732 out:
12733 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012734}
12735EXPORT_SYMBOL(cfg80211_ft_event);
12736
Arend van Spriel5de17982013-04-18 15:49:00 +020012737void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12738{
12739 struct cfg80211_registered_device *rdev;
12740 struct sk_buff *msg;
12741 void *hdr;
12742 u32 nlportid;
12743
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012744 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012745 if (!rdev->crit_proto_nlportid)
12746 return;
12747
12748 nlportid = rdev->crit_proto_nlportid;
12749 rdev->crit_proto_nlportid = 0;
12750
12751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12752 if (!msg)
12753 return;
12754
12755 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12756 if (!hdr)
12757 goto nla_put_failure;
12758
12759 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12760 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12761 goto nla_put_failure;
12762
12763 genlmsg_end(msg, hdr);
12764
12765 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12766 return;
12767
12768 nla_put_failure:
12769 if (hdr)
12770 genlmsg_cancel(msg, hdr);
12771 nlmsg_free(msg);
12772
12773}
12774EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12775
Johannes Berg348baf02014-01-24 14:06:29 +010012776void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12777{
12778 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012779 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012780 struct sk_buff *msg;
12781 void *hdr;
12782
12783 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12784 if (!msg)
12785 return;
12786
12787 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12788 if (!hdr)
12789 goto out;
12790
12791 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12792 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12793 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12794 goto out;
12795
12796 genlmsg_end(msg, hdr);
12797
12798 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12799 NL80211_MCGRP_MLME, GFP_KERNEL);
12800 return;
12801 out:
12802 nlmsg_free(msg);
12803}
12804
Johannes Berg55682962007-09-20 13:09:35 -040012805/* initialisation/exit functions */
12806
12807int nl80211_init(void)
12808{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012809 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012810
Johannes Berg2a94fe42013-11-19 15:19:39 +010012811 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12812 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012813 if (err)
12814 return err;
12815
Jouni Malinen026331c2010-02-15 12:53:10 +020012816 err = netlink_register_notifier(&nl80211_netlink_notifier);
12817 if (err)
12818 goto err_out;
12819
Johannes Berg55682962007-09-20 13:09:35 -040012820 return 0;
12821 err_out:
12822 genl_unregister_family(&nl80211_fam);
12823 return err;
12824}
12825
12826void nl80211_exit(void)
12827{
Jouni Malinen026331c2010-02-15 12:53:10 +020012828 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012829 genl_unregister_family(&nl80211_fam);
12830}