blob: 12736a7cd506959be8e6a42040161b8292cbc5d4 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
62 [NL80211_MCGRP_CONFIG] = { .name = "config", },
63 [NL80211_MCGRP_SCAN] = { .name = "scan", },
64 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
65 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010066 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
68 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
69#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee47782012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee47782012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000212static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100391 [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400398};
399
Johannes Berge31b8212010-10-05 19:39:30 +0200400/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000401static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200402 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200403 [NL80211_KEY_IDX] = { .type = NLA_U8 },
404 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200405 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200406 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
407 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200408 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100409 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
410};
411
412/* policy for the key default flags */
413static const struct nla_policy
414nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
415 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
416 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200417};
418
Johannes Bergff1b6e62011-05-04 15:37:28 +0200419/* policy for WoWLAN attributes */
420static const struct nla_policy
421nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
422 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
423 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
424 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200426 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
427 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100430 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
431};
432
433static const struct nla_policy
434nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
435 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
436 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
437 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
438 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
439 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
440 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
441 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
442 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
443 },
444 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
445 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
446 },
447 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
448 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
449 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200450};
451
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700452/* policy for coalesce rule attributes */
453static const struct nla_policy
454nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
455 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
456 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
457 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
458};
459
Johannes Berge5497d72011-07-05 16:35:40 +0200460/* policy for GTK rekey offload attributes */
461static const struct nla_policy
462nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
463 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
464 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
465 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
466};
467
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300468static const struct nla_policy
469nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200470 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300471 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700472 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300473};
474
Johannes Berg97990a02013-04-19 01:02:55 +0200475static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
476 struct netlink_callback *cb,
477 struct cfg80211_registered_device **rdev,
478 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100479{
Johannes Berg67748892010-10-04 21:14:06 +0200480 int err;
481
Johannes Berg67748892010-10-04 21:14:06 +0200482 rtnl_lock();
483
Johannes Berg97990a02013-04-19 01:02:55 +0200484 if (!cb->args[0]) {
485 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
486 nl80211_fam.attrbuf, nl80211_fam.maxattr,
487 nl80211_policy);
488 if (err)
489 goto out_unlock;
490
491 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
492 nl80211_fam.attrbuf);
493 if (IS_ERR(*wdev)) {
494 err = PTR_ERR(*wdev);
495 goto out_unlock;
496 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800497 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200498 /* 0 is the first index - add 1 to parse only once */
499 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200500 cb->args[1] = (*wdev)->identifier;
501 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200502 /* subtract the 1 again here */
503 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200504 struct wireless_dev *tmp;
505
506 if (!wiphy) {
507 err = -ENODEV;
508 goto out_unlock;
509 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800510 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200511 *wdev = NULL;
512
Johannes Berg97990a02013-04-19 01:02:55 +0200513 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
514 if (tmp->identifier == cb->args[1]) {
515 *wdev = tmp;
516 break;
517 }
518 }
Johannes Berg97990a02013-04-19 01:02:55 +0200519
520 if (!*wdev) {
521 err = -ENODEV;
522 goto out_unlock;
523 }
Johannes Berg67748892010-10-04 21:14:06 +0200524 }
525
Johannes Berg67748892010-10-04 21:14:06 +0200526 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200527 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200528 rtnl_unlock();
529 return err;
530}
531
Johannes Berg97990a02013-04-19 01:02:55 +0200532static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200533{
Johannes Berg67748892010-10-04 21:14:06 +0200534 rtnl_unlock();
535}
536
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100537/* IE validation */
538static bool is_valid_ie_attr(const struct nlattr *attr)
539{
540 const u8 *pos;
541 int len;
542
543 if (!attr)
544 return true;
545
546 pos = nla_data(attr);
547 len = nla_len(attr);
548
549 while (len) {
550 u8 elemlen;
551
552 if (len < 2)
553 return false;
554 len -= 2;
555
556 elemlen = pos[1];
557 if (elemlen > len)
558 return false;
559
560 len -= elemlen;
561 pos += 2 + elemlen;
562 }
563
564 return true;
565}
566
Johannes Berg55682962007-09-20 13:09:35 -0400567/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000568static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400569 int flags, u8 cmd)
570{
571 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000572 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400573}
574
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400575static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100576 struct ieee80211_channel *chan,
577 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400578{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200579 /* Some channels must be completely excluded from the
580 * list to protect old user-space tools from breaking
581 */
582 if (!large && chan->flags &
583 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
584 return 0;
585
David S. Miller9360ffd2012-03-29 04:41:26 -0400586 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
587 chan->center_freq))
588 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400589
David S. Miller9360ffd2012-03-29 04:41:26 -0400590 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
591 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
592 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200593 if (chan->flags & IEEE80211_CHAN_NO_IR) {
594 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
595 goto nla_put_failure;
596 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
597 goto nla_put_failure;
598 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100599 if (chan->flags & IEEE80211_CHAN_RADAR) {
600 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
601 goto nla_put_failure;
602 if (large) {
603 u32 time;
604
605 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
606
607 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
608 chan->dfs_state))
609 goto nla_put_failure;
610 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
611 time))
612 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100613 if (nla_put_u32(msg,
614 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
615 chan->dfs_cac_ms))
616 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100617 }
618 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400619
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100620 if (large) {
621 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
622 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
623 goto nla_put_failure;
624 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
625 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
626 goto nla_put_failure;
627 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
632 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200633 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
638 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200639 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
641 goto nla_put_failure;
642 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
644 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100645 }
646
David S. Miller9360ffd2012-03-29 04:41:26 -0400647 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
648 DBM_TO_MBM(chan->max_power)))
649 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400650
651 return 0;
652
653 nla_put_failure:
654 return -ENOBUFS;
655}
656
Johannes Berg55682962007-09-20 13:09:35 -0400657/* netlink command implementations */
658
Johannes Bergb9454e82009-07-08 13:29:08 +0200659struct key_parse {
660 struct key_params p;
661 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200662 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200663 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100664 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200665};
666
667static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
668{
669 struct nlattr *tb[NL80211_KEY_MAX + 1];
670 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
671 nl80211_key_policy);
672 if (err)
673 return err;
674
675 k->def = !!tb[NL80211_KEY_DEFAULT];
676 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
677
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100678 if (k->def) {
679 k->def_uni = true;
680 k->def_multi = true;
681 }
682 if (k->defmgmt)
683 k->def_multi = true;
684
Johannes Bergb9454e82009-07-08 13:29:08 +0200685 if (tb[NL80211_KEY_IDX])
686 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
687
688 if (tb[NL80211_KEY_DATA]) {
689 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
690 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
691 }
692
693 if (tb[NL80211_KEY_SEQ]) {
694 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
695 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
696 }
697
698 if (tb[NL80211_KEY_CIPHER])
699 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
700
Johannes Berge31b8212010-10-05 19:39:30 +0200701 if (tb[NL80211_KEY_TYPE]) {
702 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
703 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
704 return -EINVAL;
705 }
706
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100707 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
708 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100709 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
710 tb[NL80211_KEY_DEFAULT_TYPES],
711 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (err)
713 return err;
714
715 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
716 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
717 }
718
Johannes Bergb9454e82009-07-08 13:29:08 +0200719 return 0;
720}
721
722static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
723{
724 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
725 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
726 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
727 }
728
729 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
730 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
731 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
732 }
733
734 if (info->attrs[NL80211_ATTR_KEY_IDX])
735 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
736
737 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
738 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
739
740 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
741 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
742
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100743 if (k->def) {
744 k->def_uni = true;
745 k->def_multi = true;
746 }
747 if (k->defmgmt)
748 k->def_multi = true;
749
Johannes Berge31b8212010-10-05 19:39:30 +0200750 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
751 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
752 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
753 return -EINVAL;
754 }
755
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100756 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
757 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
758 int err = nla_parse_nested(
759 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
760 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
761 nl80211_key_default_policy);
762 if (err)
763 return err;
764
765 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
766 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
767 }
768
Johannes Bergb9454e82009-07-08 13:29:08 +0200769 return 0;
770}
771
772static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
773{
774 int err;
775
776 memset(k, 0, sizeof(*k));
777 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200778 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200779
780 if (info->attrs[NL80211_ATTR_KEY])
781 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
782 else
783 err = nl80211_parse_key_old(info, k);
784
785 if (err)
786 return err;
787
788 if (k->def && k->defmgmt)
789 return -EINVAL;
790
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100791 if (k->defmgmt) {
792 if (k->def_uni || !k->def_multi)
793 return -EINVAL;
794 }
795
Johannes Bergb9454e82009-07-08 13:29:08 +0200796 if (k->idx != -1) {
797 if (k->defmgmt) {
798 if (k->idx < 4 || k->idx > 5)
799 return -EINVAL;
800 } else if (k->def) {
801 if (k->idx < 0 || k->idx > 3)
802 return -EINVAL;
803 } else {
804 if (k->idx < 0 || k->idx > 5)
805 return -EINVAL;
806 }
807 }
808
809 return 0;
810}
811
Johannes Bergfffd0932009-07-08 14:22:54 +0200812static struct cfg80211_cached_keys *
813nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530814 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200815{
816 struct key_parse parse;
817 struct nlattr *key;
818 struct cfg80211_cached_keys *result;
819 int rem, err, def = 0;
820
821 result = kzalloc(sizeof(*result), GFP_KERNEL);
822 if (!result)
823 return ERR_PTR(-ENOMEM);
824
825 result->def = -1;
826 result->defmgmt = -1;
827
828 nla_for_each_nested(key, keys, rem) {
829 memset(&parse, 0, sizeof(parse));
830 parse.idx = -1;
831
832 err = nl80211_parse_key_new(key, &parse);
833 if (err)
834 goto error;
835 err = -EINVAL;
836 if (!parse.p.key)
837 goto error;
838 if (parse.idx < 0 || parse.idx > 4)
839 goto error;
840 if (parse.def) {
841 if (def)
842 goto error;
843 def = 1;
844 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100845 if (!parse.def_uni || !parse.def_multi)
846 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200847 } else if (parse.defmgmt)
848 goto error;
849 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200850 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200851 if (err)
852 goto error;
853 result->params[parse.idx].cipher = parse.p.cipher;
854 result->params[parse.idx].key_len = parse.p.key_len;
855 result->params[parse.idx].key = result->data[parse.idx];
856 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530857
858 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
859 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
860 if (no_ht)
861 *no_ht = true;
862 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200863 }
864
865 return result;
866 error:
867 kfree(result);
868 return ERR_PTR(err);
869}
870
871static int nl80211_key_allowed(struct wireless_dev *wdev)
872{
873 ASSERT_WDEV_LOCK(wdev);
874
Johannes Bergfffd0932009-07-08 14:22:54 +0200875 switch (wdev->iftype) {
876 case NL80211_IFTYPE_AP:
877 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200878 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700879 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200880 break;
881 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200883 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200884 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200885 return -ENOLINK;
886 break;
887 default:
888 return -EINVAL;
889 }
890
891 return 0;
892}
893
Jouni Malinen664834d2014-01-15 00:01:44 +0200894static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
895 struct nlattr *tb)
896{
897 struct ieee80211_channel *chan;
898
899 if (tb == NULL)
900 return NULL;
901 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
902 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
903 return NULL;
904 return chan;
905}
906
Johannes Berg7527a782011-05-13 10:58:57 +0200907static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
908{
909 struct nlattr *nl_modes = nla_nest_start(msg, attr);
910 int i;
911
912 if (!nl_modes)
913 goto nla_put_failure;
914
915 i = 0;
916 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400917 if ((ifmodes & 1) && nla_put_flag(msg, i))
918 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200919 ifmodes >>= 1;
920 i++;
921 }
922
923 nla_nest_end(msg, nl_modes);
924 return 0;
925
926nla_put_failure:
927 return -ENOBUFS;
928}
929
930static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100931 struct sk_buff *msg,
932 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200933{
934 struct nlattr *nl_combis;
935 int i, j;
936
937 nl_combis = nla_nest_start(msg,
938 NL80211_ATTR_INTERFACE_COMBINATIONS);
939 if (!nl_combis)
940 goto nla_put_failure;
941
942 for (i = 0; i < wiphy->n_iface_combinations; i++) {
943 const struct ieee80211_iface_combination *c;
944 struct nlattr *nl_combi, *nl_limits;
945
946 c = &wiphy->iface_combinations[i];
947
948 nl_combi = nla_nest_start(msg, i + 1);
949 if (!nl_combi)
950 goto nla_put_failure;
951
952 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
953 if (!nl_limits)
954 goto nla_put_failure;
955
956 for (j = 0; j < c->n_limits; j++) {
957 struct nlattr *nl_limit;
958
959 nl_limit = nla_nest_start(msg, j + 1);
960 if (!nl_limit)
961 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400962 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
963 c->limits[j].max))
964 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200965 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
966 c->limits[j].types))
967 goto nla_put_failure;
968 nla_nest_end(msg, nl_limit);
969 }
970
971 nla_nest_end(msg, nl_limits);
972
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (c->beacon_int_infra_match &&
974 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
975 goto nla_put_failure;
976 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
977 c->num_different_channels) ||
978 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
979 c->max_interfaces))
980 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100981 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200982 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
983 c->radar_detect_widths) ||
984 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
985 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100986 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200987
988 nla_nest_end(msg, nl_combi);
989 }
990
991 nla_nest_end(msg, nl_combis);
992
993 return 0;
994nla_put_failure:
995 return -ENOBUFS;
996}
997
Johannes Berg3713b4e2013-02-14 16:19:38 +0100998#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100999static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1000 struct sk_buff *msg)
1001{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001002 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001003 struct nlattr *nl_tcp;
1004
1005 if (!tcp)
1006 return 0;
1007
1008 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1009 if (!nl_tcp)
1010 return -ENOBUFS;
1011
1012 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1013 tcp->data_payload_max))
1014 return -ENOBUFS;
1015
1016 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1017 tcp->data_payload_max))
1018 return -ENOBUFS;
1019
1020 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1021 return -ENOBUFS;
1022
1023 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1024 sizeof(*tcp->tok), tcp->tok))
1025 return -ENOBUFS;
1026
1027 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1028 tcp->data_interval_max))
1029 return -ENOBUFS;
1030
1031 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1032 tcp->wake_payload_max))
1033 return -ENOBUFS;
1034
1035 nla_nest_end(msg, nl_tcp);
1036 return 0;
1037}
1038
Johannes Berg3713b4e2013-02-14 16:19:38 +01001039static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001040 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001041 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001042{
1043 struct nlattr *nl_wowlan;
1044
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001045 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046 return 0;
1047
1048 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1049 if (!nl_wowlan)
1050 return -ENOBUFS;
1051
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001054 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001055 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001058 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001060 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001067 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1068 return -ENOBUFS;
1069
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001071 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1073 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1074 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1075 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 };
1077
1078 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1079 sizeof(pat), &pat))
1080 return -ENOBUFS;
1081 }
1082
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001083 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001084 return -ENOBUFS;
1085
Johannes Berg3713b4e2013-02-14 16:19:38 +01001086 nla_nest_end(msg, nl_wowlan);
1087
1088 return 0;
1089}
1090#endif
1091
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001092static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001093 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001094{
1095 struct nl80211_coalesce_rule_support rule;
1096
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001097 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001098 return 0;
1099
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1101 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1102 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1103 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1104 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1105 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001106
1107 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1108 return -ENOBUFS;
1109
1110 return 0;
1111}
1112
Johannes Berg3713b4e2013-02-14 16:19:38 +01001113static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1114 struct ieee80211_supported_band *sband)
1115{
1116 struct nlattr *nl_rates, *nl_rate;
1117 struct ieee80211_rate *rate;
1118 int i;
1119
1120 /* add HT info */
1121 if (sband->ht_cap.ht_supported &&
1122 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1123 sizeof(sband->ht_cap.mcs),
1124 &sband->ht_cap.mcs) ||
1125 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1126 sband->ht_cap.cap) ||
1127 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1128 sband->ht_cap.ampdu_factor) ||
1129 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1130 sband->ht_cap.ampdu_density)))
1131 return -ENOBUFS;
1132
1133 /* add VHT info */
1134 if (sband->vht_cap.vht_supported &&
1135 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1136 sizeof(sband->vht_cap.vht_mcs),
1137 &sband->vht_cap.vht_mcs) ||
1138 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1139 sband->vht_cap.cap)))
1140 return -ENOBUFS;
1141
1142 /* add bitrates */
1143 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1144 if (!nl_rates)
1145 return -ENOBUFS;
1146
1147 for (i = 0; i < sband->n_bitrates; i++) {
1148 nl_rate = nla_nest_start(msg, i);
1149 if (!nl_rate)
1150 return -ENOBUFS;
1151
1152 rate = &sband->bitrates[i];
1153 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1154 rate->bitrate))
1155 return -ENOBUFS;
1156 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1157 nla_put_flag(msg,
1158 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1159 return -ENOBUFS;
1160
1161 nla_nest_end(msg, nl_rate);
1162 }
1163
1164 nla_nest_end(msg, nl_rates);
1165
1166 return 0;
1167}
1168
1169static int
1170nl80211_send_mgmt_stypes(struct sk_buff *msg,
1171 const struct ieee80211_txrx_stypes *mgmt_stypes)
1172{
1173 u16 stypes;
1174 struct nlattr *nl_ftypes, *nl_ifs;
1175 enum nl80211_iftype ift;
1176 int i;
1177
1178 if (!mgmt_stypes)
1179 return 0;
1180
1181 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1182 if (!nl_ifs)
1183 return -ENOBUFS;
1184
1185 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1186 nl_ftypes = nla_nest_start(msg, ift);
1187 if (!nl_ftypes)
1188 return -ENOBUFS;
1189 i = 0;
1190 stypes = mgmt_stypes[ift].tx;
1191 while (stypes) {
1192 if ((stypes & 1) &&
1193 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1194 (i << 4) | IEEE80211_FTYPE_MGMT))
1195 return -ENOBUFS;
1196 stypes >>= 1;
1197 i++;
1198 }
1199 nla_nest_end(msg, nl_ftypes);
1200 }
1201
1202 nla_nest_end(msg, nl_ifs);
1203
1204 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1205 if (!nl_ifs)
1206 return -ENOBUFS;
1207
1208 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1209 nl_ftypes = nla_nest_start(msg, ift);
1210 if (!nl_ftypes)
1211 return -ENOBUFS;
1212 i = 0;
1213 stypes = mgmt_stypes[ift].rx;
1214 while (stypes) {
1215 if ((stypes & 1) &&
1216 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1217 (i << 4) | IEEE80211_FTYPE_MGMT))
1218 return -ENOBUFS;
1219 stypes >>= 1;
1220 i++;
1221 }
1222 nla_nest_end(msg, nl_ftypes);
1223 }
1224 nla_nest_end(msg, nl_ifs);
1225
1226 return 0;
1227}
1228
Johannes Berg86e8cf92013-06-19 10:57:22 +02001229struct nl80211_dump_wiphy_state {
1230 s64 filter_wiphy;
1231 long start;
1232 long split_start, band_start, chan_start;
1233 bool split;
1234};
1235
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001236static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001237 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001239 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001240{
1241 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001242 struct nlattr *nl_bands, *nl_band;
1243 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001244 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001245 enum ieee80211_band band;
1246 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001247 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001248 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001249 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001250 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001251
Johannes Berg3bb20552014-05-26 13:52:25 +02001252 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001253 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001254 return -ENOBUFS;
1255
Johannes Berg86e8cf92013-06-19 10:57:22 +02001256 if (WARN_ON(!state))
1257 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001258
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001259 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001261 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001262 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001264 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001265
Johannes Berg3bb20552014-05-26 13:52:25 +02001266 if (cmd != NL80211_CMD_NEW_WIPHY)
1267 goto finish;
1268
Johannes Berg86e8cf92013-06-19 10:57:22 +02001269 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 case 0:
1271 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001272 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001274 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001276 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001280 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001291 goto nla_put_failure;
1292
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1295 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1298 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1301 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1304 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001305 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1307 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001308 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001310 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001311 state->split_start++;
1312 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 break;
1314 case 1:
1315 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1317 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001318 goto nla_put_failure;
1319
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001322 goto nla_put_failure;
1323
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1326 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001327
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001336 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001338
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 if ((rdev->wiphy.available_antennas_tx ||
1340 rdev->wiphy.available_antennas_rx) &&
1341 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 u32 tx_ant = 0, rx_ant = 0;
1343 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001344 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 if (!res) {
1346 if (nla_put_u32(msg,
1347 NL80211_ATTR_WIPHY_ANTENNA_TX,
1348 tx_ant) ||
1349 nla_put_u32(msg,
1350 NL80211_ATTR_WIPHY_ANTENNA_RX,
1351 rx_ant))
1352 goto nla_put_failure;
1353 }
Johannes Bergee688b002008-01-24 19:38:39 +01001354 }
1355
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 state->split_start++;
1357 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 break;
1359 case 2:
1360 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001361 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001363 state->split_start++;
1364 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001365 break;
1366 case 3:
1367 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1368 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001369 goto nla_put_failure;
1370
Johannes Berg86e8cf92013-06-19 10:57:22 +02001371 for (band = state->band_start;
1372 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 struct ieee80211_supported_band *sband;
1374
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001375 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376
1377 if (!sband)
1378 continue;
1379
1380 nl_band = nla_nest_start(msg, band);
1381 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001382 goto nla_put_failure;
1383
Johannes Berg86e8cf92013-06-19 10:57:22 +02001384 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385 case 0:
1386 if (nl80211_send_band_rateinfo(msg, sband))
1387 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001388 state->chan_start++;
1389 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001390 break;
1391 default:
1392 /* add frequencies */
1393 nl_freqs = nla_nest_start(
1394 msg, NL80211_BAND_ATTR_FREQS);
1395 if (!nl_freqs)
1396 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001397
Johannes Berg86e8cf92013-06-19 10:57:22 +02001398 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 i < sband->n_channels;
1400 i++) {
1401 nl_freq = nla_nest_start(msg, i);
1402 if (!nl_freq)
1403 goto nla_put_failure;
1404
1405 chan = &sband->channels[i];
1406
Johannes Berg86e8cf92013-06-19 10:57:22 +02001407 if (nl80211_msg_put_channel(
1408 msg, chan,
1409 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 goto nla_put_failure;
1411
1412 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001413 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 break;
1415 }
1416 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001418 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001419 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 nla_nest_end(msg, nl_freqs);
1421 }
1422
1423 nla_nest_end(msg, nl_band);
1424
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 band--;
1429 break;
1430 }
Johannes Bergee688b002008-01-24 19:38:39 +01001431 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001433
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001437 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001440 if (state->band_start == 0 && state->chan_start == 0)
1441 state->split_start++;
1442 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 break;
1444 case 4:
1445 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1446 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001447 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448
1449 i = 0;
1450#define CMD(op, n) \
1451 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001452 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 i++; \
1454 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1455 goto nla_put_failure; \
1456 } \
1457 } while (0)
1458
1459 CMD(add_virtual_intf, NEW_INTERFACE);
1460 CMD(change_virtual_intf, SET_INTERFACE);
1461 CMD(add_key, NEW_KEY);
1462 CMD(start_ap, START_AP);
1463 CMD(add_station, NEW_STATION);
1464 CMD(add_mpath, NEW_MPATH);
1465 CMD(update_mesh_config, SET_MESH_CONFIG);
1466 CMD(change_bss, SET_BSS);
1467 CMD(auth, AUTHENTICATE);
1468 CMD(assoc, ASSOCIATE);
1469 CMD(deauth, DEAUTHENTICATE);
1470 CMD(disassoc, DISASSOCIATE);
1471 CMD(join_ibss, JOIN_IBSS);
1472 CMD(join_mesh, JOIN_MESH);
1473 CMD(set_pmksa, SET_PMKSA);
1474 CMD(del_pmksa, DEL_PMKSA);
1475 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001476 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1478 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1479 CMD(mgmt_tx, FRAME);
1480 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001481 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 i++;
1483 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1484 goto nla_put_failure;
1485 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1487 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 i++;
1489 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1490 goto nla_put_failure;
1491 }
1492 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 CMD(tdls_mgmt, TDLS_MGMT);
1495 CMD(tdls_oper, TDLS_OPER);
1496 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 CMD(sched_scan_start, START_SCHED_SCAN);
1499 CMD(probe_client, PROBE_CLIENT);
1500 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001501 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 i++;
1503 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1504 goto nla_put_failure;
1505 }
1506 CMD(start_p2p_device, START_P2P_DEVICE);
1507 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001508#ifdef CONFIG_NL80211_TESTMODE
1509 CMD(testmode_cmd, TESTMODE);
1510#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001511 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001512 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1513 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001515 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001516 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001517 if (rdev->wiphy.features &
1518 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001519 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001520 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001521 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001522#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001523
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 i++;
1526 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f782010-08-12 15:38:38 +02001527 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001528 }
1529
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 i++;
1532 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1533 goto nla_put_failure;
1534 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001535
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001537 state->split_start++;
1538 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 break;
1540 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if (rdev->ops->remain_on_channel &&
1542 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 nla_put_u32(msg,
1544 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02001546 goto nla_put_failure;
1547
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001548 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1550 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001551
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1553 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001554 state->split_start++;
1555 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 break;
1557 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001558#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001561 state->split_start++;
1562 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 break;
1564#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001565 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566#endif
1567 case 7:
1568 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001569 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001570 goto nla_put_failure;
1571
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001573 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001575
Johannes Berg86e8cf92013-06-19 10:57:22 +02001576 state->split_start++;
1577 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 break;
1579 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001580 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001581 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 goto nla_put_failure;
1584
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001586 /*
1587 * We can only add the per-channel limit information if the
1588 * dump is split, otherwise it makes it too big. Therefore
1589 * only advertise it in that case.
1590 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001591 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001592 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1593 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 goto nla_put_failure;
1595
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1599 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 goto nla_put_failure;
1601
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001602 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1603 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001605 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001606 goto nla_put_failure;
1607
1608 /*
1609 * Any information below this point is only available to
1610 * applications that can deal with it being split. This
1611 * helps ensure that newly added capabilities don't break
1612 * older tools by overrunning their buffers.
1613 *
1614 * We still increment split_start so that in the split
1615 * case we'll continue with more data in the next round,
1616 * but break unconditionally so unsplit data stops here.
1617 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001618 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 break;
1620 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001622 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 rdev->wiphy.extended_capabilities_len,
1624 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001625 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 rdev->wiphy.extended_capabilities_len,
1627 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001628 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001631 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1633 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001634 goto nla_put_failure;
1635
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001636 state->split_start++;
1637 break;
1638 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001640 goto nla_put_failure;
1641
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001643 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1644 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1645 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001646
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001648 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001650 goto nla_put_failure;
1651
Johannes Bergad7e7182013-11-13 13:37:47 +01001652 state->split_start++;
1653 break;
1654 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001656 const struct nl80211_vendor_cmd_info *info;
1657 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001658
Johannes Berg567ffc32013-12-18 14:43:31 +01001659 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1660 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001661 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1664 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001665 if (nla_put(msg, i + 1, sizeof(*info), info))
1666 goto nla_put_failure;
1667 }
1668 nla_nest_end(msg, nested);
1669 }
1670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 const struct nl80211_vendor_cmd_info *info;
1673 struct nlattr *nested;
1674
1675 nested = nla_nest_start(msg,
1676 NL80211_ATTR_VENDOR_EVENTS);
1677 if (!nested)
1678 goto nla_put_failure;
1679
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1681 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001682 if (nla_put(msg, i + 1, sizeof(*info), info))
1683 goto nla_put_failure;
1684 }
1685 nla_nest_end(msg, nested);
1686 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001687 state->split_start++;
1688 break;
1689 case 12:
1690 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1691 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1692 rdev->wiphy.max_num_csa_counters))
1693 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001694
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001696 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001697 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001698 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001699 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001700 return genlmsg_end(msg, hdr);
1701
1702 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001703 genlmsg_cancel(msg, hdr);
1704 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001705}
1706
Johannes Berg86e8cf92013-06-19 10:57:22 +02001707static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1708 struct netlink_callback *cb,
1709 struct nl80211_dump_wiphy_state *state)
1710{
1711 struct nlattr **tb = nl80211_fam.attrbuf;
1712 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1713 tb, nl80211_fam.maxattr, nl80211_policy);
1714 /* ignore parse errors for backward compatibility */
1715 if (ret)
1716 return 0;
1717
1718 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1719 if (tb[NL80211_ATTR_WIPHY])
1720 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1721 if (tb[NL80211_ATTR_WDEV])
1722 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1723 if (tb[NL80211_ATTR_IFINDEX]) {
1724 struct net_device *netdev;
1725 struct cfg80211_registered_device *rdev;
1726 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1727
Ying Xue7f2b8562014-01-15 10:23:45 +08001728 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001729 if (!netdev)
1730 return -ENODEV;
1731 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001732 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001733 netdev->ieee80211_ptr->wiphy);
1734 state->filter_wiphy = rdev->wiphy_idx;
1735 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001736 }
1737
1738 return 0;
1739}
1740
Johannes Berg55682962007-09-20 13:09:35 -04001741static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1742{
Johannes Berg645e77d2013-03-01 14:03:49 +01001743 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001745 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001746
Johannes Berg5fe231e2013-05-08 21:45:15 +02001747 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001748 if (!state) {
1749 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001750 if (!state) {
1751 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001754 state->filter_wiphy = -1;
1755 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1756 if (ret) {
1757 kfree(state);
1758 rtnl_unlock();
1759 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001760 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001761 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001762 }
1763
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001764 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1765 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001766 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001767 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001768 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001769 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001770 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001771 continue;
1772 /* attempt to fit multiple wiphy data chunks into the skb */
1773 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001774 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1775 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001776 NETLINK_CB(cb->skb).portid,
1777 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 if (ret < 0) {
1780 /*
1781 * If sending the wiphy data didn't fit (ENOBUFS
1782 * or EMSGSIZE returned), this SKB is still
1783 * empty (so it's not too big because another
1784 * wiphy dataset is already in the skb) and
1785 * we've not tried to adjust the dump allocation
1786 * yet ... then adjust the alloc size to be
1787 * bigger, and return 1 but with the empty skb.
1788 * This results in an empty message being RX'ed
1789 * in userspace, but that is ignored.
1790 *
1791 * We can then retry with the larger buffer.
1792 */
1793 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001794 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001795 cb->min_dump_alloc < 4096) {
1796 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001797 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001798 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001799 return 1;
1800 }
1801 idx--;
1802 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001803 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 break;
Johannes Berg55682962007-09-20 13:09:35 -04001806 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001807 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001808
Johannes Berg86e8cf92013-06-19 10:57:22 +02001809 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001810
1811 return skb->len;
1812}
1813
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1815{
1816 kfree((void *)cb->args[0]);
1817 return 0;
1818}
1819
Johannes Berg55682962007-09-20 13:09:35 -04001820static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1821{
1822 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001824 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001825
Johannes Berg645e77d2013-03-01 14:03:49 +01001826 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001827 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001828 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001829
Johannes Berg3bb20552014-05-26 13:52:25 +02001830 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1831 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001832 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001833 nlmsg_free(msg);
1834 return -ENOBUFS;
1835 }
Johannes Berg55682962007-09-20 13:09:35 -04001836
Johannes Berg134e6372009-07-10 09:51:34 +00001837 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001838}
1839
Jouni Malinen31888482008-10-30 16:59:24 +02001840static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1841 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1842 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1843 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1844 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1845 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1846};
1847
1848static int parse_txq_params(struct nlattr *tb[],
1849 struct ieee80211_txq_params *txq_params)
1850{
Johannes Berga3304b02012-03-28 11:04:24 +02001851 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001852 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1853 !tb[NL80211_TXQ_ATTR_AIFS])
1854 return -EINVAL;
1855
Johannes Berga3304b02012-03-28 11:04:24 +02001856 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001857 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1858 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1859 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1860 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1861
Johannes Berga3304b02012-03-28 11:04:24 +02001862 if (txq_params->ac >= NL80211_NUM_ACS)
1863 return -EINVAL;
1864
Jouni Malinen31888482008-10-30 16:59:24 +02001865 return 0;
1866}
1867
Johannes Bergf444de02010-05-05 15:25:02 +02001868static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1869{
1870 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001871 * You can only set the channel explicitly for WDS interfaces,
1872 * all others have their channel managed via their respective
1873 * "establish a connection" command (connect, join, ...)
1874 *
1875 * For AP/GO and mesh mode, the channel can be set with the
1876 * channel userspace API, but is only stored and passed to the
1877 * low-level driver when the AP starts or the mesh is joined.
1878 * This is for backward compatibility, userspace can also give
1879 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001880 *
1881 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001882 * whatever else is going on, so they have their own special
1883 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001884 */
1885 return !wdev ||
1886 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001887 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001888 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1889 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001890}
1891
Johannes Berg683b6d32012-11-08 21:25:48 +01001892static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1893 struct genl_info *info,
1894 struct cfg80211_chan_def *chandef)
1895{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301896 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001897
1898 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1899 return -EINVAL;
1900
1901 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1902
1903 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001904 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1905 chandef->center_freq1 = control_freq;
1906 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001907
1908 /* Primary channel not allowed */
1909 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1910 return -EINVAL;
1911
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001912 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1913 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001914
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001915 chantype = nla_get_u32(
1916 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1917
1918 switch (chantype) {
1919 case NL80211_CHAN_NO_HT:
1920 case NL80211_CHAN_HT20:
1921 case NL80211_CHAN_HT40PLUS:
1922 case NL80211_CHAN_HT40MINUS:
1923 cfg80211_chandef_create(chandef, chandef->chan,
1924 chantype);
1925 break;
1926 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001927 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001928 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001929 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1930 chandef->width =
1931 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1932 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1933 chandef->center_freq1 =
1934 nla_get_u32(
1935 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1936 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1937 chandef->center_freq2 =
1938 nla_get_u32(
1939 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1940 }
1941
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001942 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001943 return -EINVAL;
1944
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001945 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1946 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001947 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001948
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001949 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1950 chandef->width == NL80211_CHAN_WIDTH_10) &&
1951 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1952 return -EINVAL;
1953
Johannes Berg683b6d32012-11-08 21:25:48 +01001954 return 0;
1955}
1956
Johannes Bergf444de02010-05-05 15:25:02 +02001957static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001958 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001959 struct genl_info *info)
1960{
Johannes Berg683b6d32012-11-08 21:25:48 +01001961 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001962 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001963 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001964 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001965
Jouni Malinene16821b2014-04-28 11:22:08 +03001966 if (dev)
1967 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001968 if (!nl80211_can_set_dev_channel(wdev))
1969 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001970 if (wdev)
1971 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001972
Johannes Berg683b6d32012-11-08 21:25:48 +01001973 result = nl80211_parse_chandef(rdev, info, &chandef);
1974 if (result)
1975 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001976
Johannes Berge8c9bd52012-06-06 08:18:22 +02001977 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001978 case NL80211_IFTYPE_AP:
1979 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001980 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001981 result = -EINVAL;
1982 break;
1983 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001984 if (wdev->beacon_interval) {
1985 if (!dev || !rdev->ops->set_ap_chanwidth ||
1986 !(rdev->wiphy.features &
1987 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1988 result = -EBUSY;
1989 break;
1990 }
1991
1992 /* Only allow dynamic channel width changes */
1993 if (chandef.chan != wdev->preset_chandef.chan) {
1994 result = -EBUSY;
1995 break;
1996 }
1997 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1998 if (result)
1999 break;
2000 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002001 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002002 result = 0;
2003 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002004 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002005 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002006 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002007 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002008 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002009 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002010 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002011 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002012 }
Johannes Bergf444de02010-05-05 15:25:02 +02002013
2014 return result;
2015}
2016
2017static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2018{
Johannes Berg4c476992010-10-04 21:36:35 +02002019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2020 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002021
Jouni Malinene16821b2014-04-28 11:22:08 +03002022 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002023}
2024
Bill Jordane8347eb2010-10-01 13:54:28 -04002025static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2026{
Johannes Berg43b19952010-10-07 13:10:30 +02002027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2028 struct net_device *dev = info->user_ptr[1];
2029 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002030 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002031
2032 if (!info->attrs[NL80211_ATTR_MAC])
2033 return -EINVAL;
2034
Johannes Berg43b19952010-10-07 13:10:30 +02002035 if (netif_running(dev))
2036 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002037
Johannes Berg43b19952010-10-07 13:10:30 +02002038 if (!rdev->ops->set_wds_peer)
2039 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002040
Johannes Berg43b19952010-10-07 13:10:30 +02002041 if (wdev->iftype != NL80211_IFTYPE_WDS)
2042 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002043
2044 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002045 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002046}
2047
2048
Johannes Berg55682962007-09-20 13:09:35 -04002049static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2050{
2051 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002052 struct net_device *netdev = NULL;
2053 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002054 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002055 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056 u32 changed;
2057 u8 retry_short = 0, retry_long = 0;
2058 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002059 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002060
Johannes Berg5fe231e2013-05-08 21:45:15 +02002061 ASSERT_RTNL();
2062
Johannes Bergf444de02010-05-05 15:25:02 +02002063 /*
2064 * Try to find the wiphy and netdev. Normally this
2065 * function shouldn't need the netdev, but this is
2066 * done for backward compatibility -- previously
2067 * setting the channel was done per wiphy, but now
2068 * it is per netdev. Previous userland like hostapd
2069 * also passed a netdev to set_wiphy, so that it is
2070 * possible to let that go to the right netdev!
2071 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002072
Johannes Bergf444de02010-05-05 15:25:02 +02002073 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2074 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2075
Ying Xue7f2b8562014-01-15 10:23:45 +08002076 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002077 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002078 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002079 else
Johannes Bergf444de02010-05-05 15:25:02 +02002080 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002081 }
2082
Johannes Bergf444de02010-05-05 15:25:02 +02002083 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002084 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2085 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002086 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002087 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002088 wdev = NULL;
2089 netdev = NULL;
2090 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002091 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002092 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002093
2094 /*
2095 * end workaround code, by now the rdev is available
2096 * and locked, and wdev may or may not be NULL.
2097 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002098
2099 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002100 result = cfg80211_dev_rename(
2101 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002102
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002103 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002104 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002105
Jouni Malinen31888482008-10-30 16:59:24 +02002106 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2107 struct ieee80211_txq_params txq_params;
2108 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2109
Ying Xue7f2b8562014-01-15 10:23:45 +08002110 if (!rdev->ops->set_txq_params)
2111 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002112
Ying Xue7f2b8562014-01-15 10:23:45 +08002113 if (!netdev)
2114 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002115
Johannes Berg133a3ff2011-11-03 14:50:13 +01002116 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002117 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2118 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002119
Ying Xue7f2b8562014-01-15 10:23:45 +08002120 if (!netif_running(netdev))
2121 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002122
Jouni Malinen31888482008-10-30 16:59:24 +02002123 nla_for_each_nested(nl_txq_params,
2124 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2125 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002126 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2127 nla_data(nl_txq_params),
2128 nla_len(nl_txq_params),
2129 txq_params_policy);
2130 if (result)
2131 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002132 result = parse_txq_params(tb, &txq_params);
2133 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002134 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002135
Hila Gonene35e4d22012-06-27 17:19:42 +03002136 result = rdev_set_txq_params(rdev, netdev,
2137 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002138 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002140 }
2141 }
2142
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002143 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002144 result = __nl80211_set_channel(
2145 rdev,
2146 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2147 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002148 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002149 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002150 }
2151
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002152 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002153 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002154 enum nl80211_tx_power_setting type;
2155 int idx, mbm = 0;
2156
Johannes Bergc8442112012-10-24 10:17:18 +02002157 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2158 txp_wdev = NULL;
2159
Ying Xue7f2b8562014-01-15 10:23:45 +08002160 if (!rdev->ops->set_tx_power)
2161 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002162
2163 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2164 type = nla_get_u32(info->attrs[idx]);
2165
2166 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 (type != NL80211_TX_POWER_AUTOMATIC))
2168 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002169
2170 if (type != NL80211_TX_POWER_AUTOMATIC) {
2171 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2172 mbm = nla_get_u32(info->attrs[idx]);
2173 }
2174
Johannes Bergc8442112012-10-24 10:17:18 +02002175 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002176 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002177 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002178 }
2179
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002180 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2181 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2182 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002183 if ((!rdev->wiphy.available_antennas_tx &&
2184 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002185 !rdev->ops->set_antenna)
2186 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002187
2188 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2189 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2190
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002191 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002192 * available antenna masks, except for the "all" mask */
2193 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2195 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002196
Bruno Randolf7f531e02010-12-16 11:30:22 +09002197 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2198 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002199
Hila Gonene35e4d22012-06-27 17:19:42 +03002200 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002201 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002202 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002203 }
2204
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002205 changed = 0;
2206
2207 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2208 retry_short = nla_get_u8(
2209 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 if (retry_short == 0)
2211 return -EINVAL;
2212
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002213 changed |= WIPHY_PARAM_RETRY_SHORT;
2214 }
2215
2216 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2217 retry_long = nla_get_u8(
2218 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002219 if (retry_long == 0)
2220 return -EINVAL;
2221
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002222 changed |= WIPHY_PARAM_RETRY_LONG;
2223 }
2224
2225 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2226 frag_threshold = nla_get_u32(
2227 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 if (frag_threshold < 256)
2229 return -EINVAL;
2230
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002231 if (frag_threshold != (u32) -1) {
2232 /*
2233 * Fragments (apart from the last one) are required to
2234 * have even length. Make the fragmentation code
2235 * simpler by stripping LSB should someone try to use
2236 * odd threshold value.
2237 */
2238 frag_threshold &= ~0x1;
2239 }
2240 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2241 }
2242
2243 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2244 rts_threshold = nla_get_u32(
2245 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2246 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2247 }
2248
Lukáš Turek81077e82009-12-21 22:50:47 +01002249 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002250 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2251 return -EINVAL;
2252
Lukáš Turek81077e82009-12-21 22:50:47 +01002253 coverage_class = nla_get_u8(
2254 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2255 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2256 }
2257
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002258 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2259 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2260 return -EOPNOTSUPP;
2261
2262 changed |= WIPHY_PARAM_DYN_ACK;
2263 }
2264
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002265 if (changed) {
2266 u8 old_retry_short, old_retry_long;
2267 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002268 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002269
Ying Xue7f2b8562014-01-15 10:23:45 +08002270 if (!rdev->ops->set_wiphy_params)
2271 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002272
2273 old_retry_short = rdev->wiphy.retry_short;
2274 old_retry_long = rdev->wiphy.retry_long;
2275 old_frag_threshold = rdev->wiphy.frag_threshold;
2276 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002277 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002278
2279 if (changed & WIPHY_PARAM_RETRY_SHORT)
2280 rdev->wiphy.retry_short = retry_short;
2281 if (changed & WIPHY_PARAM_RETRY_LONG)
2282 rdev->wiphy.retry_long = retry_long;
2283 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2284 rdev->wiphy.frag_threshold = frag_threshold;
2285 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2286 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002287 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2288 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002289
Hila Gonene35e4d22012-06-27 17:19:42 +03002290 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002291 if (result) {
2292 rdev->wiphy.retry_short = old_retry_short;
2293 rdev->wiphy.retry_long = old_retry_long;
2294 rdev->wiphy.frag_threshold = old_frag_threshold;
2295 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002296 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002297 }
2298 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002299 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002300}
2301
Johannes Berg71bbc992012-06-15 15:30:18 +02002302static inline u64 wdev_id(struct wireless_dev *wdev)
2303{
2304 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002305 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002306}
Johannes Berg55682962007-09-20 13:09:35 -04002307
Johannes Berg683b6d32012-11-08 21:25:48 +01002308static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002309 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002310{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002311 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002312
Johannes Berg683b6d32012-11-08 21:25:48 +01002313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2314 chandef->chan->center_freq))
2315 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002316 switch (chandef->width) {
2317 case NL80211_CHAN_WIDTH_20_NOHT:
2318 case NL80211_CHAN_WIDTH_20:
2319 case NL80211_CHAN_WIDTH_40:
2320 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2321 cfg80211_get_chandef_type(chandef)))
2322 return -ENOBUFS;
2323 break;
2324 default:
2325 break;
2326 }
2327 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2328 return -ENOBUFS;
2329 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2330 return -ENOBUFS;
2331 if (chandef->center_freq2 &&
2332 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002333 return -ENOBUFS;
2334 return 0;
2335}
2336
Eric W. Biederman15e47302012-09-07 20:12:54 +00002337static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002338 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002339 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002340{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002341 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002342 void *hdr;
2343
Eric W. Biederman15e47302012-09-07 20:12:54 +00002344 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002345 if (!hdr)
2346 return -1;
2347
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002348 if (dev &&
2349 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002350 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002351 goto nla_put_failure;
2352
2353 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2354 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002355 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002356 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002357 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2358 rdev->devlist_generation ^
2359 (cfg80211_rdev_list_generation << 2)))
2360 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002361
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002362 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002363 int ret;
2364 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002365
Johannes Berg683b6d32012-11-08 21:25:48 +01002366 ret = rdev_get_channel(rdev, wdev, &chandef);
2367 if (ret == 0) {
2368 if (nl80211_send_chandef(msg, &chandef))
2369 goto nla_put_failure;
2370 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002371 }
2372
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002373 if (wdev->ssid_len) {
2374 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2375 goto nla_put_failure;
2376 }
2377
Johannes Berg55682962007-09-20 13:09:35 -04002378 return genlmsg_end(msg, hdr);
2379
2380 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002381 genlmsg_cancel(msg, hdr);
2382 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002383}
2384
2385static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2386{
2387 int wp_idx = 0;
2388 int if_idx = 0;
2389 int wp_start = cb->args[0];
2390 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002391 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002392 struct wireless_dev *wdev;
2393
Johannes Berg5fe231e2013-05-08 21:45:15 +02002394 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002395 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2396 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002397 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002398 if (wp_idx < wp_start) {
2399 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002400 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002401 }
Johannes Berg55682962007-09-20 13:09:35 -04002402 if_idx = 0;
2403
Johannes Berg89a54e42012-06-15 14:33:17 +02002404 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002405 if (if_idx < if_start) {
2406 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002407 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002408 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002409 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002410 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002411 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002412 goto out;
2413 }
2414 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002415 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002416
2417 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002418 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002419 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002420 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002421
2422 cb->args[0] = wp_idx;
2423 cb->args[1] = if_idx;
2424
2425 return skb->len;
2426}
2427
2428static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2429{
2430 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002432 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002433
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002434 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002435 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002436 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002437
Eric W. Biederman15e47302012-09-07 20:12:54 +00002438 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002439 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002440 nlmsg_free(msg);
2441 return -ENOBUFS;
2442 }
Johannes Berg55682962007-09-20 13:09:35 -04002443
Johannes Berg134e6372009-07-10 09:51:34 +00002444 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002445}
2446
Michael Wu66f7ac52008-01-31 19:48:22 +01002447static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2448 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2449 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2450 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2451 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2452 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002453 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002454};
2455
2456static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2457{
2458 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2459 int flag;
2460
2461 *mntrflags = 0;
2462
2463 if (!nla)
2464 return -EINVAL;
2465
2466 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2467 nla, mntr_flags_policy))
2468 return -EINVAL;
2469
2470 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2471 if (flags[flag])
2472 *mntrflags |= (1<<flag);
2473
2474 return 0;
2475}
2476
Johannes Berg9bc383d2009-11-19 11:55:19 +01002477static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002478 struct net_device *netdev, u8 use_4addr,
2479 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002480{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002481 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002482 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002483 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002484 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002485 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002486
2487 switch (iftype) {
2488 case NL80211_IFTYPE_AP_VLAN:
2489 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2490 return 0;
2491 break;
2492 case NL80211_IFTYPE_STATION:
2493 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2494 return 0;
2495 break;
2496 default:
2497 break;
2498 }
2499
2500 return -EOPNOTSUPP;
2501}
2502
Johannes Berg55682962007-09-20 13:09:35 -04002503static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2504{
Johannes Berg4c476992010-10-04 21:36:35 +02002505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002506 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002507 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002508 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002509 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002510 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002511 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002512
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002513 memset(&params, 0, sizeof(params));
2514
Johannes Berg04a773a2009-04-19 21:24:32 +02002515 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002516
Johannes Berg723b0382008-09-16 20:22:09 +02002517 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002518 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002519 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002520 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002521 if (ntype > NL80211_IFTYPE_MAX)
2522 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002523 }
2524
Johannes Berg92ffe052008-09-16 20:39:36 +02002525 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002526 struct wireless_dev *wdev = dev->ieee80211_ptr;
2527
Johannes Berg4c476992010-10-04 21:36:35 +02002528 if (ntype != NL80211_IFTYPE_MESH_POINT)
2529 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002530 if (netif_running(dev))
2531 return -EBUSY;
2532
2533 wdev_lock(wdev);
2534 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2535 IEEE80211_MAX_MESH_ID_LEN);
2536 wdev->mesh_id_up_len =
2537 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2538 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2539 wdev->mesh_id_up_len);
2540 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002541 }
2542
Felix Fietkau8b787642009-11-10 18:53:10 +01002543 if (info->attrs[NL80211_ATTR_4ADDR]) {
2544 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2545 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002546 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002547 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002548 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002549 } else {
2550 params.use_4addr = -1;
2551 }
2552
Johannes Berg92ffe052008-09-16 20:39:36 +02002553 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002554 if (ntype != NL80211_IFTYPE_MONITOR)
2555 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002556 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2557 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002558 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002559 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002560
2561 flags = &_flags;
2562 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002563 }
Johannes Berg3b858752009-03-12 09:55:09 +01002564
Luciano Coelho18003292013-08-29 13:26:57 +03002565 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002566 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2567 return -EOPNOTSUPP;
2568
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002569 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002570 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002571 else
2572 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002573
Johannes Berg9bc383d2009-11-19 11:55:19 +01002574 if (!err && params.use_4addr != -1)
2575 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2576
Johannes Berg55682962007-09-20 13:09:35 -04002577 return err;
2578}
2579
2580static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2581{
Johannes Berg4c476992010-10-04 21:36:35 +02002582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002583 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002584 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002585 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002586 int err;
2587 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002588 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002589
Johannes Berg78f22b62014-03-24 17:57:27 +01002590 /* to avoid failing a new interface creation due to pending removal */
2591 cfg80211_destroy_ifaces(rdev);
2592
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002593 memset(&params, 0, sizeof(params));
2594
Johannes Berg55682962007-09-20 13:09:35 -04002595 if (!info->attrs[NL80211_ATTR_IFNAME])
2596 return -EINVAL;
2597
2598 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2599 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2600 if (type > NL80211_IFTYPE_MAX)
2601 return -EINVAL;
2602 }
2603
Johannes Berg79c97e92009-07-07 03:56:12 +02002604 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002605 !(rdev->wiphy.interface_modes & (1 << type)))
2606 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002607
Ben Greeare8f479b2014-10-22 12:23:05 -07002608 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2609 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2610 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002611 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2612 ETH_ALEN);
2613 if (!is_valid_ether_addr(params.macaddr))
2614 return -EADDRNOTAVAIL;
2615 }
2616
Johannes Berg9bc383d2009-11-19 11:55:19 +01002617 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002618 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002619 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002620 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002621 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002622 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002623
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002624 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2625 if (!msg)
2626 return -ENOMEM;
2627
Michael Wu66f7ac52008-01-31 19:48:22 +01002628 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2629 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2630 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002631
Luciano Coelho18003292013-08-29 13:26:57 +03002632 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002633 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2634 return -EOPNOTSUPP;
2635
Hila Gonene35e4d22012-06-27 17:19:42 +03002636 wdev = rdev_add_virtual_intf(rdev,
2637 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2638 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002639 if (IS_ERR(wdev)) {
2640 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002641 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002642 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002643
Johannes Berg78f22b62014-03-24 17:57:27 +01002644 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2645 wdev->owner_nlportid = info->snd_portid;
2646
Johannes Berg98104fde2012-06-16 00:19:54 +02002647 switch (type) {
2648 case NL80211_IFTYPE_MESH_POINT:
2649 if (!info->attrs[NL80211_ATTR_MESH_ID])
2650 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002651 wdev_lock(wdev);
2652 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2653 IEEE80211_MAX_MESH_ID_LEN);
2654 wdev->mesh_id_up_len =
2655 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2656 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2657 wdev->mesh_id_up_len);
2658 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002659 break;
2660 case NL80211_IFTYPE_P2P_DEVICE:
2661 /*
2662 * P2P Device doesn't have a netdev, so doesn't go
2663 * through the netdev notifier and must be added here
2664 */
2665 mutex_init(&wdev->mtx);
2666 INIT_LIST_HEAD(&wdev->event_list);
2667 spin_lock_init(&wdev->event_lock);
2668 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2669 spin_lock_init(&wdev->mgmt_registrations_lock);
2670
Johannes Berg98104fde2012-06-16 00:19:54 +02002671 wdev->identifier = ++rdev->wdev_id;
2672 list_add_rcu(&wdev->list, &rdev->wdev_list);
2673 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002674 break;
2675 default:
2676 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002677 }
2678
Eric W. Biederman15e47302012-09-07 20:12:54 +00002679 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002680 rdev, wdev) < 0) {
2681 nlmsg_free(msg);
2682 return -ENOBUFS;
2683 }
2684
2685 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002686}
2687
2688static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2689{
Johannes Berg4c476992010-10-04 21:36:35 +02002690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002691 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002692
Johannes Berg4c476992010-10-04 21:36:35 +02002693 if (!rdev->ops->del_virtual_intf)
2694 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002695
Johannes Berg84efbb82012-06-16 00:00:26 +02002696 /*
2697 * If we remove a wireless device without a netdev then clear
2698 * user_ptr[1] so that nl80211_post_doit won't dereference it
2699 * to check if it needs to do dev_put(). Otherwise it crashes
2700 * since the wdev has been freed, unlike with a netdev where
2701 * we need the dev_put() for the netdev to really be freed.
2702 */
2703 if (!wdev->netdev)
2704 info->user_ptr[1] = NULL;
2705
Hila Gonene35e4d22012-06-27 17:19:42 +03002706 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002707}
2708
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002709static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2710{
2711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2712 struct net_device *dev = info->user_ptr[1];
2713 u16 noack_map;
2714
2715 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2716 return -EINVAL;
2717
2718 if (!rdev->ops->set_noack_map)
2719 return -EOPNOTSUPP;
2720
2721 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2722
Hila Gonene35e4d22012-06-27 17:19:42 +03002723 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002724}
2725
Johannes Berg41ade002007-12-19 02:03:29 +01002726struct get_key_cookie {
2727 struct sk_buff *msg;
2728 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002729 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002730};
2731
2732static void get_key_callback(void *c, struct key_params *params)
2733{
Johannes Bergb9454e82009-07-08 13:29:08 +02002734 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002735 struct get_key_cookie *cookie = c;
2736
David S. Miller9360ffd2012-03-29 04:41:26 -04002737 if ((params->key &&
2738 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2739 params->key_len, params->key)) ||
2740 (params->seq &&
2741 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2742 params->seq_len, params->seq)) ||
2743 (params->cipher &&
2744 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2745 params->cipher)))
2746 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002747
Johannes Bergb9454e82009-07-08 13:29:08 +02002748 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2749 if (!key)
2750 goto nla_put_failure;
2751
David S. Miller9360ffd2012-03-29 04:41:26 -04002752 if ((params->key &&
2753 nla_put(cookie->msg, NL80211_KEY_DATA,
2754 params->key_len, params->key)) ||
2755 (params->seq &&
2756 nla_put(cookie->msg, NL80211_KEY_SEQ,
2757 params->seq_len, params->seq)) ||
2758 (params->cipher &&
2759 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2760 params->cipher)))
2761 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002762
David S. Miller9360ffd2012-03-29 04:41:26 -04002763 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2764 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002765
2766 nla_nest_end(cookie->msg, key);
2767
Johannes Berg41ade002007-12-19 02:03:29 +01002768 return;
2769 nla_put_failure:
2770 cookie->error = 1;
2771}
2772
2773static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2774{
Johannes Berg4c476992010-10-04 21:36:35 +02002775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002776 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002777 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002778 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002779 const u8 *mac_addr = NULL;
2780 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002781 struct get_key_cookie cookie = {
2782 .error = 0,
2783 };
2784 void *hdr;
2785 struct sk_buff *msg;
2786
2787 if (info->attrs[NL80211_ATTR_KEY_IDX])
2788 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2789
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002790 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002791 return -EINVAL;
2792
2793 if (info->attrs[NL80211_ATTR_MAC])
2794 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2795
Johannes Berge31b8212010-10-05 19:39:30 +02002796 pairwise = !!mac_addr;
2797 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2798 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2799 if (kt >= NUM_NL80211_KEYTYPES)
2800 return -EINVAL;
2801 if (kt != NL80211_KEYTYPE_GROUP &&
2802 kt != NL80211_KEYTYPE_PAIRWISE)
2803 return -EINVAL;
2804 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2805 }
2806
Johannes Berg4c476992010-10-04 21:36:35 +02002807 if (!rdev->ops->get_key)
2808 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002809
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002810 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002811 if (!msg)
2812 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002813
Eric W. Biederman15e47302012-09-07 20:12:54 +00002814 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002815 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002816 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002817 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002818
2819 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002820 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002821
David S. Miller9360ffd2012-03-29 04:41:26 -04002822 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2823 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2824 goto nla_put_failure;
2825 if (mac_addr &&
2826 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2827 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002828
Johannes Berge31b8212010-10-05 19:39:30 +02002829 if (pairwise && mac_addr &&
2830 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2831 return -ENOENT;
2832
Hila Gonene35e4d22012-06-27 17:19:42 +03002833 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2834 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002835
2836 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002837 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002838
2839 if (cookie.error)
2840 goto nla_put_failure;
2841
2842 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002843 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002844
2845 nla_put_failure:
2846 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002847 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002848 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002849 return err;
2850}
2851
2852static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2853{
Johannes Berg4c476992010-10-04 21:36:35 +02002854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002855 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002856 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002857 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002858
Johannes Bergb9454e82009-07-08 13:29:08 +02002859 err = nl80211_parse_key(info, &key);
2860 if (err)
2861 return err;
2862
2863 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002864 return -EINVAL;
2865
Johannes Bergb9454e82009-07-08 13:29:08 +02002866 /* only support setting default key */
2867 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002868 return -EINVAL;
2869
Johannes Bergfffd0932009-07-08 14:22:54 +02002870 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002871
2872 if (key.def) {
2873 if (!rdev->ops->set_default_key) {
2874 err = -EOPNOTSUPP;
2875 goto out;
2876 }
2877
2878 err = nl80211_key_allowed(dev->ieee80211_ptr);
2879 if (err)
2880 goto out;
2881
Hila Gonene35e4d22012-06-27 17:19:42 +03002882 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002883 key.def_uni, key.def_multi);
2884
2885 if (err)
2886 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002887
Johannes Berg3d23e342009-09-29 23:27:28 +02002888#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002889 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002890#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002891 } else {
2892 if (key.def_uni || !key.def_multi) {
2893 err = -EINVAL;
2894 goto out;
2895 }
2896
2897 if (!rdev->ops->set_default_mgmt_key) {
2898 err = -EOPNOTSUPP;
2899 goto out;
2900 }
2901
2902 err = nl80211_key_allowed(dev->ieee80211_ptr);
2903 if (err)
2904 goto out;
2905
Hila Gonene35e4d22012-06-27 17:19:42 +03002906 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002907 if (err)
2908 goto out;
2909
2910#ifdef CONFIG_CFG80211_WEXT
2911 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2912#endif
2913 }
2914
2915 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002916 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002917
Johannes Berg41ade002007-12-19 02:03:29 +01002918 return err;
2919}
2920
2921static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2922{
Johannes Berg4c476992010-10-04 21:36:35 +02002923 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002924 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002925 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002926 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002927 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002928
Johannes Bergb9454e82009-07-08 13:29:08 +02002929 err = nl80211_parse_key(info, &key);
2930 if (err)
2931 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002932
Johannes Bergb9454e82009-07-08 13:29:08 +02002933 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002934 return -EINVAL;
2935
Johannes Berg41ade002007-12-19 02:03:29 +01002936 if (info->attrs[NL80211_ATTR_MAC])
2937 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2938
Johannes Berge31b8212010-10-05 19:39:30 +02002939 if (key.type == -1) {
2940 if (mac_addr)
2941 key.type = NL80211_KEYTYPE_PAIRWISE;
2942 else
2943 key.type = NL80211_KEYTYPE_GROUP;
2944 }
2945
2946 /* for now */
2947 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2948 key.type != NL80211_KEYTYPE_GROUP)
2949 return -EINVAL;
2950
Johannes Berg4c476992010-10-04 21:36:35 +02002951 if (!rdev->ops->add_key)
2952 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002953
Johannes Berge31b8212010-10-05 19:39:30 +02002954 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2955 key.type == NL80211_KEYTYPE_PAIRWISE,
2956 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002957 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002958
2959 wdev_lock(dev->ieee80211_ptr);
2960 err = nl80211_key_allowed(dev->ieee80211_ptr);
2961 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002962 err = rdev_add_key(rdev, dev, key.idx,
2963 key.type == NL80211_KEYTYPE_PAIRWISE,
2964 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002965 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002966
Johannes Berg41ade002007-12-19 02:03:29 +01002967 return err;
2968}
2969
2970static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2971{
Johannes Berg4c476992010-10-04 21:36:35 +02002972 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002973 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002974 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002975 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002976 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002977
Johannes Bergb9454e82009-07-08 13:29:08 +02002978 err = nl80211_parse_key(info, &key);
2979 if (err)
2980 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002981
2982 if (info->attrs[NL80211_ATTR_MAC])
2983 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2984
Johannes Berge31b8212010-10-05 19:39:30 +02002985 if (key.type == -1) {
2986 if (mac_addr)
2987 key.type = NL80211_KEYTYPE_PAIRWISE;
2988 else
2989 key.type = NL80211_KEYTYPE_GROUP;
2990 }
2991
2992 /* for now */
2993 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2994 key.type != NL80211_KEYTYPE_GROUP)
2995 return -EINVAL;
2996
Johannes Berg4c476992010-10-04 21:36:35 +02002997 if (!rdev->ops->del_key)
2998 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002999
Johannes Bergfffd0932009-07-08 14:22:54 +02003000 wdev_lock(dev->ieee80211_ptr);
3001 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003002
3003 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3004 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3005 err = -ENOENT;
3006
Johannes Bergfffd0932009-07-08 14:22:54 +02003007 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003008 err = rdev_del_key(rdev, dev, key.idx,
3009 key.type == NL80211_KEYTYPE_PAIRWISE,
3010 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003011
Johannes Berg3d23e342009-09-29 23:27:28 +02003012#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003013 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003014 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003015 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003016 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003017 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3018 }
3019#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003020 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003021
Johannes Berg41ade002007-12-19 02:03:29 +01003022 return err;
3023}
3024
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303025/* This function returns an error or the number of nested attributes */
3026static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3027{
3028 struct nlattr *attr;
3029 int n_entries = 0, tmp;
3030
3031 nla_for_each_nested(attr, nl_attr, tmp) {
3032 if (nla_len(attr) != ETH_ALEN)
3033 return -EINVAL;
3034
3035 n_entries++;
3036 }
3037
3038 return n_entries;
3039}
3040
3041/*
3042 * This function parses ACL information and allocates memory for ACL data.
3043 * On successful return, the calling function is responsible to free the
3044 * ACL buffer returned by this function.
3045 */
3046static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3047 struct genl_info *info)
3048{
3049 enum nl80211_acl_policy acl_policy;
3050 struct nlattr *attr;
3051 struct cfg80211_acl_data *acl;
3052 int i = 0, n_entries, tmp;
3053
3054 if (!wiphy->max_acl_mac_addrs)
3055 return ERR_PTR(-EOPNOTSUPP);
3056
3057 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3058 return ERR_PTR(-EINVAL);
3059
3060 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3061 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3062 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3063 return ERR_PTR(-EINVAL);
3064
3065 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3066 return ERR_PTR(-EINVAL);
3067
3068 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3069 if (n_entries < 0)
3070 return ERR_PTR(n_entries);
3071
3072 if (n_entries > wiphy->max_acl_mac_addrs)
3073 return ERR_PTR(-ENOTSUPP);
3074
3075 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3076 GFP_KERNEL);
3077 if (!acl)
3078 return ERR_PTR(-ENOMEM);
3079
3080 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3081 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3082 i++;
3083 }
3084
3085 acl->n_acl_entries = n_entries;
3086 acl->acl_policy = acl_policy;
3087
3088 return acl;
3089}
3090
3091static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3092{
3093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3094 struct net_device *dev = info->user_ptr[1];
3095 struct cfg80211_acl_data *acl;
3096 int err;
3097
3098 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3099 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3100 return -EOPNOTSUPP;
3101
3102 if (!dev->ieee80211_ptr->beacon_interval)
3103 return -EINVAL;
3104
3105 acl = parse_acl_data(&rdev->wiphy, info);
3106 if (IS_ERR(acl))
3107 return PTR_ERR(acl);
3108
3109 err = rdev_set_mac_acl(rdev, dev, acl);
3110
3111 kfree(acl);
3112
3113 return err;
3114}
3115
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003116static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003117 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003118{
Johannes Berg88600202012-02-13 15:17:18 +01003119 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003120
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003121 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3122 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3123 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3124 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003125 return -EINVAL;
3126
Johannes Berg88600202012-02-13 15:17:18 +01003127 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003128
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003129 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3130 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3131 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003132 if (!bcn->head_len)
3133 return -EINVAL;
3134 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003135 }
3136
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003137 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3138 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3139 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003140 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003141 }
3142
Johannes Berg4c476992010-10-04 21:36:35 +02003143 if (!haveinfo)
3144 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003145
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003146 if (attrs[NL80211_ATTR_IE]) {
3147 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3148 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003149 }
3150
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003151 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003152 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003153 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003154 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003155 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003156 }
3157
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003158 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003159 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003160 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003161 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003162 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003163 }
3164
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003165 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3166 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3167 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003168 }
3169
Johannes Berg88600202012-02-13 15:17:18 +01003170 return 0;
3171}
3172
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003173static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3174 struct cfg80211_ap_settings *params)
3175{
3176 struct wireless_dev *wdev;
3177 bool ret = false;
3178
Johannes Berg89a54e42012-06-15 14:33:17 +02003179 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003180 if (wdev->iftype != NL80211_IFTYPE_AP &&
3181 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3182 continue;
3183
Johannes Berg683b6d32012-11-08 21:25:48 +01003184 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003185 continue;
3186
Johannes Berg683b6d32012-11-08 21:25:48 +01003187 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003188 ret = true;
3189 break;
3190 }
3191
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003192 return ret;
3193}
3194
Jouni Malinene39e5b52012-09-30 19:29:39 +03003195static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3196 enum nl80211_auth_type auth_type,
3197 enum nl80211_commands cmd)
3198{
3199 if (auth_type > NL80211_AUTHTYPE_MAX)
3200 return false;
3201
3202 switch (cmd) {
3203 case NL80211_CMD_AUTHENTICATE:
3204 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3205 auth_type == NL80211_AUTHTYPE_SAE)
3206 return false;
3207 return true;
3208 case NL80211_CMD_CONNECT:
3209 case NL80211_CMD_START_AP:
3210 /* SAE not supported yet */
3211 if (auth_type == NL80211_AUTHTYPE_SAE)
3212 return false;
3213 return true;
3214 default:
3215 return false;
3216 }
3217}
3218
Johannes Berg88600202012-02-13 15:17:18 +01003219static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3220{
3221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3222 struct net_device *dev = info->user_ptr[1];
3223 struct wireless_dev *wdev = dev->ieee80211_ptr;
3224 struct cfg80211_ap_settings params;
3225 int err;
3226
3227 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3228 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3229 return -EOPNOTSUPP;
3230
3231 if (!rdev->ops->start_ap)
3232 return -EOPNOTSUPP;
3233
3234 if (wdev->beacon_interval)
3235 return -EALREADY;
3236
3237 memset(&params, 0, sizeof(params));
3238
3239 /* these are required for START_AP */
3240 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3241 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3242 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3243 return -EINVAL;
3244
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003245 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003246 if (err)
3247 return err;
3248
3249 params.beacon_interval =
3250 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3251 params.dtim_period =
3252 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3253
3254 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3255 if (err)
3256 return err;
3257
3258 /*
3259 * In theory, some of these attributes should be required here
3260 * but since they were not used when the command was originally
3261 * added, keep them optional for old user space programs to let
3262 * them continue to work with drivers that do not need the
3263 * additional information -- drivers must check!
3264 */
3265 if (info->attrs[NL80211_ATTR_SSID]) {
3266 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3267 params.ssid_len =
3268 nla_len(info->attrs[NL80211_ATTR_SSID]);
3269 if (params.ssid_len == 0 ||
3270 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3271 return -EINVAL;
3272 }
3273
3274 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3275 params.hidden_ssid = nla_get_u32(
3276 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3277 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3278 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3279 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3280 return -EINVAL;
3281 }
3282
3283 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3284
3285 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3286 params.auth_type = nla_get_u32(
3287 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003288 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3289 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003290 return -EINVAL;
3291 } else
3292 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3293
3294 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3295 NL80211_MAX_NR_CIPHER_SUITES);
3296 if (err)
3297 return err;
3298
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303299 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3300 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3301 return -EOPNOTSUPP;
3302 params.inactivity_timeout = nla_get_u16(
3303 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3304 }
3305
Johannes Berg53cabad2012-11-14 15:17:28 +01003306 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3307 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3308 return -EINVAL;
3309 params.p2p_ctwindow =
3310 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3311 if (params.p2p_ctwindow > 127)
3312 return -EINVAL;
3313 if (params.p2p_ctwindow != 0 &&
3314 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3315 return -EINVAL;
3316 }
3317
3318 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3319 u8 tmp;
3320
3321 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3322 return -EINVAL;
3323 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3324 if (tmp > 1)
3325 return -EINVAL;
3326 params.p2p_opp_ps = tmp;
3327 if (params.p2p_opp_ps != 0 &&
3328 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3329 return -EINVAL;
3330 }
3331
Johannes Bergaa430da2012-05-16 23:50:18 +02003332 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003333 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3334 if (err)
3335 return err;
3336 } else if (wdev->preset_chandef.chan) {
3337 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003338 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003339 return -EINVAL;
3340
Ilan Peer174e0cd2014-02-23 09:13:01 +02003341 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3342 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003343 return -EINVAL;
3344
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303345 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3346 params.acl = parse_acl_data(&rdev->wiphy, info);
3347 if (IS_ERR(params.acl))
3348 return PTR_ERR(params.acl);
3349 }
3350
Eliad Peller18998c32014-09-10 14:07:34 +03003351 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3352 params.smps_mode =
3353 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3354 switch (params.smps_mode) {
3355 case NL80211_SMPS_OFF:
3356 break;
3357 case NL80211_SMPS_STATIC:
3358 if (!(rdev->wiphy.features &
3359 NL80211_FEATURE_STATIC_SMPS))
3360 return -EINVAL;
3361 break;
3362 case NL80211_SMPS_DYNAMIC:
3363 if (!(rdev->wiphy.features &
3364 NL80211_FEATURE_DYNAMIC_SMPS))
3365 return -EINVAL;
3366 break;
3367 default:
3368 return -EINVAL;
3369 }
3370 } else {
3371 params.smps_mode = NL80211_SMPS_OFF;
3372 }
3373
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003374 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003375 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003376 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003377 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003378 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003379 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003380 wdev->ssid_len = params.ssid_len;
3381 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003382 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003383 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303384
3385 kfree(params.acl);
3386
Johannes Berg56d18932011-05-09 18:41:15 +02003387 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003388}
3389
Johannes Berg88600202012-02-13 15:17:18 +01003390static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3391{
3392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3393 struct net_device *dev = info->user_ptr[1];
3394 struct wireless_dev *wdev = dev->ieee80211_ptr;
3395 struct cfg80211_beacon_data params;
3396 int err;
3397
3398 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3399 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3400 return -EOPNOTSUPP;
3401
3402 if (!rdev->ops->change_beacon)
3403 return -EOPNOTSUPP;
3404
3405 if (!wdev->beacon_interval)
3406 return -EINVAL;
3407
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003408 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003409 if (err)
3410 return err;
3411
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003412 wdev_lock(wdev);
3413 err = rdev_change_beacon(rdev, dev, &params);
3414 wdev_unlock(wdev);
3415
3416 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003417}
3418
3419static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003420{
Johannes Berg4c476992010-10-04 21:36:35 +02003421 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3422 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003423
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003424 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003425}
3426
Johannes Berg5727ef12007-12-19 02:03:34 +01003427static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3428 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3429 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3430 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003431 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003432 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003433 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003434};
3435
Johannes Bergeccb8e82009-05-11 21:57:56 +03003436static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003437 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003438 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003439{
3440 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003441 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003442 int flag;
3443
Johannes Bergeccb8e82009-05-11 21:57:56 +03003444 /*
3445 * Try parsing the new attribute first so userspace
3446 * can specify both for older kernels.
3447 */
3448 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3449 if (nla) {
3450 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003451
Johannes Bergeccb8e82009-05-11 21:57:56 +03003452 sta_flags = nla_data(nla);
3453 params->sta_flags_mask = sta_flags->mask;
3454 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003455 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003456 if ((params->sta_flags_mask |
3457 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3458 return -EINVAL;
3459 return 0;
3460 }
3461
3462 /* if present, parse the old attribute */
3463
3464 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003465 if (!nla)
3466 return 0;
3467
3468 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3469 nla, sta_flags_policy))
3470 return -EINVAL;
3471
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003472 /*
3473 * Only allow certain flags for interface types so that
3474 * other attributes are silently ignored. Remember that
3475 * this is backward compatibility code with old userspace
3476 * and shouldn't be hit in other cases anyway.
3477 */
3478 switch (iftype) {
3479 case NL80211_IFTYPE_AP:
3480 case NL80211_IFTYPE_AP_VLAN:
3481 case NL80211_IFTYPE_P2P_GO:
3482 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3483 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3484 BIT(NL80211_STA_FLAG_WME) |
3485 BIT(NL80211_STA_FLAG_MFP);
3486 break;
3487 case NL80211_IFTYPE_P2P_CLIENT:
3488 case NL80211_IFTYPE_STATION:
3489 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3490 BIT(NL80211_STA_FLAG_TDLS_PEER);
3491 break;
3492 case NL80211_IFTYPE_MESH_POINT:
3493 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3494 BIT(NL80211_STA_FLAG_MFP) |
3495 BIT(NL80211_STA_FLAG_AUTHORIZED);
3496 default:
3497 return -EINVAL;
3498 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003499
Johannes Berg3383b5a2012-05-10 20:14:43 +02003500 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3501 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003502 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003503
Johannes Berg3383b5a2012-05-10 20:14:43 +02003504 /* no longer support new API additions in old API */
3505 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3506 return -EINVAL;
3507 }
3508 }
3509
Johannes Berg5727ef12007-12-19 02:03:34 +01003510 return 0;
3511}
3512
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003513static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3514 int attr)
3515{
3516 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003517 u32 bitrate;
3518 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003519
3520 rate = nla_nest_start(msg, attr);
3521 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003522 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003523
3524 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3525 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003526 /* report 16-bit bitrate only if we can */
3527 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003528 if (bitrate > 0 &&
3529 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3530 return false;
3531 if (bitrate_compat > 0 &&
3532 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3533 return false;
3534
3535 if (info->flags & RATE_INFO_FLAGS_MCS) {
3536 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3537 return false;
3538 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3539 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3540 return false;
3541 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3542 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3543 return false;
3544 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3545 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3546 return false;
3547 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3548 return false;
3549 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3550 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3551 return false;
3552 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3553 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3554 return false;
3555 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3556 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3557 return false;
3558 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3559 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3560 return false;
3561 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3562 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3563 return false;
3564 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003565
3566 nla_nest_end(msg, rate);
3567 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003568}
3569
Felix Fietkau119363c2013-04-22 16:29:30 +02003570static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3571 int id)
3572{
3573 void *attr;
3574 int i = 0;
3575
3576 if (!mask)
3577 return true;
3578
3579 attr = nla_nest_start(msg, id);
3580 if (!attr)
3581 return false;
3582
3583 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3584 if (!(mask & BIT(i)))
3585 continue;
3586
3587 if (nla_put_u8(msg, i, signal[i]))
3588 return false;
3589 }
3590
3591 nla_nest_end(msg, attr);
3592
3593 return true;
3594}
3595
Eric W. Biederman15e47302012-09-07 20:12:54 +00003596static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003597 int flags,
3598 struct cfg80211_registered_device *rdev,
3599 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003600 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003601{
3602 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003603 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003604
Eric W. Biederman15e47302012-09-07 20:12:54 +00003605 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003606 if (!hdr)
3607 return -1;
3608
David S. Miller9360ffd2012-03-29 04:41:26 -04003609 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3610 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3611 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3612 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003613
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003614 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3615 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003616 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003617 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3618 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3619 sinfo->connected_time))
3620 goto nla_put_failure;
3621 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3622 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3623 sinfo->inactive_time))
3624 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003625 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3626 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003627 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003628 (u32)sinfo->rx_bytes))
3629 goto nla_put_failure;
3630 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003631 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003632 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3633 (u32)sinfo->tx_bytes))
3634 goto nla_put_failure;
3635 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3636 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003637 sinfo->rx_bytes))
3638 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003639 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3640 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003641 sinfo->tx_bytes))
3642 goto nla_put_failure;
3643 if ((sinfo->filled & STATION_INFO_LLID) &&
3644 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3645 goto nla_put_failure;
3646 if ((sinfo->filled & STATION_INFO_PLID) &&
3647 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3648 goto nla_put_failure;
3649 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3650 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3651 sinfo->plink_state))
3652 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003653 switch (rdev->wiphy.signal_type) {
3654 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003655 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3656 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3657 sinfo->signal))
3658 goto nla_put_failure;
3659 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3660 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3661 sinfo->signal_avg))
3662 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003663 break;
3664 default:
3665 break;
3666 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003667 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3668 if (!nl80211_put_signal(msg, sinfo->chains,
3669 sinfo->chain_signal,
3670 NL80211_STA_INFO_CHAIN_SIGNAL))
3671 goto nla_put_failure;
3672 }
3673 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3674 if (!nl80211_put_signal(msg, sinfo->chains,
3675 sinfo->chain_signal_avg,
3676 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3677 goto nla_put_failure;
3678 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003679 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003680 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3681 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003682 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003683 }
3684 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3685 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3686 NL80211_STA_INFO_RX_BITRATE))
3687 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003688 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003689 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3690 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3691 sinfo->rx_packets))
3692 goto nla_put_failure;
3693 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3694 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3695 sinfo->tx_packets))
3696 goto nla_put_failure;
3697 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3698 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3699 sinfo->tx_retries))
3700 goto nla_put_failure;
3701 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3702 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3703 sinfo->tx_failed))
3704 goto nla_put_failure;
Antonio Quartulli867d849f2014-05-19 21:53:19 +02003705 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3706 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3707 sinfo->expected_throughput))
3708 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003709 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3710 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3711 sinfo->beacon_loss_count))
3712 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003713 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3714 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3715 sinfo->local_pm))
3716 goto nla_put_failure;
3717 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3718 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3719 sinfo->peer_pm))
3720 goto nla_put_failure;
3721 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3722 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3723 sinfo->nonpeer_pm))
3724 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003725 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3726 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3727 if (!bss_param)
3728 goto nla_put_failure;
3729
David S. Miller9360ffd2012-03-29 04:41:26 -04003730 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3731 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3732 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3733 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3734 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3735 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3736 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3737 sinfo->bss_param.dtim_period) ||
3738 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3739 sinfo->bss_param.beacon_interval))
3740 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003741
3742 nla_nest_end(msg, bss_param);
3743 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003744 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3745 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3746 sizeof(struct nl80211_sta_flag_update),
3747 &sinfo->sta_flags))
3748 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003749 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3750 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3751 sinfo->t_offset))
3752 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003753 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003754
David S. Miller9360ffd2012-03-29 04:41:26 -04003755 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3756 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3757 sinfo->assoc_req_ies))
3758 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003759
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003760 return genlmsg_end(msg, hdr);
3761
3762 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003763 genlmsg_cancel(msg, hdr);
3764 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003765}
3766
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003767static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003768 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003769{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003770 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003771 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003772 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003773 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003774 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003775 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003776
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003777 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003778 if (err)
3779 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003780
Johannes Berg97990a02013-04-19 01:02:55 +02003781 if (!wdev->netdev) {
3782 err = -EINVAL;
3783 goto out_err;
3784 }
3785
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003786 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003787 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003788 goto out_err;
3789 }
3790
Johannes Bergbba95fe2008-07-29 13:22:51 +02003791 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003792 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003793 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003794 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003795 if (err == -ENOENT)
3796 break;
3797 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003798 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003799
3800 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003801 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003802 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003803 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003804 &sinfo) < 0)
3805 goto out;
3806
3807 sta_idx++;
3808 }
3809
3810
3811 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003812 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003813 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003814 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003815 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003816
3817 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003818}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003819
Johannes Berg5727ef12007-12-19 02:03:34 +01003820static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3821{
Johannes Berg4c476992010-10-04 21:36:35 +02003822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3823 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003824 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003825 struct sk_buff *msg;
3826 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003827 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003828
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003829 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003830
3831 if (!info->attrs[NL80211_ATTR_MAC])
3832 return -EINVAL;
3833
3834 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3835
Johannes Berg4c476992010-10-04 21:36:35 +02003836 if (!rdev->ops->get_station)
3837 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003838
Hila Gonene35e4d22012-06-27 17:19:42 +03003839 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003840 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003841 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003842
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003843 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003844 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003845 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003846
Eric W. Biederman15e47302012-09-07 20:12:54 +00003847 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003848 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003849 nlmsg_free(msg);
3850 return -ENOBUFS;
3851 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003852
Johannes Berg4c476992010-10-04 21:36:35 +02003853 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003854}
3855
Johannes Berg77ee7c82013-02-15 00:48:33 +01003856int cfg80211_check_station_change(struct wiphy *wiphy,
3857 struct station_parameters *params,
3858 enum cfg80211_station_type statype)
3859{
3860 if (params->listen_interval != -1)
3861 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003862 if (params->aid &&
3863 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003864 return -EINVAL;
3865
3866 /* When you run into this, adjust the code below for the new flag */
3867 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3868
3869 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003870 case CFG80211_STA_MESH_PEER_KERNEL:
3871 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003872 /*
3873 * No ignoring the TDLS flag here -- the userspace mesh
3874 * code doesn't have the bug of including TDLS in the
3875 * mask everywhere.
3876 */
3877 if (params->sta_flags_mask &
3878 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3879 BIT(NL80211_STA_FLAG_MFP) |
3880 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3881 return -EINVAL;
3882 break;
3883 case CFG80211_STA_TDLS_PEER_SETUP:
3884 case CFG80211_STA_TDLS_PEER_ACTIVE:
3885 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3886 return -EINVAL;
3887 /* ignore since it can't change */
3888 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3889 break;
3890 default:
3891 /* disallow mesh-specific things */
3892 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3893 return -EINVAL;
3894 if (params->local_pm)
3895 return -EINVAL;
3896 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3897 return -EINVAL;
3898 }
3899
3900 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3901 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3902 /* TDLS can't be set, ... */
3903 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3904 return -EINVAL;
3905 /*
3906 * ... but don't bother the driver with it. This works around
3907 * a hostapd/wpa_supplicant issue -- it always includes the
3908 * TLDS_PEER flag in the mask even for AP mode.
3909 */
3910 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3911 }
3912
3913 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3914 /* reject other things that can't change */
3915 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3916 return -EINVAL;
3917 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3918 return -EINVAL;
3919 if (params->supported_rates)
3920 return -EINVAL;
3921 if (params->ext_capab || params->ht_capa || params->vht_capa)
3922 return -EINVAL;
3923 }
3924
3925 if (statype != CFG80211_STA_AP_CLIENT) {
3926 if (params->vlan)
3927 return -EINVAL;
3928 }
3929
3930 switch (statype) {
3931 case CFG80211_STA_AP_MLME_CLIENT:
3932 /* Use this only for authorizing/unauthorizing a station */
3933 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3934 return -EOPNOTSUPP;
3935 break;
3936 case CFG80211_STA_AP_CLIENT:
3937 /* accept only the listed bits */
3938 if (params->sta_flags_mask &
3939 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3940 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3941 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3942 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3943 BIT(NL80211_STA_FLAG_WME) |
3944 BIT(NL80211_STA_FLAG_MFP)))
3945 return -EINVAL;
3946
3947 /* but authenticated/associated only if driver handles it */
3948 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3949 params->sta_flags_mask &
3950 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3951 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3952 return -EINVAL;
3953 break;
3954 case CFG80211_STA_IBSS:
3955 case CFG80211_STA_AP_STA:
3956 /* reject any changes other than AUTHORIZED */
3957 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3958 return -EINVAL;
3959 break;
3960 case CFG80211_STA_TDLS_PEER_SETUP:
3961 /* reject any changes other than AUTHORIZED or WME */
3962 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3963 BIT(NL80211_STA_FLAG_WME)))
3964 return -EINVAL;
3965 /* force (at least) rates when authorizing */
3966 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3967 !params->supported_rates)
3968 return -EINVAL;
3969 break;
3970 case CFG80211_STA_TDLS_PEER_ACTIVE:
3971 /* reject any changes */
3972 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003973 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003974 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3975 return -EINVAL;
3976 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003977 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003978 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3979 return -EINVAL;
3980 break;
3981 }
3982
3983 return 0;
3984}
3985EXPORT_SYMBOL(cfg80211_check_station_change);
3986
Johannes Berg5727ef12007-12-19 02:03:34 +01003987/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003988 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003989 */
Johannes Berg80b99892011-11-18 16:23:01 +01003990static struct net_device *get_vlan(struct genl_info *info,
3991 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003992{
Johannes Berg463d0182009-07-14 00:33:35 +02003993 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003994 struct net_device *v;
3995 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003996
Johannes Berg80b99892011-11-18 16:23:01 +01003997 if (!vlanattr)
3998 return NULL;
3999
4000 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4001 if (!v)
4002 return ERR_PTR(-ENODEV);
4003
4004 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4005 ret = -EINVAL;
4006 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004007 }
Johannes Berg80b99892011-11-18 16:23:01 +01004008
Johannes Berg77ee7c82013-02-15 00:48:33 +01004009 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4010 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4011 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4012 ret = -EINVAL;
4013 goto error;
4014 }
4015
Johannes Berg80b99892011-11-18 16:23:01 +01004016 if (!netif_running(v)) {
4017 ret = -ENETDOWN;
4018 goto error;
4019 }
4020
4021 return v;
4022 error:
4023 dev_put(v);
4024 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004025}
4026
Johannes Berg94e860f2014-01-20 23:58:15 +01004027static const struct nla_policy
4028nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004029 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4030 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4031};
4032
Johannes Bergff276692013-02-15 00:09:01 +01004033static int nl80211_parse_sta_wme(struct genl_info *info,
4034 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004035{
Jouni Malinendf881292013-02-14 21:10:54 +02004036 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4037 struct nlattr *nla;
4038 int err;
4039
Jouni Malinendf881292013-02-14 21:10:54 +02004040 /* parse WME attributes if present */
4041 if (!info->attrs[NL80211_ATTR_STA_WME])
4042 return 0;
4043
4044 nla = info->attrs[NL80211_ATTR_STA_WME];
4045 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4046 nl80211_sta_wme_policy);
4047 if (err)
4048 return err;
4049
4050 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4051 params->uapsd_queues = nla_get_u8(
4052 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4053 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4054 return -EINVAL;
4055
4056 if (tb[NL80211_STA_WME_MAX_SP])
4057 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4058
4059 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4060 return -EINVAL;
4061
4062 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4063
4064 return 0;
4065}
4066
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304067static int nl80211_parse_sta_channel_info(struct genl_info *info,
4068 struct station_parameters *params)
4069{
4070 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4071 params->supported_channels =
4072 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4073 params->supported_channels_len =
4074 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4075 /*
4076 * Need to include at least one (first channel, number of
4077 * channels) tuple for each subband, and must have proper
4078 * tuples for the rest of the data as well.
4079 */
4080 if (params->supported_channels_len < 2)
4081 return -EINVAL;
4082 if (params->supported_channels_len % 2)
4083 return -EINVAL;
4084 }
4085
4086 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4087 params->supported_oper_classes =
4088 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4089 params->supported_oper_classes_len =
4090 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4091 /*
4092 * The value of the Length field of the Supported Operating
4093 * Classes element is between 2 and 253.
4094 */
4095 if (params->supported_oper_classes_len < 2 ||
4096 params->supported_oper_classes_len > 253)
4097 return -EINVAL;
4098 }
4099 return 0;
4100}
4101
Johannes Bergff276692013-02-15 00:09:01 +01004102static int nl80211_set_station_tdls(struct genl_info *info,
4103 struct station_parameters *params)
4104{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304105 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004106 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004107 if (info->attrs[NL80211_ATTR_PEER_AID])
4108 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004109 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4110 params->ht_capa =
4111 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4112 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4113 params->vht_capa =
4114 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4115
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304116 err = nl80211_parse_sta_channel_info(info, params);
4117 if (err)
4118 return err;
4119
Johannes Bergff276692013-02-15 00:09:01 +01004120 return nl80211_parse_sta_wme(info, params);
4121}
4122
Johannes Berg5727ef12007-12-19 02:03:34 +01004123static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4124{
Johannes Berg4c476992010-10-04 21:36:35 +02004125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004126 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004127 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004128 u8 *mac_addr;
4129 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004130
4131 memset(&params, 0, sizeof(params));
4132
4133 params.listen_interval = -1;
4134
Johannes Berg77ee7c82013-02-15 00:48:33 +01004135 if (!rdev->ops->change_station)
4136 return -EOPNOTSUPP;
4137
Johannes Berg5727ef12007-12-19 02:03:34 +01004138 if (info->attrs[NL80211_ATTR_STA_AID])
4139 return -EINVAL;
4140
4141 if (!info->attrs[NL80211_ATTR_MAC])
4142 return -EINVAL;
4143
4144 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4145
4146 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4147 params.supported_rates =
4148 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4149 params.supported_rates_len =
4150 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4151 }
4152
Jouni Malinen9d62a982013-02-14 21:10:13 +02004153 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4154 params.capability =
4155 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4156 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4157 }
4158
4159 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4160 params.ext_capab =
4161 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4162 params.ext_capab_len =
4163 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4164 }
4165
Jouni Malinendf881292013-02-14 21:10:54 +02004166 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004167 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004168
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004169 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004170 return -EINVAL;
4171
Johannes Bergf8bacc22013-02-14 23:27:01 +01004172 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004173 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004174 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4175 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4176 return -EINVAL;
4177 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004178
Johannes Bergf8bacc22013-02-14 23:27:01 +01004179 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004180 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004181 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4182 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4183 return -EINVAL;
4184 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4185 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004186
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004187 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4188 enum nl80211_mesh_power_mode pm = nla_get_u32(
4189 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4190
4191 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4192 pm > NL80211_MESH_POWER_MAX)
4193 return -EINVAL;
4194
4195 params.local_pm = pm;
4196 }
4197
Johannes Berg77ee7c82013-02-15 00:48:33 +01004198 /* Include parameters for TDLS peer (will check later) */
4199 err = nl80211_set_station_tdls(info, &params);
4200 if (err)
4201 return err;
4202
4203 params.vlan = get_vlan(info, rdev);
4204 if (IS_ERR(params.vlan))
4205 return PTR_ERR(params.vlan);
4206
Johannes Berga97f4422009-06-18 17:23:43 +02004207 switch (dev->ieee80211_ptr->iftype) {
4208 case NL80211_IFTYPE_AP:
4209 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004210 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004211 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004212 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004213 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004214 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004215 break;
4216 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004217 err = -EOPNOTSUPP;
4218 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004219 }
4220
Johannes Berg77ee7c82013-02-15 00:48:33 +01004221 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004222 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004223
Johannes Berg77ee7c82013-02-15 00:48:33 +01004224 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004225 if (params.vlan)
4226 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004227
Johannes Berg5727ef12007-12-19 02:03:34 +01004228 return err;
4229}
4230
4231static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4232{
Johannes Berg4c476992010-10-04 21:36:35 +02004233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004234 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004235 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004236 struct station_parameters params;
4237 u8 *mac_addr = NULL;
4238
4239 memset(&params, 0, sizeof(params));
4240
Johannes Berg984c3112013-02-14 23:43:25 +01004241 if (!rdev->ops->add_station)
4242 return -EOPNOTSUPP;
4243
Johannes Berg5727ef12007-12-19 02:03:34 +01004244 if (!info->attrs[NL80211_ATTR_MAC])
4245 return -EINVAL;
4246
Johannes Berg5727ef12007-12-19 02:03:34 +01004247 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4248 return -EINVAL;
4249
4250 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4251 return -EINVAL;
4252
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004253 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4254 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004255 return -EINVAL;
4256
Johannes Berg5727ef12007-12-19 02:03:34 +01004257 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4258 params.supported_rates =
4259 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4260 params.supported_rates_len =
4261 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4262 params.listen_interval =
4263 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004264
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004265 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004266 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004267 else
4268 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004269 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4270 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004271
Jouni Malinen9d62a982013-02-14 21:10:13 +02004272 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4273 params.capability =
4274 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4275 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4276 }
4277
4278 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4279 params.ext_capab =
4280 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4281 params.ext_capab_len =
4282 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4283 }
4284
Jouni Malinen36aedc92008-08-25 11:58:58 +03004285 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4286 params.ht_capa =
4287 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004288
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004289 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4290 params.vht_capa =
4291 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4292
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004293 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4294 params.opmode_notif_used = true;
4295 params.opmode_notif =
4296 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4297 }
4298
Johannes Bergf8bacc22013-02-14 23:27:01 +01004299 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004300 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004301 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4302 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4303 return -EINVAL;
4304 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004305
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304306 err = nl80211_parse_sta_channel_info(info, &params);
4307 if (err)
4308 return err;
4309
Johannes Bergff276692013-02-15 00:09:01 +01004310 err = nl80211_parse_sta_wme(info, &params);
4311 if (err)
4312 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004313
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004314 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004315 return -EINVAL;
4316
Johannes Berg77ee7c82013-02-15 00:48:33 +01004317 /* When you run into this, adjust the code below for the new flag */
4318 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4319
Johannes Bergbdd90d52011-12-14 12:20:27 +01004320 switch (dev->ieee80211_ptr->iftype) {
4321 case NL80211_IFTYPE_AP:
4322 case NL80211_IFTYPE_AP_VLAN:
4323 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004324 /* ignore WME attributes if iface/sta is not capable */
4325 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4326 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4327 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004328
Johannes Bergbdd90d52011-12-14 12:20:27 +01004329 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004330 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4331 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004332 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004333 /* but don't bother the driver with it */
4334 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004335
Johannes Bergd582cff2012-10-26 17:53:44 +02004336 /* allow authenticated/associated only if driver handles it */
4337 if (!(rdev->wiphy.features &
4338 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4339 params.sta_flags_mask &
4340 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4341 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4342 return -EINVAL;
4343
Johannes Bergbdd90d52011-12-14 12:20:27 +01004344 /* must be last in here for error handling */
4345 params.vlan = get_vlan(info, rdev);
4346 if (IS_ERR(params.vlan))
4347 return PTR_ERR(params.vlan);
4348 break;
4349 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004350 /* ignore uAPSD data */
4351 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4352
Johannes Bergd582cff2012-10-26 17:53:44 +02004353 /* associated is disallowed */
4354 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4355 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004356 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004357 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4358 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004359 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004360 break;
4361 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004362 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004363 /* ignore uAPSD data */
4364 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4365
Johannes Berg77ee7c82013-02-15 00:48:33 +01004366 /* these are disallowed */
4367 if (params.sta_flags_mask &
4368 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4369 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004370 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004371 /* Only TDLS peers can be added */
4372 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4373 return -EINVAL;
4374 /* Can only add if TDLS ... */
4375 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4376 return -EOPNOTSUPP;
4377 /* ... with external setup is supported */
4378 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4379 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004380 /*
4381 * Older wpa_supplicant versions always mark the TDLS peer
4382 * as authorized, but it shouldn't yet be.
4383 */
4384 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004385 break;
4386 default:
4387 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004388 }
4389
Johannes Bergbdd90d52011-12-14 12:20:27 +01004390 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004391
Hila Gonene35e4d22012-06-27 17:19:42 +03004392 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004393
Johannes Berg5727ef12007-12-19 02:03:34 +01004394 if (params.vlan)
4395 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004396 return err;
4397}
4398
4399static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4400{
Johannes Berg4c476992010-10-04 21:36:35 +02004401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4402 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004403 struct station_del_parameters params;
4404
4405 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004406
4407 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004408 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004409
Johannes Berge80cf852009-05-11 14:43:13 +02004410 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004411 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004412 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004413 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4414 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004415
Johannes Berg4c476992010-10-04 21:36:35 +02004416 if (!rdev->ops->del_station)
4417 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004418
Jouni Malinen98856862014-10-20 13:20:45 +03004419 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4420 params.subtype =
4421 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4422 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4423 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4424 return -EINVAL;
4425 } else {
4426 /* Default to Deauthentication frame */
4427 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4428 }
4429
4430 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4431 params.reason_code =
4432 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4433 if (params.reason_code == 0)
4434 return -EINVAL; /* 0 is reserved */
4435 } else {
4436 /* Default to reason code 2 */
4437 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4438 }
4439
Jouni Malinen89c771e2014-10-10 20:52:40 +03004440 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004441}
4442
Eric W. Biederman15e47302012-09-07 20:12:54 +00004443static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004444 int flags, struct net_device *dev,
4445 u8 *dst, u8 *next_hop,
4446 struct mpath_info *pinfo)
4447{
4448 void *hdr;
4449 struct nlattr *pinfoattr;
4450
Eric W. Biederman15e47302012-09-07 20:12:54 +00004451 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004452 if (!hdr)
4453 return -1;
4454
David S. Miller9360ffd2012-03-29 04:41:26 -04004455 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4456 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4457 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4458 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4459 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004460
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004461 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4462 if (!pinfoattr)
4463 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004464 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4465 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4466 pinfo->frame_qlen))
4467 goto nla_put_failure;
4468 if (((pinfo->filled & MPATH_INFO_SN) &&
4469 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4470 ((pinfo->filled & MPATH_INFO_METRIC) &&
4471 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4472 pinfo->metric)) ||
4473 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4474 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4475 pinfo->exptime)) ||
4476 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4477 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4478 pinfo->flags)) ||
4479 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4480 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4481 pinfo->discovery_timeout)) ||
4482 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4483 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4484 pinfo->discovery_retries)))
4485 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004486
4487 nla_nest_end(msg, pinfoattr);
4488
4489 return genlmsg_end(msg, hdr);
4490
4491 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004492 genlmsg_cancel(msg, hdr);
4493 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004494}
4495
4496static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004497 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004498{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004499 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004500 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004501 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004502 u8 dst[ETH_ALEN];
4503 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004504 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004505 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004507 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004508 if (err)
4509 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004510
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004511 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004512 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004513 goto out_err;
4514 }
4515
Johannes Berg97990a02013-04-19 01:02:55 +02004516 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004517 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004518 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004519 }
4520
Johannes Bergbba95fe2008-07-29 13:22:51 +02004521 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004522 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004523 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004524 if (err == -ENOENT)
4525 break;
4526 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004527 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004528
Eric W. Biederman15e47302012-09-07 20:12:54 +00004529 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004530 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004531 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004532 &pinfo) < 0)
4533 goto out;
4534
4535 path_idx++;
4536 }
4537
4538
4539 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004540 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004541 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004542 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004543 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004544 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004545}
4546
4547static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4548{
Johannes Berg4c476992010-10-04 21:36:35 +02004549 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004550 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004551 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004552 struct mpath_info pinfo;
4553 struct sk_buff *msg;
4554 u8 *dst = NULL;
4555 u8 next_hop[ETH_ALEN];
4556
4557 memset(&pinfo, 0, sizeof(pinfo));
4558
4559 if (!info->attrs[NL80211_ATTR_MAC])
4560 return -EINVAL;
4561
4562 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4563
Johannes Berg4c476992010-10-04 21:36:35 +02004564 if (!rdev->ops->get_mpath)
4565 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004566
Johannes Berg4c476992010-10-04 21:36:35 +02004567 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4568 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004569
Hila Gonene35e4d22012-06-27 17:19:42 +03004570 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004571 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004572 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004573
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004574 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004575 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004576 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004577
Eric W. Biederman15e47302012-09-07 20:12:54 +00004578 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004579 dev, dst, next_hop, &pinfo) < 0) {
4580 nlmsg_free(msg);
4581 return -ENOBUFS;
4582 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004583
Johannes Berg4c476992010-10-04 21:36:35 +02004584 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004585}
4586
4587static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4588{
Johannes Berg4c476992010-10-04 21:36:35 +02004589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4590 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004591 u8 *dst = NULL;
4592 u8 *next_hop = NULL;
4593
4594 if (!info->attrs[NL80211_ATTR_MAC])
4595 return -EINVAL;
4596
4597 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4598 return -EINVAL;
4599
4600 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4601 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4602
Johannes Berg4c476992010-10-04 21:36:35 +02004603 if (!rdev->ops->change_mpath)
4604 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004605
Johannes Berg4c476992010-10-04 21:36:35 +02004606 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4607 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004608
Hila Gonene35e4d22012-06-27 17:19:42 +03004609 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004610}
Johannes Berg4c476992010-10-04 21:36:35 +02004611
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004612static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4613{
Johannes Berg4c476992010-10-04 21:36:35 +02004614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4615 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004616 u8 *dst = NULL;
4617 u8 *next_hop = NULL;
4618
4619 if (!info->attrs[NL80211_ATTR_MAC])
4620 return -EINVAL;
4621
4622 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4623 return -EINVAL;
4624
4625 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4626 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4627
Johannes Berg4c476992010-10-04 21:36:35 +02004628 if (!rdev->ops->add_mpath)
4629 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004630
Johannes Berg4c476992010-10-04 21:36:35 +02004631 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4632 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004633
Hila Gonene35e4d22012-06-27 17:19:42 +03004634 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004635}
4636
4637static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4638{
Johannes Berg4c476992010-10-04 21:36:35 +02004639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4640 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004641 u8 *dst = NULL;
4642
4643 if (info->attrs[NL80211_ATTR_MAC])
4644 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4645
Johannes Berg4c476992010-10-04 21:36:35 +02004646 if (!rdev->ops->del_mpath)
4647 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004648
Hila Gonene35e4d22012-06-27 17:19:42 +03004649 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004650}
4651
Henning Rogge66be7d22014-09-12 08:58:49 +02004652static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4653{
4654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4655 int err;
4656 struct net_device *dev = info->user_ptr[1];
4657 struct mpath_info pinfo;
4658 struct sk_buff *msg;
4659 u8 *dst = NULL;
4660 u8 mpp[ETH_ALEN];
4661
4662 memset(&pinfo, 0, sizeof(pinfo));
4663
4664 if (!info->attrs[NL80211_ATTR_MAC])
4665 return -EINVAL;
4666
4667 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4668
4669 if (!rdev->ops->get_mpp)
4670 return -EOPNOTSUPP;
4671
4672 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4673 return -EOPNOTSUPP;
4674
4675 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4676 if (err)
4677 return err;
4678
4679 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4680 if (!msg)
4681 return -ENOMEM;
4682
4683 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4684 dev, dst, mpp, &pinfo) < 0) {
4685 nlmsg_free(msg);
4686 return -ENOBUFS;
4687 }
4688
4689 return genlmsg_reply(msg, info);
4690}
4691
4692static int nl80211_dump_mpp(struct sk_buff *skb,
4693 struct netlink_callback *cb)
4694{
4695 struct mpath_info pinfo;
4696 struct cfg80211_registered_device *rdev;
4697 struct wireless_dev *wdev;
4698 u8 dst[ETH_ALEN];
4699 u8 mpp[ETH_ALEN];
4700 int path_idx = cb->args[2];
4701 int err;
4702
4703 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4704 if (err)
4705 return err;
4706
4707 if (!rdev->ops->dump_mpp) {
4708 err = -EOPNOTSUPP;
4709 goto out_err;
4710 }
4711
4712 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4713 err = -EOPNOTSUPP;
4714 goto out_err;
4715 }
4716
4717 while (1) {
4718 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4719 mpp, &pinfo);
4720 if (err == -ENOENT)
4721 break;
4722 if (err)
4723 goto out_err;
4724
4725 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4726 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4727 wdev->netdev, dst, mpp,
4728 &pinfo) < 0)
4729 goto out;
4730
4731 path_idx++;
4732 }
4733
4734 out:
4735 cb->args[2] = path_idx;
4736 err = skb->len;
4737 out_err:
4738 nl80211_finish_wdev_dump(rdev);
4739 return err;
4740}
4741
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004742static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4743{
Johannes Berg4c476992010-10-04 21:36:35 +02004744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4745 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004746 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004747 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004748 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004749
4750 memset(&params, 0, sizeof(params));
4751 /* default to not changing parameters */
4752 params.use_cts_prot = -1;
4753 params.use_short_preamble = -1;
4754 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004755 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004756 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004757 params.p2p_ctwindow = -1;
4758 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004759
4760 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4761 params.use_cts_prot =
4762 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4763 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4764 params.use_short_preamble =
4765 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4766 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4767 params.use_short_slot_time =
4768 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004769 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4770 params.basic_rates =
4771 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4772 params.basic_rates_len =
4773 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4774 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004775 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4776 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004777 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4778 params.ht_opmode =
4779 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004780
Johannes Berg53cabad2012-11-14 15:17:28 +01004781 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4782 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4783 return -EINVAL;
4784 params.p2p_ctwindow =
4785 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4786 if (params.p2p_ctwindow < 0)
4787 return -EINVAL;
4788 if (params.p2p_ctwindow != 0 &&
4789 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4790 return -EINVAL;
4791 }
4792
4793 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4794 u8 tmp;
4795
4796 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4797 return -EINVAL;
4798 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4799 if (tmp > 1)
4800 return -EINVAL;
4801 params.p2p_opp_ps = tmp;
4802 if (params.p2p_opp_ps &&
4803 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4804 return -EINVAL;
4805 }
4806
Johannes Berg4c476992010-10-04 21:36:35 +02004807 if (!rdev->ops->change_bss)
4808 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004809
Johannes Berg074ac8d2010-09-16 14:58:22 +02004810 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004811 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4812 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004813
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004814 wdev_lock(wdev);
4815 err = rdev_change_bss(rdev, dev, &params);
4816 wdev_unlock(wdev);
4817
4818 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004819}
4820
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004821static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004822 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4823 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4824 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4825 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4826 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4827 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004828 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004829};
4830
4831static int parse_reg_rule(struct nlattr *tb[],
4832 struct ieee80211_reg_rule *reg_rule)
4833{
4834 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4835 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4836
4837 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4838 return -EINVAL;
4839 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4840 return -EINVAL;
4841 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4842 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004843 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4844 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004845 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4846 return -EINVAL;
4847
4848 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4849
4850 freq_range->start_freq_khz =
4851 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4852 freq_range->end_freq_khz =
4853 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004854 freq_range->max_bandwidth_khz =
4855 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004856
4857 power_rule->max_eirp =
4858 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4859
4860 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4861 power_rule->max_antenna_gain =
4862 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4863
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004864 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4865 reg_rule->dfs_cac_ms =
4866 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4867
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004868 return 0;
4869}
4870
4871static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4872{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004873 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004874 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004875
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004876 /*
4877 * You should only get this when cfg80211 hasn't yet initialized
4878 * completely when built-in to the kernel right between the time
4879 * window between nl80211_init() and regulatory_init(), if that is
4880 * even possible.
4881 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004882 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004883 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004884
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004885 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4886 user_reg_hint_type =
4887 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4888 else
4889 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4890
4891 switch (user_reg_hint_type) {
4892 case NL80211_USER_REG_HINT_USER:
4893 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004894 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4895 return -EINVAL;
4896
4897 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4898 return regulatory_hint_user(data, user_reg_hint_type);
4899 case NL80211_USER_REG_HINT_INDOOR:
4900 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004901 default:
4902 return -EINVAL;
4903 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004904}
4905
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004906static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004907 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004908{
Johannes Berg4c476992010-10-04 21:36:35 +02004909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004910 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004911 struct wireless_dev *wdev = dev->ieee80211_ptr;
4912 struct mesh_config cur_params;
4913 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004914 void *hdr;
4915 struct nlattr *pinfoattr;
4916 struct sk_buff *msg;
4917
Johannes Berg29cbe682010-12-03 09:20:44 +01004918 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4919 return -EOPNOTSUPP;
4920
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004921 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004922 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004923
Johannes Berg29cbe682010-12-03 09:20:44 +01004924 wdev_lock(wdev);
4925 /* If not connected, get default parameters */
4926 if (!wdev->mesh_id_len)
4927 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4928 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004929 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004930 wdev_unlock(wdev);
4931
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004932 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004933 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004934
4935 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004936 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004937 if (!msg)
4938 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004939 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004940 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004941 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004942 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004943 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004944 if (!pinfoattr)
4945 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004946 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4947 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4948 cur_params.dot11MeshRetryTimeout) ||
4949 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4950 cur_params.dot11MeshConfirmTimeout) ||
4951 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4952 cur_params.dot11MeshHoldingTimeout) ||
4953 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4954 cur_params.dot11MeshMaxPeerLinks) ||
4955 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4956 cur_params.dot11MeshMaxRetries) ||
4957 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4958 cur_params.dot11MeshTTL) ||
4959 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4960 cur_params.element_ttl) ||
4961 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4962 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004963 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4964 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004965 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4966 cur_params.dot11MeshHWMPmaxPREQretries) ||
4967 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4968 cur_params.path_refresh_time) ||
4969 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4970 cur_params.min_discovery_timeout) ||
4971 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4972 cur_params.dot11MeshHWMPactivePathTimeout) ||
4973 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4974 cur_params.dot11MeshHWMPpreqMinInterval) ||
4975 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4976 cur_params.dot11MeshHWMPperrMinInterval) ||
4977 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4978 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4979 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4980 cur_params.dot11MeshHWMPRootMode) ||
4981 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4982 cur_params.dot11MeshHWMPRannInterval) ||
4983 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4984 cur_params.dot11MeshGateAnnouncementProtocol) ||
4985 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4986 cur_params.dot11MeshForwarding) ||
4987 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004988 cur_params.rssi_threshold) ||
4989 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004990 cur_params.ht_opmode) ||
4991 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4992 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4993 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004994 cur_params.dot11MeshHWMProotInterval) ||
4995 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004996 cur_params.dot11MeshHWMPconfirmationInterval) ||
4997 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4998 cur_params.power_mode) ||
4999 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005000 cur_params.dot11MeshAwakeWindowDuration) ||
5001 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5002 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005003 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005004 nla_nest_end(msg, pinfoattr);
5005 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005006 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005007
Johannes Berg3b858752009-03-12 09:55:09 +01005008 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005009 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005010 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005011 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005012 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005013}
5014
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005015static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005016 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5017 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5018 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5019 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5020 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5021 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005022 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005023 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005024 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005025 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5026 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5027 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5028 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5029 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005030 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005031 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005032 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005033 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005034 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005035 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005036 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5037 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005038 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5039 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005040 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005041 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5042 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005043 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005044};
5045
Javier Cardonac80d5452010-12-16 17:37:49 -08005046static const struct nla_policy
5047 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005048 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005049 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5050 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005051 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005052 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005053 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005054 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005055 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005056 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005057};
5058
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005059static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005060 struct mesh_config *cfg,
5061 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005062{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005063 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005064 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005065
Marco Porschea54fba2013-01-07 16:04:48 +01005066#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5067do { \
5068 if (tb[attr]) { \
5069 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5070 return -EINVAL; \
5071 cfg->param = fn(tb[attr]); \
5072 mask |= (1 << (attr - 1)); \
5073 } \
5074} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005075
5076
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005077 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005078 return -EINVAL;
5079 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005080 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005081 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005082 return -EINVAL;
5083
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005084 /* This makes sure that there aren't more than 32 mesh config
5085 * parameters (otherwise our bitfield scheme would not work.) */
5086 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5087
5088 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005089 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005090 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5091 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005092 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005093 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5094 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005095 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005096 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5097 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005098 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005099 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5100 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005101 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005102 mask, NL80211_MESHCONF_MAX_RETRIES,
5103 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005104 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005105 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005107 mask, NL80211_MESHCONF_ELEMENT_TTL,
5108 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005109 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005110 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5111 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005112 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5113 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005114 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5115 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005116 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005117 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5118 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005119 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005120 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5121 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005122 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005123 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5124 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005125 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5126 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005127 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5128 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005129 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005130 1, 65535, mask,
5131 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005132 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005133 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005134 1, 65535, mask,
5135 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005136 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005137 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005138 dot11MeshHWMPnetDiameterTraversalTime,
5139 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005140 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5141 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005142 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5143 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5144 nla_get_u8);
5145 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5146 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005147 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005148 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005149 dot11MeshGateAnnouncementProtocol, 0, 1,
5150 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005151 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005152 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005153 mask, NL80211_MESHCONF_FORWARDING,
5154 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005155 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005156 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005157 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005158 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005159 mask, NL80211_MESHCONF_HT_OPMODE,
5160 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005161 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005162 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005163 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5164 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005165 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005166 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5167 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005168 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005169 dot11MeshHWMPconfirmationInterval,
5170 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005171 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5172 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005173 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5174 NL80211_MESH_POWER_ACTIVE,
5175 NL80211_MESH_POWER_MAX,
5176 mask, NL80211_MESHCONF_POWER_MODE,
5177 nla_get_u32);
5178 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5179 0, 65535, mask,
5180 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005181 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5182 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5183 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005184 if (mask_out)
5185 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005186
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005187 return 0;
5188
5189#undef FILL_IN_MESH_PARAM_IF_SET
5190}
5191
Javier Cardonac80d5452010-12-16 17:37:49 -08005192static int nl80211_parse_mesh_setup(struct genl_info *info,
5193 struct mesh_setup *setup)
5194{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005196 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5197
5198 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5199 return -EINVAL;
5200 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5201 info->attrs[NL80211_ATTR_MESH_SETUP],
5202 nl80211_mesh_setup_params_policy))
5203 return -EINVAL;
5204
Javier Cardonad299a1f2012-03-31 11:31:33 -07005205 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5206 setup->sync_method =
5207 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5208 IEEE80211_SYNC_METHOD_VENDOR :
5209 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5210
Javier Cardonac80d5452010-12-16 17:37:49 -08005211 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5212 setup->path_sel_proto =
5213 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5214 IEEE80211_PATH_PROTOCOL_VENDOR :
5215 IEEE80211_PATH_PROTOCOL_HWMP;
5216
5217 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5218 setup->path_metric =
5219 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5220 IEEE80211_PATH_METRIC_VENDOR :
5221 IEEE80211_PATH_METRIC_AIRTIME;
5222
Javier Cardona581a8b02011-04-07 15:08:27 -07005223
5224 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005225 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005226 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005227 if (!is_valid_ie_attr(ieattr))
5228 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005229 setup->ie = nla_data(ieattr);
5230 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005231 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005232 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5233 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5234 return -EINVAL;
5235 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005236 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5237 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005238 if (setup->is_secure)
5239 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005240
Colleen Twitty6e16d902013-05-08 11:45:59 -07005241 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5242 if (!setup->user_mpm)
5243 return -EINVAL;
5244 setup->auth_id =
5245 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5246 }
5247
Javier Cardonac80d5452010-12-16 17:37:49 -08005248 return 0;
5249}
5250
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005251static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005252 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005253{
5254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5255 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005256 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005257 struct mesh_config cfg;
5258 u32 mask;
5259 int err;
5260
Johannes Berg29cbe682010-12-03 09:20:44 +01005261 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5262 return -EOPNOTSUPP;
5263
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005264 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005265 return -EOPNOTSUPP;
5266
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005267 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005268 if (err)
5269 return err;
5270
Johannes Berg29cbe682010-12-03 09:20:44 +01005271 wdev_lock(wdev);
5272 if (!wdev->mesh_id_len)
5273 err = -ENOLINK;
5274
5275 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005276 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005277
5278 wdev_unlock(wdev);
5279
5280 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005281}
5282
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005283static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5284{
Johannes Berg458f4f92012-12-06 15:47:38 +01005285 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005286 struct sk_buff *msg;
5287 void *hdr = NULL;
5288 struct nlattr *nl_reg_rules;
5289 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005290
5291 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005292 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005293
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005294 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005295 if (!msg)
5296 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005297
Eric W. Biederman15e47302012-09-07 20:12:54 +00005298 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005299 NL80211_CMD_GET_REG);
5300 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005301 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005302
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005303 if (reg_last_request_cell_base() &&
5304 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5305 NL80211_USER_REG_HINT_CELL_BASE))
5306 goto nla_put_failure;
5307
Johannes Berg458f4f92012-12-06 15:47:38 +01005308 rcu_read_lock();
5309 regdom = rcu_dereference(cfg80211_regdomain);
5310
5311 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5312 (regdom->dfs_region &&
5313 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5314 goto nla_put_failure_rcu;
5315
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005316 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5317 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005318 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005319
Johannes Berg458f4f92012-12-06 15:47:38 +01005320 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005321 struct nlattr *nl_reg_rule;
5322 const struct ieee80211_reg_rule *reg_rule;
5323 const struct ieee80211_freq_range *freq_range;
5324 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005325 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005326
Johannes Berg458f4f92012-12-06 15:47:38 +01005327 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005328 freq_range = &reg_rule->freq_range;
5329 power_rule = &reg_rule->power_rule;
5330
5331 nl_reg_rule = nla_nest_start(msg, i);
5332 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005333 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005334
Janusz Dziedzic97524822014-01-30 09:52:20 +01005335 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5336 if (!max_bandwidth_khz)
5337 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5338 reg_rule);
5339
David S. Miller9360ffd2012-03-29 04:41:26 -04005340 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5341 reg_rule->flags) ||
5342 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5343 freq_range->start_freq_khz) ||
5344 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5345 freq_range->end_freq_khz) ||
5346 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005347 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005348 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5349 power_rule->max_antenna_gain) ||
5350 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005351 power_rule->max_eirp) ||
5352 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5353 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005354 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005355
5356 nla_nest_end(msg, nl_reg_rule);
5357 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005358 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005359
5360 nla_nest_end(msg, nl_reg_rules);
5361
5362 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005363 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005364
Johannes Berg458f4f92012-12-06 15:47:38 +01005365nla_put_failure_rcu:
5366 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005367nla_put_failure:
5368 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005369put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005370 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005371 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005372}
5373
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005374static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5375{
5376 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5377 struct nlattr *nl_reg_rule;
5378 char *alpha2 = NULL;
5379 int rem_reg_rules = 0, r = 0;
5380 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005381 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005382 struct ieee80211_regdomain *rd = NULL;
5383
5384 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5385 return -EINVAL;
5386
5387 if (!info->attrs[NL80211_ATTR_REG_RULES])
5388 return -EINVAL;
5389
5390 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5391
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005392 if (info->attrs[NL80211_ATTR_DFS_REGION])
5393 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5394
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005395 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005396 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005397 num_rules++;
5398 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005399 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005400 }
5401
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005402 if (!reg_is_valid_request(alpha2))
5403 return -EINVAL;
5404
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005405 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005406 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005407
5408 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005409 if (!rd)
5410 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005411
5412 rd->n_reg_rules = num_rules;
5413 rd->alpha2[0] = alpha2[0];
5414 rd->alpha2[1] = alpha2[1];
5415
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005416 /*
5417 * Disable DFS master mode if the DFS region was
5418 * not supported or known on this kernel.
5419 */
5420 if (reg_supported_dfs_region(dfs_region))
5421 rd->dfs_region = dfs_region;
5422
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005423 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005424 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005425 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5426 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5427 reg_rule_policy);
5428 if (r)
5429 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005430 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5431 if (r)
5432 goto bad_reg;
5433
5434 rule_idx++;
5435
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005436 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5437 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005438 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005439 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005440 }
5441
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005442 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005443 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005444 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005445
Johannes Bergd2372b32008-10-24 20:32:20 +02005446 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005447 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005448 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005449}
5450
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005451static int validate_scan_freqs(struct nlattr *freqs)
5452{
5453 struct nlattr *attr1, *attr2;
5454 int n_channels = 0, tmp1, tmp2;
5455
5456 nla_for_each_nested(attr1, freqs, tmp1) {
5457 n_channels++;
5458 /*
5459 * Some hardware has a limited channel list for
5460 * scanning, and it is pretty much nonsensical
5461 * to scan for a channel twice, so disallow that
5462 * and don't require drivers to check that the
5463 * channel list they get isn't longer than what
5464 * they can scan, as long as they can scan all
5465 * the channels they registered at once.
5466 */
5467 nla_for_each_nested(attr2, freqs, tmp2)
5468 if (attr1 != attr2 &&
5469 nla_get_u32(attr1) == nla_get_u32(attr2))
5470 return 0;
5471 }
5472
5473 return n_channels;
5474}
5475
Johannes Berg2a519312009-02-10 21:25:55 +01005476static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5477{
Johannes Berg4c476992010-10-04 21:36:35 +02005478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005479 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005480 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005481 struct nlattr *attr;
5482 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005483 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005484 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005485
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005486 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5487 return -EINVAL;
5488
Johannes Berg79c97e92009-07-07 03:56:12 +02005489 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005490
Johannes Berg4c476992010-10-04 21:36:35 +02005491 if (!rdev->ops->scan)
5492 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005493
Johannes Bergf9d15d12014-01-22 11:14:19 +02005494 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005495 err = -EBUSY;
5496 goto unlock;
5497 }
Johannes Berg2a519312009-02-10 21:25:55 +01005498
5499 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005500 n_channels = validate_scan_freqs(
5501 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005502 if (!n_channels) {
5503 err = -EINVAL;
5504 goto unlock;
5505 }
Johannes Berg2a519312009-02-10 21:25:55 +01005506 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005507 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005508 }
5509
5510 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5511 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5512 n_ssids++;
5513
Johannes Bergf9f47522013-03-19 15:04:07 +01005514 if (n_ssids > wiphy->max_scan_ssids) {
5515 err = -EINVAL;
5516 goto unlock;
5517 }
Johannes Berg2a519312009-02-10 21:25:55 +01005518
Jouni Malinen70692ad2009-02-16 19:39:13 +02005519 if (info->attrs[NL80211_ATTR_IE])
5520 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5521 else
5522 ie_len = 0;
5523
Johannes Bergf9f47522013-03-19 15:04:07 +01005524 if (ie_len > wiphy->max_scan_ie_len) {
5525 err = -EINVAL;
5526 goto unlock;
5527 }
Johannes Berg18a83652009-03-31 12:12:05 +02005528
Johannes Berg2a519312009-02-10 21:25:55 +01005529 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005530 + sizeof(*request->ssids) * n_ssids
5531 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005532 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005533 if (!request) {
5534 err = -ENOMEM;
5535 goto unlock;
5536 }
Johannes Berg2a519312009-02-10 21:25:55 +01005537
Johannes Berg2a519312009-02-10 21:25:55 +01005538 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005539 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005540 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005541 if (ie_len) {
5542 if (request->ssids)
5543 request->ie = (void *)(request->ssids + n_ssids);
5544 else
5545 request->ie = (void *)(request->channels + n_channels);
5546 }
Johannes Berg2a519312009-02-10 21:25:55 +01005547
Johannes Berg584991d2009-11-02 13:32:03 +01005548 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005549 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5550 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005551 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005552 struct ieee80211_channel *chan;
5553
5554 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5555
5556 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005557 err = -EINVAL;
5558 goto out_free;
5559 }
Johannes Berg584991d2009-11-02 13:32:03 +01005560
5561 /* ignore disabled channels */
5562 if (chan->flags & IEEE80211_CHAN_DISABLED)
5563 continue;
5564
5565 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005566 i++;
5567 }
5568 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005569 enum ieee80211_band band;
5570
Johannes Berg2a519312009-02-10 21:25:55 +01005571 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005572 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5573 int j;
5574 if (!wiphy->bands[band])
5575 continue;
5576 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005577 struct ieee80211_channel *chan;
5578
5579 chan = &wiphy->bands[band]->channels[j];
5580
5581 if (chan->flags & IEEE80211_CHAN_DISABLED)
5582 continue;
5583
5584 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005585 i++;
5586 }
5587 }
5588 }
5589
Johannes Berg584991d2009-11-02 13:32:03 +01005590 if (!i) {
5591 err = -EINVAL;
5592 goto out_free;
5593 }
5594
5595 request->n_channels = i;
5596
Johannes Berg2a519312009-02-10 21:25:55 +01005597 i = 0;
5598 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5599 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005600 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005601 err = -EINVAL;
5602 goto out_free;
5603 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005604 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005605 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005606 i++;
5607 }
5608 }
5609
Jouni Malinen70692ad2009-02-16 19:39:13 +02005610 if (info->attrs[NL80211_ATTR_IE]) {
5611 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02005612 memcpy((void *)request->ie,
5613 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005614 request->ie_len);
5615 }
5616
Johannes Berg34850ab2011-07-18 18:08:35 +02005617 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005618 if (wiphy->bands[i])
5619 request->rates[i] =
5620 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005621
5622 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5623 nla_for_each_nested(attr,
5624 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5625 tmp) {
5626 enum ieee80211_band band = nla_type(attr);
5627
Dan Carpenter84404622011-07-29 11:52:18 +03005628 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005629 err = -EINVAL;
5630 goto out_free;
5631 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005632
5633 if (!wiphy->bands[band])
5634 continue;
5635
Johannes Berg34850ab2011-07-18 18:08:35 +02005636 err = ieee80211_get_ratemask(wiphy->bands[band],
5637 nla_data(attr),
5638 nla_len(attr),
5639 &request->rates[band]);
5640 if (err)
5641 goto out_free;
5642 }
5643 }
5644
Sam Leffler46856bb2012-10-11 21:03:32 -07005645 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005646 request->flags = nla_get_u32(
5647 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005648 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5649 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005650 err = -EOPNOTSUPP;
5651 goto out_free;
5652 }
5653 }
Sam Lefflered4737712012-10-11 21:03:31 -07005654
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305655 request->no_cck =
5656 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5657
Johannes Bergfd014282012-06-18 19:17:03 +02005658 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005659 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005660 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005661
Johannes Berg79c97e92009-07-07 03:56:12 +02005662 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005663 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005664
Johannes Berg463d0182009-07-14 00:33:35 +02005665 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005666 nl80211_send_scan_start(rdev, wdev);
5667 if (wdev->netdev)
5668 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005669 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005670 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005671 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005672 kfree(request);
5673 }
Johannes Berg3b858752009-03-12 09:55:09 +01005674
Johannes Bergf9f47522013-03-19 15:04:07 +01005675 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005676 return err;
5677}
5678
Luciano Coelho807f8a82011-05-11 17:09:35 +03005679static int nl80211_start_sched_scan(struct sk_buff *skb,
5680 struct genl_info *info)
5681{
5682 struct cfg80211_sched_scan_request *request;
5683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5684 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005685 struct nlattr *attr;
5686 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005687 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005688 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005689 enum ieee80211_band band;
5690 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005691 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005692 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005693
5694 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5695 !rdev->ops->sched_scan_start)
5696 return -EOPNOTSUPP;
5697
5698 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5699 return -EINVAL;
5700
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005701 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5702 return -EINVAL;
5703
5704 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5705 if (interval == 0)
5706 return -EINVAL;
5707
Luciano Coelho807f8a82011-05-11 17:09:35 +03005708 wiphy = &rdev->wiphy;
5709
5710 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5711 n_channels = validate_scan_freqs(
5712 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5713 if (!n_channels)
5714 return -EINVAL;
5715 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005716 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005717 }
5718
5719 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5720 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5721 tmp)
5722 n_ssids++;
5723
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005724 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005725 return -EINVAL;
5726
Johannes Bergea73cbc2014-01-24 10:53:53 +01005727 /*
5728 * First, count the number of 'real' matchsets. Due to an issue with
5729 * the old implementation, matchsets containing only the RSSI attribute
5730 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5731 * RSSI for all matchsets, rather than their own matchset for reporting
5732 * all APs with a strong RSSI. This is needed to be compatible with
5733 * older userspace that treated a matchset with only the RSSI as the
5734 * global RSSI for all other matchsets - if there are other matchsets.
5735 */
5736 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005737 nla_for_each_nested(attr,
5738 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005739 tmp) {
5740 struct nlattr *rssi;
5741
5742 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5743 nla_data(attr), nla_len(attr),
5744 nl80211_match_policy);
5745 if (err)
5746 return err;
5747 /* add other standalone attributes here */
5748 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5749 n_match_sets++;
5750 continue;
5751 }
5752 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5753 if (rssi)
5754 default_match_rssi = nla_get_s32(rssi);
5755 }
5756 }
5757
5758 /* However, if there's no other matchset, add the RSSI one */
5759 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5760 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005761
5762 if (n_match_sets > wiphy->max_match_sets)
5763 return -EINVAL;
5764
Luciano Coelho807f8a82011-05-11 17:09:35 +03005765 if (info->attrs[NL80211_ATTR_IE])
5766 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5767 else
5768 ie_len = 0;
5769
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005770 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005771 return -EINVAL;
5772
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005773 if (rdev->sched_scan_req) {
5774 err = -EINPROGRESS;
5775 goto out;
5776 }
5777
Luciano Coelho807f8a82011-05-11 17:09:35 +03005778 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005779 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005780 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005781 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005782 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005783 if (!request) {
5784 err = -ENOMEM;
5785 goto out;
5786 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005787
5788 if (n_ssids)
5789 request->ssids = (void *)&request->channels[n_channels];
5790 request->n_ssids = n_ssids;
5791 if (ie_len) {
5792 if (request->ssids)
5793 request->ie = (void *)(request->ssids + n_ssids);
5794 else
5795 request->ie = (void *)(request->channels + n_channels);
5796 }
5797
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005798 if (n_match_sets) {
5799 if (request->ie)
5800 request->match_sets = (void *)(request->ie + ie_len);
5801 else if (request->ssids)
5802 request->match_sets =
5803 (void *)(request->ssids + n_ssids);
5804 else
5805 request->match_sets =
5806 (void *)(request->channels + n_channels);
5807 }
5808 request->n_match_sets = n_match_sets;
5809
Luciano Coelho807f8a82011-05-11 17:09:35 +03005810 i = 0;
5811 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5812 /* user specified, bail out if channel not found */
5813 nla_for_each_nested(attr,
5814 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5815 tmp) {
5816 struct ieee80211_channel *chan;
5817
5818 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5819
5820 if (!chan) {
5821 err = -EINVAL;
5822 goto out_free;
5823 }
5824
5825 /* ignore disabled channels */
5826 if (chan->flags & IEEE80211_CHAN_DISABLED)
5827 continue;
5828
5829 request->channels[i] = chan;
5830 i++;
5831 }
5832 } else {
5833 /* all channels */
5834 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5835 int j;
5836 if (!wiphy->bands[band])
5837 continue;
5838 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5839 struct ieee80211_channel *chan;
5840
5841 chan = &wiphy->bands[band]->channels[j];
5842
5843 if (chan->flags & IEEE80211_CHAN_DISABLED)
5844 continue;
5845
5846 request->channels[i] = chan;
5847 i++;
5848 }
5849 }
5850 }
5851
5852 if (!i) {
5853 err = -EINVAL;
5854 goto out_free;
5855 }
5856
5857 request->n_channels = i;
5858
5859 i = 0;
5860 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5861 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5862 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005863 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005864 err = -EINVAL;
5865 goto out_free;
5866 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005867 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005868 memcpy(request->ssids[i].ssid, nla_data(attr),
5869 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005870 i++;
5871 }
5872 }
5873
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005874 i = 0;
5875 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5876 nla_for_each_nested(attr,
5877 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5878 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005879 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005880
Johannes Bergae811e22014-01-24 10:17:47 +01005881 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5882 nla_data(attr), nla_len(attr),
5883 nl80211_match_policy);
5884 if (err)
5885 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005886 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005887 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005888 if (WARN_ON(i >= n_match_sets)) {
5889 /* this indicates a programming error,
5890 * the loop above should have verified
5891 * things properly
5892 */
5893 err = -EINVAL;
5894 goto out_free;
5895 }
5896
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005897 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5898 err = -EINVAL;
5899 goto out_free;
5900 }
5901 memcpy(request->match_sets[i].ssid.ssid,
5902 nla_data(ssid), nla_len(ssid));
5903 request->match_sets[i].ssid.ssid_len =
5904 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005905 /* special attribute - old implemenation w/a */
5906 request->match_sets[i].rssi_thold =
5907 default_match_rssi;
5908 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5909 if (rssi)
5910 request->match_sets[i].rssi_thold =
5911 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005912 }
5913 i++;
5914 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005915
5916 /* there was no other matchset, so the RSSI one is alone */
5917 if (i == 0)
5918 request->match_sets[0].rssi_thold = default_match_rssi;
5919
5920 request->min_rssi_thold = INT_MAX;
5921 for (i = 0; i < n_match_sets; i++)
5922 request->min_rssi_thold =
5923 min(request->match_sets[i].rssi_thold,
5924 request->min_rssi_thold);
5925 } else {
5926 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005927 }
5928
Johannes Berg9900e482014-02-04 21:01:25 +01005929 if (ie_len) {
5930 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005931 memcpy((void *)request->ie,
5932 nla_data(info->attrs[NL80211_ATTR_IE]),
5933 request->ie_len);
5934 }
5935
Sam Leffler46856bb2012-10-11 21:03:32 -07005936 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005937 request->flags = nla_get_u32(
5938 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005939 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5940 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005941 err = -EOPNOTSUPP;
5942 goto out_free;
5943 }
5944 }
Sam Lefflered4737712012-10-11 21:03:31 -07005945
Luciano Coelho807f8a82011-05-11 17:09:35 +03005946 request->dev = dev;
5947 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005948 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005949 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005950
Hila Gonene35e4d22012-06-27 17:19:42 +03005951 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005952 if (!err) {
5953 rdev->sched_scan_req = request;
5954 nl80211_send_sched_scan(rdev, dev,
5955 NL80211_CMD_START_SCHED_SCAN);
5956 goto out;
5957 }
5958
5959out_free:
5960 kfree(request);
5961out:
5962 return err;
5963}
5964
5965static int nl80211_stop_sched_scan(struct sk_buff *skb,
5966 struct genl_info *info)
5967{
5968 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5969
5970 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5971 !rdev->ops->sched_scan_stop)
5972 return -EOPNOTSUPP;
5973
Johannes Berg5fe231e2013-05-08 21:45:15 +02005974 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005975}
5976
Simon Wunderlich04f39042013-02-08 18:16:19 +01005977static int nl80211_start_radar_detection(struct sk_buff *skb,
5978 struct genl_info *info)
5979{
5980 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5981 struct net_device *dev = info->user_ptr[1];
5982 struct wireless_dev *wdev = dev->ieee80211_ptr;
5983 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005984 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005985 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005986 int err;
5987
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005988 dfs_region = reg_get_dfs_region(wdev->wiphy);
5989 if (dfs_region == NL80211_DFS_UNSET)
5990 return -EINVAL;
5991
Simon Wunderlich04f39042013-02-08 18:16:19 +01005992 err = nl80211_parse_chandef(rdev, info, &chandef);
5993 if (err)
5994 return err;
5995
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005996 if (netif_carrier_ok(dev))
5997 return -EBUSY;
5998
Simon Wunderlich04f39042013-02-08 18:16:19 +01005999 if (wdev->cac_started)
6000 return -EBUSY;
6001
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006002 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006003 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006004 if (err < 0)
6005 return err;
6006
6007 if (err == 0)
6008 return -EINVAL;
6009
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006010 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006011 return -EINVAL;
6012
6013 if (!rdev->ops->start_radar_detection)
6014 return -EOPNOTSUPP;
6015
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006016 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6017 if (WARN_ON(!cac_time_ms))
6018 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6019
6020 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6021 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006022 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006023 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006024 wdev->cac_started = true;
6025 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006026 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006027 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006028 return err;
6029}
6030
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006031static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6032{
6033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6034 struct net_device *dev = info->user_ptr[1];
6035 struct wireless_dev *wdev = dev->ieee80211_ptr;
6036 struct cfg80211_csa_settings params;
6037 /* csa_attrs is defined static to avoid waste of stack size - this
6038 * function is called under RTNL lock, so this should not be a problem.
6039 */
6040 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
6041 u8 radar_detect_width = 0;
6042 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006043 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006044 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006045 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006046
6047 if (!rdev->ops->channel_switch ||
6048 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6049 return -EOPNOTSUPP;
6050
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006051 switch (dev->ieee80211_ptr->iftype) {
6052 case NL80211_IFTYPE_AP:
6053 case NL80211_IFTYPE_P2P_GO:
6054 need_new_beacon = true;
6055
6056 /* useless if AP is not running */
6057 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006058 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006059 break;
6060 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006061 if (!wdev->ssid_len)
6062 return -ENOTCONN;
6063 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006064 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006065 if (!wdev->mesh_id_len)
6066 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006067 break;
6068 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006069 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006070 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006071
6072 memset(&params, 0, sizeof(params));
6073
6074 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6075 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6076 return -EINVAL;
6077
6078 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006079 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006080 return -EINVAL;
6081
Luciano Coelho252e07c2014-10-08 09:48:34 +03006082 /* Even though the attribute is u32, the specification says
6083 * u8, so let's make sure we don't overflow.
6084 */
6085 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6086 if (cs_count > 255)
6087 return -EINVAL;
6088
6089 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006090
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006091 if (!need_new_beacon)
6092 goto skip_beacons;
6093
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006094 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6095 if (err)
6096 return err;
6097
6098 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6099 info->attrs[NL80211_ATTR_CSA_IES],
6100 nl80211_policy);
6101 if (err)
6102 return err;
6103
6104 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6105 if (err)
6106 return err;
6107
6108 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6109 return -EINVAL;
6110
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006111 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6112 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006113 return -EINVAL;
6114
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006115 params.n_counter_offsets_beacon = len / sizeof(u16);
6116 if (rdev->wiphy.max_num_csa_counters &&
6117 (params.n_counter_offsets_beacon >
6118 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006119 return -EINVAL;
6120
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006121 params.counter_offsets_beacon =
6122 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6123
6124 /* sanity checks - counters should fit and be the same */
6125 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6126 u16 offset = params.counter_offsets_beacon[i];
6127
6128 if (offset >= params.beacon_csa.tail_len)
6129 return -EINVAL;
6130
6131 if (params.beacon_csa.tail[offset] != params.count)
6132 return -EINVAL;
6133 }
6134
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006135 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006136 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6137 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006138 return -EINVAL;
6139
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006140 params.n_counter_offsets_presp = len / sizeof(u16);
6141 if (rdev->wiphy.max_num_csa_counters &&
6142 (params.n_counter_offsets_beacon >
6143 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006144 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006145
6146 params.counter_offsets_presp =
6147 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6148
6149 /* sanity checks - counters should fit and be the same */
6150 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6151 u16 offset = params.counter_offsets_presp[i];
6152
6153 if (offset >= params.beacon_csa.probe_resp_len)
6154 return -EINVAL;
6155
6156 if (params.beacon_csa.probe_resp[offset] !=
6157 params.count)
6158 return -EINVAL;
6159 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006160 }
6161
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006162skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006163 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6164 if (err)
6165 return err;
6166
Ilan Peer174e0cd2014-02-23 09:13:01 +02006167 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6168 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006169 return -EINVAL;
6170
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006171 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6172 &params.chandef,
6173 wdev->iftype);
6174 if (err < 0)
6175 return err;
6176
6177 if (err > 0) {
6178 radar_detect_width = BIT(params.chandef.width);
6179 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006180 }
6181
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006182 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6183 params.block_tx = true;
6184
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006185 wdev_lock(wdev);
6186 err = rdev_channel_switch(rdev, dev, &params);
6187 wdev_unlock(wdev);
6188
6189 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006190}
6191
Johannes Berg9720bb32011-06-21 09:45:33 +02006192static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6193 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006194 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006195 struct wireless_dev *wdev,
6196 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006197{
Johannes Berg48ab9052009-07-10 18:42:31 +02006198 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006199 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006200 void *hdr;
6201 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006202
6203 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006204
Eric W. Biederman15e47302012-09-07 20:12:54 +00006205 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006206 NL80211_CMD_NEW_SCAN_RESULTS);
6207 if (!hdr)
6208 return -1;
6209
Johannes Berg9720bb32011-06-21 09:45:33 +02006210 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6211
Johannes Berg97990a02013-04-19 01:02:55 +02006212 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6213 goto nla_put_failure;
6214 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006215 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6216 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006217 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6218 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006219
6220 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6221 if (!bss)
6222 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006223 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006224 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006225 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006226
6227 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006228 /* indicate whether we have probe response data or not */
6229 if (rcu_access_pointer(res->proberesp_ies) &&
6230 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6231 goto fail_unlock_rcu;
6232
6233 /* this pointer prefers to be pointed to probe response data
6234 * but is always valid
6235 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006236 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006237 if (ies) {
6238 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6239 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006240 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6241 ies->len, ies->data))
6242 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006243 }
Johannes Berg0e227082014-08-12 20:34:30 +02006244
6245 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006246 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006247 if (ies && ies->from_beacon) {
6248 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006249 goto fail_unlock_rcu;
6250 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6251 ies->len, ies->data))
6252 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006253 }
6254 rcu_read_unlock();
6255
David S. Miller9360ffd2012-03-29 04:41:26 -04006256 if (res->beacon_interval &&
6257 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6258 goto nla_put_failure;
6259 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6260 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006261 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006262 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6263 jiffies_to_msecs(jiffies - intbss->ts)))
6264 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006265
Johannes Berg77965c972009-02-18 18:45:06 +01006266 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006267 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006268 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6269 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006270 break;
6271 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006272 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6273 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006274 break;
6275 default:
6276 break;
6277 }
6278
Johannes Berg48ab9052009-07-10 18:42:31 +02006279 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006280 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006281 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006282 if (intbss == wdev->current_bss &&
6283 nla_put_u32(msg, NL80211_BSS_STATUS,
6284 NL80211_BSS_STATUS_ASSOCIATED))
6285 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006286 break;
6287 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006288 if (intbss == wdev->current_bss &&
6289 nla_put_u32(msg, NL80211_BSS_STATUS,
6290 NL80211_BSS_STATUS_IBSS_JOINED))
6291 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006292 break;
6293 default:
6294 break;
6295 }
6296
Johannes Berg2a519312009-02-10 21:25:55 +01006297 nla_nest_end(msg, bss);
6298
6299 return genlmsg_end(msg, hdr);
6300
Johannes Berg8cef2c92013-02-05 16:54:31 +01006301 fail_unlock_rcu:
6302 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006303 nla_put_failure:
6304 genlmsg_cancel(msg, hdr);
6305 return -EMSGSIZE;
6306}
6307
Johannes Berg97990a02013-04-19 01:02:55 +02006308static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006309{
Johannes Berg48ab9052009-07-10 18:42:31 +02006310 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006311 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006312 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006313 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006314 int err;
6315
Johannes Berg97990a02013-04-19 01:02:55 +02006316 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006317 if (err)
6318 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006319
Johannes Berg48ab9052009-07-10 18:42:31 +02006320 wdev_lock(wdev);
6321 spin_lock_bh(&rdev->bss_lock);
6322 cfg80211_bss_expire(rdev);
6323
Johannes Berg9720bb32011-06-21 09:45:33 +02006324 cb->seq = rdev->bss_generation;
6325
Johannes Berg48ab9052009-07-10 18:42:31 +02006326 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006327 if (++idx <= start)
6328 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006329 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006330 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006331 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006332 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006333 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006334 }
6335 }
6336
Johannes Berg48ab9052009-07-10 18:42:31 +02006337 spin_unlock_bh(&rdev->bss_lock);
6338 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006339
Johannes Berg97990a02013-04-19 01:02:55 +02006340 cb->args[2] = idx;
6341 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006342
Johannes Berg67748892010-10-04 21:14:06 +02006343 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006344}
6345
Eric W. Biederman15e47302012-09-07 20:12:54 +00006346static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006347 int flags, struct net_device *dev,
6348 struct survey_info *survey)
6349{
6350 void *hdr;
6351 struct nlattr *infoattr;
6352
Eric W. Biederman15e47302012-09-07 20:12:54 +00006353 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006354 NL80211_CMD_NEW_SURVEY_RESULTS);
6355 if (!hdr)
6356 return -ENOMEM;
6357
David S. Miller9360ffd2012-03-29 04:41:26 -04006358 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6359 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006360
6361 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6362 if (!infoattr)
6363 goto nla_put_failure;
6364
David S. Miller9360ffd2012-03-29 04:41:26 -04006365 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6366 survey->channel->center_freq))
6367 goto nla_put_failure;
6368
6369 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6370 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6371 goto nla_put_failure;
6372 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6373 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6374 goto nla_put_failure;
6375 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6376 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6377 survey->channel_time))
6378 goto nla_put_failure;
6379 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6380 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6381 survey->channel_time_busy))
6382 goto nla_put_failure;
6383 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6384 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6385 survey->channel_time_ext_busy))
6386 goto nla_put_failure;
6387 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6388 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6389 survey->channel_time_rx))
6390 goto nla_put_failure;
6391 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6392 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6393 survey->channel_time_tx))
6394 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006395
6396 nla_nest_end(msg, infoattr);
6397
6398 return genlmsg_end(msg, hdr);
6399
6400 nla_put_failure:
6401 genlmsg_cancel(msg, hdr);
6402 return -EMSGSIZE;
6403}
6404
6405static int nl80211_dump_survey(struct sk_buff *skb,
6406 struct netlink_callback *cb)
6407{
6408 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006409 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006410 struct wireless_dev *wdev;
6411 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006412 int res;
6413
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006414 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006415 if (res)
6416 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006417
Johannes Berg97990a02013-04-19 01:02:55 +02006418 if (!wdev->netdev) {
6419 res = -EINVAL;
6420 goto out_err;
6421 }
6422
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006423 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006424 res = -EOPNOTSUPP;
6425 goto out_err;
6426 }
6427
6428 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006429 struct ieee80211_channel *chan;
6430
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006431 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006432 if (res == -ENOENT)
6433 break;
6434 if (res)
6435 goto out_err;
6436
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006437 /* Survey without a channel doesn't make sense */
6438 if (!survey.channel) {
6439 res = -EINVAL;
6440 goto out;
6441 }
6442
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006443 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006444 survey.channel->center_freq);
6445 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6446 survey_idx++;
6447 continue;
6448 }
6449
Holger Schurig61fa7132009-11-11 12:25:40 +01006450 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006451 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006452 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006453 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006454 goto out;
6455 survey_idx++;
6456 }
6457
6458 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006459 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006460 res = skb->len;
6461 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006462 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006463 return res;
6464}
6465
Samuel Ortizb23aa672009-07-01 21:26:54 +02006466static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6467{
6468 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6469 NL80211_WPA_VERSION_2));
6470}
6471
Jouni Malinen636a5d32009-03-19 13:39:22 +02006472static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6473{
Johannes Berg4c476992010-10-04 21:36:35 +02006474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6475 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006476 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006477 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6478 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006479 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006480 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006481 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006482
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006483 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6484 return -EINVAL;
6485
6486 if (!info->attrs[NL80211_ATTR_MAC])
6487 return -EINVAL;
6488
Jouni Malinen17780922009-03-27 20:52:47 +02006489 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6490 return -EINVAL;
6491
Johannes Berg19957bb2009-07-02 17:20:43 +02006492 if (!info->attrs[NL80211_ATTR_SSID])
6493 return -EINVAL;
6494
6495 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6496 return -EINVAL;
6497
Johannes Bergfffd0932009-07-08 14:22:54 +02006498 err = nl80211_parse_key(info, &key);
6499 if (err)
6500 return err;
6501
6502 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006503 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6504 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006505 if (!key.p.key || !key.p.key_len)
6506 return -EINVAL;
6507 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6508 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6509 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6510 key.p.key_len != WLAN_KEY_LEN_WEP104))
6511 return -EINVAL;
6512 if (key.idx > 4)
6513 return -EINVAL;
6514 } else {
6515 key.p.key_len = 0;
6516 key.p.key = NULL;
6517 }
6518
Johannes Bergafea0b72010-08-10 09:46:42 +02006519 if (key.idx >= 0) {
6520 int i;
6521 bool ok = false;
6522 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6523 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6524 ok = true;
6525 break;
6526 }
6527 }
Johannes Berg4c476992010-10-04 21:36:35 +02006528 if (!ok)
6529 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006530 }
6531
Johannes Berg4c476992010-10-04 21:36:35 +02006532 if (!rdev->ops->auth)
6533 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006534
Johannes Berg074ac8d2010-09-16 14:58:22 +02006535 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006536 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6537 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006538
Johannes Berg19957bb2009-07-02 17:20:43 +02006539 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006540 chan = nl80211_get_valid_chan(&rdev->wiphy,
6541 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6542 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006543 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006544
Johannes Berg19957bb2009-07-02 17:20:43 +02006545 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6546 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6547
6548 if (info->attrs[NL80211_ATTR_IE]) {
6549 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6550 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6551 }
6552
6553 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006554 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006555 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006556
Jouni Malinene39e5b52012-09-30 19:29:39 +03006557 if (auth_type == NL80211_AUTHTYPE_SAE &&
6558 !info->attrs[NL80211_ATTR_SAE_DATA])
6559 return -EINVAL;
6560
6561 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6562 if (auth_type != NL80211_AUTHTYPE_SAE)
6563 return -EINVAL;
6564 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6565 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6566 /* need to include at least Auth Transaction and Status Code */
6567 if (sae_data_len < 4)
6568 return -EINVAL;
6569 }
6570
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006571 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6572
Johannes Berg95de8172012-01-20 13:55:25 +01006573 /*
6574 * Since we no longer track auth state, ignore
6575 * requests to only change local state.
6576 */
6577 if (local_state_change)
6578 return 0;
6579
Johannes Berg91bf9b22013-05-15 17:44:01 +02006580 wdev_lock(dev->ieee80211_ptr);
6581 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6582 ssid, ssid_len, ie, ie_len,
6583 key.p.key, key.p.key_len, key.idx,
6584 sae_data, sae_data_len);
6585 wdev_unlock(dev->ieee80211_ptr);
6586 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006587}
6588
Johannes Bergc0692b82010-08-27 14:26:53 +03006589static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6590 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006591 struct cfg80211_crypto_settings *settings,
6592 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006593{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006594 memset(settings, 0, sizeof(*settings));
6595
Samuel Ortizb23aa672009-07-01 21:26:54 +02006596 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6597
Johannes Bergc0692b82010-08-27 14:26:53 +03006598 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6599 u16 proto;
6600 proto = nla_get_u16(
6601 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6602 settings->control_port_ethertype = cpu_to_be16(proto);
6603 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6604 proto != ETH_P_PAE)
6605 return -EINVAL;
6606 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6607 settings->control_port_no_encrypt = true;
6608 } else
6609 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6610
Samuel Ortizb23aa672009-07-01 21:26:54 +02006611 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6612 void *data;
6613 int len, i;
6614
6615 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6616 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6617 settings->n_ciphers_pairwise = len / sizeof(u32);
6618
6619 if (len % sizeof(u32))
6620 return -EINVAL;
6621
Johannes Berg3dc27d22009-07-02 21:36:37 +02006622 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006623 return -EINVAL;
6624
6625 memcpy(settings->ciphers_pairwise, data, len);
6626
6627 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006628 if (!cfg80211_supported_cipher_suite(
6629 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006630 settings->ciphers_pairwise[i]))
6631 return -EINVAL;
6632 }
6633
6634 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6635 settings->cipher_group =
6636 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006637 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6638 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006639 return -EINVAL;
6640 }
6641
6642 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6643 settings->wpa_versions =
6644 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6645 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6646 return -EINVAL;
6647 }
6648
6649 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6650 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006651 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006652
6653 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6654 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6655 settings->n_akm_suites = len / sizeof(u32);
6656
6657 if (len % sizeof(u32))
6658 return -EINVAL;
6659
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006660 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6661 return -EINVAL;
6662
Samuel Ortizb23aa672009-07-01 21:26:54 +02006663 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006664 }
6665
6666 return 0;
6667}
6668
Jouni Malinen636a5d32009-03-19 13:39:22 +02006669static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6670{
Johannes Berg4c476992010-10-04 21:36:35 +02006671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6672 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006673 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006674 struct cfg80211_assoc_request req = {};
6675 const u8 *bssid, *ssid;
6676 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006677
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006678 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6679 return -EINVAL;
6680
6681 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006682 !info->attrs[NL80211_ATTR_SSID] ||
6683 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006684 return -EINVAL;
6685
Johannes Berg4c476992010-10-04 21:36:35 +02006686 if (!rdev->ops->assoc)
6687 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006688
Johannes Berg074ac8d2010-09-16 14:58:22 +02006689 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006690 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6691 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006692
Johannes Berg19957bb2009-07-02 17:20:43 +02006693 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006694
Jouni Malinen664834d2014-01-15 00:01:44 +02006695 chan = nl80211_get_valid_chan(&rdev->wiphy,
6696 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6697 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006698 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006699
Johannes Berg19957bb2009-07-02 17:20:43 +02006700 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6701 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006702
6703 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006704 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6705 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006706 }
6707
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006708 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006709 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006710 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006711 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006712 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006713 else if (mfp != NL80211_MFP_NO)
6714 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006715 }
6716
Johannes Berg3e5d7642009-07-07 14:37:26 +02006717 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006718 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006719
Ben Greear7e7c8922011-11-18 11:31:59 -08006720 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006721 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006722
6723 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006724 memcpy(&req.ht_capa_mask,
6725 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6726 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006727
6728 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006729 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006730 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006731 memcpy(&req.ht_capa,
6732 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6733 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006734 }
6735
Johannes Bergee2aca32013-02-21 17:36:01 +01006736 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006737 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006738
6739 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006740 memcpy(&req.vht_capa_mask,
6741 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6742 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006743
6744 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006745 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006746 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006747 memcpy(&req.vht_capa,
6748 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6749 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006750 }
6751
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006752 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6753 if (!(rdev->wiphy.features &
6754 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6755 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6756 return -EINVAL;
6757 req.flags |= ASSOC_REQ_USE_RRM;
6758 }
6759
Johannes Bergf62fab72013-02-21 20:09:09 +01006760 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006761 if (!err) {
6762 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006763 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6764 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006765 wdev_unlock(dev->ieee80211_ptr);
6766 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006767
Jouni Malinen636a5d32009-03-19 13:39:22 +02006768 return err;
6769}
6770
6771static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6772{
Johannes Berg4c476992010-10-04 21:36:35 +02006773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6774 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006775 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006776 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006777 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006778 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006779
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006780 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6781 return -EINVAL;
6782
6783 if (!info->attrs[NL80211_ATTR_MAC])
6784 return -EINVAL;
6785
6786 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6787 return -EINVAL;
6788
Johannes Berg4c476992010-10-04 21:36:35 +02006789 if (!rdev->ops->deauth)
6790 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006791
Johannes Berg074ac8d2010-09-16 14:58:22 +02006792 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006793 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6794 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006795
Johannes Berg19957bb2009-07-02 17:20:43 +02006796 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006797
Johannes Berg19957bb2009-07-02 17:20:43 +02006798 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6799 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006800 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006801 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006802 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006803
6804 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006805 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6806 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006807 }
6808
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006809 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6810
Johannes Berg91bf9b22013-05-15 17:44:01 +02006811 wdev_lock(dev->ieee80211_ptr);
6812 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6813 local_state_change);
6814 wdev_unlock(dev->ieee80211_ptr);
6815 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006816}
6817
6818static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6819{
Johannes Berg4c476992010-10-04 21:36:35 +02006820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6821 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006822 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006823 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006824 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006825 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006826
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006827 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6828 return -EINVAL;
6829
6830 if (!info->attrs[NL80211_ATTR_MAC])
6831 return -EINVAL;
6832
6833 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6834 return -EINVAL;
6835
Johannes Berg4c476992010-10-04 21:36:35 +02006836 if (!rdev->ops->disassoc)
6837 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006838
Johannes Berg074ac8d2010-09-16 14:58:22 +02006839 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006840 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6841 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006842
Johannes Berg19957bb2009-07-02 17:20:43 +02006843 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006844
Johannes Berg19957bb2009-07-02 17:20:43 +02006845 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6846 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006847 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006848 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006849 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006850
6851 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006852 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6853 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006854 }
6855
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006856 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6857
Johannes Berg91bf9b22013-05-15 17:44:01 +02006858 wdev_lock(dev->ieee80211_ptr);
6859 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6860 local_state_change);
6861 wdev_unlock(dev->ieee80211_ptr);
6862 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006863}
6864
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006865static bool
6866nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6867 int mcast_rate[IEEE80211_NUM_BANDS],
6868 int rateval)
6869{
6870 struct wiphy *wiphy = &rdev->wiphy;
6871 bool found = false;
6872 int band, i;
6873
6874 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6875 struct ieee80211_supported_band *sband;
6876
6877 sband = wiphy->bands[band];
6878 if (!sband)
6879 continue;
6880
6881 for (i = 0; i < sband->n_bitrates; i++) {
6882 if (sband->bitrates[i].bitrate == rateval) {
6883 mcast_rate[band] = i + 1;
6884 found = true;
6885 break;
6886 }
6887 }
6888 }
6889
6890 return found;
6891}
6892
Johannes Berg04a773a2009-04-19 21:24:32 +02006893static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6894{
Johannes Berg4c476992010-10-04 21:36:35 +02006895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6896 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006897 struct cfg80211_ibss_params ibss;
6898 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006899 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006900 int err;
6901
Johannes Berg8e30bc52009-04-22 17:45:38 +02006902 memset(&ibss, 0, sizeof(ibss));
6903
Johannes Berg04a773a2009-04-19 21:24:32 +02006904 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6905 return -EINVAL;
6906
Johannes Berg683b6d32012-11-08 21:25:48 +01006907 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006908 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6909 return -EINVAL;
6910
Johannes Berg8e30bc52009-04-22 17:45:38 +02006911 ibss.beacon_interval = 100;
6912
6913 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6914 ibss.beacon_interval =
6915 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6916 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6917 return -EINVAL;
6918 }
6919
Johannes Berg4c476992010-10-04 21:36:35 +02006920 if (!rdev->ops->join_ibss)
6921 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006922
Johannes Berg4c476992010-10-04 21:36:35 +02006923 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6924 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006925
Johannes Berg79c97e92009-07-07 03:56:12 +02006926 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006927
Johannes Berg39193492011-09-16 13:45:25 +02006928 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006929 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006930
6931 if (!is_valid_ether_addr(ibss.bssid))
6932 return -EINVAL;
6933 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006934 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6935 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6936
6937 if (info->attrs[NL80211_ATTR_IE]) {
6938 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6939 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6940 }
6941
Johannes Berg683b6d32012-11-08 21:25:48 +01006942 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6943 if (err)
6944 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006945
Ilan Peer174e0cd2014-02-23 09:13:01 +02006946 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6947 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006948 return -EINVAL;
6949
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006950 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006951 case NL80211_CHAN_WIDTH_5:
6952 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006953 case NL80211_CHAN_WIDTH_20_NOHT:
6954 break;
6955 case NL80211_CHAN_WIDTH_20:
6956 case NL80211_CHAN_WIDTH_40:
6957 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6958 break;
6959 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006960 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006961 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006962
Johannes Berg04a773a2009-04-19 21:24:32 +02006963 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006964 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006965
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006966 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6967 u8 *rates =
6968 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6969 int n_rates =
6970 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6971 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006972 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006973
Johannes Berg34850ab2011-07-18 18:08:35 +02006974 err = ieee80211_get_ratemask(sband, rates, n_rates,
6975 &ibss.basic_rates);
6976 if (err)
6977 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006978 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006979
Simon Wunderlich803768f2013-06-28 10:39:58 +02006980 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6981 memcpy(&ibss.ht_capa_mask,
6982 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6983 sizeof(ibss.ht_capa_mask));
6984
6985 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6986 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6987 return -EINVAL;
6988 memcpy(&ibss.ht_capa,
6989 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6990 sizeof(ibss.ht_capa));
6991 }
6992
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006993 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6994 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6995 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6996 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006997
Johannes Berg4c476992010-10-04 21:36:35 +02006998 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306999 bool no_ht = false;
7000
Johannes Berg4c476992010-10-04 21:36:35 +02007001 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307002 info->attrs[NL80211_ATTR_KEYS],
7003 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007004 if (IS_ERR(connkeys))
7005 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307006
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007007 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7008 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307009 kfree(connkeys);
7010 return -EINVAL;
7011 }
Johannes Berg4c476992010-10-04 21:36:35 +02007012 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007013
Antonio Quartulli267335d2012-01-31 20:25:47 +01007014 ibss.control_port =
7015 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7016
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007017 ibss.userspace_handles_dfs =
7018 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7019
Johannes Berg4c476992010-10-04 21:36:35 +02007020 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007021 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007022 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007023 return err;
7024}
7025
7026static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7027{
Johannes Berg4c476992010-10-04 21:36:35 +02007028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7029 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007030
Johannes Berg4c476992010-10-04 21:36:35 +02007031 if (!rdev->ops->leave_ibss)
7032 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007033
Johannes Berg4c476992010-10-04 21:36:35 +02007034 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7035 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007036
Johannes Berg4c476992010-10-04 21:36:35 +02007037 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007038}
7039
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007040static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7041{
7042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7043 struct net_device *dev = info->user_ptr[1];
7044 int mcast_rate[IEEE80211_NUM_BANDS];
7045 u32 nla_rate;
7046 int err;
7047
7048 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7049 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7050 return -EOPNOTSUPP;
7051
7052 if (!rdev->ops->set_mcast_rate)
7053 return -EOPNOTSUPP;
7054
7055 memset(mcast_rate, 0, sizeof(mcast_rate));
7056
7057 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7058 return -EINVAL;
7059
7060 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7061 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7062 return -EINVAL;
7063
7064 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7065
7066 return err;
7067}
7068
Johannes Bergad7e7182013-11-13 13:37:47 +01007069static struct sk_buff *
7070__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7071 int approxlen, u32 portid, u32 seq,
7072 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007073 enum nl80211_attrs attr,
7074 const struct nl80211_vendor_cmd_info *info,
7075 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007076{
7077 struct sk_buff *skb;
7078 void *hdr;
7079 struct nlattr *data;
7080
7081 skb = nlmsg_new(approxlen + 100, gfp);
7082 if (!skb)
7083 return NULL;
7084
7085 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7086 if (!hdr) {
7087 kfree_skb(skb);
7088 return NULL;
7089 }
7090
7091 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7092 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007093
7094 if (info) {
7095 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7096 info->vendor_id))
7097 goto nla_put_failure;
7098 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7099 info->subcmd))
7100 goto nla_put_failure;
7101 }
7102
Johannes Bergad7e7182013-11-13 13:37:47 +01007103 data = nla_nest_start(skb, attr);
7104
7105 ((void **)skb->cb)[0] = rdev;
7106 ((void **)skb->cb)[1] = hdr;
7107 ((void **)skb->cb)[2] = data;
7108
7109 return skb;
7110
7111 nla_put_failure:
7112 kfree_skb(skb);
7113 return NULL;
7114}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007115
Johannes Berge03ad6e2014-01-01 17:22:30 +01007116struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7117 enum nl80211_commands cmd,
7118 enum nl80211_attrs attr,
7119 int vendor_event_idx,
7120 int approxlen, gfp_t gfp)
7121{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007122 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007123 const struct nl80211_vendor_cmd_info *info;
7124
7125 switch (cmd) {
7126 case NL80211_CMD_TESTMODE:
7127 if (WARN_ON(vendor_event_idx != -1))
7128 return NULL;
7129 info = NULL;
7130 break;
7131 case NL80211_CMD_VENDOR:
7132 if (WARN_ON(vendor_event_idx < 0 ||
7133 vendor_event_idx >= wiphy->n_vendor_events))
7134 return NULL;
7135 info = &wiphy->vendor_events[vendor_event_idx];
7136 break;
7137 default:
7138 WARN_ON(1);
7139 return NULL;
7140 }
7141
7142 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7143 cmd, attr, info, gfp);
7144}
7145EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7146
7147void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7148{
7149 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7150 void *hdr = ((void **)skb->cb)[1];
7151 struct nlattr *data = ((void **)skb->cb)[2];
7152 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7153
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007154 /* clear CB data for netlink core to own from now on */
7155 memset(skb->cb, 0, sizeof(skb->cb));
7156
Johannes Berge03ad6e2014-01-01 17:22:30 +01007157 nla_nest_end(skb, data);
7158 genlmsg_end(skb, hdr);
7159
7160 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7161 mcgrp = NL80211_MCGRP_VENDOR;
7162
7163 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7164 mcgrp, gfp);
7165}
7166EXPORT_SYMBOL(__cfg80211_send_event_skb);
7167
Johannes Bergaff89a92009-07-01 21:26:51 +02007168#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007169static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7170{
Johannes Berg4c476992010-10-04 21:36:35 +02007171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007172 struct wireless_dev *wdev =
7173 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007174 int err;
7175
David Spinadelfc73f112013-07-31 18:04:15 +03007176 if (!rdev->ops->testmode_cmd)
7177 return -EOPNOTSUPP;
7178
7179 if (IS_ERR(wdev)) {
7180 err = PTR_ERR(wdev);
7181 if (err != -EINVAL)
7182 return err;
7183 wdev = NULL;
7184 } else if (wdev->wiphy != &rdev->wiphy) {
7185 return -EINVAL;
7186 }
7187
Johannes Bergaff89a92009-07-01 21:26:51 +02007188 if (!info->attrs[NL80211_ATTR_TESTDATA])
7189 return -EINVAL;
7190
Johannes Bergad7e7182013-11-13 13:37:47 +01007191 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007192 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007193 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7194 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007195 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007196
Johannes Bergaff89a92009-07-01 21:26:51 +02007197 return err;
7198}
7199
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007200static int nl80211_testmode_dump(struct sk_buff *skb,
7201 struct netlink_callback *cb)
7202{
Johannes Berg00918d32011-12-13 17:22:05 +01007203 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007204 int err;
7205 long phy_idx;
7206 void *data = NULL;
7207 int data_len = 0;
7208
Johannes Berg5fe231e2013-05-08 21:45:15 +02007209 rtnl_lock();
7210
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007211 if (cb->args[0]) {
7212 /*
7213 * 0 is a valid index, but not valid for args[0],
7214 * so we need to offset by 1.
7215 */
7216 phy_idx = cb->args[0] - 1;
7217 } else {
7218 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7219 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7220 nl80211_policy);
7221 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007222 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007223
Johannes Berg2bd7e352012-06-15 14:23:16 +02007224 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7225 nl80211_fam.attrbuf);
7226 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007227 err = PTR_ERR(rdev);
7228 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007229 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007230 phy_idx = rdev->wiphy_idx;
7231 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007232
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007233 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7234 cb->args[1] =
7235 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7236 }
7237
7238 if (cb->args[1]) {
7239 data = nla_data((void *)cb->args[1]);
7240 data_len = nla_len((void *)cb->args[1]);
7241 }
7242
Johannes Berg00918d32011-12-13 17:22:05 +01007243 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7244 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007245 err = -ENOENT;
7246 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007247 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007248
Johannes Berg00918d32011-12-13 17:22:05 +01007249 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007250 err = -EOPNOTSUPP;
7251 goto out_err;
7252 }
7253
7254 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007255 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007256 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7257 NL80211_CMD_TESTMODE);
7258 struct nlattr *tmdata;
7259
Dan Carpentercb35fba2013-08-14 14:50:01 +03007260 if (!hdr)
7261 break;
7262
David S. Miller9360ffd2012-03-29 04:41:26 -04007263 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007264 genlmsg_cancel(skb, hdr);
7265 break;
7266 }
7267
7268 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7269 if (!tmdata) {
7270 genlmsg_cancel(skb, hdr);
7271 break;
7272 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007273 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007274 nla_nest_end(skb, tmdata);
7275
7276 if (err == -ENOBUFS || err == -ENOENT) {
7277 genlmsg_cancel(skb, hdr);
7278 break;
7279 } else if (err) {
7280 genlmsg_cancel(skb, hdr);
7281 goto out_err;
7282 }
7283
7284 genlmsg_end(skb, hdr);
7285 }
7286
7287 err = skb->len;
7288 /* see above */
7289 cb->args[0] = phy_idx + 1;
7290 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007291 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007292 return err;
7293}
Johannes Bergaff89a92009-07-01 21:26:51 +02007294#endif
7295
Samuel Ortizb23aa672009-07-01 21:26:54 +02007296static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7297{
Johannes Berg4c476992010-10-04 21:36:35 +02007298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7299 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007300 struct cfg80211_connect_params connect;
7301 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007302 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007303 int err;
7304
7305 memset(&connect, 0, sizeof(connect));
7306
7307 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7308 return -EINVAL;
7309
7310 if (!info->attrs[NL80211_ATTR_SSID] ||
7311 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7312 return -EINVAL;
7313
7314 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7315 connect.auth_type =
7316 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007317 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7318 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007319 return -EINVAL;
7320 } else
7321 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7322
7323 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7324
Johannes Bergc0692b82010-08-27 14:26:53 +03007325 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007326 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007327 if (err)
7328 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007329
Johannes Berg074ac8d2010-09-16 14:58:22 +02007330 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007331 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7332 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007333
Johannes Berg79c97e92009-07-07 03:56:12 +02007334 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007335
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307336 connect.bg_scan_period = -1;
7337 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7338 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7339 connect.bg_scan_period =
7340 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7341 }
7342
Samuel Ortizb23aa672009-07-01 21:26:54 +02007343 if (info->attrs[NL80211_ATTR_MAC])
7344 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007345 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7346 connect.bssid_hint =
7347 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007348 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7349 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7350
7351 if (info->attrs[NL80211_ATTR_IE]) {
7352 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7353 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7354 }
7355
Jouni Malinencee00a92013-01-15 17:15:57 +02007356 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7357 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7358 if (connect.mfp != NL80211_MFP_REQUIRED &&
7359 connect.mfp != NL80211_MFP_NO)
7360 return -EINVAL;
7361 } else {
7362 connect.mfp = NL80211_MFP_NO;
7363 }
7364
Samuel Ortizb23aa672009-07-01 21:26:54 +02007365 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007366 connect.channel = nl80211_get_valid_chan(
7367 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7368 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007369 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007370 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007371 connect.channel_hint = nl80211_get_valid_chan(
7372 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7373 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007374 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007375 }
7376
Johannes Bergfffd0932009-07-08 14:22:54 +02007377 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7378 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307379 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007380 if (IS_ERR(connkeys))
7381 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007382 }
7383
Ben Greear7e7c8922011-11-18 11:31:59 -08007384 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7385 connect.flags |= ASSOC_REQ_DISABLE_HT;
7386
7387 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7388 memcpy(&connect.ht_capa_mask,
7389 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7390 sizeof(connect.ht_capa_mask));
7391
7392 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007393 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007394 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007395 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007396 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007397 memcpy(&connect.ht_capa,
7398 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7399 sizeof(connect.ht_capa));
7400 }
7401
Johannes Bergee2aca32013-02-21 17:36:01 +01007402 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7403 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7404
7405 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7406 memcpy(&connect.vht_capa_mask,
7407 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7408 sizeof(connect.vht_capa_mask));
7409
7410 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7411 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007412 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007413 return -EINVAL;
7414 }
7415 memcpy(&connect.vht_capa,
7416 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7417 sizeof(connect.vht_capa));
7418 }
7419
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007420 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7421 if (!(rdev->wiphy.features &
7422 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7423 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7424 return -EINVAL;
7425 connect.flags |= ASSOC_REQ_USE_RRM;
7426 }
7427
Johannes Berg83739b02013-05-15 17:44:01 +02007428 wdev_lock(dev->ieee80211_ptr);
7429 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7430 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007431 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007432 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007433 return err;
7434}
7435
7436static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7437{
Johannes Berg4c476992010-10-04 21:36:35 +02007438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7439 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007440 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007441 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007442
7443 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7444 reason = WLAN_REASON_DEAUTH_LEAVING;
7445 else
7446 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7447
7448 if (reason == 0)
7449 return -EINVAL;
7450
Johannes Berg074ac8d2010-09-16 14:58:22 +02007451 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007452 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7453 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007454
Johannes Berg83739b02013-05-15 17:44:01 +02007455 wdev_lock(dev->ieee80211_ptr);
7456 ret = cfg80211_disconnect(rdev, dev, reason, true);
7457 wdev_unlock(dev->ieee80211_ptr);
7458 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007459}
7460
Johannes Berg463d0182009-07-14 00:33:35 +02007461static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7462{
Johannes Berg4c476992010-10-04 21:36:35 +02007463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007464 struct net *net;
7465 int err;
7466 u32 pid;
7467
7468 if (!info->attrs[NL80211_ATTR_PID])
7469 return -EINVAL;
7470
7471 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7472
Johannes Berg463d0182009-07-14 00:33:35 +02007473 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007474 if (IS_ERR(net))
7475 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007476
7477 err = 0;
7478
7479 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007480 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7481 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007482
Johannes Berg463d0182009-07-14 00:33:35 +02007483 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007484 return err;
7485}
7486
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007487static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7488{
Johannes Berg4c476992010-10-04 21:36:35 +02007489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007490 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7491 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007492 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007493 struct cfg80211_pmksa pmksa;
7494
7495 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7496
7497 if (!info->attrs[NL80211_ATTR_MAC])
7498 return -EINVAL;
7499
7500 if (!info->attrs[NL80211_ATTR_PMKID])
7501 return -EINVAL;
7502
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007503 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7504 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7505
Johannes Berg074ac8d2010-09-16 14:58:22 +02007506 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007507 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7508 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007509
7510 switch (info->genlhdr->cmd) {
7511 case NL80211_CMD_SET_PMKSA:
7512 rdev_ops = rdev->ops->set_pmksa;
7513 break;
7514 case NL80211_CMD_DEL_PMKSA:
7515 rdev_ops = rdev->ops->del_pmksa;
7516 break;
7517 default:
7518 WARN_ON(1);
7519 break;
7520 }
7521
Johannes Berg4c476992010-10-04 21:36:35 +02007522 if (!rdev_ops)
7523 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007524
Johannes Berg4c476992010-10-04 21:36:35 +02007525 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007526}
7527
7528static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7529{
Johannes Berg4c476992010-10-04 21:36:35 +02007530 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7531 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007532
Johannes Berg074ac8d2010-09-16 14:58:22 +02007533 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007534 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7535 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007536
Johannes Berg4c476992010-10-04 21:36:35 +02007537 if (!rdev->ops->flush_pmksa)
7538 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007539
Hila Gonene35e4d22012-06-27 17:19:42 +03007540 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007541}
7542
Arik Nemtsov109086c2011-09-28 14:12:50 +03007543static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7544{
7545 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7546 struct net_device *dev = info->user_ptr[1];
7547 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307548 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007549 u16 status_code;
7550 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007551 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007552
7553 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7554 !rdev->ops->tdls_mgmt)
7555 return -EOPNOTSUPP;
7556
7557 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7558 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7559 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7560 !info->attrs[NL80211_ATTR_IE] ||
7561 !info->attrs[NL80211_ATTR_MAC])
7562 return -EINVAL;
7563
7564 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7565 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7566 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7567 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007568 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307569 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7570 peer_capability =
7571 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007572
Hila Gonene35e4d22012-06-27 17:19:42 +03007573 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307574 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007575 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007576 nla_data(info->attrs[NL80211_ATTR_IE]),
7577 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007578}
7579
7580static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7581{
7582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7583 struct net_device *dev = info->user_ptr[1];
7584 enum nl80211_tdls_operation operation;
7585 u8 *peer;
7586
7587 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7588 !rdev->ops->tdls_oper)
7589 return -EOPNOTSUPP;
7590
7591 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7592 !info->attrs[NL80211_ATTR_MAC])
7593 return -EINVAL;
7594
7595 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7596 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7597
Hila Gonene35e4d22012-06-27 17:19:42 +03007598 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007599}
7600
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007601static int nl80211_remain_on_channel(struct sk_buff *skb,
7602 struct genl_info *info)
7603{
Johannes Berg4c476992010-10-04 21:36:35 +02007604 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007605 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007606 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007607 struct sk_buff *msg;
7608 void *hdr;
7609 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007610 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007611 int err;
7612
7613 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7614 !info->attrs[NL80211_ATTR_DURATION])
7615 return -EINVAL;
7616
7617 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7618
Johannes Berg7c4ef712011-11-18 15:33:48 +01007619 if (!rdev->ops->remain_on_channel ||
7620 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007621 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007622
Johannes Bergebf348f2012-06-01 12:50:54 +02007623 /*
7624 * We should be on that channel for at least a minimum amount of
7625 * time (10ms) but no longer than the driver supports.
7626 */
7627 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7628 duration > rdev->wiphy.max_remain_on_channel_duration)
7629 return -EINVAL;
7630
Johannes Berg683b6d32012-11-08 21:25:48 +01007631 err = nl80211_parse_chandef(rdev, info, &chandef);
7632 if (err)
7633 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007634
7635 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007636 if (!msg)
7637 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007638
Eric W. Biederman15e47302012-09-07 20:12:54 +00007639 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007640 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007641 if (!hdr) {
7642 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007643 goto free_msg;
7644 }
7645
Johannes Berg683b6d32012-11-08 21:25:48 +01007646 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7647 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007648
7649 if (err)
7650 goto free_msg;
7651
David S. Miller9360ffd2012-03-29 04:41:26 -04007652 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7653 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007654
7655 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007656
7657 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007658
7659 nla_put_failure:
7660 err = -ENOBUFS;
7661 free_msg:
7662 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007663 return err;
7664}
7665
7666static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7667 struct genl_info *info)
7668{
Johannes Berg4c476992010-10-04 21:36:35 +02007669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007670 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007671 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007672
7673 if (!info->attrs[NL80211_ATTR_COOKIE])
7674 return -EINVAL;
7675
Johannes Berg4c476992010-10-04 21:36:35 +02007676 if (!rdev->ops->cancel_remain_on_channel)
7677 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007678
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007679 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7680
Hila Gonene35e4d22012-06-27 17:19:42 +03007681 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007682}
7683
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007684static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7685 u8 *rates, u8 rates_len)
7686{
7687 u8 i;
7688 u32 mask = 0;
7689
7690 for (i = 0; i < rates_len; i++) {
7691 int rate = (rates[i] & 0x7f) * 5;
7692 int ridx;
7693 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7694 struct ieee80211_rate *srate =
7695 &sband->bitrates[ridx];
7696 if (rate == srate->bitrate) {
7697 mask |= 1 << ridx;
7698 break;
7699 }
7700 }
7701 if (ridx == sband->n_bitrates)
7702 return 0; /* rate not found */
7703 }
7704
7705 return mask;
7706}
7707
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007708static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7709 u8 *rates, u8 rates_len,
7710 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7711{
7712 u8 i;
7713
7714 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7715
7716 for (i = 0; i < rates_len; i++) {
7717 int ridx, rbit;
7718
7719 ridx = rates[i] / 8;
7720 rbit = BIT(rates[i] % 8);
7721
7722 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007723 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007724 return false;
7725
7726 /* check availability */
7727 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7728 mcs[ridx] |= rbit;
7729 else
7730 return false;
7731 }
7732
7733 return true;
7734}
7735
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007736static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7737{
7738 u16 mcs_mask = 0;
7739
7740 switch (vht_mcs_map) {
7741 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7742 break;
7743 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7744 mcs_mask = 0x00FF;
7745 break;
7746 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7747 mcs_mask = 0x01FF;
7748 break;
7749 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7750 mcs_mask = 0x03FF;
7751 break;
7752 default:
7753 break;
7754 }
7755
7756 return mcs_mask;
7757}
7758
7759static void vht_build_mcs_mask(u16 vht_mcs_map,
7760 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7761{
7762 u8 nss;
7763
7764 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7765 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7766 vht_mcs_map >>= 2;
7767 }
7768}
7769
7770static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7771 struct nl80211_txrate_vht *txrate,
7772 u16 mcs[NL80211_VHT_NSS_MAX])
7773{
7774 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7775 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7776 u8 i;
7777
7778 if (!sband->vht_cap.vht_supported)
7779 return false;
7780
7781 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7782
7783 /* Build vht_mcs_mask from VHT capabilities */
7784 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7785
7786 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7787 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7788 mcs[i] = txrate->mcs[i];
7789 else
7790 return false;
7791 }
7792
7793 return true;
7794}
7795
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007796static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007797 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7798 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007799 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7800 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007801 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007802 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007803};
7804
7805static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7806 struct genl_info *info)
7807{
7808 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007810 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007811 int rem, i;
7812 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007813 struct nlattr *tx_rates;
7814 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007815 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007816
Johannes Berg4c476992010-10-04 21:36:35 +02007817 if (!rdev->ops->set_bitrate_mask)
7818 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007819
7820 memset(&mask, 0, sizeof(mask));
7821 /* Default to all rates enabled */
7822 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7823 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007824
7825 if (!sband)
7826 continue;
7827
7828 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007829 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007830 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007831 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007832
7833 if (!sband->vht_cap.vht_supported)
7834 continue;
7835
7836 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7837 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007838 }
7839
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007840 /* if no rates are given set it back to the defaults */
7841 if (!info->attrs[NL80211_ATTR_TX_RATES])
7842 goto out;
7843
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007844 /*
7845 * The nested attribute uses enum nl80211_band as the index. This maps
7846 * directly to the enum ieee80211_band values used in cfg80211.
7847 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007848 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007849 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007850 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007851 int err;
7852
Johannes Berg4c476992010-10-04 21:36:35 +02007853 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7854 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007855 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007856 if (sband == NULL)
7857 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007858 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7859 nla_len(tx_rates), nl80211_txattr_policy);
7860 if (err)
7861 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007862 if (tb[NL80211_TXRATE_LEGACY]) {
7863 mask.control[band].legacy = rateset_to_mask(
7864 sband,
7865 nla_data(tb[NL80211_TXRATE_LEGACY]),
7866 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307867 if ((mask.control[band].legacy == 0) &&
7868 nla_len(tb[NL80211_TXRATE_LEGACY]))
7869 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007870 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007871 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007872 if (!ht_rateset_to_mask(
7873 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007874 nla_data(tb[NL80211_TXRATE_HT]),
7875 nla_len(tb[NL80211_TXRATE_HT]),
7876 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007877 return -EINVAL;
7878 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007879 if (tb[NL80211_TXRATE_VHT]) {
7880 if (!vht_set_mcs_mask(
7881 sband,
7882 nla_data(tb[NL80211_TXRATE_VHT]),
7883 mask.control[band].vht_mcs))
7884 return -EINVAL;
7885 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007886 if (tb[NL80211_TXRATE_GI]) {
7887 mask.control[band].gi =
7888 nla_get_u8(tb[NL80211_TXRATE_GI]);
7889 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7890 return -EINVAL;
7891 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007892
7893 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007894 /* don't allow empty legacy rates if HT or VHT
7895 * are not even supported.
7896 */
7897 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7898 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007899 return -EINVAL;
7900
7901 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007902 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007903 goto out;
7904
7905 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7906 if (mask.control[band].vht_mcs[i])
7907 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007908
7909 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007910 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007911 }
7912 }
7913
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007914out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007915 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007916}
7917
Johannes Berg2e161f782010-08-12 15:38:38 +02007918static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007919{
Johannes Berg4c476992010-10-04 21:36:35 +02007920 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007921 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02007922 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007923
7924 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7925 return -EINVAL;
7926
Johannes Berg2e161f782010-08-12 15:38:38 +02007927 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7928 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007929
Johannes Berg71bbc992012-06-15 15:30:18 +02007930 switch (wdev->iftype) {
7931 case NL80211_IFTYPE_STATION:
7932 case NL80211_IFTYPE_ADHOC:
7933 case NL80211_IFTYPE_P2P_CLIENT:
7934 case NL80211_IFTYPE_AP:
7935 case NL80211_IFTYPE_AP_VLAN:
7936 case NL80211_IFTYPE_MESH_POINT:
7937 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007938 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007939 break;
7940 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007941 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007942 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007943
7944 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007945 if (!rdev->ops->mgmt_tx)
7946 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007947
Eric W. Biederman15e47302012-09-07 20:12:54 +00007948 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007949 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7950 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007951}
7952
Johannes Berg2e161f782010-08-12 15:38:38 +02007953static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007954{
Johannes Berg4c476992010-10-04 21:36:35 +02007955 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007956 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007957 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007958 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007959 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007960 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007961 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007962 struct cfg80211_mgmt_tx_params params = {
7963 .dont_wait_for_ack =
7964 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7965 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007966
Johannes Berg683b6d32012-11-08 21:25:48 +01007967 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007968 return -EINVAL;
7969
Johannes Berg4c476992010-10-04 21:36:35 +02007970 if (!rdev->ops->mgmt_tx)
7971 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007972
Johannes Berg71bbc992012-06-15 15:30:18 +02007973 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007974 case NL80211_IFTYPE_P2P_DEVICE:
7975 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7976 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007977 case NL80211_IFTYPE_STATION:
7978 case NL80211_IFTYPE_ADHOC:
7979 case NL80211_IFTYPE_P2P_CLIENT:
7980 case NL80211_IFTYPE_AP:
7981 case NL80211_IFTYPE_AP_VLAN:
7982 case NL80211_IFTYPE_MESH_POINT:
7983 case NL80211_IFTYPE_P2P_GO:
7984 break;
7985 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007986 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007987 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007988
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007989 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007990 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007991 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007992 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007993
7994 /*
7995 * We should wait on the channel for at least a minimum amount
7996 * of time (10ms) but no longer than the driver supports.
7997 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007998 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7999 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008000 return -EINVAL;
8001
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008002 }
8003
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008004 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008005
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008006 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008007 return -EINVAL;
8008
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008009 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308010
Antonio Quartulliea141b752013-06-11 14:20:03 +02008011 /* get the channel if any has been specified, otherwise pass NULL to
8012 * the driver. The latter will use the current one
8013 */
8014 chandef.chan = NULL;
8015 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8016 err = nl80211_parse_chandef(rdev, info, &chandef);
8017 if (err)
8018 return err;
8019 }
8020
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008021 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008022 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008023
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008024 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8025 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8026
8027 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8028 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8029 int i;
8030
8031 if (len % sizeof(u16))
8032 return -EINVAL;
8033
8034 params.n_csa_offsets = len / sizeof(u16);
8035 params.csa_offsets =
8036 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8037
8038 /* check that all the offsets fit the frame */
8039 for (i = 0; i < params.n_csa_offsets; i++) {
8040 if (params.csa_offsets[i] >= params.len)
8041 return -EINVAL;
8042 }
8043 }
8044
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008045 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8047 if (!msg)
8048 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008049
Eric W. Biederman15e47302012-09-07 20:12:54 +00008050 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008051 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008052 if (!hdr) {
8053 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008054 goto free_msg;
8055 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008056 }
Johannes Berge247bd902011-11-04 11:18:21 +01008057
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008058 params.chan = chandef.chan;
8059 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008060 if (err)
8061 goto free_msg;
8062
Johannes Berge247bd902011-11-04 11:18:21 +01008063 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008064 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8065 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008066
Johannes Berge247bd902011-11-04 11:18:21 +01008067 genlmsg_end(msg, hdr);
8068 return genlmsg_reply(msg, info);
8069 }
8070
8071 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008072
8073 nla_put_failure:
8074 err = -ENOBUFS;
8075 free_msg:
8076 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008077 return err;
8078}
8079
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008080static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8081{
8082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008083 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008084 u64 cookie;
8085
8086 if (!info->attrs[NL80211_ATTR_COOKIE])
8087 return -EINVAL;
8088
8089 if (!rdev->ops->mgmt_tx_cancel_wait)
8090 return -EOPNOTSUPP;
8091
Johannes Berg71bbc992012-06-15 15:30:18 +02008092 switch (wdev->iftype) {
8093 case NL80211_IFTYPE_STATION:
8094 case NL80211_IFTYPE_ADHOC:
8095 case NL80211_IFTYPE_P2P_CLIENT:
8096 case NL80211_IFTYPE_AP:
8097 case NL80211_IFTYPE_AP_VLAN:
8098 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008099 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008100 break;
8101 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008102 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008103 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008104
8105 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8106
Hila Gonene35e4d22012-06-27 17:19:42 +03008107 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008108}
8109
Kalle Valoffb9eb32010-02-17 17:58:10 +02008110static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8111{
Johannes Berg4c476992010-10-04 21:36:35 +02008112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008113 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008114 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008115 u8 ps_state;
8116 bool state;
8117 int err;
8118
Johannes Berg4c476992010-10-04 21:36:35 +02008119 if (!info->attrs[NL80211_ATTR_PS_STATE])
8120 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008121
8122 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8123
Johannes Berg4c476992010-10-04 21:36:35 +02008124 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8125 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008126
8127 wdev = dev->ieee80211_ptr;
8128
Johannes Berg4c476992010-10-04 21:36:35 +02008129 if (!rdev->ops->set_power_mgmt)
8130 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008131
8132 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8133
8134 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008135 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008136
Hila Gonene35e4d22012-06-27 17:19:42 +03008137 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008138 if (!err)
8139 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008140 return err;
8141}
8142
8143static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8144{
Johannes Berg4c476992010-10-04 21:36:35 +02008145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008146 enum nl80211_ps_state ps_state;
8147 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008148 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008149 struct sk_buff *msg;
8150 void *hdr;
8151 int err;
8152
Kalle Valoffb9eb32010-02-17 17:58:10 +02008153 wdev = dev->ieee80211_ptr;
8154
Johannes Berg4c476992010-10-04 21:36:35 +02008155 if (!rdev->ops->set_power_mgmt)
8156 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008157
8158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008159 if (!msg)
8160 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008161
Eric W. Biederman15e47302012-09-07 20:12:54 +00008162 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008163 NL80211_CMD_GET_POWER_SAVE);
8164 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008165 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008166 goto free_msg;
8167 }
8168
8169 if (wdev->ps)
8170 ps_state = NL80211_PS_ENABLED;
8171 else
8172 ps_state = NL80211_PS_DISABLED;
8173
David S. Miller9360ffd2012-03-29 04:41:26 -04008174 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8175 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008176
8177 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008178 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008179
Johannes Berg4c476992010-10-04 21:36:35 +02008180 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008181 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008182 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008183 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008184 return err;
8185}
8186
Johannes Berg94e860f2014-01-20 23:58:15 +01008187static const struct nla_policy
8188nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008189 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8190 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8191 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008192 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8193 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8194 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008195};
8196
Thomas Pedersen84f10702012-07-12 16:17:33 -07008197static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008198 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008199{
8200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008201 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008202 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008203
Johannes Bergd9d8b012012-11-26 12:51:52 +01008204 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008205 return -EINVAL;
8206
Thomas Pedersen84f10702012-07-12 16:17:33 -07008207 if (!rdev->ops->set_cqm_txe_config)
8208 return -EOPNOTSUPP;
8209
8210 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8211 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8212 return -EOPNOTSUPP;
8213
Hila Gonene35e4d22012-06-27 17:19:42 +03008214 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008215}
8216
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008217static int nl80211_set_cqm_rssi(struct genl_info *info,
8218 s32 threshold, u32 hysteresis)
8219{
Johannes Berg4c476992010-10-04 21:36:35 +02008220 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008221 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008222 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008223
8224 if (threshold > 0)
8225 return -EINVAL;
8226
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008227 /* disabling - hysteresis should also be zero then */
8228 if (threshold == 0)
8229 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008230
Johannes Berg4c476992010-10-04 21:36:35 +02008231 if (!rdev->ops->set_cqm_rssi_config)
8232 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008233
Johannes Berg074ac8d2010-09-16 14:58:22 +02008234 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008235 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8236 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008237
Hila Gonene35e4d22012-06-27 17:19:42 +03008238 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008239}
8240
8241static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8242{
8243 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8244 struct nlattr *cqm;
8245 int err;
8246
8247 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008248 if (!cqm)
8249 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008250
8251 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8252 nl80211_attr_cqm_policy);
8253 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008254 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008255
8256 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8257 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008258 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8259 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008260
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008261 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8262 }
8263
8264 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8265 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8266 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8267 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8268 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8269 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8270
8271 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8272 }
8273
8274 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008275}
8276
Johannes Berg29cbe682010-12-03 09:20:44 +01008277static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8278{
8279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8280 struct net_device *dev = info->user_ptr[1];
8281 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008282 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008283 int err;
8284
8285 /* start with default */
8286 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008287 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008288
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008289 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008290 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008291 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008292 if (err)
8293 return err;
8294 }
8295
8296 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8297 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8298 return -EINVAL;
8299
Javier Cardonac80d5452010-12-16 17:37:49 -08008300 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8301 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8302
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008303 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8304 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8305 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8306 return -EINVAL;
8307
Marco Porsch9bdbf042013-01-07 16:04:51 +01008308 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8309 setup.beacon_interval =
8310 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8311 if (setup.beacon_interval < 10 ||
8312 setup.beacon_interval > 10000)
8313 return -EINVAL;
8314 }
8315
8316 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8317 setup.dtim_period =
8318 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8319 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8320 return -EINVAL;
8321 }
8322
Javier Cardonac80d5452010-12-16 17:37:49 -08008323 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8324 /* parse additional setup parameters if given */
8325 err = nl80211_parse_mesh_setup(info, &setup);
8326 if (err)
8327 return err;
8328 }
8329
Thomas Pedersend37bb182013-03-04 13:06:13 -08008330 if (setup.user_mpm)
8331 cfg.auto_open_plinks = false;
8332
Johannes Bergcc1d2802012-05-16 23:50:20 +02008333 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008334 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8335 if (err)
8336 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008337 } else {
8338 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008339 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008340 }
8341
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008342 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8343 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8344 int n_rates =
8345 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8346 struct ieee80211_supported_band *sband;
8347
8348 if (!setup.chandef.chan)
8349 return -EINVAL;
8350
8351 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8352
8353 err = ieee80211_get_ratemask(sband, rates, n_rates,
8354 &setup.basic_rates);
8355 if (err)
8356 return err;
8357 }
8358
Javier Cardonac80d5452010-12-16 17:37:49 -08008359 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008360}
8361
8362static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8363{
8364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8365 struct net_device *dev = info->user_ptr[1];
8366
8367 return cfg80211_leave_mesh(rdev, dev);
8368}
8369
Johannes Bergdfb89c52012-06-27 09:23:48 +02008370#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008371static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8372 struct cfg80211_registered_device *rdev)
8373{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008374 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008375 struct nlattr *nl_pats, *nl_pat;
8376 int i, pat_len;
8377
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008378 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008379 return 0;
8380
8381 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8382 if (!nl_pats)
8383 return -ENOBUFS;
8384
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008385 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008386 nl_pat = nla_nest_start(msg, i + 1);
8387 if (!nl_pat)
8388 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008389 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008390 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008391 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008392 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8393 wowlan->patterns[i].pattern) ||
8394 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008395 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008396 return -ENOBUFS;
8397 nla_nest_end(msg, nl_pat);
8398 }
8399 nla_nest_end(msg, nl_pats);
8400
8401 return 0;
8402}
8403
Johannes Berg2a0e0472013-01-23 22:57:40 +01008404static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8405 struct cfg80211_wowlan_tcp *tcp)
8406{
8407 struct nlattr *nl_tcp;
8408
8409 if (!tcp)
8410 return 0;
8411
8412 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8413 if (!nl_tcp)
8414 return -ENOBUFS;
8415
8416 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8417 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8418 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8419 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8420 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8421 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8422 tcp->payload_len, tcp->payload) ||
8423 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8424 tcp->data_interval) ||
8425 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8426 tcp->wake_len, tcp->wake_data) ||
8427 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8428 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8429 return -ENOBUFS;
8430
8431 if (tcp->payload_seq.len &&
8432 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8433 sizeof(tcp->payload_seq), &tcp->payload_seq))
8434 return -ENOBUFS;
8435
8436 if (tcp->payload_tok.len &&
8437 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8438 sizeof(tcp->payload_tok) + tcp->tokens_size,
8439 &tcp->payload_tok))
8440 return -ENOBUFS;
8441
Johannes Berge248ad32013-05-16 10:24:28 +02008442 nla_nest_end(msg, nl_tcp);
8443
Johannes Berg2a0e0472013-01-23 22:57:40 +01008444 return 0;
8445}
8446
Johannes Bergff1b6e62011-05-04 15:37:28 +02008447static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8448{
8449 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8450 struct sk_buff *msg;
8451 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008452 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008453
Johannes Berg964dc9e2013-06-03 17:25:34 +02008454 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008455 return -EOPNOTSUPP;
8456
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008457 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008458 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008459 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8460 rdev->wiphy.wowlan_config->tcp->payload_len +
8461 rdev->wiphy.wowlan_config->tcp->wake_len +
8462 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008463 }
8464
8465 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008466 if (!msg)
8467 return -ENOMEM;
8468
Eric W. Biederman15e47302012-09-07 20:12:54 +00008469 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008470 NL80211_CMD_GET_WOWLAN);
8471 if (!hdr)
8472 goto nla_put_failure;
8473
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008474 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008475 struct nlattr *nl_wowlan;
8476
8477 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8478 if (!nl_wowlan)
8479 goto nla_put_failure;
8480
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008481 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008482 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008483 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008484 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008485 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008486 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008487 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008488 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008489 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008490 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008491 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008492 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008493 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008494 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8495 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008496
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008497 if (nl80211_send_wowlan_patterns(msg, rdev))
8498 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008499
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008500 if (nl80211_send_wowlan_tcp(msg,
8501 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008502 goto nla_put_failure;
8503
Johannes Bergff1b6e62011-05-04 15:37:28 +02008504 nla_nest_end(msg, nl_wowlan);
8505 }
8506
8507 genlmsg_end(msg, hdr);
8508 return genlmsg_reply(msg, info);
8509
8510nla_put_failure:
8511 nlmsg_free(msg);
8512 return -ENOBUFS;
8513}
8514
Johannes Berg2a0e0472013-01-23 22:57:40 +01008515static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8516 struct nlattr *attr,
8517 struct cfg80211_wowlan *trig)
8518{
8519 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8520 struct cfg80211_wowlan_tcp *cfg;
8521 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8522 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8523 u32 size;
8524 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8525 int err, port;
8526
Johannes Berg964dc9e2013-06-03 17:25:34 +02008527 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008528 return -EINVAL;
8529
8530 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8531 nla_data(attr), nla_len(attr),
8532 nl80211_wowlan_tcp_policy);
8533 if (err)
8534 return err;
8535
8536 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8537 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8538 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8539 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8540 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8541 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8542 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8543 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8544 return -EINVAL;
8545
8546 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008547 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008548 return -EINVAL;
8549
8550 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008551 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008552 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008553 return -EINVAL;
8554
8555 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008556 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008557 return -EINVAL;
8558
8559 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8560 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8561 return -EINVAL;
8562
8563 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8564 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8565
8566 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8567 tokens_size = tokln - sizeof(*tok);
8568
8569 if (!tok->len || tokens_size % tok->len)
8570 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008571 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008572 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008573 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008574 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008575 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008576 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008577 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008578 return -EINVAL;
8579 if (tok->offset + tok->len > data_size)
8580 return -EINVAL;
8581 }
8582
8583 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8584 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008585 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008586 return -EINVAL;
8587 if (seq->len == 0 || seq->len > 4)
8588 return -EINVAL;
8589 if (seq->len + seq->offset > data_size)
8590 return -EINVAL;
8591 }
8592
8593 size = sizeof(*cfg);
8594 size += data_size;
8595 size += wake_size + wake_mask_size;
8596 size += tokens_size;
8597
8598 cfg = kzalloc(size, GFP_KERNEL);
8599 if (!cfg)
8600 return -ENOMEM;
8601 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8602 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8603 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8604 ETH_ALEN);
8605 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8606 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8607 else
8608 port = 0;
8609#ifdef CONFIG_INET
8610 /* allocate a socket and port for it and use it */
8611 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8612 IPPROTO_TCP, &cfg->sock, 1);
8613 if (err) {
8614 kfree(cfg);
8615 return err;
8616 }
8617 if (inet_csk_get_port(cfg->sock->sk, port)) {
8618 sock_release(cfg->sock);
8619 kfree(cfg);
8620 return -EADDRINUSE;
8621 }
8622 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8623#else
8624 if (!port) {
8625 kfree(cfg);
8626 return -EINVAL;
8627 }
8628 cfg->src_port = port;
8629#endif
8630
8631 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8632 cfg->payload_len = data_size;
8633 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8634 memcpy((void *)cfg->payload,
8635 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8636 data_size);
8637 if (seq)
8638 cfg->payload_seq = *seq;
8639 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8640 cfg->wake_len = wake_size;
8641 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8642 memcpy((void *)cfg->wake_data,
8643 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8644 wake_size);
8645 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8646 data_size + wake_size;
8647 memcpy((void *)cfg->wake_mask,
8648 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8649 wake_mask_size);
8650 if (tok) {
8651 cfg->tokens_size = tokens_size;
8652 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8653 }
8654
8655 trig->tcp = cfg;
8656
8657 return 0;
8658}
8659
Johannes Bergff1b6e62011-05-04 15:37:28 +02008660static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8661{
8662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8663 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008664 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008665 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008666 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008667 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008668 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008669
Johannes Berg964dc9e2013-06-03 17:25:34 +02008670 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008671 return -EOPNOTSUPP;
8672
Johannes Bergae33bd82012-07-12 16:25:02 +02008673 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8674 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008675 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008676 goto set_wakeup;
8677 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008678
8679 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8680 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8681 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8682 nl80211_wowlan_policy);
8683 if (err)
8684 return err;
8685
8686 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8687 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8688 return -EINVAL;
8689 new_triggers.any = true;
8690 }
8691
8692 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8693 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8694 return -EINVAL;
8695 new_triggers.disconnect = true;
8696 }
8697
8698 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8699 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8700 return -EINVAL;
8701 new_triggers.magic_pkt = true;
8702 }
8703
Johannes Berg77dbbb12011-07-13 10:48:55 +02008704 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8705 return -EINVAL;
8706
8707 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8708 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8709 return -EINVAL;
8710 new_triggers.gtk_rekey_failure = true;
8711 }
8712
8713 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8714 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8715 return -EINVAL;
8716 new_triggers.eap_identity_req = true;
8717 }
8718
8719 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8720 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8721 return -EINVAL;
8722 new_triggers.four_way_handshake = true;
8723 }
8724
8725 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8726 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8727 return -EINVAL;
8728 new_triggers.rfkill_release = true;
8729 }
8730
Johannes Bergff1b6e62011-05-04 15:37:28 +02008731 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8732 struct nlattr *pat;
8733 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008734 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008735 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008736
8737 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8738 rem)
8739 n_patterns++;
8740 if (n_patterns > wowlan->n_patterns)
8741 return -EINVAL;
8742
8743 new_triggers.patterns = kcalloc(n_patterns,
8744 sizeof(new_triggers.patterns[0]),
8745 GFP_KERNEL);
8746 if (!new_triggers.patterns)
8747 return -ENOMEM;
8748
8749 new_triggers.n_patterns = n_patterns;
8750 i = 0;
8751
8752 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8753 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008754 u8 *mask_pat;
8755
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008756 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8757 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008758 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008759 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8760 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008761 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008762 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008763 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008764 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008765 goto error;
8766 if (pat_len > wowlan->pattern_max_len ||
8767 pat_len < wowlan->pattern_min_len)
8768 goto error;
8769
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008770 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008771 pkt_offset = 0;
8772 else
8773 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008774 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008775 if (pkt_offset > wowlan->max_pkt_offset)
8776 goto error;
8777 new_triggers.patterns[i].pkt_offset = pkt_offset;
8778
Johannes Berg922bd802014-05-19 17:59:50 +02008779 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8780 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008781 err = -ENOMEM;
8782 goto error;
8783 }
Johannes Berg922bd802014-05-19 17:59:50 +02008784 new_triggers.patterns[i].mask = mask_pat;
8785 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008786 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008787 mask_pat += mask_len;
8788 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008789 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008790 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008791 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008792 pat_len);
8793 i++;
8794 }
8795 }
8796
Johannes Berg2a0e0472013-01-23 22:57:40 +01008797 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8798 err = nl80211_parse_wowlan_tcp(
8799 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8800 &new_triggers);
8801 if (err)
8802 goto error;
8803 }
8804
Johannes Bergae33bd82012-07-12 16:25:02 +02008805 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8806 if (!ntrig) {
8807 err = -ENOMEM;
8808 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008809 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008810 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008811 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008812
Johannes Bergae33bd82012-07-12 16:25:02 +02008813 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008814 if (rdev->ops->set_wakeup &&
8815 prev_enabled != !!rdev->wiphy.wowlan_config)
8816 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008817
Johannes Bergff1b6e62011-05-04 15:37:28 +02008818 return 0;
8819 error:
8820 for (i = 0; i < new_triggers.n_patterns; i++)
8821 kfree(new_triggers.patterns[i].mask);
8822 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008823 if (new_triggers.tcp && new_triggers.tcp->sock)
8824 sock_release(new_triggers.tcp->sock);
8825 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008826 return err;
8827}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008828#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008829
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07008830static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8831 struct cfg80211_registered_device *rdev)
8832{
8833 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8834 int i, j, pat_len;
8835 struct cfg80211_coalesce_rules *rule;
8836
8837 if (!rdev->coalesce->n_rules)
8838 return 0;
8839
8840 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8841 if (!nl_rules)
8842 return -ENOBUFS;
8843
8844 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8845 nl_rule = nla_nest_start(msg, i + 1);
8846 if (!nl_rule)
8847 return -ENOBUFS;
8848
8849 rule = &rdev->coalesce->rules[i];
8850 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8851 rule->delay))
8852 return -ENOBUFS;
8853
8854 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8855 rule->condition))
8856 return -ENOBUFS;
8857
8858 nl_pats = nla_nest_start(msg,
8859 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8860 if (!nl_pats)
8861 return -ENOBUFS;
8862
8863 for (j = 0; j < rule->n_patterns; j++) {
8864 nl_pat = nla_nest_start(msg, j + 1);
8865 if (!nl_pat)
8866 return -ENOBUFS;
8867 pat_len = rule->patterns[j].pattern_len;
8868 if (nla_put(msg, NL80211_PKTPAT_MASK,
8869 DIV_ROUND_UP(pat_len, 8),
8870 rule->patterns[j].mask) ||
8871 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8872 rule->patterns[j].pattern) ||
8873 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8874 rule->patterns[j].pkt_offset))
8875 return -ENOBUFS;
8876 nla_nest_end(msg, nl_pat);
8877 }
8878 nla_nest_end(msg, nl_pats);
8879 nla_nest_end(msg, nl_rule);
8880 }
8881 nla_nest_end(msg, nl_rules);
8882
8883 return 0;
8884}
8885
8886static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8887{
8888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8889 struct sk_buff *msg;
8890 void *hdr;
8891
8892 if (!rdev->wiphy.coalesce)
8893 return -EOPNOTSUPP;
8894
8895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8896 if (!msg)
8897 return -ENOMEM;
8898
8899 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8900 NL80211_CMD_GET_COALESCE);
8901 if (!hdr)
8902 goto nla_put_failure;
8903
8904 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8905 goto nla_put_failure;
8906
8907 genlmsg_end(msg, hdr);
8908 return genlmsg_reply(msg, info);
8909
8910nla_put_failure:
8911 nlmsg_free(msg);
8912 return -ENOBUFS;
8913}
8914
8915void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8916{
8917 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8918 int i, j;
8919 struct cfg80211_coalesce_rules *rule;
8920
8921 if (!coalesce)
8922 return;
8923
8924 for (i = 0; i < coalesce->n_rules; i++) {
8925 rule = &coalesce->rules[i];
8926 for (j = 0; j < rule->n_patterns; j++)
8927 kfree(rule->patterns[j].mask);
8928 kfree(rule->patterns);
8929 }
8930 kfree(coalesce->rules);
8931 kfree(coalesce);
8932 rdev->coalesce = NULL;
8933}
8934
8935static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8936 struct nlattr *rule,
8937 struct cfg80211_coalesce_rules *new_rule)
8938{
8939 int err, i;
8940 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8941 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8942 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8943 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8944
8945 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8946 nla_len(rule), nl80211_coalesce_policy);
8947 if (err)
8948 return err;
8949
8950 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8951 new_rule->delay =
8952 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8953 if (new_rule->delay > coalesce->max_delay)
8954 return -EINVAL;
8955
8956 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8957 new_rule->condition =
8958 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8959 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8960 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8961 return -EINVAL;
8962
8963 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8964 return -EINVAL;
8965
8966 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8967 rem)
8968 n_patterns++;
8969 if (n_patterns > coalesce->n_patterns)
8970 return -EINVAL;
8971
8972 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8973 GFP_KERNEL);
8974 if (!new_rule->patterns)
8975 return -ENOMEM;
8976
8977 new_rule->n_patterns = n_patterns;
8978 i = 0;
8979
8980 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8981 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008982 u8 *mask_pat;
8983
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07008984 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8985 nla_len(pat), NULL);
8986 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8987 !pat_tb[NL80211_PKTPAT_PATTERN])
8988 return -EINVAL;
8989 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8990 mask_len = DIV_ROUND_UP(pat_len, 8);
8991 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8992 return -EINVAL;
8993 if (pat_len > coalesce->pattern_max_len ||
8994 pat_len < coalesce->pattern_min_len)
8995 return -EINVAL;
8996
8997 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8998 pkt_offset = 0;
8999 else
9000 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9001 if (pkt_offset > coalesce->max_pkt_offset)
9002 return -EINVAL;
9003 new_rule->patterns[i].pkt_offset = pkt_offset;
9004
Johannes Berg922bd802014-05-19 17:59:50 +02009005 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9006 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009007 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009008
9009 new_rule->patterns[i].mask = mask_pat;
9010 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9011 mask_len);
9012
9013 mask_pat += mask_len;
9014 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009015 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009016 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9017 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009018 i++;
9019 }
9020
9021 return 0;
9022}
9023
9024static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9025{
9026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9027 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9028 struct cfg80211_coalesce new_coalesce = {};
9029 struct cfg80211_coalesce *n_coalesce;
9030 int err, rem_rule, n_rules = 0, i, j;
9031 struct nlattr *rule;
9032 struct cfg80211_coalesce_rules *tmp_rule;
9033
9034 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9035 return -EOPNOTSUPP;
9036
9037 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9038 cfg80211_rdev_free_coalesce(rdev);
9039 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9040 return 0;
9041 }
9042
9043 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9044 rem_rule)
9045 n_rules++;
9046 if (n_rules > coalesce->n_rules)
9047 return -EINVAL;
9048
9049 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9050 GFP_KERNEL);
9051 if (!new_coalesce.rules)
9052 return -ENOMEM;
9053
9054 new_coalesce.n_rules = n_rules;
9055 i = 0;
9056
9057 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9058 rem_rule) {
9059 err = nl80211_parse_coalesce_rule(rdev, rule,
9060 &new_coalesce.rules[i]);
9061 if (err)
9062 goto error;
9063
9064 i++;
9065 }
9066
9067 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9068 if (err)
9069 goto error;
9070
9071 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9072 if (!n_coalesce) {
9073 err = -ENOMEM;
9074 goto error;
9075 }
9076 cfg80211_rdev_free_coalesce(rdev);
9077 rdev->coalesce = n_coalesce;
9078
9079 return 0;
9080error:
9081 for (i = 0; i < new_coalesce.n_rules; i++) {
9082 tmp_rule = &new_coalesce.rules[i];
9083 for (j = 0; j < tmp_rule->n_patterns; j++)
9084 kfree(tmp_rule->patterns[j].mask);
9085 kfree(tmp_rule->patterns);
9086 }
9087 kfree(new_coalesce.rules);
9088
9089 return err;
9090}
9091
Johannes Berge5497d72011-07-05 16:35:40 +02009092static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9093{
9094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9095 struct net_device *dev = info->user_ptr[1];
9096 struct wireless_dev *wdev = dev->ieee80211_ptr;
9097 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9098 struct cfg80211_gtk_rekey_data rekey_data;
9099 int err;
9100
9101 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9102 return -EINVAL;
9103
9104 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9105 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9106 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9107 nl80211_rekey_policy);
9108 if (err)
9109 return err;
9110
9111 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9112 return -ERANGE;
9113 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9114 return -ERANGE;
9115 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9116 return -ERANGE;
9117
Johannes Berg78f686c2014-09-10 22:28:06 +03009118 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9119 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9120 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009121
9122 wdev_lock(wdev);
9123 if (!wdev->current_bss) {
9124 err = -ENOTCONN;
9125 goto out;
9126 }
9127
9128 if (!rdev->ops->set_rekey_data) {
9129 err = -EOPNOTSUPP;
9130 goto out;
9131 }
9132
Hila Gonene35e4d22012-06-27 17:19:42 +03009133 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009134 out:
9135 wdev_unlock(wdev);
9136 return err;
9137}
9138
Johannes Berg28946da2011-11-04 11:18:12 +01009139static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9140 struct genl_info *info)
9141{
9142 struct net_device *dev = info->user_ptr[1];
9143 struct wireless_dev *wdev = dev->ieee80211_ptr;
9144
9145 if (wdev->iftype != NL80211_IFTYPE_AP &&
9146 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9147 return -EINVAL;
9148
Eric W. Biederman15e47302012-09-07 20:12:54 +00009149 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009150 return -EBUSY;
9151
Eric W. Biederman15e47302012-09-07 20:12:54 +00009152 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009153 return 0;
9154}
9155
Johannes Berg7f6cf312011-11-04 11:18:15 +01009156static int nl80211_probe_client(struct sk_buff *skb,
9157 struct genl_info *info)
9158{
9159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9160 struct net_device *dev = info->user_ptr[1];
9161 struct wireless_dev *wdev = dev->ieee80211_ptr;
9162 struct sk_buff *msg;
9163 void *hdr;
9164 const u8 *addr;
9165 u64 cookie;
9166 int err;
9167
9168 if (wdev->iftype != NL80211_IFTYPE_AP &&
9169 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9170 return -EOPNOTSUPP;
9171
9172 if (!info->attrs[NL80211_ATTR_MAC])
9173 return -EINVAL;
9174
9175 if (!rdev->ops->probe_client)
9176 return -EOPNOTSUPP;
9177
9178 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9179 if (!msg)
9180 return -ENOMEM;
9181
Eric W. Biederman15e47302012-09-07 20:12:54 +00009182 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009183 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009184 if (!hdr) {
9185 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009186 goto free_msg;
9187 }
9188
9189 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9190
Hila Gonene35e4d22012-06-27 17:19:42 +03009191 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009192 if (err)
9193 goto free_msg;
9194
David S. Miller9360ffd2012-03-29 04:41:26 -04009195 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9196 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009197
9198 genlmsg_end(msg, hdr);
9199
9200 return genlmsg_reply(msg, info);
9201
9202 nla_put_failure:
9203 err = -ENOBUFS;
9204 free_msg:
9205 nlmsg_free(msg);
9206 return err;
9207}
9208
Johannes Berg5e760232011-11-04 11:18:17 +01009209static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9210{
9211 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009212 struct cfg80211_beacon_registration *reg, *nreg;
9213 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009214
9215 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9216 return -EOPNOTSUPP;
9217
Ben Greear37c73b52012-10-26 14:49:25 -07009218 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9219 if (!nreg)
9220 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009221
Ben Greear37c73b52012-10-26 14:49:25 -07009222 /* First, check if already registered. */
9223 spin_lock_bh(&rdev->beacon_registrations_lock);
9224 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9225 if (reg->nlportid == info->snd_portid) {
9226 rv = -EALREADY;
9227 goto out_err;
9228 }
9229 }
9230 /* Add it to the list */
9231 nreg->nlportid = info->snd_portid;
9232 list_add(&nreg->list, &rdev->beacon_registrations);
9233
9234 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009235
9236 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009237out_err:
9238 spin_unlock_bh(&rdev->beacon_registrations_lock);
9239 kfree(nreg);
9240 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009241}
9242
Johannes Berg98104fde2012-06-16 00:19:54 +02009243static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9244{
9245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9246 struct wireless_dev *wdev = info->user_ptr[1];
9247 int err;
9248
9249 if (!rdev->ops->start_p2p_device)
9250 return -EOPNOTSUPP;
9251
9252 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9253 return -EOPNOTSUPP;
9254
9255 if (wdev->p2p_started)
9256 return 0;
9257
Luciano Coelhob6a55012014-02-27 11:07:21 +02009258 if (rfkill_blocked(rdev->rfkill))
9259 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009260
Johannes Bergeeb126e2012-10-23 15:16:50 +02009261 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009262 if (err)
9263 return err;
9264
9265 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009266 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009267
9268 return 0;
9269}
9270
9271static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9272{
9273 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9274 struct wireless_dev *wdev = info->user_ptr[1];
9275
9276 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9277 return -EOPNOTSUPP;
9278
9279 if (!rdev->ops->stop_p2p_device)
9280 return -EOPNOTSUPP;
9281
Johannes Bergf9f47522013-03-19 15:04:07 +01009282 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009283
9284 return 0;
9285}
9286
Johannes Berg3713b4e2013-02-14 16:19:38 +01009287static int nl80211_get_protocol_features(struct sk_buff *skb,
9288 struct genl_info *info)
9289{
9290 void *hdr;
9291 struct sk_buff *msg;
9292
9293 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9294 if (!msg)
9295 return -ENOMEM;
9296
9297 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9298 NL80211_CMD_GET_PROTOCOL_FEATURES);
9299 if (!hdr)
9300 goto nla_put_failure;
9301
9302 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9303 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9304 goto nla_put_failure;
9305
9306 genlmsg_end(msg, hdr);
9307 return genlmsg_reply(msg, info);
9308
9309 nla_put_failure:
9310 kfree_skb(msg);
9311 return -ENOBUFS;
9312}
9313
Jouni Malinen355199e2013-02-27 17:14:27 +02009314static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9315{
9316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9317 struct cfg80211_update_ft_ies_params ft_params;
9318 struct net_device *dev = info->user_ptr[1];
9319
9320 if (!rdev->ops->update_ft_ies)
9321 return -EOPNOTSUPP;
9322
9323 if (!info->attrs[NL80211_ATTR_MDID] ||
9324 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9325 return -EINVAL;
9326
9327 memset(&ft_params, 0, sizeof(ft_params));
9328 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9329 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9330 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9331
9332 return rdev_update_ft_ies(rdev, dev, &ft_params);
9333}
9334
Arend van Spriel5de17982013-04-18 15:49:00 +02009335static int nl80211_crit_protocol_start(struct sk_buff *skb,
9336 struct genl_info *info)
9337{
9338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9339 struct wireless_dev *wdev = info->user_ptr[1];
9340 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9341 u16 duration;
9342 int ret;
9343
9344 if (!rdev->ops->crit_proto_start)
9345 return -EOPNOTSUPP;
9346
9347 if (WARN_ON(!rdev->ops->crit_proto_stop))
9348 return -EINVAL;
9349
9350 if (rdev->crit_proto_nlportid)
9351 return -EBUSY;
9352
9353 /* determine protocol if provided */
9354 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9355 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9356
9357 if (proto >= NUM_NL80211_CRIT_PROTO)
9358 return -EINVAL;
9359
9360 /* timeout must be provided */
9361 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9362 return -EINVAL;
9363
9364 duration =
9365 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9366
9367 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9368 return -ERANGE;
9369
9370 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9371 if (!ret)
9372 rdev->crit_proto_nlportid = info->snd_portid;
9373
9374 return ret;
9375}
9376
9377static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9378 struct genl_info *info)
9379{
9380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9381 struct wireless_dev *wdev = info->user_ptr[1];
9382
9383 if (!rdev->ops->crit_proto_stop)
9384 return -EOPNOTSUPP;
9385
9386 if (rdev->crit_proto_nlportid) {
9387 rdev->crit_proto_nlportid = 0;
9388 rdev_crit_proto_stop(rdev, wdev);
9389 }
9390 return 0;
9391}
9392
Johannes Bergad7e7182013-11-13 13:37:47 +01009393static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9394{
9395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9396 struct wireless_dev *wdev =
9397 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9398 int i, err;
9399 u32 vid, subcmd;
9400
9401 if (!rdev->wiphy.vendor_commands)
9402 return -EOPNOTSUPP;
9403
9404 if (IS_ERR(wdev)) {
9405 err = PTR_ERR(wdev);
9406 if (err != -EINVAL)
9407 return err;
9408 wdev = NULL;
9409 } else if (wdev->wiphy != &rdev->wiphy) {
9410 return -EINVAL;
9411 }
9412
9413 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9414 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9415 return -EINVAL;
9416
9417 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9418 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9419 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9420 const struct wiphy_vendor_command *vcmd;
9421 void *data = NULL;
9422 int len = 0;
9423
9424 vcmd = &rdev->wiphy.vendor_commands[i];
9425
9426 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9427 continue;
9428
9429 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9430 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9431 if (!wdev)
9432 return -EINVAL;
9433 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9434 !wdev->netdev)
9435 return -EINVAL;
9436
9437 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9438 if (wdev->netdev &&
9439 !netif_running(wdev->netdev))
9440 return -ENETDOWN;
9441 if (!wdev->netdev && !wdev->p2p_started)
9442 return -ENETDOWN;
9443 }
9444 } else {
9445 wdev = NULL;
9446 }
9447
9448 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9449 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9450 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9451 }
9452
9453 rdev->cur_cmd_info = info;
9454 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9455 data, len);
9456 rdev->cur_cmd_info = NULL;
9457 return err;
9458 }
9459
9460 return -EOPNOTSUPP;
9461}
9462
9463struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9464 enum nl80211_commands cmd,
9465 enum nl80211_attrs attr,
9466 int approxlen)
9467{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009468 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009469
9470 if (WARN_ON(!rdev->cur_cmd_info))
9471 return NULL;
9472
9473 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9474 rdev->cur_cmd_info->snd_portid,
9475 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009476 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009477}
9478EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9479
9480int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9481{
9482 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9483 void *hdr = ((void **)skb->cb)[1];
9484 struct nlattr *data = ((void **)skb->cb)[2];
9485
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009486 /* clear CB data for netlink core to own from now on */
9487 memset(skb->cb, 0, sizeof(skb->cb));
9488
Johannes Bergad7e7182013-11-13 13:37:47 +01009489 if (WARN_ON(!rdev->cur_cmd_info)) {
9490 kfree_skb(skb);
9491 return -EINVAL;
9492 }
9493
9494 nla_nest_end(skb, data);
9495 genlmsg_end(skb, hdr);
9496 return genlmsg_reply(skb, rdev->cur_cmd_info);
9497}
9498EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9499
9500
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009501static int nl80211_set_qos_map(struct sk_buff *skb,
9502 struct genl_info *info)
9503{
9504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9505 struct cfg80211_qos_map *qos_map = NULL;
9506 struct net_device *dev = info->user_ptr[1];
9507 u8 *pos, len, num_des, des_len, des;
9508 int ret;
9509
9510 if (!rdev->ops->set_qos_map)
9511 return -EOPNOTSUPP;
9512
9513 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9514 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9515 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9516
9517 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9518 len > IEEE80211_QOS_MAP_LEN_MAX)
9519 return -EINVAL;
9520
9521 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9522 if (!qos_map)
9523 return -ENOMEM;
9524
9525 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9526 if (num_des) {
9527 des_len = num_des *
9528 sizeof(struct cfg80211_dscp_exception);
9529 memcpy(qos_map->dscp_exception, pos, des_len);
9530 qos_map->num_des = num_des;
9531 for (des = 0; des < num_des; des++) {
9532 if (qos_map->dscp_exception[des].up > 7) {
9533 kfree(qos_map);
9534 return -EINVAL;
9535 }
9536 }
9537 pos += des_len;
9538 }
9539 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9540 }
9541
9542 wdev_lock(dev->ieee80211_ptr);
9543 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9544 if (!ret)
9545 ret = rdev_set_qos_map(rdev, dev, qos_map);
9546 wdev_unlock(dev->ieee80211_ptr);
9547
9548 kfree(qos_map);
9549 return ret;
9550}
9551
Johannes Berg960d01a2014-09-09 22:55:35 +03009552static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9553{
9554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9555 struct net_device *dev = info->user_ptr[1];
9556 struct wireless_dev *wdev = dev->ieee80211_ptr;
9557 const u8 *peer;
9558 u8 tsid, up;
9559 u16 admitted_time = 0;
9560 int err;
9561
Johannes Berg723e73a2014-10-22 09:25:06 +02009562 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009563 return -EOPNOTSUPP;
9564
9565 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9566 !info->attrs[NL80211_ATTR_USER_PRIO])
9567 return -EINVAL;
9568
9569 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9570 if (tsid >= IEEE80211_NUM_TIDS)
9571 return -EINVAL;
9572
9573 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9574 if (up >= IEEE80211_NUM_UPS)
9575 return -EINVAL;
9576
9577 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009578 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009579 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009580 * need more attributes for that (e.g. BA session requirement);
9581 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009582 */
9583 return -EINVAL;
9584 }
9585
9586 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9587
9588 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9589 admitted_time =
9590 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9591 if (!admitted_time)
9592 return -EINVAL;
9593 }
9594
9595 wdev_lock(wdev);
9596 switch (wdev->iftype) {
9597 case NL80211_IFTYPE_STATION:
9598 case NL80211_IFTYPE_P2P_CLIENT:
9599 if (wdev->current_bss)
9600 break;
9601 err = -ENOTCONN;
9602 goto out;
9603 default:
9604 err = -EOPNOTSUPP;
9605 goto out;
9606 }
9607
9608 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9609
9610 out:
9611 wdev_unlock(wdev);
9612 return err;
9613}
9614
9615static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9616{
9617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9618 struct net_device *dev = info->user_ptr[1];
9619 struct wireless_dev *wdev = dev->ieee80211_ptr;
9620 const u8 *peer;
9621 u8 tsid;
9622 int err;
9623
9624 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9625 return -EINVAL;
9626
9627 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9628 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9629
9630 wdev_lock(wdev);
9631 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9632 wdev_unlock(wdev);
9633
9634 return err;
9635}
9636
Johannes Berg4c476992010-10-04 21:36:35 +02009637#define NL80211_FLAG_NEED_WIPHY 0x01
9638#define NL80211_FLAG_NEED_NETDEV 0x02
9639#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009640#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9641#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9642 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009643#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009644/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009645#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9646 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +03009647#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +02009648
Johannes Bergf84f7712013-11-14 17:14:45 +01009649static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009650 struct genl_info *info)
9651{
9652 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009653 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009654 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009655 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9656
9657 if (rtnl)
9658 rtnl_lock();
9659
9660 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009661 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009662 if (IS_ERR(rdev)) {
9663 if (rtnl)
9664 rtnl_unlock();
9665 return PTR_ERR(rdev);
9666 }
9667 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009668 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9669 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009670 ASSERT_RTNL();
9671
Johannes Berg89a54e42012-06-15 14:33:17 +02009672 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9673 info->attrs);
9674 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009675 if (rtnl)
9676 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009677 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009678 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009679
Johannes Berg89a54e42012-06-15 14:33:17 +02009680 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009681 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009682
Johannes Berg1bf614e2012-06-15 15:23:36 +02009683 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9684 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009685 if (rtnl)
9686 rtnl_unlock();
9687 return -EINVAL;
9688 }
9689
9690 info->user_ptr[1] = dev;
9691 } else {
9692 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009693 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009694
Johannes Berg1bf614e2012-06-15 15:23:36 +02009695 if (dev) {
9696 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9697 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009698 if (rtnl)
9699 rtnl_unlock();
9700 return -ENETDOWN;
9701 }
9702
9703 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009704 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9705 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009706 if (rtnl)
9707 rtnl_unlock();
9708 return -ENETDOWN;
9709 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009710 }
9711
Johannes Berg4c476992010-10-04 21:36:35 +02009712 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009713 }
9714
9715 return 0;
9716}
9717
Johannes Bergf84f7712013-11-14 17:14:45 +01009718static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009719 struct genl_info *info)
9720{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009721 if (info->user_ptr[1]) {
9722 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9723 struct wireless_dev *wdev = info->user_ptr[1];
9724
9725 if (wdev->netdev)
9726 dev_put(wdev->netdev);
9727 } else {
9728 dev_put(info->user_ptr[1]);
9729 }
9730 }
Johannes Berg5393b912014-09-10 15:00:16 +03009731
Johannes Berg4c476992010-10-04 21:36:35 +02009732 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9733 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +03009734
9735 /* If needed, clear the netlink message payload from the SKB
9736 * as it might contain key data that shouldn't stick around on
9737 * the heap after the SKB is freed. The netlink message header
9738 * is still needed for further processing, so leave it intact.
9739 */
9740 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
9741 struct nlmsghdr *nlh = nlmsg_hdr(skb);
9742
9743 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
9744 }
Johannes Berg4c476992010-10-04 21:36:35 +02009745}
9746
Johannes Berg4534de82013-11-14 17:14:46 +01009747static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009748 {
9749 .cmd = NL80211_CMD_GET_WIPHY,
9750 .doit = nl80211_get_wiphy,
9751 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009752 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009753 .policy = nl80211_policy,
9754 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009755 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9756 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009757 },
9758 {
9759 .cmd = NL80211_CMD_SET_WIPHY,
9760 .doit = nl80211_set_wiphy,
9761 .policy = nl80211_policy,
9762 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009763 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009764 },
9765 {
9766 .cmd = NL80211_CMD_GET_INTERFACE,
9767 .doit = nl80211_get_interface,
9768 .dumpit = nl80211_dump_interface,
9769 .policy = nl80211_policy,
9770 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009771 .internal_flags = NL80211_FLAG_NEED_WDEV |
9772 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009773 },
9774 {
9775 .cmd = NL80211_CMD_SET_INTERFACE,
9776 .doit = nl80211_set_interface,
9777 .policy = nl80211_policy,
9778 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009779 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9780 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009781 },
9782 {
9783 .cmd = NL80211_CMD_NEW_INTERFACE,
9784 .doit = nl80211_new_interface,
9785 .policy = nl80211_policy,
9786 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009787 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9788 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009789 },
9790 {
9791 .cmd = NL80211_CMD_DEL_INTERFACE,
9792 .doit = nl80211_del_interface,
9793 .policy = nl80211_policy,
9794 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009795 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009796 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009797 },
Johannes Berg41ade002007-12-19 02:03:29 +01009798 {
9799 .cmd = NL80211_CMD_GET_KEY,
9800 .doit = nl80211_get_key,
9801 .policy = nl80211_policy,
9802 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009804 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009805 },
9806 {
9807 .cmd = NL80211_CMD_SET_KEY,
9808 .doit = nl80211_set_key,
9809 .policy = nl80211_policy,
9810 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009812 NL80211_FLAG_NEED_RTNL |
9813 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009814 },
9815 {
9816 .cmd = NL80211_CMD_NEW_KEY,
9817 .doit = nl80211_new_key,
9818 .policy = nl80211_policy,
9819 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009821 NL80211_FLAG_NEED_RTNL |
9822 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009823 },
9824 {
9825 .cmd = NL80211_CMD_DEL_KEY,
9826 .doit = nl80211_del_key,
9827 .policy = nl80211_policy,
9828 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009830 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009831 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009832 {
9833 .cmd = NL80211_CMD_SET_BEACON,
9834 .policy = nl80211_policy,
9835 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009836 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009837 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009838 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009839 },
9840 {
Johannes Berg88600202012-02-13 15:17:18 +01009841 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009842 .policy = nl80211_policy,
9843 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009844 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009845 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009846 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009847 },
9848 {
Johannes Berg88600202012-02-13 15:17:18 +01009849 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009850 .policy = nl80211_policy,
9851 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009852 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009854 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009855 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009856 {
9857 .cmd = NL80211_CMD_GET_STATION,
9858 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009859 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009860 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009861 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9862 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009863 },
9864 {
9865 .cmd = NL80211_CMD_SET_STATION,
9866 .doit = nl80211_set_station,
9867 .policy = nl80211_policy,
9868 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009869 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009870 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009871 },
9872 {
9873 .cmd = NL80211_CMD_NEW_STATION,
9874 .doit = nl80211_new_station,
9875 .policy = nl80211_policy,
9876 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009877 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009878 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009879 },
9880 {
9881 .cmd = NL80211_CMD_DEL_STATION,
9882 .doit = nl80211_del_station,
9883 .policy = nl80211_policy,
9884 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009885 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009886 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009887 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009888 {
9889 .cmd = NL80211_CMD_GET_MPATH,
9890 .doit = nl80211_get_mpath,
9891 .dumpit = nl80211_dump_mpath,
9892 .policy = nl80211_policy,
9893 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009894 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009895 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009896 },
9897 {
Henning Rogge66be7d22014-09-12 08:58:49 +02009898 .cmd = NL80211_CMD_GET_MPP,
9899 .doit = nl80211_get_mpp,
9900 .dumpit = nl80211_dump_mpp,
9901 .policy = nl80211_policy,
9902 .flags = GENL_ADMIN_PERM,
9903 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9904 NL80211_FLAG_NEED_RTNL,
9905 },
9906 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009907 .cmd = NL80211_CMD_SET_MPATH,
9908 .doit = nl80211_set_mpath,
9909 .policy = nl80211_policy,
9910 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009911 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009912 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009913 },
9914 {
9915 .cmd = NL80211_CMD_NEW_MPATH,
9916 .doit = nl80211_new_mpath,
9917 .policy = nl80211_policy,
9918 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009919 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009920 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009921 },
9922 {
9923 .cmd = NL80211_CMD_DEL_MPATH,
9924 .doit = nl80211_del_mpath,
9925 .policy = nl80211_policy,
9926 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009927 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009928 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009929 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009930 {
9931 .cmd = NL80211_CMD_SET_BSS,
9932 .doit = nl80211_set_bss,
9933 .policy = nl80211_policy,
9934 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009936 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009937 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009938 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009939 .cmd = NL80211_CMD_GET_REG,
9940 .doit = nl80211_get_reg,
9941 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009942 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009943 /* can be retrieved by unprivileged users */
9944 },
9945 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009946 .cmd = NL80211_CMD_SET_REG,
9947 .doit = nl80211_set_reg,
9948 .policy = nl80211_policy,
9949 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009950 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009951 },
9952 {
9953 .cmd = NL80211_CMD_REQ_SET_REG,
9954 .doit = nl80211_req_set_reg,
9955 .policy = nl80211_policy,
9956 .flags = GENL_ADMIN_PERM,
9957 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009958 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009959 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9960 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009961 .policy = nl80211_policy,
9962 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009963 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009964 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009965 },
9966 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009967 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9968 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009969 .policy = nl80211_policy,
9970 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009971 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009972 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009973 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009974 {
Johannes Berg2a519312009-02-10 21:25:55 +01009975 .cmd = NL80211_CMD_TRIGGER_SCAN,
9976 .doit = nl80211_trigger_scan,
9977 .policy = nl80211_policy,
9978 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009979 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009980 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009981 },
9982 {
9983 .cmd = NL80211_CMD_GET_SCAN,
9984 .policy = nl80211_policy,
9985 .dumpit = nl80211_dump_scan,
9986 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009987 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009988 .cmd = NL80211_CMD_START_SCHED_SCAN,
9989 .doit = nl80211_start_sched_scan,
9990 .policy = nl80211_policy,
9991 .flags = GENL_ADMIN_PERM,
9992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9993 NL80211_FLAG_NEED_RTNL,
9994 },
9995 {
9996 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9997 .doit = nl80211_stop_sched_scan,
9998 .policy = nl80211_policy,
9999 .flags = GENL_ADMIN_PERM,
10000 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10001 NL80211_FLAG_NEED_RTNL,
10002 },
10003 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010004 .cmd = NL80211_CMD_AUTHENTICATE,
10005 .doit = nl80211_authenticate,
10006 .policy = nl80211_policy,
10007 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010009 NL80211_FLAG_NEED_RTNL |
10010 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010011 },
10012 {
10013 .cmd = NL80211_CMD_ASSOCIATE,
10014 .doit = nl80211_associate,
10015 .policy = nl80211_policy,
10016 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010017 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010018 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010019 },
10020 {
10021 .cmd = NL80211_CMD_DEAUTHENTICATE,
10022 .doit = nl80211_deauthenticate,
10023 .policy = nl80211_policy,
10024 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010025 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010026 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010027 },
10028 {
10029 .cmd = NL80211_CMD_DISASSOCIATE,
10030 .doit = nl80211_disassociate,
10031 .policy = nl80211_policy,
10032 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010034 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010035 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010036 {
10037 .cmd = NL80211_CMD_JOIN_IBSS,
10038 .doit = nl80211_join_ibss,
10039 .policy = nl80211_policy,
10040 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010042 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010043 },
10044 {
10045 .cmd = NL80211_CMD_LEAVE_IBSS,
10046 .doit = nl80211_leave_ibss,
10047 .policy = nl80211_policy,
10048 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010050 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010051 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010052#ifdef CONFIG_NL80211_TESTMODE
10053 {
10054 .cmd = NL80211_CMD_TESTMODE,
10055 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010056 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010057 .policy = nl80211_policy,
10058 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010059 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10060 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010061 },
10062#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010063 {
10064 .cmd = NL80211_CMD_CONNECT,
10065 .doit = nl80211_connect,
10066 .policy = nl80211_policy,
10067 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010068 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010069 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010070 },
10071 {
10072 .cmd = NL80211_CMD_DISCONNECT,
10073 .doit = nl80211_disconnect,
10074 .policy = nl80211_policy,
10075 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010076 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010077 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010078 },
Johannes Berg463d0182009-07-14 00:33:35 +020010079 {
10080 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10081 .doit = nl80211_wiphy_netns,
10082 .policy = nl80211_policy,
10083 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010084 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10085 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010086 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010087 {
10088 .cmd = NL80211_CMD_GET_SURVEY,
10089 .policy = nl80211_policy,
10090 .dumpit = nl80211_dump_survey,
10091 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010092 {
10093 .cmd = NL80211_CMD_SET_PMKSA,
10094 .doit = nl80211_setdel_pmksa,
10095 .policy = nl80211_policy,
10096 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010097 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010098 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010099 },
10100 {
10101 .cmd = NL80211_CMD_DEL_PMKSA,
10102 .doit = nl80211_setdel_pmksa,
10103 .policy = nl80211_policy,
10104 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010105 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010106 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010107 },
10108 {
10109 .cmd = NL80211_CMD_FLUSH_PMKSA,
10110 .doit = nl80211_flush_pmksa,
10111 .policy = nl80211_policy,
10112 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010113 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010114 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010115 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010116 {
10117 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10118 .doit = nl80211_remain_on_channel,
10119 .policy = nl80211_policy,
10120 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010121 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010122 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010123 },
10124 {
10125 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10126 .doit = nl80211_cancel_remain_on_channel,
10127 .policy = nl80211_policy,
10128 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010129 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010130 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010131 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010132 {
10133 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10134 .doit = nl80211_set_tx_bitrate_mask,
10135 .policy = nl80211_policy,
10136 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010137 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10138 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010139 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010140 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010141 .cmd = NL80211_CMD_REGISTER_FRAME,
10142 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010143 .policy = nl80211_policy,
10144 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010145 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010146 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010147 },
10148 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010149 .cmd = NL80211_CMD_FRAME,
10150 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010151 .policy = nl80211_policy,
10152 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010153 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010154 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010155 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010156 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010157 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10158 .doit = nl80211_tx_mgmt_cancel_wait,
10159 .policy = nl80211_policy,
10160 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010161 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010162 NL80211_FLAG_NEED_RTNL,
10163 },
10164 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010165 .cmd = NL80211_CMD_SET_POWER_SAVE,
10166 .doit = nl80211_set_power_save,
10167 .policy = nl80211_policy,
10168 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010169 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10170 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010171 },
10172 {
10173 .cmd = NL80211_CMD_GET_POWER_SAVE,
10174 .doit = nl80211_get_power_save,
10175 .policy = nl80211_policy,
10176 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010177 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10178 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010179 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010180 {
10181 .cmd = NL80211_CMD_SET_CQM,
10182 .doit = nl80211_set_cqm,
10183 .policy = nl80211_policy,
10184 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010185 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10186 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010187 },
Johannes Bergf444de02010-05-05 15:25:02 +020010188 {
10189 .cmd = NL80211_CMD_SET_CHANNEL,
10190 .doit = nl80211_set_channel,
10191 .policy = nl80211_policy,
10192 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010193 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10194 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010195 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010196 {
10197 .cmd = NL80211_CMD_SET_WDS_PEER,
10198 .doit = nl80211_set_wds_peer,
10199 .policy = nl80211_policy,
10200 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010201 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10202 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010203 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010204 {
10205 .cmd = NL80211_CMD_JOIN_MESH,
10206 .doit = nl80211_join_mesh,
10207 .policy = nl80211_policy,
10208 .flags = GENL_ADMIN_PERM,
10209 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10210 NL80211_FLAG_NEED_RTNL,
10211 },
10212 {
10213 .cmd = NL80211_CMD_LEAVE_MESH,
10214 .doit = nl80211_leave_mesh,
10215 .policy = nl80211_policy,
10216 .flags = GENL_ADMIN_PERM,
10217 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10218 NL80211_FLAG_NEED_RTNL,
10219 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010220#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010221 {
10222 .cmd = NL80211_CMD_GET_WOWLAN,
10223 .doit = nl80211_get_wowlan,
10224 .policy = nl80211_policy,
10225 /* can be retrieved by unprivileged users */
10226 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10227 NL80211_FLAG_NEED_RTNL,
10228 },
10229 {
10230 .cmd = NL80211_CMD_SET_WOWLAN,
10231 .doit = nl80211_set_wowlan,
10232 .policy = nl80211_policy,
10233 .flags = GENL_ADMIN_PERM,
10234 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10235 NL80211_FLAG_NEED_RTNL,
10236 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010237#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010238 {
10239 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10240 .doit = nl80211_set_rekey_data,
10241 .policy = nl80211_policy,
10242 .flags = GENL_ADMIN_PERM,
10243 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010244 NL80211_FLAG_NEED_RTNL |
10245 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010246 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010247 {
10248 .cmd = NL80211_CMD_TDLS_MGMT,
10249 .doit = nl80211_tdls_mgmt,
10250 .policy = nl80211_policy,
10251 .flags = GENL_ADMIN_PERM,
10252 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10253 NL80211_FLAG_NEED_RTNL,
10254 },
10255 {
10256 .cmd = NL80211_CMD_TDLS_OPER,
10257 .doit = nl80211_tdls_oper,
10258 .policy = nl80211_policy,
10259 .flags = GENL_ADMIN_PERM,
10260 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10261 NL80211_FLAG_NEED_RTNL,
10262 },
Johannes Berg28946da2011-11-04 11:18:12 +010010263 {
10264 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10265 .doit = nl80211_register_unexpected_frame,
10266 .policy = nl80211_policy,
10267 .flags = GENL_ADMIN_PERM,
10268 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10269 NL80211_FLAG_NEED_RTNL,
10270 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010271 {
10272 .cmd = NL80211_CMD_PROBE_CLIENT,
10273 .doit = nl80211_probe_client,
10274 .policy = nl80211_policy,
10275 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010276 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010277 NL80211_FLAG_NEED_RTNL,
10278 },
Johannes Berg5e760232011-11-04 11:18:17 +010010279 {
10280 .cmd = NL80211_CMD_REGISTER_BEACONS,
10281 .doit = nl80211_register_beacons,
10282 .policy = nl80211_policy,
10283 .flags = GENL_ADMIN_PERM,
10284 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10285 NL80211_FLAG_NEED_RTNL,
10286 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010287 {
10288 .cmd = NL80211_CMD_SET_NOACK_MAP,
10289 .doit = nl80211_set_noack_map,
10290 .policy = nl80211_policy,
10291 .flags = GENL_ADMIN_PERM,
10292 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10293 NL80211_FLAG_NEED_RTNL,
10294 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010295 {
10296 .cmd = NL80211_CMD_START_P2P_DEVICE,
10297 .doit = nl80211_start_p2p_device,
10298 .policy = nl80211_policy,
10299 .flags = GENL_ADMIN_PERM,
10300 .internal_flags = NL80211_FLAG_NEED_WDEV |
10301 NL80211_FLAG_NEED_RTNL,
10302 },
10303 {
10304 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10305 .doit = nl80211_stop_p2p_device,
10306 .policy = nl80211_policy,
10307 .flags = GENL_ADMIN_PERM,
10308 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10309 NL80211_FLAG_NEED_RTNL,
10310 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010311 {
10312 .cmd = NL80211_CMD_SET_MCAST_RATE,
10313 .doit = nl80211_set_mcast_rate,
10314 .policy = nl80211_policy,
10315 .flags = GENL_ADMIN_PERM,
10316 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10317 NL80211_FLAG_NEED_RTNL,
10318 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010319 {
10320 .cmd = NL80211_CMD_SET_MAC_ACL,
10321 .doit = nl80211_set_mac_acl,
10322 .policy = nl80211_policy,
10323 .flags = GENL_ADMIN_PERM,
10324 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10325 NL80211_FLAG_NEED_RTNL,
10326 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010327 {
10328 .cmd = NL80211_CMD_RADAR_DETECT,
10329 .doit = nl80211_start_radar_detection,
10330 .policy = nl80211_policy,
10331 .flags = GENL_ADMIN_PERM,
10332 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10333 NL80211_FLAG_NEED_RTNL,
10334 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010335 {
10336 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10337 .doit = nl80211_get_protocol_features,
10338 .policy = nl80211_policy,
10339 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010340 {
10341 .cmd = NL80211_CMD_UPDATE_FT_IES,
10342 .doit = nl80211_update_ft_ies,
10343 .policy = nl80211_policy,
10344 .flags = GENL_ADMIN_PERM,
10345 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10346 NL80211_FLAG_NEED_RTNL,
10347 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010348 {
10349 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10350 .doit = nl80211_crit_protocol_start,
10351 .policy = nl80211_policy,
10352 .flags = GENL_ADMIN_PERM,
10353 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10354 NL80211_FLAG_NEED_RTNL,
10355 },
10356 {
10357 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10358 .doit = nl80211_crit_protocol_stop,
10359 .policy = nl80211_policy,
10360 .flags = GENL_ADMIN_PERM,
10361 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10362 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010363 },
10364 {
10365 .cmd = NL80211_CMD_GET_COALESCE,
10366 .doit = nl80211_get_coalesce,
10367 .policy = nl80211_policy,
10368 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10369 NL80211_FLAG_NEED_RTNL,
10370 },
10371 {
10372 .cmd = NL80211_CMD_SET_COALESCE,
10373 .doit = nl80211_set_coalesce,
10374 .policy = nl80211_policy,
10375 .flags = GENL_ADMIN_PERM,
10376 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10377 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010378 },
10379 {
10380 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10381 .doit = nl80211_channel_switch,
10382 .policy = nl80211_policy,
10383 .flags = GENL_ADMIN_PERM,
10384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10385 NL80211_FLAG_NEED_RTNL,
10386 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010387 {
10388 .cmd = NL80211_CMD_VENDOR,
10389 .doit = nl80211_vendor_cmd,
10390 .policy = nl80211_policy,
10391 .flags = GENL_ADMIN_PERM,
10392 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10393 NL80211_FLAG_NEED_RTNL,
10394 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010395 {
10396 .cmd = NL80211_CMD_SET_QOS_MAP,
10397 .doit = nl80211_set_qos_map,
10398 .policy = nl80211_policy,
10399 .flags = GENL_ADMIN_PERM,
10400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10401 NL80211_FLAG_NEED_RTNL,
10402 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010403 {
10404 .cmd = NL80211_CMD_ADD_TX_TS,
10405 .doit = nl80211_add_tx_ts,
10406 .policy = nl80211_policy,
10407 .flags = GENL_ADMIN_PERM,
10408 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10409 NL80211_FLAG_NEED_RTNL,
10410 },
10411 {
10412 .cmd = NL80211_CMD_DEL_TX_TS,
10413 .doit = nl80211_del_tx_ts,
10414 .policy = nl80211_policy,
10415 .flags = GENL_ADMIN_PERM,
10416 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10417 NL80211_FLAG_NEED_RTNL,
10418 },
Johannes Berg55682962007-09-20 13:09:35 -040010419};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010420
Johannes Berg55682962007-09-20 13:09:35 -040010421/* notification functions */
10422
Johannes Berg3bb20552014-05-26 13:52:25 +020010423void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10424 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010425{
10426 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010427 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010428
Johannes Berg3bb20552014-05-26 13:52:25 +020010429 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10430 cmd != NL80211_CMD_DEL_WIPHY);
10431
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010433 if (!msg)
10434 return;
10435
Johannes Berg3bb20552014-05-26 13:52:25 +020010436 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010437 nlmsg_free(msg);
10438 return;
10439 }
10440
Johannes Berg68eb5502013-11-19 15:19:38 +010010441 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010442 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010443}
10444
Johannes Berg362a4152009-05-24 16:43:15 +020010445static int nl80211_add_scan_req(struct sk_buff *msg,
10446 struct cfg80211_registered_device *rdev)
10447{
10448 struct cfg80211_scan_request *req = rdev->scan_req;
10449 struct nlattr *nest;
10450 int i;
10451
10452 if (WARN_ON(!req))
10453 return 0;
10454
10455 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10456 if (!nest)
10457 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010458 for (i = 0; i < req->n_ssids; i++) {
10459 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10460 goto nla_put_failure;
10461 }
Johannes Berg362a4152009-05-24 16:43:15 +020010462 nla_nest_end(msg, nest);
10463
10464 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10465 if (!nest)
10466 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010467 for (i = 0; i < req->n_channels; i++) {
10468 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10469 goto nla_put_failure;
10470 }
Johannes Berg362a4152009-05-24 16:43:15 +020010471 nla_nest_end(msg, nest);
10472
David S. Miller9360ffd2012-03-29 04:41:26 -040010473 if (req->ie &&
10474 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10475 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010476
Johannes Bergae917c92013-10-25 11:05:22 +020010477 if (req->flags &&
10478 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10479 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010480
Johannes Berg362a4152009-05-24 16:43:15 +020010481 return 0;
10482 nla_put_failure:
10483 return -ENOBUFS;
10484}
10485
Johannes Berga538e2d2009-06-16 19:56:42 +020010486static int nl80211_send_scan_msg(struct sk_buff *msg,
10487 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010488 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010489 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010490 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010491{
10492 void *hdr;
10493
Eric W. Biederman15e47302012-09-07 20:12:54 +000010494 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010495 if (!hdr)
10496 return -1;
10497
David S. Miller9360ffd2012-03-29 04:41:26 -040010498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010499 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10500 wdev->netdev->ifindex)) ||
10501 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010502 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010503
Johannes Berg362a4152009-05-24 16:43:15 +020010504 /* ignore errors and send incomplete event anyway */
10505 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010506
10507 return genlmsg_end(msg, hdr);
10508
10509 nla_put_failure:
10510 genlmsg_cancel(msg, hdr);
10511 return -EMSGSIZE;
10512}
10513
Luciano Coelho807f8a82011-05-11 17:09:35 +030010514static int
10515nl80211_send_sched_scan_msg(struct sk_buff *msg,
10516 struct cfg80211_registered_device *rdev,
10517 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010518 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010519{
10520 void *hdr;
10521
Eric W. Biederman15e47302012-09-07 20:12:54 +000010522 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010523 if (!hdr)
10524 return -1;
10525
David S. Miller9360ffd2012-03-29 04:41:26 -040010526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10527 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10528 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010529
10530 return genlmsg_end(msg, hdr);
10531
10532 nla_put_failure:
10533 genlmsg_cancel(msg, hdr);
10534 return -EMSGSIZE;
10535}
10536
Johannes Berga538e2d2009-06-16 19:56:42 +020010537void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010538 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010539{
10540 struct sk_buff *msg;
10541
Thomas Graf58050fc2012-06-28 03:57:45 +000010542 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010543 if (!msg)
10544 return;
10545
Johannes Bergfd014282012-06-18 19:17:03 +020010546 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010547 NL80211_CMD_TRIGGER_SCAN) < 0) {
10548 nlmsg_free(msg);
10549 return;
10550 }
10551
Johannes Berg68eb5502013-11-19 15:19:38 +010010552 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010553 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010554}
10555
Johannes Bergf9d15d12014-01-22 11:14:19 +020010556struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10557 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010558{
10559 struct sk_buff *msg;
10560
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010561 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010562 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010563 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010564
Johannes Bergfd014282012-06-18 19:17:03 +020010565 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010566 aborted ? NL80211_CMD_SCAN_ABORTED :
10567 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010568 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010569 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010570 }
10571
Johannes Bergf9d15d12014-01-22 11:14:19 +020010572 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010573}
10574
Johannes Bergf9d15d12014-01-22 11:14:19 +020010575void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10576 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010577{
Johannes Berg2a519312009-02-10 21:25:55 +010010578 if (!msg)
10579 return;
10580
Johannes Berg68eb5502013-11-19 15:19:38 +010010581 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010582 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010583}
10584
Luciano Coelho807f8a82011-05-11 17:09:35 +030010585void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10586 struct net_device *netdev)
10587{
10588 struct sk_buff *msg;
10589
10590 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10591 if (!msg)
10592 return;
10593
10594 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10595 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10596 nlmsg_free(msg);
10597 return;
10598 }
10599
Johannes Berg68eb5502013-11-19 15:19:38 +010010600 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010601 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010602}
10603
10604void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10605 struct net_device *netdev, u32 cmd)
10606{
10607 struct sk_buff *msg;
10608
Thomas Graf58050fc2012-06-28 03:57:45 +000010609 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010610 if (!msg)
10611 return;
10612
10613 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10614 nlmsg_free(msg);
10615 return;
10616 }
10617
Johannes Berg68eb5502013-11-19 15:19:38 +010010618 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010619 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010620}
10621
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010622/*
10623 * This can happen on global regulatory changes or device specific settings
10624 * based on custom world regulatory domains.
10625 */
10626void nl80211_send_reg_change_event(struct regulatory_request *request)
10627{
10628 struct sk_buff *msg;
10629 void *hdr;
10630
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010631 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010632 if (!msg)
10633 return;
10634
10635 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10636 if (!hdr) {
10637 nlmsg_free(msg);
10638 return;
10639 }
10640
10641 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010642 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10643 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010644
David S. Miller9360ffd2012-03-29 04:41:26 -040010645 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10646 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10647 NL80211_REGDOM_TYPE_WORLD))
10648 goto nla_put_failure;
10649 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10650 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10651 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10652 goto nla_put_failure;
10653 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10654 request->intersect) {
10655 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10656 NL80211_REGDOM_TYPE_INTERSECTION))
10657 goto nla_put_failure;
10658 } else {
10659 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10660 NL80211_REGDOM_TYPE_COUNTRY) ||
10661 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10662 request->alpha2))
10663 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010664 }
10665
Johannes Bergf4173762012-12-03 18:23:37 +010010666 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010667 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10668 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010669
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010670 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010671
Johannes Bergbc43b282009-07-25 10:54:13 +020010672 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010673 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010674 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010675 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010676
10677 return;
10678
10679nla_put_failure:
10680 genlmsg_cancel(msg, hdr);
10681 nlmsg_free(msg);
10682}
10683
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010684static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10685 struct net_device *netdev,
10686 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010687 enum nl80211_commands cmd, gfp_t gfp,
10688 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010689{
10690 struct sk_buff *msg;
10691 void *hdr;
10692
Johannes Berge6d6e342009-07-01 21:26:47 +020010693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010694 if (!msg)
10695 return;
10696
10697 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10698 if (!hdr) {
10699 nlmsg_free(msg);
10700 return;
10701 }
10702
David S. Miller9360ffd2012-03-29 04:41:26 -040010703 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10704 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10705 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10706 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010707
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010708 if (uapsd_queues >= 0) {
10709 struct nlattr *nla_wmm =
10710 nla_nest_start(msg, NL80211_ATTR_STA_WME);
10711 if (!nla_wmm)
10712 goto nla_put_failure;
10713
10714 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
10715 uapsd_queues))
10716 goto nla_put_failure;
10717
10718 nla_nest_end(msg, nla_wmm);
10719 }
10720
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010721 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010722
Johannes Berg68eb5502013-11-19 15:19:38 +010010723 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010724 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010725 return;
10726
10727 nla_put_failure:
10728 genlmsg_cancel(msg, hdr);
10729 nlmsg_free(msg);
10730}
10731
10732void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010733 struct net_device *netdev, const u8 *buf,
10734 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010735{
10736 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010737 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010738}
10739
10740void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10741 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010742 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010743{
Johannes Berge6d6e342009-07-01 21:26:47 +020010744 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010745 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010746}
10747
Jouni Malinen53b46b82009-03-27 20:53:56 +020010748void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010749 struct net_device *netdev, const u8 *buf,
10750 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010751{
10752 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010753 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010754}
10755
Jouni Malinen53b46b82009-03-27 20:53:56 +020010756void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10757 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010758 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010759{
10760 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010761 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010762}
10763
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010764void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10765 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010766{
Johannes Berg947add32013-02-22 22:05:20 +010010767 struct wireless_dev *wdev = dev->ieee80211_ptr;
10768 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010769 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010770 const struct ieee80211_mgmt *mgmt = (void *)buf;
10771 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010772
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010773 if (WARN_ON(len < 2))
10774 return;
10775
10776 if (ieee80211_is_deauth(mgmt->frame_control))
10777 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10778 else
10779 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10780
10781 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010782 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010783}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010784EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010785
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010786static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10787 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010788 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010789{
10790 struct sk_buff *msg;
10791 void *hdr;
10792
Johannes Berge6d6e342009-07-01 21:26:47 +020010793 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010794 if (!msg)
10795 return;
10796
10797 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10798 if (!hdr) {
10799 nlmsg_free(msg);
10800 return;
10801 }
10802
David S. Miller9360ffd2012-03-29 04:41:26 -040010803 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10804 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10805 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10806 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10807 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010808
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010809 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010810
Johannes Berg68eb5502013-11-19 15:19:38 +010010811 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010812 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010813 return;
10814
10815 nla_put_failure:
10816 genlmsg_cancel(msg, hdr);
10817 nlmsg_free(msg);
10818}
10819
10820void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010821 struct net_device *netdev, const u8 *addr,
10822 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010823{
10824 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010825 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010826}
10827
10828void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010829 struct net_device *netdev, const u8 *addr,
10830 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010831{
Johannes Berge6d6e342009-07-01 21:26:47 +020010832 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10833 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010834}
10835
Samuel Ortizb23aa672009-07-01 21:26:54 +020010836void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10837 struct net_device *netdev, const u8 *bssid,
10838 const u8 *req_ie, size_t req_ie_len,
10839 const u8 *resp_ie, size_t resp_ie_len,
10840 u16 status, gfp_t gfp)
10841{
10842 struct sk_buff *msg;
10843 void *hdr;
10844
Thomas Graf58050fc2012-06-28 03:57:45 +000010845 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010846 if (!msg)
10847 return;
10848
10849 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10850 if (!hdr) {
10851 nlmsg_free(msg);
10852 return;
10853 }
10854
David S. Miller9360ffd2012-03-29 04:41:26 -040010855 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10857 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10858 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10859 (req_ie &&
10860 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10861 (resp_ie &&
10862 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10863 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010864
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010865 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010866
Johannes Berg68eb5502013-11-19 15:19:38 +010010867 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010868 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010869 return;
10870
10871 nla_put_failure:
10872 genlmsg_cancel(msg, hdr);
10873 nlmsg_free(msg);
10874
10875}
10876
10877void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10878 struct net_device *netdev, const u8 *bssid,
10879 const u8 *req_ie, size_t req_ie_len,
10880 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10881{
10882 struct sk_buff *msg;
10883 void *hdr;
10884
Thomas Graf58050fc2012-06-28 03:57:45 +000010885 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010886 if (!msg)
10887 return;
10888
10889 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10890 if (!hdr) {
10891 nlmsg_free(msg);
10892 return;
10893 }
10894
David S. Miller9360ffd2012-03-29 04:41:26 -040010895 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10896 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10897 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10898 (req_ie &&
10899 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10900 (resp_ie &&
10901 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10902 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010903
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010904 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010905
Johannes Berg68eb5502013-11-19 15:19:38 +010010906 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010907 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010908 return;
10909
10910 nla_put_failure:
10911 genlmsg_cancel(msg, hdr);
10912 nlmsg_free(msg);
10913
10914}
10915
10916void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10917 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010918 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010919{
10920 struct sk_buff *msg;
10921 void *hdr;
10922
Thomas Graf58050fc2012-06-28 03:57:45 +000010923 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010924 if (!msg)
10925 return;
10926
10927 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10928 if (!hdr) {
10929 nlmsg_free(msg);
10930 return;
10931 }
10932
David S. Miller9360ffd2012-03-29 04:41:26 -040010933 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10934 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10935 (from_ap && reason &&
10936 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10937 (from_ap &&
10938 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10939 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10940 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010941
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010942 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010943
Johannes Berg68eb5502013-11-19 15:19:38 +010010944 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010945 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010946 return;
10947
10948 nla_put_failure:
10949 genlmsg_cancel(msg, hdr);
10950 nlmsg_free(msg);
10951
10952}
10953
Johannes Berg04a773a2009-04-19 21:24:32 +020010954void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10955 struct net_device *netdev, const u8 *bssid,
10956 gfp_t gfp)
10957{
10958 struct sk_buff *msg;
10959 void *hdr;
10960
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010961 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010962 if (!msg)
10963 return;
10964
10965 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10966 if (!hdr) {
10967 nlmsg_free(msg);
10968 return;
10969 }
10970
David S. Miller9360ffd2012-03-29 04:41:26 -040010971 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10972 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10973 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10974 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010975
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010976 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010977
Johannes Berg68eb5502013-11-19 15:19:38 +010010978 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010979 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010980 return;
10981
10982 nla_put_failure:
10983 genlmsg_cancel(msg, hdr);
10984 nlmsg_free(msg);
10985}
10986
Johannes Berg947add32013-02-22 22:05:20 +010010987void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10988 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010989{
Johannes Berg947add32013-02-22 22:05:20 +010010990 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010991 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010992 struct sk_buff *msg;
10993 void *hdr;
10994
Johannes Berg947add32013-02-22 22:05:20 +010010995 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10996 return;
10997
10998 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10999
Javier Cardonac93b5e72011-04-07 15:08:34 -070011000 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11001 if (!msg)
11002 return;
11003
11004 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11005 if (!hdr) {
11006 nlmsg_free(msg);
11007 return;
11008 }
11009
David S. Miller9360ffd2012-03-29 04:41:26 -040011010 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011011 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11012 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011013 (ie_len && ie &&
11014 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11015 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011016
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011017 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011018
Johannes Berg68eb5502013-11-19 15:19:38 +010011019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011020 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011021 return;
11022
11023 nla_put_failure:
11024 genlmsg_cancel(msg, hdr);
11025 nlmsg_free(msg);
11026}
Johannes Berg947add32013-02-22 22:05:20 +010011027EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011028
Jouni Malinena3b8b052009-03-27 21:59:49 +020011029void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11030 struct net_device *netdev, const u8 *addr,
11031 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011032 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011033{
11034 struct sk_buff *msg;
11035 void *hdr;
11036
Johannes Berge6d6e342009-07-01 21:26:47 +020011037 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011038 if (!msg)
11039 return;
11040
11041 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11042 if (!hdr) {
11043 nlmsg_free(msg);
11044 return;
11045 }
11046
David S. Miller9360ffd2012-03-29 04:41:26 -040011047 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11048 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11049 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11050 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11051 (key_id != -1 &&
11052 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11053 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11054 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011055
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011056 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011057
Johannes Berg68eb5502013-11-19 15:19:38 +010011058 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011059 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011060 return;
11061
11062 nla_put_failure:
11063 genlmsg_cancel(msg, hdr);
11064 nlmsg_free(msg);
11065}
11066
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011067void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11068 struct ieee80211_channel *channel_before,
11069 struct ieee80211_channel *channel_after)
11070{
11071 struct sk_buff *msg;
11072 void *hdr;
11073 struct nlattr *nl_freq;
11074
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011076 if (!msg)
11077 return;
11078
11079 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11080 if (!hdr) {
11081 nlmsg_free(msg);
11082 return;
11083 }
11084
11085 /*
11086 * Since we are applying the beacon hint to a wiphy we know its
11087 * wiphy_idx is valid
11088 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011089 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11090 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011091
11092 /* Before */
11093 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11094 if (!nl_freq)
11095 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011096 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011097 goto nla_put_failure;
11098 nla_nest_end(msg, nl_freq);
11099
11100 /* After */
11101 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11102 if (!nl_freq)
11103 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011104 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011105 goto nla_put_failure;
11106 nla_nest_end(msg, nl_freq);
11107
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011108 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011109
Johannes Berg463d0182009-07-14 00:33:35 +020011110 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011111 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011112 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011113 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011114
11115 return;
11116
11117nla_put_failure:
11118 genlmsg_cancel(msg, hdr);
11119 nlmsg_free(msg);
11120}
11121
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011122static void nl80211_send_remain_on_chan_event(
11123 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011124 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011125 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011126 unsigned int duration, gfp_t gfp)
11127{
11128 struct sk_buff *msg;
11129 void *hdr;
11130
11131 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11132 if (!msg)
11133 return;
11134
11135 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11136 if (!hdr) {
11137 nlmsg_free(msg);
11138 return;
11139 }
11140
David S. Miller9360ffd2012-03-29 04:41:26 -040011141 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011142 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11143 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011144 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011145 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011146 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11147 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011148 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11149 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011150
David S. Miller9360ffd2012-03-29 04:41:26 -040011151 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11152 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11153 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011154
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011155 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011156
Johannes Berg68eb5502013-11-19 15:19:38 +010011157 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011158 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011159 return;
11160
11161 nla_put_failure:
11162 genlmsg_cancel(msg, hdr);
11163 nlmsg_free(msg);
11164}
11165
Johannes Berg947add32013-02-22 22:05:20 +010011166void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11167 struct ieee80211_channel *chan,
11168 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011169{
Johannes Berg947add32013-02-22 22:05:20 +010011170 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011171 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011172
11173 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011174 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011175 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011176 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011177}
Johannes Berg947add32013-02-22 22:05:20 +010011178EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011179
Johannes Berg947add32013-02-22 22:05:20 +010011180void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11181 struct ieee80211_channel *chan,
11182 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011183{
Johannes Berg947add32013-02-22 22:05:20 +010011184 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011185 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011186
11187 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011188 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011189 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011190}
Johannes Berg947add32013-02-22 22:05:20 +010011191EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011192
Johannes Berg947add32013-02-22 22:05:20 +010011193void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11194 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011195{
Johannes Berg947add32013-02-22 22:05:20 +010011196 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011197 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011198 struct sk_buff *msg;
11199
Johannes Berg947add32013-02-22 22:05:20 +010011200 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11201
Thomas Graf58050fc2012-06-28 03:57:45 +000011202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011203 if (!msg)
11204 return;
11205
John W. Linville66266b32012-03-15 13:25:41 -040011206 if (nl80211_send_station(msg, 0, 0, 0,
11207 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011208 nlmsg_free(msg);
11209 return;
11210 }
11211
Johannes Berg68eb5502013-11-19 15:19:38 +010011212 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011213 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011214}
Johannes Berg947add32013-02-22 22:05:20 +010011215EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011216
Johannes Berg947add32013-02-22 22:05:20 +010011217void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011218{
Johannes Berg947add32013-02-22 22:05:20 +010011219 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011220 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011221 struct sk_buff *msg;
11222 void *hdr;
11223
Johannes Berg947add32013-02-22 22:05:20 +010011224 trace_cfg80211_del_sta(dev, mac_addr);
11225
Thomas Graf58050fc2012-06-28 03:57:45 +000011226 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011227 if (!msg)
11228 return;
11229
11230 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11231 if (!hdr) {
11232 nlmsg_free(msg);
11233 return;
11234 }
11235
David S. Miller9360ffd2012-03-29 04:41:26 -040011236 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11237 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11238 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011239
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011240 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011241
Johannes Berg68eb5502013-11-19 15:19:38 +010011242 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011243 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011244 return;
11245
11246 nla_put_failure:
11247 genlmsg_cancel(msg, hdr);
11248 nlmsg_free(msg);
11249}
Johannes Berg947add32013-02-22 22:05:20 +010011250EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011251
Johannes Berg947add32013-02-22 22:05:20 +010011252void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11253 enum nl80211_connect_failed_reason reason,
11254 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011255{
Johannes Berg947add32013-02-22 22:05:20 +010011256 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011257 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011258 struct sk_buff *msg;
11259 void *hdr;
11260
11261 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11262 if (!msg)
11263 return;
11264
11265 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11266 if (!hdr) {
11267 nlmsg_free(msg);
11268 return;
11269 }
11270
11271 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11272 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11273 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11274 goto nla_put_failure;
11275
11276 genlmsg_end(msg, hdr);
11277
Johannes Berg68eb5502013-11-19 15:19:38 +010011278 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011279 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011280 return;
11281
11282 nla_put_failure:
11283 genlmsg_cancel(msg, hdr);
11284 nlmsg_free(msg);
11285}
Johannes Berg947add32013-02-22 22:05:20 +010011286EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011287
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011288static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11289 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011290{
11291 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011292 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011293 struct sk_buff *msg;
11294 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011295 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011296
Eric W. Biederman15e47302012-09-07 20:12:54 +000011297 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011298 return false;
11299
11300 msg = nlmsg_new(100, gfp);
11301 if (!msg)
11302 return true;
11303
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011304 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011305 if (!hdr) {
11306 nlmsg_free(msg);
11307 return true;
11308 }
11309
David S. Miller9360ffd2012-03-29 04:41:26 -040011310 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11311 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11312 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11313 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011314
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011315 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011316 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011317 return true;
11318
11319 nla_put_failure:
11320 genlmsg_cancel(msg, hdr);
11321 nlmsg_free(msg);
11322 return true;
11323}
11324
Johannes Berg947add32013-02-22 22:05:20 +010011325bool cfg80211_rx_spurious_frame(struct net_device *dev,
11326 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011327{
Johannes Berg947add32013-02-22 22:05:20 +010011328 struct wireless_dev *wdev = dev->ieee80211_ptr;
11329 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011330
Johannes Berg947add32013-02-22 22:05:20 +010011331 trace_cfg80211_rx_spurious_frame(dev, addr);
11332
11333 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11334 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11335 trace_cfg80211_return_bool(false);
11336 return false;
11337 }
11338 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11339 addr, gfp);
11340 trace_cfg80211_return_bool(ret);
11341 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011342}
Johannes Berg947add32013-02-22 22:05:20 +010011343EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11344
11345bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11346 const u8 *addr, gfp_t gfp)
11347{
11348 struct wireless_dev *wdev = dev->ieee80211_ptr;
11349 bool ret;
11350
11351 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11352
11353 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11354 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11355 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11356 trace_cfg80211_return_bool(false);
11357 return false;
11358 }
11359 ret = __nl80211_unexpected_frame(dev,
11360 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11361 addr, gfp);
11362 trace_cfg80211_return_bool(ret);
11363 return ret;
11364}
11365EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011366
Johannes Berg2e161f782010-08-12 15:38:38 +020011367int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011368 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011369 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011370 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011371{
Johannes Berg71bbc992012-06-15 15:30:18 +020011372 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011373 struct sk_buff *msg;
11374 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011375
11376 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11377 if (!msg)
11378 return -ENOMEM;
11379
Johannes Berg2e161f782010-08-12 15:38:38 +020011380 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011381 if (!hdr) {
11382 nlmsg_free(msg);
11383 return -ENOMEM;
11384 }
11385
David S. Miller9360ffd2012-03-29 04:41:26 -040011386 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011387 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11388 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011389 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011390 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11391 (sig_dbm &&
11392 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011393 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11394 (flags &&
11395 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011396 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011397
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011398 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011399
Eric W. Biederman15e47302012-09-07 20:12:54 +000011400 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011401
11402 nla_put_failure:
11403 genlmsg_cancel(msg, hdr);
11404 nlmsg_free(msg);
11405 return -ENOBUFS;
11406}
11407
Johannes Berg947add32013-02-22 22:05:20 +010011408void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11409 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011410{
Johannes Berg947add32013-02-22 22:05:20 +010011411 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011412 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011413 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011414 struct sk_buff *msg;
11415 void *hdr;
11416
Johannes Berg947add32013-02-22 22:05:20 +010011417 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11418
Jouni Malinen026331c2010-02-15 12:53:10 +020011419 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11420 if (!msg)
11421 return;
11422
Johannes Berg2e161f782010-08-12 15:38:38 +020011423 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011424 if (!hdr) {
11425 nlmsg_free(msg);
11426 return;
11427 }
11428
David S. Miller9360ffd2012-03-29 04:41:26 -040011429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011430 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11431 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011432 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011433 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11434 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11435 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11436 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011437
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011438 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011439
Johannes Berg68eb5502013-11-19 15:19:38 +010011440 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011441 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011442 return;
11443
11444 nla_put_failure:
11445 genlmsg_cancel(msg, hdr);
11446 nlmsg_free(msg);
11447}
Johannes Berg947add32013-02-22 22:05:20 +010011448EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011449
Johannes Berg947add32013-02-22 22:05:20 +010011450void cfg80211_cqm_rssi_notify(struct net_device *dev,
11451 enum nl80211_cqm_rssi_threshold_event rssi_event,
11452 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011453{
Johannes Berg947add32013-02-22 22:05:20 +010011454 struct wireless_dev *wdev = dev->ieee80211_ptr;
11455 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011456 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011457 struct sk_buff *msg;
11458 struct nlattr *pinfoattr;
11459 void *hdr;
11460
Johannes Berg947add32013-02-22 22:05:20 +010011461 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11462
Thomas Graf58050fc2012-06-28 03:57:45 +000011463 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011464 if (!msg)
11465 return;
11466
11467 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11468 if (!hdr) {
11469 nlmsg_free(msg);
11470 return;
11471 }
11472
David S. Miller9360ffd2012-03-29 04:41:26 -040011473 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011474 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011475 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011476
11477 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11478 if (!pinfoattr)
11479 goto nla_put_failure;
11480
David S. Miller9360ffd2012-03-29 04:41:26 -040011481 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11482 rssi_event))
11483 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011484
11485 nla_nest_end(msg, pinfoattr);
11486
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011487 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011488
Johannes Berg68eb5502013-11-19 15:19:38 +010011489 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011490 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011491 return;
11492
11493 nla_put_failure:
11494 genlmsg_cancel(msg, hdr);
11495 nlmsg_free(msg);
11496}
Johannes Berg947add32013-02-22 22:05:20 +010011497EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011498
Johannes Berg947add32013-02-22 22:05:20 +010011499static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11500 struct net_device *netdev, const u8 *bssid,
11501 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011502{
11503 struct sk_buff *msg;
11504 struct nlattr *rekey_attr;
11505 void *hdr;
11506
Thomas Graf58050fc2012-06-28 03:57:45 +000011507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011508 if (!msg)
11509 return;
11510
11511 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11512 if (!hdr) {
11513 nlmsg_free(msg);
11514 return;
11515 }
11516
David S. Miller9360ffd2012-03-29 04:41:26 -040011517 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11518 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11519 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11520 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011521
11522 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11523 if (!rekey_attr)
11524 goto nla_put_failure;
11525
David S. Miller9360ffd2012-03-29 04:41:26 -040011526 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11527 NL80211_REPLAY_CTR_LEN, replay_ctr))
11528 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011529
11530 nla_nest_end(msg, rekey_attr);
11531
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011532 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011533
Johannes Berg68eb5502013-11-19 15:19:38 +010011534 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011535 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011536 return;
11537
11538 nla_put_failure:
11539 genlmsg_cancel(msg, hdr);
11540 nlmsg_free(msg);
11541}
11542
Johannes Berg947add32013-02-22 22:05:20 +010011543void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11544 const u8 *replay_ctr, gfp_t gfp)
11545{
11546 struct wireless_dev *wdev = dev->ieee80211_ptr;
11547 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011548 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011549
11550 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11551 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11552}
11553EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11554
11555static void
11556nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11557 struct net_device *netdev, int index,
11558 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011559{
11560 struct sk_buff *msg;
11561 struct nlattr *attr;
11562 void *hdr;
11563
Thomas Graf58050fc2012-06-28 03:57:45 +000011564 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011565 if (!msg)
11566 return;
11567
11568 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11569 if (!hdr) {
11570 nlmsg_free(msg);
11571 return;
11572 }
11573
David S. Miller9360ffd2012-03-29 04:41:26 -040011574 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11575 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11576 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011577
11578 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11579 if (!attr)
11580 goto nla_put_failure;
11581
David S. Miller9360ffd2012-03-29 04:41:26 -040011582 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11583 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11584 (preauth &&
11585 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11586 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011587
11588 nla_nest_end(msg, attr);
11589
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011590 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011591
Johannes Berg68eb5502013-11-19 15:19:38 +010011592 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011593 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011594 return;
11595
11596 nla_put_failure:
11597 genlmsg_cancel(msg, hdr);
11598 nlmsg_free(msg);
11599}
11600
Johannes Berg947add32013-02-22 22:05:20 +010011601void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11602 const u8 *bssid, bool preauth, gfp_t gfp)
11603{
11604 struct wireless_dev *wdev = dev->ieee80211_ptr;
11605 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011606 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011607
11608 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11609 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11610}
11611EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11612
11613static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11614 struct net_device *netdev,
11615 struct cfg80211_chan_def *chandef,
11616 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011617{
11618 struct sk_buff *msg;
11619 void *hdr;
11620
Thomas Graf58050fc2012-06-28 03:57:45 +000011621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011622 if (!msg)
11623 return;
11624
11625 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11626 if (!hdr) {
11627 nlmsg_free(msg);
11628 return;
11629 }
11630
Johannes Berg683b6d32012-11-08 21:25:48 +010011631 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11632 goto nla_put_failure;
11633
11634 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011635 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011636
11637 genlmsg_end(msg, hdr);
11638
Johannes Berg68eb5502013-11-19 15:19:38 +010011639 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011640 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011641 return;
11642
11643 nla_put_failure:
11644 genlmsg_cancel(msg, hdr);
11645 nlmsg_free(msg);
11646}
11647
Johannes Berg947add32013-02-22 22:05:20 +010011648void cfg80211_ch_switch_notify(struct net_device *dev,
11649 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011650{
Johannes Berg947add32013-02-22 22:05:20 +010011651 struct wireless_dev *wdev = dev->ieee80211_ptr;
11652 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011653 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011654
Simon Wunderliche487eae2013-11-21 18:19:51 +010011655 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011656
Simon Wunderliche487eae2013-11-21 18:19:51 +010011657 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011658
11659 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011660 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011661 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11662 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011663 return;
Johannes Berg947add32013-02-22 22:05:20 +010011664
Michal Kazior9e0e2962014-01-29 14:22:27 +010011665 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011666 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011667 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011668}
11669EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11670
11671void cfg80211_cqm_txe_notify(struct net_device *dev,
11672 const u8 *peer, u32 num_packets,
11673 u32 rate, u32 intvl, gfp_t gfp)
11674{
11675 struct wireless_dev *wdev = dev->ieee80211_ptr;
11676 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011677 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011678 struct sk_buff *msg;
11679 struct nlattr *pinfoattr;
11680 void *hdr;
11681
11682 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11683 if (!msg)
11684 return;
11685
11686 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11687 if (!hdr) {
11688 nlmsg_free(msg);
11689 return;
11690 }
11691
11692 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011693 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011694 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11695 goto nla_put_failure;
11696
11697 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11698 if (!pinfoattr)
11699 goto nla_put_failure;
11700
11701 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11702 goto nla_put_failure;
11703
11704 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11705 goto nla_put_failure;
11706
11707 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11708 goto nla_put_failure;
11709
11710 nla_nest_end(msg, pinfoattr);
11711
11712 genlmsg_end(msg, hdr);
11713
Johannes Berg68eb5502013-11-19 15:19:38 +010011714 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011715 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011716 return;
11717
11718 nla_put_failure:
11719 genlmsg_cancel(msg, hdr);
11720 nlmsg_free(msg);
11721}
Johannes Berg947add32013-02-22 22:05:20 +010011722EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011723
11724void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011725nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011726 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011727 enum nl80211_radar_event event,
11728 struct net_device *netdev, gfp_t gfp)
11729{
11730 struct sk_buff *msg;
11731 void *hdr;
11732
11733 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11734 if (!msg)
11735 return;
11736
11737 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11738 if (!hdr) {
11739 nlmsg_free(msg);
11740 return;
11741 }
11742
11743 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11744 goto nla_put_failure;
11745
11746 /* NOP and radar events don't need a netdev parameter */
11747 if (netdev) {
11748 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11749
11750 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11751 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11752 goto nla_put_failure;
11753 }
11754
11755 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11756 goto nla_put_failure;
11757
11758 if (nl80211_send_chandef(msg, chandef))
11759 goto nla_put_failure;
11760
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011761 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011762
Johannes Berg68eb5502013-11-19 15:19:38 +010011763 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011764 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011765 return;
11766
11767 nla_put_failure:
11768 genlmsg_cancel(msg, hdr);
11769 nlmsg_free(msg);
11770}
11771
Johannes Berg947add32013-02-22 22:05:20 +010011772void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11773 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011774{
Johannes Berg947add32013-02-22 22:05:20 +010011775 struct wireless_dev *wdev = dev->ieee80211_ptr;
11776 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011777 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011778 struct sk_buff *msg;
11779 struct nlattr *pinfoattr;
11780 void *hdr;
11781
Johannes Berg947add32013-02-22 22:05:20 +010011782 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11783
Thomas Graf58050fc2012-06-28 03:57:45 +000011784 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011785 if (!msg)
11786 return;
11787
11788 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11789 if (!hdr) {
11790 nlmsg_free(msg);
11791 return;
11792 }
11793
David S. Miller9360ffd2012-03-29 04:41:26 -040011794 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011795 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011796 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11797 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011798
11799 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11800 if (!pinfoattr)
11801 goto nla_put_failure;
11802
David S. Miller9360ffd2012-03-29 04:41:26 -040011803 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11804 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011805
11806 nla_nest_end(msg, pinfoattr);
11807
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011808 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011809
Johannes Berg68eb5502013-11-19 15:19:38 +010011810 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011811 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011812 return;
11813
11814 nla_put_failure:
11815 genlmsg_cancel(msg, hdr);
11816 nlmsg_free(msg);
11817}
Johannes Berg947add32013-02-22 22:05:20 +010011818EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011819
Johannes Berg7f6cf312011-11-04 11:18:15 +010011820void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11821 u64 cookie, bool acked, gfp_t gfp)
11822{
11823 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011824 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011825 struct sk_buff *msg;
11826 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011827
Beni Lev4ee3e062012-08-27 12:49:39 +030011828 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11829
Thomas Graf58050fc2012-06-28 03:57:45 +000011830 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011831
Johannes Berg7f6cf312011-11-04 11:18:15 +010011832 if (!msg)
11833 return;
11834
11835 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11836 if (!hdr) {
11837 nlmsg_free(msg);
11838 return;
11839 }
11840
David S. Miller9360ffd2012-03-29 04:41:26 -040011841 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11842 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11843 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11844 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11845 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11846 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011847
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011848 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011849
Johannes Berg68eb5502013-11-19 15:19:38 +010011850 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011851 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011852 return;
11853
11854 nla_put_failure:
11855 genlmsg_cancel(msg, hdr);
11856 nlmsg_free(msg);
11857}
11858EXPORT_SYMBOL(cfg80211_probe_status);
11859
Johannes Berg5e760232011-11-04 11:18:17 +010011860void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11861 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011862 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011863{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011864 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011865 struct sk_buff *msg;
11866 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011867 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011868
Beni Lev4ee3e062012-08-27 12:49:39 +030011869 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11870
Ben Greear37c73b52012-10-26 14:49:25 -070011871 spin_lock_bh(&rdev->beacon_registrations_lock);
11872 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11873 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11874 if (!msg) {
11875 spin_unlock_bh(&rdev->beacon_registrations_lock);
11876 return;
11877 }
Johannes Berg5e760232011-11-04 11:18:17 +010011878
Ben Greear37c73b52012-10-26 14:49:25 -070011879 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11880 if (!hdr)
11881 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011882
Ben Greear37c73b52012-10-26 14:49:25 -070011883 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11884 (freq &&
11885 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11886 (sig_dbm &&
11887 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11888 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11889 goto nla_put_failure;
11890
11891 genlmsg_end(msg, hdr);
11892
11893 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011894 }
Ben Greear37c73b52012-10-26 14:49:25 -070011895 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011896 return;
11897
11898 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011899 spin_unlock_bh(&rdev->beacon_registrations_lock);
11900 if (hdr)
11901 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011902 nlmsg_free(msg);
11903}
11904EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11905
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011906#ifdef CONFIG_PM
11907void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11908 struct cfg80211_wowlan_wakeup *wakeup,
11909 gfp_t gfp)
11910{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011911 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011912 struct sk_buff *msg;
11913 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011914 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011915
11916 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11917
11918 if (wakeup)
11919 size += wakeup->packet_present_len;
11920
11921 msg = nlmsg_new(size, gfp);
11922 if (!msg)
11923 return;
11924
11925 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11926 if (!hdr)
11927 goto free_msg;
11928
11929 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11930 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11931 goto free_msg;
11932
11933 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11934 wdev->netdev->ifindex))
11935 goto free_msg;
11936
11937 if (wakeup) {
11938 struct nlattr *reasons;
11939
11940 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011941 if (!reasons)
11942 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011943
11944 if (wakeup->disconnect &&
11945 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11946 goto free_msg;
11947 if (wakeup->magic_pkt &&
11948 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11949 goto free_msg;
11950 if (wakeup->gtk_rekey_failure &&
11951 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11952 goto free_msg;
11953 if (wakeup->eap_identity_req &&
11954 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11955 goto free_msg;
11956 if (wakeup->four_way_handshake &&
11957 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11958 goto free_msg;
11959 if (wakeup->rfkill_release &&
11960 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11961 goto free_msg;
11962
11963 if (wakeup->pattern_idx >= 0 &&
11964 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11965 wakeup->pattern_idx))
11966 goto free_msg;
11967
Johannes Bergae917c92013-10-25 11:05:22 +020011968 if (wakeup->tcp_match &&
11969 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11970 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011971
Johannes Bergae917c92013-10-25 11:05:22 +020011972 if (wakeup->tcp_connlost &&
11973 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11974 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011975
Johannes Bergae917c92013-10-25 11:05:22 +020011976 if (wakeup->tcp_nomoretokens &&
11977 nla_put_flag(msg,
11978 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11979 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011980
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011981 if (wakeup->packet) {
11982 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11983 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11984
11985 if (!wakeup->packet_80211) {
11986 pkt_attr =
11987 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11988 len_attr =
11989 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11990 }
11991
11992 if (wakeup->packet_len &&
11993 nla_put_u32(msg, len_attr, wakeup->packet_len))
11994 goto free_msg;
11995
11996 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11997 wakeup->packet))
11998 goto free_msg;
11999 }
12000
12001 nla_nest_end(msg, reasons);
12002 }
12003
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012004 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012005
Johannes Berg68eb5502013-11-19 15:19:38 +010012006 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012007 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012008 return;
12009
12010 free_msg:
12011 nlmsg_free(msg);
12012}
12013EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12014#endif
12015
Jouni Malinen3475b092012-11-16 22:49:57 +020012016void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12017 enum nl80211_tdls_operation oper,
12018 u16 reason_code, gfp_t gfp)
12019{
12020 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012021 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012022 struct sk_buff *msg;
12023 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012024
12025 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12026 reason_code);
12027
12028 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12029 if (!msg)
12030 return;
12031
12032 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12033 if (!hdr) {
12034 nlmsg_free(msg);
12035 return;
12036 }
12037
12038 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12039 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12040 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12041 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12042 (reason_code > 0 &&
12043 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12044 goto nla_put_failure;
12045
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012046 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012047
Johannes Berg68eb5502013-11-19 15:19:38 +010012048 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012049 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012050 return;
12051
12052 nla_put_failure:
12053 genlmsg_cancel(msg, hdr);
12054 nlmsg_free(msg);
12055}
12056EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12057
Jouni Malinen026331c2010-02-15 12:53:10 +020012058static int nl80211_netlink_notify(struct notifier_block * nb,
12059 unsigned long state,
12060 void *_notify)
12061{
12062 struct netlink_notify *notify = _notify;
12063 struct cfg80211_registered_device *rdev;
12064 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012065 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012066
12067 if (state != NETLINK_URELEASE)
12068 return NOTIFY_DONE;
12069
12070 rcu_read_lock();
12071
Johannes Berg5e760232011-11-04 11:18:17 +010012072 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012073 bool schedule_destroy_work = false;
12074
12075 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012076 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012077
Johannes Berg78f22b62014-03-24 17:57:27 +010012078 if (wdev->owner_nlportid == notify->portid)
12079 schedule_destroy_work = true;
12080 }
12081
Ben Greear37c73b52012-10-26 14:49:25 -070012082 spin_lock_bh(&rdev->beacon_registrations_lock);
12083 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12084 list) {
12085 if (reg->nlportid == notify->portid) {
12086 list_del(&reg->list);
12087 kfree(reg);
12088 break;
12089 }
12090 }
12091 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012092
12093 if (schedule_destroy_work) {
12094 struct cfg80211_iface_destroy *destroy;
12095
12096 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12097 if (destroy) {
12098 destroy->nlportid = notify->portid;
12099 spin_lock(&rdev->destroy_list_lock);
12100 list_add(&destroy->list, &rdev->destroy_list);
12101 spin_unlock(&rdev->destroy_list_lock);
12102 schedule_work(&rdev->destroy_work);
12103 }
12104 }
Johannes Berg5e760232011-11-04 11:18:17 +010012105 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012106
12107 rcu_read_unlock();
12108
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012109 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012110}
12111
12112static struct notifier_block nl80211_netlink_notifier = {
12113 .notifier_call = nl80211_netlink_notify,
12114};
12115
Jouni Malinen355199e2013-02-27 17:14:27 +020012116void cfg80211_ft_event(struct net_device *netdev,
12117 struct cfg80211_ft_event_params *ft_event)
12118{
12119 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012120 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012121 struct sk_buff *msg;
12122 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012123
12124 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12125
12126 if (!ft_event->target_ap)
12127 return;
12128
12129 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12130 if (!msg)
12131 return;
12132
12133 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012134 if (!hdr)
12135 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012136
Johannes Bergae917c92013-10-25 11:05:22 +020012137 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12138 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12139 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12140 goto out;
12141
12142 if (ft_event->ies &&
12143 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12144 goto out;
12145 if (ft_event->ric_ies &&
12146 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12147 ft_event->ric_ies))
12148 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012149
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012150 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012151
Johannes Berg68eb5502013-11-19 15:19:38 +010012152 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012153 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012154 return;
12155 out:
12156 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012157}
12158EXPORT_SYMBOL(cfg80211_ft_event);
12159
Arend van Spriel5de17982013-04-18 15:49:00 +020012160void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12161{
12162 struct cfg80211_registered_device *rdev;
12163 struct sk_buff *msg;
12164 void *hdr;
12165 u32 nlportid;
12166
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012167 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012168 if (!rdev->crit_proto_nlportid)
12169 return;
12170
12171 nlportid = rdev->crit_proto_nlportid;
12172 rdev->crit_proto_nlportid = 0;
12173
12174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12175 if (!msg)
12176 return;
12177
12178 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12179 if (!hdr)
12180 goto nla_put_failure;
12181
12182 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12183 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12184 goto nla_put_failure;
12185
12186 genlmsg_end(msg, hdr);
12187
12188 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12189 return;
12190
12191 nla_put_failure:
12192 if (hdr)
12193 genlmsg_cancel(msg, hdr);
12194 nlmsg_free(msg);
12195
12196}
12197EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12198
Johannes Berg348baf02014-01-24 14:06:29 +010012199void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12200{
12201 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012202 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012203 struct sk_buff *msg;
12204 void *hdr;
12205
12206 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12207 if (!msg)
12208 return;
12209
12210 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12211 if (!hdr)
12212 goto out;
12213
12214 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12215 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12216 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12217 goto out;
12218
12219 genlmsg_end(msg, hdr);
12220
12221 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12222 NL80211_MCGRP_MLME, GFP_KERNEL);
12223 return;
12224 out:
12225 nlmsg_free(msg);
12226}
12227
Johannes Berg55682962007-09-20 13:09:35 -040012228/* initialisation/exit functions */
12229
12230int nl80211_init(void)
12231{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012232 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012233
Johannes Berg2a94fe42013-11-19 15:19:39 +010012234 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12235 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012236 if (err)
12237 return err;
12238
Jouni Malinen026331c2010-02-15 12:53:10 +020012239 err = netlink_register_notifier(&nl80211_netlink_notifier);
12240 if (err)
12241 goto err_out;
12242
Johannes Berg55682962007-09-20 13:09:35 -040012243 return 0;
12244 err_out:
12245 genl_unregister_family(&nl80211_fam);
12246 return err;
12247}
12248
12249void nl80211_exit(void)
12250{
Jouni Malinen026331c2010-02-15 12:53:10 +020012251 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012252 genl_unregister_family(&nl80211_fam);
12253}