blob: 1a31736914e5ca9a9ac2cd2083deb43bfb7e6fc3 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
62 [NL80211_MCGRP_CONFIG] = { .name = "config", },
63 [NL80211_MCGRP_SCAN] = { .name = "scan", },
64 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
65 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010066 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
68 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
69#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
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 Malinendc6382c2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
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 Karwarbe29b992013-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;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100887 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100888 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100889 case NL80211_IFTYPE_MONITOR:
890 case NL80211_IFTYPE_P2P_DEVICE:
891 case NL80211_IFTYPE_WDS:
892 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200893 return -EINVAL;
894 }
895
896 return 0;
897}
898
Jouni Malinen664834d2014-01-15 00:01:44 +0200899static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
900 struct nlattr *tb)
901{
902 struct ieee80211_channel *chan;
903
904 if (tb == NULL)
905 return NULL;
906 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
907 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
908 return NULL;
909 return chan;
910}
911
Johannes Berg7527a782011-05-13 10:58:57 +0200912static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
913{
914 struct nlattr *nl_modes = nla_nest_start(msg, attr);
915 int i;
916
917 if (!nl_modes)
918 goto nla_put_failure;
919
920 i = 0;
921 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400922 if ((ifmodes & 1) && nla_put_flag(msg, i))
923 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200924 ifmodes >>= 1;
925 i++;
926 }
927
928 nla_nest_end(msg, nl_modes);
929 return 0;
930
931nla_put_failure:
932 return -ENOBUFS;
933}
934
935static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100936 struct sk_buff *msg,
937 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200938{
939 struct nlattr *nl_combis;
940 int i, j;
941
942 nl_combis = nla_nest_start(msg,
943 NL80211_ATTR_INTERFACE_COMBINATIONS);
944 if (!nl_combis)
945 goto nla_put_failure;
946
947 for (i = 0; i < wiphy->n_iface_combinations; i++) {
948 const struct ieee80211_iface_combination *c;
949 struct nlattr *nl_combi, *nl_limits;
950
951 c = &wiphy->iface_combinations[i];
952
953 nl_combi = nla_nest_start(msg, i + 1);
954 if (!nl_combi)
955 goto nla_put_failure;
956
957 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
958 if (!nl_limits)
959 goto nla_put_failure;
960
961 for (j = 0; j < c->n_limits; j++) {
962 struct nlattr *nl_limit;
963
964 nl_limit = nla_nest_start(msg, j + 1);
965 if (!nl_limit)
966 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400967 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
968 c->limits[j].max))
969 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200970 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
971 c->limits[j].types))
972 goto nla_put_failure;
973 nla_nest_end(msg, nl_limit);
974 }
975
976 nla_nest_end(msg, nl_limits);
977
David S. Miller9360ffd2012-03-29 04:41:26 -0400978 if (c->beacon_int_infra_match &&
979 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
980 goto nla_put_failure;
981 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
982 c->num_different_channels) ||
983 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
984 c->max_interfaces))
985 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100986 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200987 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
988 c->radar_detect_widths) ||
989 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
990 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100991 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200992
993 nla_nest_end(msg, nl_combi);
994 }
995
996 nla_nest_end(msg, nl_combis);
997
998 return 0;
999nla_put_failure:
1000 return -ENOBUFS;
1001}
1002
Johannes Berg3713b4e2013-02-14 16:19:38 +01001003#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001004static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1005 struct sk_buff *msg)
1006{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001007 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001008 struct nlattr *nl_tcp;
1009
1010 if (!tcp)
1011 return 0;
1012
1013 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1014 if (!nl_tcp)
1015 return -ENOBUFS;
1016
1017 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1018 tcp->data_payload_max))
1019 return -ENOBUFS;
1020
1021 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1022 tcp->data_payload_max))
1023 return -ENOBUFS;
1024
1025 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1026 return -ENOBUFS;
1027
1028 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1029 sizeof(*tcp->tok), tcp->tok))
1030 return -ENOBUFS;
1031
1032 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1033 tcp->data_interval_max))
1034 return -ENOBUFS;
1035
1036 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1037 tcp->wake_payload_max))
1038 return -ENOBUFS;
1039
1040 nla_nest_end(msg, nl_tcp);
1041 return 0;
1042}
1043
Johannes Berg3713b4e2013-02-14 16:19:38 +01001044static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001045 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001046 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001047{
1048 struct nlattr *nl_wowlan;
1049
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001050 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001051 return 0;
1052
1053 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1054 if (!nl_wowlan)
1055 return -ENOBUFS;
1056
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001057 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001058 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001061 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001062 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001066 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001069 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1073 return -ENOBUFS;
1074
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001076 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1078 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1079 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1080 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001081 };
1082
1083 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1084 sizeof(pat), &pat))
1085 return -ENOBUFS;
1086 }
1087
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001089 return -ENOBUFS;
1090
Johannes Berg3713b4e2013-02-14 16:19:38 +01001091 nla_nest_end(msg, nl_wowlan);
1092
1093 return 0;
1094}
1095#endif
1096
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001097static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001098 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001099{
1100 struct nl80211_coalesce_rule_support rule;
1101
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001103 return 0;
1104
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001105 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1106 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1107 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1108 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1109 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1110 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001111
1112 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1113 return -ENOBUFS;
1114
1115 return 0;
1116}
1117
Johannes Berg3713b4e2013-02-14 16:19:38 +01001118static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1119 struct ieee80211_supported_band *sband)
1120{
1121 struct nlattr *nl_rates, *nl_rate;
1122 struct ieee80211_rate *rate;
1123 int i;
1124
1125 /* add HT info */
1126 if (sband->ht_cap.ht_supported &&
1127 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1128 sizeof(sband->ht_cap.mcs),
1129 &sband->ht_cap.mcs) ||
1130 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1131 sband->ht_cap.cap) ||
1132 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1133 sband->ht_cap.ampdu_factor) ||
1134 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1135 sband->ht_cap.ampdu_density)))
1136 return -ENOBUFS;
1137
1138 /* add VHT info */
1139 if (sband->vht_cap.vht_supported &&
1140 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1141 sizeof(sband->vht_cap.vht_mcs),
1142 &sband->vht_cap.vht_mcs) ||
1143 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1144 sband->vht_cap.cap)))
1145 return -ENOBUFS;
1146
1147 /* add bitrates */
1148 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1149 if (!nl_rates)
1150 return -ENOBUFS;
1151
1152 for (i = 0; i < sband->n_bitrates; i++) {
1153 nl_rate = nla_nest_start(msg, i);
1154 if (!nl_rate)
1155 return -ENOBUFS;
1156
1157 rate = &sband->bitrates[i];
1158 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1159 rate->bitrate))
1160 return -ENOBUFS;
1161 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1162 nla_put_flag(msg,
1163 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1164 return -ENOBUFS;
1165
1166 nla_nest_end(msg, nl_rate);
1167 }
1168
1169 nla_nest_end(msg, nl_rates);
1170
1171 return 0;
1172}
1173
1174static int
1175nl80211_send_mgmt_stypes(struct sk_buff *msg,
1176 const struct ieee80211_txrx_stypes *mgmt_stypes)
1177{
1178 u16 stypes;
1179 struct nlattr *nl_ftypes, *nl_ifs;
1180 enum nl80211_iftype ift;
1181 int i;
1182
1183 if (!mgmt_stypes)
1184 return 0;
1185
1186 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1187 if (!nl_ifs)
1188 return -ENOBUFS;
1189
1190 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1191 nl_ftypes = nla_nest_start(msg, ift);
1192 if (!nl_ftypes)
1193 return -ENOBUFS;
1194 i = 0;
1195 stypes = mgmt_stypes[ift].tx;
1196 while (stypes) {
1197 if ((stypes & 1) &&
1198 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1199 (i << 4) | IEEE80211_FTYPE_MGMT))
1200 return -ENOBUFS;
1201 stypes >>= 1;
1202 i++;
1203 }
1204 nla_nest_end(msg, nl_ftypes);
1205 }
1206
1207 nla_nest_end(msg, nl_ifs);
1208
1209 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1210 if (!nl_ifs)
1211 return -ENOBUFS;
1212
1213 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1214 nl_ftypes = nla_nest_start(msg, ift);
1215 if (!nl_ftypes)
1216 return -ENOBUFS;
1217 i = 0;
1218 stypes = mgmt_stypes[ift].rx;
1219 while (stypes) {
1220 if ((stypes & 1) &&
1221 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1222 (i << 4) | IEEE80211_FTYPE_MGMT))
1223 return -ENOBUFS;
1224 stypes >>= 1;
1225 i++;
1226 }
1227 nla_nest_end(msg, nl_ftypes);
1228 }
1229 nla_nest_end(msg, nl_ifs);
1230
1231 return 0;
1232}
1233
Johannes Berg86e8cf92013-06-19 10:57:22 +02001234struct nl80211_dump_wiphy_state {
1235 s64 filter_wiphy;
1236 long start;
1237 long split_start, band_start, chan_start;
1238 bool split;
1239};
1240
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001241static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001242 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001243 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001244 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001245{
1246 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001247 struct nlattr *nl_bands, *nl_band;
1248 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001249 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001250 enum ieee80211_band band;
1251 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001252 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001253 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001254 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001255 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001256
Johannes Berg3bb20552014-05-26 13:52:25 +02001257 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001258 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001259 return -ENOBUFS;
1260
Johannes Berg86e8cf92013-06-19 10:57:22 +02001261 if (WARN_ON(!state))
1262 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001263
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001264 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001265 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001266 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001267 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001269 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001270
Johannes Berg3bb20552014-05-26 13:52:25 +02001271 if (cmd != NL80211_CMD_NEW_WIPHY)
1272 goto finish;
1273
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 case 0:
1276 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001279 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001285 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001287 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001289 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001291 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001296 goto nla_put_failure;
1297
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1300 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1303 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1306 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1309 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001310 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1312 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001315 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001316 state->split_start++;
1317 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 break;
1319 case 1:
1320 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1322 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001323 goto nla_put_failure;
1324
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001326 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001327 goto nla_put_failure;
1328
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1331 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001332
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001336 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001338
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001341 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001343
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001344 if ((rdev->wiphy.available_antennas_tx ||
1345 rdev->wiphy.available_antennas_rx) &&
1346 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 u32 tx_ant = 0, rx_ant = 0;
1348 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 if (!res) {
1351 if (nla_put_u32(msg,
1352 NL80211_ATTR_WIPHY_ANTENNA_TX,
1353 tx_ant) ||
1354 nla_put_u32(msg,
1355 NL80211_ATTR_WIPHY_ANTENNA_RX,
1356 rx_ant))
1357 goto nla_put_failure;
1358 }
Johannes Bergee688b002008-01-24 19:38:39 +01001359 }
1360
Johannes Berg86e8cf92013-06-19 10:57:22 +02001361 state->split_start++;
1362 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001363 break;
1364 case 2:
1365 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001366 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001368 state->split_start++;
1369 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 break;
1371 case 3:
1372 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1373 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001374 goto nla_put_failure;
1375
Johannes Berg86e8cf92013-06-19 10:57:22 +02001376 for (band = state->band_start;
1377 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 struct ieee80211_supported_band *sband;
1379
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001380 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381
1382 if (!sband)
1383 continue;
1384
1385 nl_band = nla_nest_start(msg, band);
1386 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001387 goto nla_put_failure;
1388
Johannes Berg86e8cf92013-06-19 10:57:22 +02001389 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001390 case 0:
1391 if (nl80211_send_band_rateinfo(msg, sband))
1392 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001393 state->chan_start++;
1394 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 break;
1396 default:
1397 /* add frequencies */
1398 nl_freqs = nla_nest_start(
1399 msg, NL80211_BAND_ATTR_FREQS);
1400 if (!nl_freqs)
1401 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001402
Johannes Berg86e8cf92013-06-19 10:57:22 +02001403 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 i < sband->n_channels;
1405 i++) {
1406 nl_freq = nla_nest_start(msg, i);
1407 if (!nl_freq)
1408 goto nla_put_failure;
1409
1410 chan = &sband->channels[i];
1411
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 if (nl80211_msg_put_channel(
1413 msg, chan,
1414 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 goto nla_put_failure;
1416
1417 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001418 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 break;
1420 }
1421 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001424 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001425 nla_nest_end(msg, nl_freqs);
1426 }
1427
1428 nla_nest_end(msg, nl_band);
1429
Johannes Berg86e8cf92013-06-19 10:57:22 +02001430 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 band--;
1434 break;
1435 }
Johannes Bergee688b002008-01-24 19:38:39 +01001436 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001440 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001441 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001442 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001443
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001445 if (state->band_start == 0 && state->chan_start == 0)
1446 state->split_start++;
1447 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 break;
1449 case 4:
1450 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1451 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001452 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453
1454 i = 0;
1455#define CMD(op, n) \
1456 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001457 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 i++; \
1459 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1460 goto nla_put_failure; \
1461 } \
1462 } while (0)
1463
1464 CMD(add_virtual_intf, NEW_INTERFACE);
1465 CMD(change_virtual_intf, SET_INTERFACE);
1466 CMD(add_key, NEW_KEY);
1467 CMD(start_ap, START_AP);
1468 CMD(add_station, NEW_STATION);
1469 CMD(add_mpath, NEW_MPATH);
1470 CMD(update_mesh_config, SET_MESH_CONFIG);
1471 CMD(change_bss, SET_BSS);
1472 CMD(auth, AUTHENTICATE);
1473 CMD(assoc, ASSOCIATE);
1474 CMD(deauth, DEAUTHENTICATE);
1475 CMD(disassoc, DISASSOCIATE);
1476 CMD(join_ibss, JOIN_IBSS);
1477 CMD(join_mesh, JOIN_MESH);
1478 CMD(set_pmksa, SET_PMKSA);
1479 CMD(del_pmksa, DEL_PMKSA);
1480 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001481 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1483 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1484 CMD(mgmt_tx, FRAME);
1485 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001487 i++;
1488 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1489 goto nla_put_failure;
1490 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001491 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1492 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 i++;
1494 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1495 goto nla_put_failure;
1496 }
1497 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001498 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001499 CMD(tdls_mgmt, TDLS_MGMT);
1500 CMD(tdls_oper, TDLS_OPER);
1501 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 CMD(sched_scan_start, START_SCHED_SCAN);
1504 CMD(probe_client, PROBE_CLIENT);
1505 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 i++;
1508 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1509 goto nla_put_failure;
1510 }
1511 CMD(start_p2p_device, START_P2P_DEVICE);
1512 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001513#ifdef CONFIG_NL80211_TESTMODE
1514 CMD(testmode_cmd, TESTMODE);
1515#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001516 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001517 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1518 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001519 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001520 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001521 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001522 if (rdev->wiphy.features &
1523 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001524 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001525 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001526 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001527#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001528
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001529 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 i++;
1531 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001532 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001533 }
1534
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001535 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 i++;
1537 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1538 goto nla_put_failure;
1539 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001540
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001542 state->split_start++;
1543 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 break;
1545 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001546 if (rdev->ops->remain_on_channel &&
1547 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 nla_put_u32(msg,
1549 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001550 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001551 goto nla_put_failure;
1552
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001553 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1555 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001556
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1558 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 state->split_start++;
1560 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 break;
1562 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001563#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001564 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 state->split_start++;
1567 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 break;
1569#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001570 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571#endif
1572 case 7:
1573 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001574 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001575 goto nla_put_failure;
1576
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001578 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001580
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 state->split_start++;
1582 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 break;
1584 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001587 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 goto nla_put_failure;
1589
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001590 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001591 /*
1592 * We can only add the per-channel limit information if the
1593 * dump is split, otherwise it makes it too big. Therefore
1594 * only advertise it in that case.
1595 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001596 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001597 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1598 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 goto nla_put_failure;
1600
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001601 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001602 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001603 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1604 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001605 goto nla_put_failure;
1606
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1608 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 goto nla_put_failure;
1612
1613 /*
1614 * Any information below this point is only available to
1615 * applications that can deal with it being split. This
1616 * helps ensure that newly added capabilities don't break
1617 * older tools by overrunning their buffers.
1618 *
1619 * We still increment split_start so that in the split
1620 * case we'll continue with more data in the next round,
1621 * but break unconditionally so unsplit data stops here.
1622 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001623 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 break;
1625 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001627 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001628 rdev->wiphy.extended_capabilities_len,
1629 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001630 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 rdev->wiphy.extended_capabilities_len,
1632 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001633 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001635 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001636 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1638 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001639 goto nla_put_failure;
1640
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001641 state->split_start++;
1642 break;
1643 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001644 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001645 goto nla_put_failure;
1646
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001648 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1649 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1650 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001651
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001652 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001653 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001655 goto nla_put_failure;
1656
Johannes Bergad7e7182013-11-13 13:37:47 +01001657 state->split_start++;
1658 break;
1659 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001660 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001661 const struct nl80211_vendor_cmd_info *info;
1662 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001663
Johannes Berg567ffc32013-12-18 14:43:31 +01001664 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1665 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001666 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001667
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001668 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1669 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001670 if (nla_put(msg, i + 1, sizeof(*info), info))
1671 goto nla_put_failure;
1672 }
1673 nla_nest_end(msg, nested);
1674 }
1675
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001676 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001677 const struct nl80211_vendor_cmd_info *info;
1678 struct nlattr *nested;
1679
1680 nested = nla_nest_start(msg,
1681 NL80211_ATTR_VENDOR_EVENTS);
1682 if (!nested)
1683 goto nla_put_failure;
1684
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001685 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1686 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001687 if (nla_put(msg, i + 1, sizeof(*info), info))
1688 goto nla_put_failure;
1689 }
1690 nla_nest_end(msg, nested);
1691 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001692 state->split_start++;
1693 break;
1694 case 12:
1695 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1696 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1697 rdev->wiphy.max_num_csa_counters))
1698 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001699
Johannes Berg3713b4e2013-02-14 16:19:38 +01001700 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001701 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001702 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001703 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001704 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001705 return genlmsg_end(msg, hdr);
1706
1707 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001708 genlmsg_cancel(msg, hdr);
1709 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001710}
1711
Johannes Berg86e8cf92013-06-19 10:57:22 +02001712static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1713 struct netlink_callback *cb,
1714 struct nl80211_dump_wiphy_state *state)
1715{
1716 struct nlattr **tb = nl80211_fam.attrbuf;
1717 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1718 tb, nl80211_fam.maxattr, nl80211_policy);
1719 /* ignore parse errors for backward compatibility */
1720 if (ret)
1721 return 0;
1722
1723 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1724 if (tb[NL80211_ATTR_WIPHY])
1725 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1726 if (tb[NL80211_ATTR_WDEV])
1727 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1728 if (tb[NL80211_ATTR_IFINDEX]) {
1729 struct net_device *netdev;
1730 struct cfg80211_registered_device *rdev;
1731 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1732
Ying Xue7f2b8562014-01-15 10:23:45 +08001733 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001734 if (!netdev)
1735 return -ENODEV;
1736 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001737 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 netdev->ieee80211_ptr->wiphy);
1739 state->filter_wiphy = rdev->wiphy_idx;
1740 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001741 }
1742
1743 return 0;
1744}
1745
Johannes Berg55682962007-09-20 13:09:35 -04001746static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1747{
Johannes Berg645e77d2013-03-01 14:03:49 +01001748 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001749 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001750 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001751
Johannes Berg5fe231e2013-05-08 21:45:15 +02001752 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001753 if (!state) {
1754 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001755 if (!state) {
1756 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001758 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 state->filter_wiphy = -1;
1760 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1761 if (ret) {
1762 kfree(state);
1763 rtnl_unlock();
1764 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001765 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001766 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001767 }
1768
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001769 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1770 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001771 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001772 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001773 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001774 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001775 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001776 continue;
1777 /* attempt to fit multiple wiphy data chunks into the skb */
1778 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001779 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1780 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001781 NETLINK_CB(cb->skb).portid,
1782 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001783 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001784 if (ret < 0) {
1785 /*
1786 * If sending the wiphy data didn't fit (ENOBUFS
1787 * or EMSGSIZE returned), this SKB is still
1788 * empty (so it's not too big because another
1789 * wiphy dataset is already in the skb) and
1790 * we've not tried to adjust the dump allocation
1791 * yet ... then adjust the alloc size to be
1792 * bigger, and return 1 but with the empty skb.
1793 * This results in an empty message being RX'ed
1794 * in userspace, but that is ignored.
1795 *
1796 * We can then retry with the larger buffer.
1797 */
1798 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001799 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001800 cb->min_dump_alloc < 4096) {
1801 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001802 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001803 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001804 return 1;
1805 }
1806 idx--;
1807 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001808 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001809 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001810 break;
Johannes Berg55682962007-09-20 13:09:35 -04001811 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001812 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001813
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001815
1816 return skb->len;
1817}
1818
Johannes Berg86e8cf92013-06-19 10:57:22 +02001819static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1820{
1821 kfree((void *)cb->args[0]);
1822 return 0;
1823}
1824
Johannes Berg55682962007-09-20 13:09:35 -04001825static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1826{
1827 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001829 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001830
Johannes Berg645e77d2013-03-01 14:03:49 +01001831 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001832 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001833 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001834
Johannes Berg3bb20552014-05-26 13:52:25 +02001835 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1836 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001837 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001838 nlmsg_free(msg);
1839 return -ENOBUFS;
1840 }
Johannes Berg55682962007-09-20 13:09:35 -04001841
Johannes Berg134e6372009-07-10 09:51:34 +00001842 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001843}
1844
Jouni Malinen31888482008-10-30 16:59:24 +02001845static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1846 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1847 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1848 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1849 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1850 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1851};
1852
1853static int parse_txq_params(struct nlattr *tb[],
1854 struct ieee80211_txq_params *txq_params)
1855{
Johannes Berga3304b02012-03-28 11:04:24 +02001856 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001857 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1858 !tb[NL80211_TXQ_ATTR_AIFS])
1859 return -EINVAL;
1860
Johannes Berga3304b02012-03-28 11:04:24 +02001861 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001862 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1863 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1864 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1865 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1866
Johannes Berga3304b02012-03-28 11:04:24 +02001867 if (txq_params->ac >= NL80211_NUM_ACS)
1868 return -EINVAL;
1869
Jouni Malinen31888482008-10-30 16:59:24 +02001870 return 0;
1871}
1872
Johannes Bergf444de02010-05-05 15:25:02 +02001873static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1874{
1875 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001876 * You can only set the channel explicitly for WDS interfaces,
1877 * all others have their channel managed via their respective
1878 * "establish a connection" command (connect, join, ...)
1879 *
1880 * For AP/GO and mesh mode, the channel can be set with the
1881 * channel userspace API, but is only stored and passed to the
1882 * low-level driver when the AP starts or the mesh is joined.
1883 * This is for backward compatibility, userspace can also give
1884 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001885 *
1886 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001887 * whatever else is going on, so they have their own special
1888 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001889 */
1890 return !wdev ||
1891 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001892 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001893 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1894 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001895}
1896
Johannes Berg683b6d32012-11-08 21:25:48 +01001897static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1898 struct genl_info *info,
1899 struct cfg80211_chan_def *chandef)
1900{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301901 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001902
1903 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1904 return -EINVAL;
1905
1906 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1907
1908 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001909 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1910 chandef->center_freq1 = control_freq;
1911 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001912
1913 /* Primary channel not allowed */
1914 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1915 return -EINVAL;
1916
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001917 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1918 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001919
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001920 chantype = nla_get_u32(
1921 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1922
1923 switch (chantype) {
1924 case NL80211_CHAN_NO_HT:
1925 case NL80211_CHAN_HT20:
1926 case NL80211_CHAN_HT40PLUS:
1927 case NL80211_CHAN_HT40MINUS:
1928 cfg80211_chandef_create(chandef, chandef->chan,
1929 chantype);
1930 break;
1931 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001932 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001933 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001934 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1935 chandef->width =
1936 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1937 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1938 chandef->center_freq1 =
1939 nla_get_u32(
1940 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1941 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1942 chandef->center_freq2 =
1943 nla_get_u32(
1944 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1945 }
1946
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001947 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001948 return -EINVAL;
1949
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001950 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1951 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001952 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001953
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001954 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1955 chandef->width == NL80211_CHAN_WIDTH_10) &&
1956 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1957 return -EINVAL;
1958
Johannes Berg683b6d32012-11-08 21:25:48 +01001959 return 0;
1960}
1961
Johannes Bergf444de02010-05-05 15:25:02 +02001962static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001963 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001964 struct genl_info *info)
1965{
Johannes Berg683b6d32012-11-08 21:25:48 +01001966 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001967 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001968 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001969 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001970
Jouni Malinene16821b2014-04-28 11:22:08 +03001971 if (dev)
1972 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001973 if (!nl80211_can_set_dev_channel(wdev))
1974 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001975 if (wdev)
1976 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001977
Johannes Berg683b6d32012-11-08 21:25:48 +01001978 result = nl80211_parse_chandef(rdev, info, &chandef);
1979 if (result)
1980 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001981
Johannes Berge8c9bd52012-06-06 08:18:22 +02001982 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001983 case NL80211_IFTYPE_AP:
1984 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001985 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001986 result = -EINVAL;
1987 break;
1988 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001989 if (wdev->beacon_interval) {
1990 if (!dev || !rdev->ops->set_ap_chanwidth ||
1991 !(rdev->wiphy.features &
1992 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1993 result = -EBUSY;
1994 break;
1995 }
1996
1997 /* Only allow dynamic channel width changes */
1998 if (chandef.chan != wdev->preset_chandef.chan) {
1999 result = -EBUSY;
2000 break;
2001 }
2002 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2003 if (result)
2004 break;
2005 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002006 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002007 result = 0;
2008 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002009 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002010 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002011 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002012 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002013 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002014 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002015 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002016 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002017 }
Johannes Bergf444de02010-05-05 15:25:02 +02002018
2019 return result;
2020}
2021
2022static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2023{
Johannes Berg4c476992010-10-04 21:36:35 +02002024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2025 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002026
Jouni Malinene16821b2014-04-28 11:22:08 +03002027 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002028}
2029
Bill Jordane8347eb2010-10-01 13:54:28 -04002030static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2031{
Johannes Berg43b19952010-10-07 13:10:30 +02002032 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2033 struct net_device *dev = info->user_ptr[1];
2034 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002035 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002036
2037 if (!info->attrs[NL80211_ATTR_MAC])
2038 return -EINVAL;
2039
Johannes Berg43b19952010-10-07 13:10:30 +02002040 if (netif_running(dev))
2041 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002042
Johannes Berg43b19952010-10-07 13:10:30 +02002043 if (!rdev->ops->set_wds_peer)
2044 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002045
Johannes Berg43b19952010-10-07 13:10:30 +02002046 if (wdev->iftype != NL80211_IFTYPE_WDS)
2047 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002048
2049 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002050 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002051}
2052
2053
Johannes Berg55682962007-09-20 13:09:35 -04002054static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2055{
2056 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002057 struct net_device *netdev = NULL;
2058 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002059 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002060 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002061 u32 changed;
2062 u8 retry_short = 0, retry_long = 0;
2063 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002064 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002065
Johannes Berg5fe231e2013-05-08 21:45:15 +02002066 ASSERT_RTNL();
2067
Johannes Bergf444de02010-05-05 15:25:02 +02002068 /*
2069 * Try to find the wiphy and netdev. Normally this
2070 * function shouldn't need the netdev, but this is
2071 * done for backward compatibility -- previously
2072 * setting the channel was done per wiphy, but now
2073 * it is per netdev. Previous userland like hostapd
2074 * also passed a netdev to set_wiphy, so that it is
2075 * possible to let that go to the right netdev!
2076 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002077
Johannes Bergf444de02010-05-05 15:25:02 +02002078 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2079 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2080
Ying Xue7f2b8562014-01-15 10:23:45 +08002081 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002082 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002083 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002084 else
Johannes Bergf444de02010-05-05 15:25:02 +02002085 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002086 }
2087
Johannes Bergf444de02010-05-05 15:25:02 +02002088 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002089 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2090 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002091 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002092 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002093 wdev = NULL;
2094 netdev = NULL;
2095 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002096 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002097 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002098
2099 /*
2100 * end workaround code, by now the rdev is available
2101 * and locked, and wdev may or may not be NULL.
2102 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002103
2104 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002105 result = cfg80211_dev_rename(
2106 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002107
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002108 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002109 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002110
Jouni Malinen31888482008-10-30 16:59:24 +02002111 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2112 struct ieee80211_txq_params txq_params;
2113 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2114
Ying Xue7f2b8562014-01-15 10:23:45 +08002115 if (!rdev->ops->set_txq_params)
2116 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002117
Ying Xue7f2b8562014-01-15 10:23:45 +08002118 if (!netdev)
2119 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002120
Johannes Berg133a3ff2011-11-03 14:50:13 +01002121 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002122 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2123 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002124
Ying Xue7f2b8562014-01-15 10:23:45 +08002125 if (!netif_running(netdev))
2126 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002127
Jouni Malinen31888482008-10-30 16:59:24 +02002128 nla_for_each_nested(nl_txq_params,
2129 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2130 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002131 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2132 nla_data(nl_txq_params),
2133 nla_len(nl_txq_params),
2134 txq_params_policy);
2135 if (result)
2136 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002137 result = parse_txq_params(tb, &txq_params);
2138 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002140
Hila Gonene35e4d22012-06-27 17:19:42 +03002141 result = rdev_set_txq_params(rdev, netdev,
2142 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002143 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002144 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002145 }
2146 }
2147
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002148 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002149 result = __nl80211_set_channel(
2150 rdev,
2151 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2152 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002153 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002154 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002155 }
2156
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002157 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002158 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002159 enum nl80211_tx_power_setting type;
2160 int idx, mbm = 0;
2161
Johannes Bergc8442112012-10-24 10:17:18 +02002162 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2163 txp_wdev = NULL;
2164
Ying Xue7f2b8562014-01-15 10:23:45 +08002165 if (!rdev->ops->set_tx_power)
2166 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002167
2168 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2169 type = nla_get_u32(info->attrs[idx]);
2170
2171 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002172 (type != NL80211_TX_POWER_AUTOMATIC))
2173 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002174
2175 if (type != NL80211_TX_POWER_AUTOMATIC) {
2176 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2177 mbm = nla_get_u32(info->attrs[idx]);
2178 }
2179
Johannes Bergc8442112012-10-24 10:17:18 +02002180 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002181 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002182 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002183 }
2184
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002185 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2186 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2187 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002188 if ((!rdev->wiphy.available_antennas_tx &&
2189 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002190 !rdev->ops->set_antenna)
2191 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002192
2193 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2194 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2195
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002196 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002197 * available antenna masks, except for the "all" mask */
2198 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002199 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2200 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002201
Bruno Randolf7f531e02010-12-16 11:30:22 +09002202 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2203 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002204
Hila Gonene35e4d22012-06-27 17:19:42 +03002205 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002206 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002207 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002208 }
2209
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002210 changed = 0;
2211
2212 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2213 retry_short = nla_get_u8(
2214 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002215 if (retry_short == 0)
2216 return -EINVAL;
2217
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002218 changed |= WIPHY_PARAM_RETRY_SHORT;
2219 }
2220
2221 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2222 retry_long = nla_get_u8(
2223 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002224 if (retry_long == 0)
2225 return -EINVAL;
2226
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002227 changed |= WIPHY_PARAM_RETRY_LONG;
2228 }
2229
2230 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2231 frag_threshold = nla_get_u32(
2232 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002233 if (frag_threshold < 256)
2234 return -EINVAL;
2235
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002236 if (frag_threshold != (u32) -1) {
2237 /*
2238 * Fragments (apart from the last one) are required to
2239 * have even length. Make the fragmentation code
2240 * simpler by stripping LSB should someone try to use
2241 * odd threshold value.
2242 */
2243 frag_threshold &= ~0x1;
2244 }
2245 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2246 }
2247
2248 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2249 rts_threshold = nla_get_u32(
2250 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2251 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2252 }
2253
Lukáš Turek81077e82009-12-21 22:50:47 +01002254 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002255 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2256 return -EINVAL;
2257
Lukáš Turek81077e82009-12-21 22:50:47 +01002258 coverage_class = nla_get_u8(
2259 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2260 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2261 }
2262
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002263 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2264 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2265 return -EOPNOTSUPP;
2266
2267 changed |= WIPHY_PARAM_DYN_ACK;
2268 }
2269
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002270 if (changed) {
2271 u8 old_retry_short, old_retry_long;
2272 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002273 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002274
Ying Xue7f2b8562014-01-15 10:23:45 +08002275 if (!rdev->ops->set_wiphy_params)
2276 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002277
2278 old_retry_short = rdev->wiphy.retry_short;
2279 old_retry_long = rdev->wiphy.retry_long;
2280 old_frag_threshold = rdev->wiphy.frag_threshold;
2281 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002282 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002283
2284 if (changed & WIPHY_PARAM_RETRY_SHORT)
2285 rdev->wiphy.retry_short = retry_short;
2286 if (changed & WIPHY_PARAM_RETRY_LONG)
2287 rdev->wiphy.retry_long = retry_long;
2288 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2289 rdev->wiphy.frag_threshold = frag_threshold;
2290 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2291 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002292 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2293 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002294
Hila Gonene35e4d22012-06-27 17:19:42 +03002295 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002296 if (result) {
2297 rdev->wiphy.retry_short = old_retry_short;
2298 rdev->wiphy.retry_long = old_retry_long;
2299 rdev->wiphy.frag_threshold = old_frag_threshold;
2300 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002301 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002302 }
2303 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002304 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002305}
2306
Johannes Berg71bbc992012-06-15 15:30:18 +02002307static inline u64 wdev_id(struct wireless_dev *wdev)
2308{
2309 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002310 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002311}
Johannes Berg55682962007-09-20 13:09:35 -04002312
Johannes Berg683b6d32012-11-08 21:25:48 +01002313static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002314 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002315{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002316 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002317
Johannes Berg683b6d32012-11-08 21:25:48 +01002318 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2319 chandef->chan->center_freq))
2320 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002321 switch (chandef->width) {
2322 case NL80211_CHAN_WIDTH_20_NOHT:
2323 case NL80211_CHAN_WIDTH_20:
2324 case NL80211_CHAN_WIDTH_40:
2325 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2326 cfg80211_get_chandef_type(chandef)))
2327 return -ENOBUFS;
2328 break;
2329 default:
2330 break;
2331 }
2332 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2333 return -ENOBUFS;
2334 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2335 return -ENOBUFS;
2336 if (chandef->center_freq2 &&
2337 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002338 return -ENOBUFS;
2339 return 0;
2340}
2341
Eric W. Biederman15e47302012-09-07 20:12:54 +00002342static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002343 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002344 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002345{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002346 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002347 void *hdr;
2348
Eric W. Biederman15e47302012-09-07 20:12:54 +00002349 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002350 if (!hdr)
2351 return -1;
2352
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002353 if (dev &&
2354 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002355 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002356 goto nla_put_failure;
2357
2358 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2359 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002360 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002361 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002362 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2363 rdev->devlist_generation ^
2364 (cfg80211_rdev_list_generation << 2)))
2365 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002366
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002367 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002368 int ret;
2369 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002370
Johannes Berg683b6d32012-11-08 21:25:48 +01002371 ret = rdev_get_channel(rdev, wdev, &chandef);
2372 if (ret == 0) {
2373 if (nl80211_send_chandef(msg, &chandef))
2374 goto nla_put_failure;
2375 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002376 }
2377
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002378 if (wdev->ssid_len) {
2379 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2380 goto nla_put_failure;
2381 }
2382
Johannes Berg55682962007-09-20 13:09:35 -04002383 return genlmsg_end(msg, hdr);
2384
2385 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002386 genlmsg_cancel(msg, hdr);
2387 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002388}
2389
2390static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2391{
2392 int wp_idx = 0;
2393 int if_idx = 0;
2394 int wp_start = cb->args[0];
2395 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002396 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002397 struct wireless_dev *wdev;
2398
Johannes Berg5fe231e2013-05-08 21:45:15 +02002399 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002400 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2401 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002402 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002403 if (wp_idx < wp_start) {
2404 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002405 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002406 }
Johannes Berg55682962007-09-20 13:09:35 -04002407 if_idx = 0;
2408
Johannes Berg89a54e42012-06-15 14:33:17 +02002409 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002410 if (if_idx < if_start) {
2411 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002412 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002413 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002414 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002415 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002416 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002417 goto out;
2418 }
2419 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002420 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002421
2422 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002423 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002424 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002425 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002426
2427 cb->args[0] = wp_idx;
2428 cb->args[1] = if_idx;
2429
2430 return skb->len;
2431}
2432
2433static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2434{
2435 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002437 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002438
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002439 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002440 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002441 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002442
Eric W. Biederman15e47302012-09-07 20:12:54 +00002443 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002444 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002445 nlmsg_free(msg);
2446 return -ENOBUFS;
2447 }
Johannes Berg55682962007-09-20 13:09:35 -04002448
Johannes Berg134e6372009-07-10 09:51:34 +00002449 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002450}
2451
Michael Wu66f7ac52008-01-31 19:48:22 +01002452static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2453 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2454 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2455 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2456 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2457 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002458 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002459};
2460
2461static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2462{
2463 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2464 int flag;
2465
2466 *mntrflags = 0;
2467
2468 if (!nla)
2469 return -EINVAL;
2470
2471 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2472 nla, mntr_flags_policy))
2473 return -EINVAL;
2474
2475 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2476 if (flags[flag])
2477 *mntrflags |= (1<<flag);
2478
2479 return 0;
2480}
2481
Johannes Berg9bc383d2009-11-19 11:55:19 +01002482static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002483 struct net_device *netdev, u8 use_4addr,
2484 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002485{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002486 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002487 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002488 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002489 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002490 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002491
2492 switch (iftype) {
2493 case NL80211_IFTYPE_AP_VLAN:
2494 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2495 return 0;
2496 break;
2497 case NL80211_IFTYPE_STATION:
2498 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2499 return 0;
2500 break;
2501 default:
2502 break;
2503 }
2504
2505 return -EOPNOTSUPP;
2506}
2507
Johannes Berg55682962007-09-20 13:09:35 -04002508static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2509{
Johannes Berg4c476992010-10-04 21:36:35 +02002510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002511 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002512 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002513 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002514 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002515 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002516 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002517
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002518 memset(&params, 0, sizeof(params));
2519
Johannes Berg04a773a2009-04-19 21:24:32 +02002520 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002521
Johannes Berg723b0382008-09-16 20:22:09 +02002522 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002523 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002524 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002525 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002526 if (ntype > NL80211_IFTYPE_MAX)
2527 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002528 }
2529
Johannes Berg92ffe052008-09-16 20:39:36 +02002530 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002531 struct wireless_dev *wdev = dev->ieee80211_ptr;
2532
Johannes Berg4c476992010-10-04 21:36:35 +02002533 if (ntype != NL80211_IFTYPE_MESH_POINT)
2534 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002535 if (netif_running(dev))
2536 return -EBUSY;
2537
2538 wdev_lock(wdev);
2539 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2540 IEEE80211_MAX_MESH_ID_LEN);
2541 wdev->mesh_id_up_len =
2542 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2543 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2544 wdev->mesh_id_up_len);
2545 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002546 }
2547
Felix Fietkau8b787642009-11-10 18:53:10 +01002548 if (info->attrs[NL80211_ATTR_4ADDR]) {
2549 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2550 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002551 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002552 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002553 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002554 } else {
2555 params.use_4addr = -1;
2556 }
2557
Johannes Berg92ffe052008-09-16 20:39:36 +02002558 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002559 if (ntype != NL80211_IFTYPE_MONITOR)
2560 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002561 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2562 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002563 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002564 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002565
2566 flags = &_flags;
2567 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002568 }
Johannes Berg3b858752009-03-12 09:55:09 +01002569
Luciano Coelho18003292013-08-29 13:26:57 +03002570 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002571 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2572 return -EOPNOTSUPP;
2573
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002574 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002575 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002576 else
2577 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002578
Johannes Berg9bc383d2009-11-19 11:55:19 +01002579 if (!err && params.use_4addr != -1)
2580 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2581
Johannes Berg55682962007-09-20 13:09:35 -04002582 return err;
2583}
2584
2585static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2586{
Johannes Berg4c476992010-10-04 21:36:35 +02002587 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002588 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002589 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002590 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002591 int err;
2592 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002593 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002594
Johannes Berg78f22b62014-03-24 17:57:27 +01002595 /* to avoid failing a new interface creation due to pending removal */
2596 cfg80211_destroy_ifaces(rdev);
2597
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002598 memset(&params, 0, sizeof(params));
2599
Johannes Berg55682962007-09-20 13:09:35 -04002600 if (!info->attrs[NL80211_ATTR_IFNAME])
2601 return -EINVAL;
2602
2603 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2604 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2605 if (type > NL80211_IFTYPE_MAX)
2606 return -EINVAL;
2607 }
2608
Johannes Berg79c97e92009-07-07 03:56:12 +02002609 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002610 !(rdev->wiphy.interface_modes & (1 << type)))
2611 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002612
Ben Greeare8f479b2014-10-22 12:23:05 -07002613 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2614 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2615 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002616 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2617 ETH_ALEN);
2618 if (!is_valid_ether_addr(params.macaddr))
2619 return -EADDRNOTAVAIL;
2620 }
2621
Johannes Berg9bc383d2009-11-19 11:55:19 +01002622 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002623 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002624 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002625 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002626 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002627 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002628
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002629 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2630 if (!msg)
2631 return -ENOMEM;
2632
Michael Wu66f7ac52008-01-31 19:48:22 +01002633 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2634 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2635 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002636
Luciano Coelho18003292013-08-29 13:26:57 +03002637 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002638 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2639 return -EOPNOTSUPP;
2640
Hila Gonene35e4d22012-06-27 17:19:42 +03002641 wdev = rdev_add_virtual_intf(rdev,
2642 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2643 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002644 if (IS_ERR(wdev)) {
2645 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002646 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002647 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002648
Johannes Berg78f22b62014-03-24 17:57:27 +01002649 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2650 wdev->owner_nlportid = info->snd_portid;
2651
Johannes Berg98104fde2012-06-16 00:19:54 +02002652 switch (type) {
2653 case NL80211_IFTYPE_MESH_POINT:
2654 if (!info->attrs[NL80211_ATTR_MESH_ID])
2655 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002656 wdev_lock(wdev);
2657 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2658 IEEE80211_MAX_MESH_ID_LEN);
2659 wdev->mesh_id_up_len =
2660 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2661 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2662 wdev->mesh_id_up_len);
2663 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002664 break;
2665 case NL80211_IFTYPE_P2P_DEVICE:
2666 /*
2667 * P2P Device doesn't have a netdev, so doesn't go
2668 * through the netdev notifier and must be added here
2669 */
2670 mutex_init(&wdev->mtx);
2671 INIT_LIST_HEAD(&wdev->event_list);
2672 spin_lock_init(&wdev->event_lock);
2673 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2674 spin_lock_init(&wdev->mgmt_registrations_lock);
2675
Johannes Berg98104fde2012-06-16 00:19:54 +02002676 wdev->identifier = ++rdev->wdev_id;
2677 list_add_rcu(&wdev->list, &rdev->wdev_list);
2678 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002679 break;
2680 default:
2681 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002682 }
2683
Eric W. Biederman15e47302012-09-07 20:12:54 +00002684 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002685 rdev, wdev) < 0) {
2686 nlmsg_free(msg);
2687 return -ENOBUFS;
2688 }
2689
2690 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002691}
2692
2693static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2694{
Johannes Berg4c476992010-10-04 21:36:35 +02002695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002696 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002697
Johannes Berg4c476992010-10-04 21:36:35 +02002698 if (!rdev->ops->del_virtual_intf)
2699 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002700
Johannes Berg84efbb82012-06-16 00:00:26 +02002701 /*
2702 * If we remove a wireless device without a netdev then clear
2703 * user_ptr[1] so that nl80211_post_doit won't dereference it
2704 * to check if it needs to do dev_put(). Otherwise it crashes
2705 * since the wdev has been freed, unlike with a netdev where
2706 * we need the dev_put() for the netdev to really be freed.
2707 */
2708 if (!wdev->netdev)
2709 info->user_ptr[1] = NULL;
2710
Hila Gonene35e4d22012-06-27 17:19:42 +03002711 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002712}
2713
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002714static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2715{
2716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2717 struct net_device *dev = info->user_ptr[1];
2718 u16 noack_map;
2719
2720 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2721 return -EINVAL;
2722
2723 if (!rdev->ops->set_noack_map)
2724 return -EOPNOTSUPP;
2725
2726 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2727
Hila Gonene35e4d22012-06-27 17:19:42 +03002728 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002729}
2730
Johannes Berg41ade002007-12-19 02:03:29 +01002731struct get_key_cookie {
2732 struct sk_buff *msg;
2733 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002734 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002735};
2736
2737static void get_key_callback(void *c, struct key_params *params)
2738{
Johannes Bergb9454e82009-07-08 13:29:08 +02002739 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002740 struct get_key_cookie *cookie = c;
2741
David S. Miller9360ffd2012-03-29 04:41:26 -04002742 if ((params->key &&
2743 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2744 params->key_len, params->key)) ||
2745 (params->seq &&
2746 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2747 params->seq_len, params->seq)) ||
2748 (params->cipher &&
2749 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2750 params->cipher)))
2751 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002752
Johannes Bergb9454e82009-07-08 13:29:08 +02002753 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2754 if (!key)
2755 goto nla_put_failure;
2756
David S. Miller9360ffd2012-03-29 04:41:26 -04002757 if ((params->key &&
2758 nla_put(cookie->msg, NL80211_KEY_DATA,
2759 params->key_len, params->key)) ||
2760 (params->seq &&
2761 nla_put(cookie->msg, NL80211_KEY_SEQ,
2762 params->seq_len, params->seq)) ||
2763 (params->cipher &&
2764 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2765 params->cipher)))
2766 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002767
David S. Miller9360ffd2012-03-29 04:41:26 -04002768 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2769 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002770
2771 nla_nest_end(cookie->msg, key);
2772
Johannes Berg41ade002007-12-19 02:03:29 +01002773 return;
2774 nla_put_failure:
2775 cookie->error = 1;
2776}
2777
2778static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2779{
Johannes Berg4c476992010-10-04 21:36:35 +02002780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002781 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002782 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002783 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002784 const u8 *mac_addr = NULL;
2785 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002786 struct get_key_cookie cookie = {
2787 .error = 0,
2788 };
2789 void *hdr;
2790 struct sk_buff *msg;
2791
2792 if (info->attrs[NL80211_ATTR_KEY_IDX])
2793 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2794
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002795 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002796 return -EINVAL;
2797
2798 if (info->attrs[NL80211_ATTR_MAC])
2799 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2800
Johannes Berge31b8212010-10-05 19:39:30 +02002801 pairwise = !!mac_addr;
2802 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2803 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2804 if (kt >= NUM_NL80211_KEYTYPES)
2805 return -EINVAL;
2806 if (kt != NL80211_KEYTYPE_GROUP &&
2807 kt != NL80211_KEYTYPE_PAIRWISE)
2808 return -EINVAL;
2809 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2810 }
2811
Johannes Berg4c476992010-10-04 21:36:35 +02002812 if (!rdev->ops->get_key)
2813 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002814
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002815 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002816 if (!msg)
2817 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002818
Eric W. Biederman15e47302012-09-07 20:12:54 +00002819 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002820 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002821 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002822 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002823
2824 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002825 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002826
David S. Miller9360ffd2012-03-29 04:41:26 -04002827 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2828 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2829 goto nla_put_failure;
2830 if (mac_addr &&
2831 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2832 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002833
Johannes Berge31b8212010-10-05 19:39:30 +02002834 if (pairwise && mac_addr &&
2835 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2836 return -ENOENT;
2837
Hila Gonene35e4d22012-06-27 17:19:42 +03002838 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2839 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002840
2841 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002842 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002843
2844 if (cookie.error)
2845 goto nla_put_failure;
2846
2847 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002848 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002849
2850 nla_put_failure:
2851 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002852 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002853 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002854 return err;
2855}
2856
2857static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2858{
Johannes Berg4c476992010-10-04 21:36:35 +02002859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002860 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002861 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002862 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002863
Johannes Bergb9454e82009-07-08 13:29:08 +02002864 err = nl80211_parse_key(info, &key);
2865 if (err)
2866 return err;
2867
2868 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002869 return -EINVAL;
2870
Johannes Bergb9454e82009-07-08 13:29:08 +02002871 /* only support setting default key */
2872 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002873 return -EINVAL;
2874
Johannes Bergfffd0932009-07-08 14:22:54 +02002875 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002876
2877 if (key.def) {
2878 if (!rdev->ops->set_default_key) {
2879 err = -EOPNOTSUPP;
2880 goto out;
2881 }
2882
2883 err = nl80211_key_allowed(dev->ieee80211_ptr);
2884 if (err)
2885 goto out;
2886
Hila Gonene35e4d22012-06-27 17:19:42 +03002887 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002888 key.def_uni, key.def_multi);
2889
2890 if (err)
2891 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002892
Johannes Berg3d23e342009-09-29 23:27:28 +02002893#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002894 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002895#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002896 } else {
2897 if (key.def_uni || !key.def_multi) {
2898 err = -EINVAL;
2899 goto out;
2900 }
2901
2902 if (!rdev->ops->set_default_mgmt_key) {
2903 err = -EOPNOTSUPP;
2904 goto out;
2905 }
2906
2907 err = nl80211_key_allowed(dev->ieee80211_ptr);
2908 if (err)
2909 goto out;
2910
Hila Gonene35e4d22012-06-27 17:19:42 +03002911 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002912 if (err)
2913 goto out;
2914
2915#ifdef CONFIG_CFG80211_WEXT
2916 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2917#endif
2918 }
2919
2920 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002921 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002922
Johannes Berg41ade002007-12-19 02:03:29 +01002923 return err;
2924}
2925
2926static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2927{
Johannes Berg4c476992010-10-04 21:36:35 +02002928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002929 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002930 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002931 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002932 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002933
Johannes Bergb9454e82009-07-08 13:29:08 +02002934 err = nl80211_parse_key(info, &key);
2935 if (err)
2936 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002937
Johannes Bergb9454e82009-07-08 13:29:08 +02002938 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002939 return -EINVAL;
2940
Johannes Berg41ade002007-12-19 02:03:29 +01002941 if (info->attrs[NL80211_ATTR_MAC])
2942 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2943
Johannes Berge31b8212010-10-05 19:39:30 +02002944 if (key.type == -1) {
2945 if (mac_addr)
2946 key.type = NL80211_KEYTYPE_PAIRWISE;
2947 else
2948 key.type = NL80211_KEYTYPE_GROUP;
2949 }
2950
2951 /* for now */
2952 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2953 key.type != NL80211_KEYTYPE_GROUP)
2954 return -EINVAL;
2955
Johannes Berg4c476992010-10-04 21:36:35 +02002956 if (!rdev->ops->add_key)
2957 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002958
Johannes Berge31b8212010-10-05 19:39:30 +02002959 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2960 key.type == NL80211_KEYTYPE_PAIRWISE,
2961 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002962 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002963
2964 wdev_lock(dev->ieee80211_ptr);
2965 err = nl80211_key_allowed(dev->ieee80211_ptr);
2966 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002967 err = rdev_add_key(rdev, dev, key.idx,
2968 key.type == NL80211_KEYTYPE_PAIRWISE,
2969 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002970 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002971
Johannes Berg41ade002007-12-19 02:03:29 +01002972 return err;
2973}
2974
2975static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2976{
Johannes Berg4c476992010-10-04 21:36:35 +02002977 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002978 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002979 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002980 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002981 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002982
Johannes Bergb9454e82009-07-08 13:29:08 +02002983 err = nl80211_parse_key(info, &key);
2984 if (err)
2985 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002986
2987 if (info->attrs[NL80211_ATTR_MAC])
2988 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2989
Johannes Berge31b8212010-10-05 19:39:30 +02002990 if (key.type == -1) {
2991 if (mac_addr)
2992 key.type = NL80211_KEYTYPE_PAIRWISE;
2993 else
2994 key.type = NL80211_KEYTYPE_GROUP;
2995 }
2996
2997 /* for now */
2998 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2999 key.type != NL80211_KEYTYPE_GROUP)
3000 return -EINVAL;
3001
Johannes Berg4c476992010-10-04 21:36:35 +02003002 if (!rdev->ops->del_key)
3003 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003004
Johannes Bergfffd0932009-07-08 14:22:54 +02003005 wdev_lock(dev->ieee80211_ptr);
3006 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003007
3008 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3009 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3010 err = -ENOENT;
3011
Johannes Bergfffd0932009-07-08 14:22:54 +02003012 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003013 err = rdev_del_key(rdev, dev, key.idx,
3014 key.type == NL80211_KEYTYPE_PAIRWISE,
3015 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003016
Johannes Berg3d23e342009-09-29 23:27:28 +02003017#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003018 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003019 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003020 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003021 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003022 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3023 }
3024#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003025 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003026
Johannes Berg41ade002007-12-19 02:03:29 +01003027 return err;
3028}
3029
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303030/* This function returns an error or the number of nested attributes */
3031static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3032{
3033 struct nlattr *attr;
3034 int n_entries = 0, tmp;
3035
3036 nla_for_each_nested(attr, nl_attr, tmp) {
3037 if (nla_len(attr) != ETH_ALEN)
3038 return -EINVAL;
3039
3040 n_entries++;
3041 }
3042
3043 return n_entries;
3044}
3045
3046/*
3047 * This function parses ACL information and allocates memory for ACL data.
3048 * On successful return, the calling function is responsible to free the
3049 * ACL buffer returned by this function.
3050 */
3051static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3052 struct genl_info *info)
3053{
3054 enum nl80211_acl_policy acl_policy;
3055 struct nlattr *attr;
3056 struct cfg80211_acl_data *acl;
3057 int i = 0, n_entries, tmp;
3058
3059 if (!wiphy->max_acl_mac_addrs)
3060 return ERR_PTR(-EOPNOTSUPP);
3061
3062 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3063 return ERR_PTR(-EINVAL);
3064
3065 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3066 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3067 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3068 return ERR_PTR(-EINVAL);
3069
3070 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3071 return ERR_PTR(-EINVAL);
3072
3073 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3074 if (n_entries < 0)
3075 return ERR_PTR(n_entries);
3076
3077 if (n_entries > wiphy->max_acl_mac_addrs)
3078 return ERR_PTR(-ENOTSUPP);
3079
3080 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3081 GFP_KERNEL);
3082 if (!acl)
3083 return ERR_PTR(-ENOMEM);
3084
3085 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3086 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3087 i++;
3088 }
3089
3090 acl->n_acl_entries = n_entries;
3091 acl->acl_policy = acl_policy;
3092
3093 return acl;
3094}
3095
3096static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3097{
3098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3099 struct net_device *dev = info->user_ptr[1];
3100 struct cfg80211_acl_data *acl;
3101 int err;
3102
3103 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3104 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3105 return -EOPNOTSUPP;
3106
3107 if (!dev->ieee80211_ptr->beacon_interval)
3108 return -EINVAL;
3109
3110 acl = parse_acl_data(&rdev->wiphy, info);
3111 if (IS_ERR(acl))
3112 return PTR_ERR(acl);
3113
3114 err = rdev_set_mac_acl(rdev, dev, acl);
3115
3116 kfree(acl);
3117
3118 return err;
3119}
3120
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003121static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003122 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003123{
Johannes Berg88600202012-02-13 15:17:18 +01003124 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003125
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003126 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3127 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3128 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3129 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003130 return -EINVAL;
3131
Johannes Berg88600202012-02-13 15:17:18 +01003132 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003133
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003134 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3135 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3136 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003137 if (!bcn->head_len)
3138 return -EINVAL;
3139 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003140 }
3141
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003142 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3143 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3144 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003145 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003146 }
3147
Johannes Berg4c476992010-10-04 21:36:35 +02003148 if (!haveinfo)
3149 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003150
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003151 if (attrs[NL80211_ATTR_IE]) {
3152 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3153 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003154 }
3155
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003156 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003157 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003158 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003159 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003160 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003161 }
3162
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003163 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003164 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003165 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003166 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003167 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003168 }
3169
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003170 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3171 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3172 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003173 }
3174
Johannes Berg88600202012-02-13 15:17:18 +01003175 return 0;
3176}
3177
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003178static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3179 struct cfg80211_ap_settings *params)
3180{
3181 struct wireless_dev *wdev;
3182 bool ret = false;
3183
Johannes Berg89a54e42012-06-15 14:33:17 +02003184 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003185 if (wdev->iftype != NL80211_IFTYPE_AP &&
3186 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3187 continue;
3188
Johannes Berg683b6d32012-11-08 21:25:48 +01003189 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003190 continue;
3191
Johannes Berg683b6d32012-11-08 21:25:48 +01003192 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003193 ret = true;
3194 break;
3195 }
3196
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003197 return ret;
3198}
3199
Jouni Malinene39e5b52012-09-30 19:29:39 +03003200static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3201 enum nl80211_auth_type auth_type,
3202 enum nl80211_commands cmd)
3203{
3204 if (auth_type > NL80211_AUTHTYPE_MAX)
3205 return false;
3206
3207 switch (cmd) {
3208 case NL80211_CMD_AUTHENTICATE:
3209 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3210 auth_type == NL80211_AUTHTYPE_SAE)
3211 return false;
3212 return true;
3213 case NL80211_CMD_CONNECT:
3214 case NL80211_CMD_START_AP:
3215 /* SAE not supported yet */
3216 if (auth_type == NL80211_AUTHTYPE_SAE)
3217 return false;
3218 return true;
3219 default:
3220 return false;
3221 }
3222}
3223
Johannes Berg88600202012-02-13 15:17:18 +01003224static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3225{
3226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3227 struct net_device *dev = info->user_ptr[1];
3228 struct wireless_dev *wdev = dev->ieee80211_ptr;
3229 struct cfg80211_ap_settings params;
3230 int err;
3231
3232 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3233 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3234 return -EOPNOTSUPP;
3235
3236 if (!rdev->ops->start_ap)
3237 return -EOPNOTSUPP;
3238
3239 if (wdev->beacon_interval)
3240 return -EALREADY;
3241
3242 memset(&params, 0, sizeof(params));
3243
3244 /* these are required for START_AP */
3245 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3246 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3247 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3248 return -EINVAL;
3249
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003250 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003251 if (err)
3252 return err;
3253
3254 params.beacon_interval =
3255 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3256 params.dtim_period =
3257 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3258
3259 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3260 if (err)
3261 return err;
3262
3263 /*
3264 * In theory, some of these attributes should be required here
3265 * but since they were not used when the command was originally
3266 * added, keep them optional for old user space programs to let
3267 * them continue to work with drivers that do not need the
3268 * additional information -- drivers must check!
3269 */
3270 if (info->attrs[NL80211_ATTR_SSID]) {
3271 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3272 params.ssid_len =
3273 nla_len(info->attrs[NL80211_ATTR_SSID]);
3274 if (params.ssid_len == 0 ||
3275 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3276 return -EINVAL;
3277 }
3278
3279 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3280 params.hidden_ssid = nla_get_u32(
3281 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3282 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3283 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3284 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3285 return -EINVAL;
3286 }
3287
3288 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3289
3290 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3291 params.auth_type = nla_get_u32(
3292 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003293 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3294 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003295 return -EINVAL;
3296 } else
3297 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3298
3299 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3300 NL80211_MAX_NR_CIPHER_SUITES);
3301 if (err)
3302 return err;
3303
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303304 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3305 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3306 return -EOPNOTSUPP;
3307 params.inactivity_timeout = nla_get_u16(
3308 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3309 }
3310
Johannes Berg53cabad2012-11-14 15:17:28 +01003311 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3312 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3313 return -EINVAL;
3314 params.p2p_ctwindow =
3315 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3316 if (params.p2p_ctwindow > 127)
3317 return -EINVAL;
3318 if (params.p2p_ctwindow != 0 &&
3319 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3320 return -EINVAL;
3321 }
3322
3323 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3324 u8 tmp;
3325
3326 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3327 return -EINVAL;
3328 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3329 if (tmp > 1)
3330 return -EINVAL;
3331 params.p2p_opp_ps = tmp;
3332 if (params.p2p_opp_ps != 0 &&
3333 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3334 return -EINVAL;
3335 }
3336
Johannes Bergaa430da2012-05-16 23:50:18 +02003337 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003338 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3339 if (err)
3340 return err;
3341 } else if (wdev->preset_chandef.chan) {
3342 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003343 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003344 return -EINVAL;
3345
Ilan Peer174e0cd2014-02-23 09:13:01 +02003346 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3347 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003348 return -EINVAL;
3349
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303350 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3351 params.acl = parse_acl_data(&rdev->wiphy, info);
3352 if (IS_ERR(params.acl))
3353 return PTR_ERR(params.acl);
3354 }
3355
Eliad Peller18998c32014-09-10 14:07:34 +03003356 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3357 params.smps_mode =
3358 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3359 switch (params.smps_mode) {
3360 case NL80211_SMPS_OFF:
3361 break;
3362 case NL80211_SMPS_STATIC:
3363 if (!(rdev->wiphy.features &
3364 NL80211_FEATURE_STATIC_SMPS))
3365 return -EINVAL;
3366 break;
3367 case NL80211_SMPS_DYNAMIC:
3368 if (!(rdev->wiphy.features &
3369 NL80211_FEATURE_DYNAMIC_SMPS))
3370 return -EINVAL;
3371 break;
3372 default:
3373 return -EINVAL;
3374 }
3375 } else {
3376 params.smps_mode = NL80211_SMPS_OFF;
3377 }
3378
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003379 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003380 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003381 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003382 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003383 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003384 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003385 wdev->ssid_len = params.ssid_len;
3386 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003387 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003388 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303389
3390 kfree(params.acl);
3391
Johannes Berg56d18932011-05-09 18:41:15 +02003392 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003393}
3394
Johannes Berg88600202012-02-13 15:17:18 +01003395static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3396{
3397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3398 struct net_device *dev = info->user_ptr[1];
3399 struct wireless_dev *wdev = dev->ieee80211_ptr;
3400 struct cfg80211_beacon_data params;
3401 int err;
3402
3403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3404 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3405 return -EOPNOTSUPP;
3406
3407 if (!rdev->ops->change_beacon)
3408 return -EOPNOTSUPP;
3409
3410 if (!wdev->beacon_interval)
3411 return -EINVAL;
3412
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003413 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003414 if (err)
3415 return err;
3416
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003417 wdev_lock(wdev);
3418 err = rdev_change_beacon(rdev, dev, &params);
3419 wdev_unlock(wdev);
3420
3421 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003422}
3423
3424static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003425{
Johannes Berg4c476992010-10-04 21:36:35 +02003426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3427 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003428
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003429 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003430}
3431
Johannes Berg5727ef12007-12-19 02:03:34 +01003432static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3433 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3434 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3435 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003436 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003437 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003438 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003439};
3440
Johannes Bergeccb8e82009-05-11 21:57:56 +03003441static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003442 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003443 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003444{
3445 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003446 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003447 int flag;
3448
Johannes Bergeccb8e82009-05-11 21:57:56 +03003449 /*
3450 * Try parsing the new attribute first so userspace
3451 * can specify both for older kernels.
3452 */
3453 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3454 if (nla) {
3455 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003456
Johannes Bergeccb8e82009-05-11 21:57:56 +03003457 sta_flags = nla_data(nla);
3458 params->sta_flags_mask = sta_flags->mask;
3459 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003460 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003461 if ((params->sta_flags_mask |
3462 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3463 return -EINVAL;
3464 return 0;
3465 }
3466
3467 /* if present, parse the old attribute */
3468
3469 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003470 if (!nla)
3471 return 0;
3472
3473 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3474 nla, sta_flags_policy))
3475 return -EINVAL;
3476
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003477 /*
3478 * Only allow certain flags for interface types so that
3479 * other attributes are silently ignored. Remember that
3480 * this is backward compatibility code with old userspace
3481 * and shouldn't be hit in other cases anyway.
3482 */
3483 switch (iftype) {
3484 case NL80211_IFTYPE_AP:
3485 case NL80211_IFTYPE_AP_VLAN:
3486 case NL80211_IFTYPE_P2P_GO:
3487 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3488 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3489 BIT(NL80211_STA_FLAG_WME) |
3490 BIT(NL80211_STA_FLAG_MFP);
3491 break;
3492 case NL80211_IFTYPE_P2P_CLIENT:
3493 case NL80211_IFTYPE_STATION:
3494 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3495 BIT(NL80211_STA_FLAG_TDLS_PEER);
3496 break;
3497 case NL80211_IFTYPE_MESH_POINT:
3498 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3499 BIT(NL80211_STA_FLAG_MFP) |
3500 BIT(NL80211_STA_FLAG_AUTHORIZED);
3501 default:
3502 return -EINVAL;
3503 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003504
Johannes Berg3383b5a2012-05-10 20:14:43 +02003505 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3506 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003507 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003508
Johannes Berg3383b5a2012-05-10 20:14:43 +02003509 /* no longer support new API additions in old API */
3510 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3511 return -EINVAL;
3512 }
3513 }
3514
Johannes Berg5727ef12007-12-19 02:03:34 +01003515 return 0;
3516}
3517
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003518static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3519 int attr)
3520{
3521 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003522 u32 bitrate;
3523 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003524
3525 rate = nla_nest_start(msg, attr);
3526 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003527 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003528
3529 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3530 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003531 /* report 16-bit bitrate only if we can */
3532 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003533 if (bitrate > 0 &&
3534 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3535 return false;
3536 if (bitrate_compat > 0 &&
3537 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3538 return false;
3539
3540 if (info->flags & RATE_INFO_FLAGS_MCS) {
3541 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3542 return false;
3543 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3544 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3545 return false;
3546 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3547 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3548 return false;
3549 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3550 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3551 return false;
3552 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3553 return false;
3554 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3555 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3556 return false;
3557 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3558 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3559 return false;
3560 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3561 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3562 return false;
3563 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3564 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3565 return false;
3566 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3567 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3568 return false;
3569 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003570
3571 nla_nest_end(msg, rate);
3572 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003573}
3574
Felix Fietkau119363c2013-04-22 16:29:30 +02003575static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3576 int id)
3577{
3578 void *attr;
3579 int i = 0;
3580
3581 if (!mask)
3582 return true;
3583
3584 attr = nla_nest_start(msg, id);
3585 if (!attr)
3586 return false;
3587
3588 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3589 if (!(mask & BIT(i)))
3590 continue;
3591
3592 if (nla_put_u8(msg, i, signal[i]))
3593 return false;
3594 }
3595
3596 nla_nest_end(msg, attr);
3597
3598 return true;
3599}
3600
Eric W. Biederman15e47302012-09-07 20:12:54 +00003601static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003602 int flags,
3603 struct cfg80211_registered_device *rdev,
3604 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003605 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003606{
3607 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003608 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003609
Eric W. Biederman15e47302012-09-07 20:12:54 +00003610 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003611 if (!hdr)
3612 return -1;
3613
David S. Miller9360ffd2012-03-29 04:41:26 -04003614 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3615 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3616 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3617 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003618
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003619 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3620 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003621 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003622 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3623 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3624 sinfo->connected_time))
3625 goto nla_put_failure;
3626 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3627 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3628 sinfo->inactive_time))
3629 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003630 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3631 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003632 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003633 (u32)sinfo->rx_bytes))
3634 goto nla_put_failure;
3635 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003636 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003637 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3638 (u32)sinfo->tx_bytes))
3639 goto nla_put_failure;
3640 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3641 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003642 sinfo->rx_bytes))
3643 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003644 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3645 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003646 sinfo->tx_bytes))
3647 goto nla_put_failure;
3648 if ((sinfo->filled & STATION_INFO_LLID) &&
3649 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3650 goto nla_put_failure;
3651 if ((sinfo->filled & STATION_INFO_PLID) &&
3652 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3653 goto nla_put_failure;
3654 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3655 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3656 sinfo->plink_state))
3657 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003658 switch (rdev->wiphy.signal_type) {
3659 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003660 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3661 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3662 sinfo->signal))
3663 goto nla_put_failure;
3664 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3665 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3666 sinfo->signal_avg))
3667 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003668 break;
3669 default:
3670 break;
3671 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003672 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3673 if (!nl80211_put_signal(msg, sinfo->chains,
3674 sinfo->chain_signal,
3675 NL80211_STA_INFO_CHAIN_SIGNAL))
3676 goto nla_put_failure;
3677 }
3678 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3679 if (!nl80211_put_signal(msg, sinfo->chains,
3680 sinfo->chain_signal_avg,
3681 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3682 goto nla_put_failure;
3683 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003684 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003685 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3686 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003687 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003688 }
3689 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3690 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3691 NL80211_STA_INFO_RX_BITRATE))
3692 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003693 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003694 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3695 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3696 sinfo->rx_packets))
3697 goto nla_put_failure;
3698 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3699 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3700 sinfo->tx_packets))
3701 goto nla_put_failure;
3702 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3703 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3704 sinfo->tx_retries))
3705 goto nla_put_failure;
3706 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3707 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3708 sinfo->tx_failed))
3709 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003710 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3711 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3712 sinfo->expected_throughput))
3713 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003714 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3715 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3716 sinfo->beacon_loss_count))
3717 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003718 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3719 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3720 sinfo->local_pm))
3721 goto nla_put_failure;
3722 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3723 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3724 sinfo->peer_pm))
3725 goto nla_put_failure;
3726 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3727 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3728 sinfo->nonpeer_pm))
3729 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003730 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3731 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3732 if (!bss_param)
3733 goto nla_put_failure;
3734
David S. Miller9360ffd2012-03-29 04:41:26 -04003735 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3736 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3737 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3738 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3739 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3740 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3741 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3742 sinfo->bss_param.dtim_period) ||
3743 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3744 sinfo->bss_param.beacon_interval))
3745 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003746
3747 nla_nest_end(msg, bss_param);
3748 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003749 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3750 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3751 sizeof(struct nl80211_sta_flag_update),
3752 &sinfo->sta_flags))
3753 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003754 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3755 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3756 sinfo->t_offset))
3757 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003758 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003759
David S. Miller9360ffd2012-03-29 04:41:26 -04003760 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3761 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3762 sinfo->assoc_req_ies))
3763 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003764
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003765 return genlmsg_end(msg, hdr);
3766
3767 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003768 genlmsg_cancel(msg, hdr);
3769 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003770}
3771
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003772static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003773 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003774{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003775 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003776 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003777 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003778 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003779 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003780 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003781
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003782 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003783 if (err)
3784 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003785
Johannes Berg97990a02013-04-19 01:02:55 +02003786 if (!wdev->netdev) {
3787 err = -EINVAL;
3788 goto out_err;
3789 }
3790
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003791 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003792 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003793 goto out_err;
3794 }
3795
Johannes Bergbba95fe2008-07-29 13:22:51 +02003796 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003797 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003798 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003799 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003800 if (err == -ENOENT)
3801 break;
3802 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003803 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003804
3805 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003806 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003807 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003808 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003809 &sinfo) < 0)
3810 goto out;
3811
3812 sta_idx++;
3813 }
3814
3815
3816 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003817 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003818 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003819 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003820 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003821
3822 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003823}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003824
Johannes Berg5727ef12007-12-19 02:03:34 +01003825static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3826{
Johannes Berg4c476992010-10-04 21:36:35 +02003827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3828 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003829 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003830 struct sk_buff *msg;
3831 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003832 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003833
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003834 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003835
3836 if (!info->attrs[NL80211_ATTR_MAC])
3837 return -EINVAL;
3838
3839 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3840
Johannes Berg4c476992010-10-04 21:36:35 +02003841 if (!rdev->ops->get_station)
3842 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003843
Hila Gonene35e4d22012-06-27 17:19:42 +03003844 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003845 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003846 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003847
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003848 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003849 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003850 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003851
Eric W. Biederman15e47302012-09-07 20:12:54 +00003852 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003853 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003854 nlmsg_free(msg);
3855 return -ENOBUFS;
3856 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003857
Johannes Berg4c476992010-10-04 21:36:35 +02003858 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003859}
3860
Johannes Berg77ee7c82013-02-15 00:48:33 +01003861int cfg80211_check_station_change(struct wiphy *wiphy,
3862 struct station_parameters *params,
3863 enum cfg80211_station_type statype)
3864{
3865 if (params->listen_interval != -1)
3866 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003867 if (params->aid &&
3868 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003869 return -EINVAL;
3870
3871 /* When you run into this, adjust the code below for the new flag */
3872 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3873
3874 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003875 case CFG80211_STA_MESH_PEER_KERNEL:
3876 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003877 /*
3878 * No ignoring the TDLS flag here -- the userspace mesh
3879 * code doesn't have the bug of including TDLS in the
3880 * mask everywhere.
3881 */
3882 if (params->sta_flags_mask &
3883 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3884 BIT(NL80211_STA_FLAG_MFP) |
3885 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3886 return -EINVAL;
3887 break;
3888 case CFG80211_STA_TDLS_PEER_SETUP:
3889 case CFG80211_STA_TDLS_PEER_ACTIVE:
3890 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3891 return -EINVAL;
3892 /* ignore since it can't change */
3893 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3894 break;
3895 default:
3896 /* disallow mesh-specific things */
3897 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3898 return -EINVAL;
3899 if (params->local_pm)
3900 return -EINVAL;
3901 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3902 return -EINVAL;
3903 }
3904
3905 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3906 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3907 /* TDLS can't be set, ... */
3908 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3909 return -EINVAL;
3910 /*
3911 * ... but don't bother the driver with it. This works around
3912 * a hostapd/wpa_supplicant issue -- it always includes the
3913 * TLDS_PEER flag in the mask even for AP mode.
3914 */
3915 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3916 }
3917
3918 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3919 /* reject other things that can't change */
3920 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3921 return -EINVAL;
3922 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3923 return -EINVAL;
3924 if (params->supported_rates)
3925 return -EINVAL;
3926 if (params->ext_capab || params->ht_capa || params->vht_capa)
3927 return -EINVAL;
3928 }
3929
3930 if (statype != CFG80211_STA_AP_CLIENT) {
3931 if (params->vlan)
3932 return -EINVAL;
3933 }
3934
3935 switch (statype) {
3936 case CFG80211_STA_AP_MLME_CLIENT:
3937 /* Use this only for authorizing/unauthorizing a station */
3938 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3939 return -EOPNOTSUPP;
3940 break;
3941 case CFG80211_STA_AP_CLIENT:
3942 /* accept only the listed bits */
3943 if (params->sta_flags_mask &
3944 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3945 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3946 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3947 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3948 BIT(NL80211_STA_FLAG_WME) |
3949 BIT(NL80211_STA_FLAG_MFP)))
3950 return -EINVAL;
3951
3952 /* but authenticated/associated only if driver handles it */
3953 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3954 params->sta_flags_mask &
3955 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3956 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3957 return -EINVAL;
3958 break;
3959 case CFG80211_STA_IBSS:
3960 case CFG80211_STA_AP_STA:
3961 /* reject any changes other than AUTHORIZED */
3962 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3963 return -EINVAL;
3964 break;
3965 case CFG80211_STA_TDLS_PEER_SETUP:
3966 /* reject any changes other than AUTHORIZED or WME */
3967 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3968 BIT(NL80211_STA_FLAG_WME)))
3969 return -EINVAL;
3970 /* force (at least) rates when authorizing */
3971 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3972 !params->supported_rates)
3973 return -EINVAL;
3974 break;
3975 case CFG80211_STA_TDLS_PEER_ACTIVE:
3976 /* reject any changes */
3977 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003978 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003979 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3980 return -EINVAL;
3981 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003982 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003983 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3984 return -EINVAL;
3985 break;
3986 }
3987
3988 return 0;
3989}
3990EXPORT_SYMBOL(cfg80211_check_station_change);
3991
Johannes Berg5727ef12007-12-19 02:03:34 +01003992/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003993 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003994 */
Johannes Berg80b99892011-11-18 16:23:01 +01003995static struct net_device *get_vlan(struct genl_info *info,
3996 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003997{
Johannes Berg463d0182009-07-14 00:33:35 +02003998 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003999 struct net_device *v;
4000 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004001
Johannes Berg80b99892011-11-18 16:23:01 +01004002 if (!vlanattr)
4003 return NULL;
4004
4005 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4006 if (!v)
4007 return ERR_PTR(-ENODEV);
4008
4009 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4010 ret = -EINVAL;
4011 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004012 }
Johannes Berg80b99892011-11-18 16:23:01 +01004013
Johannes Berg77ee7c82013-02-15 00:48:33 +01004014 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4015 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4016 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4017 ret = -EINVAL;
4018 goto error;
4019 }
4020
Johannes Berg80b99892011-11-18 16:23:01 +01004021 if (!netif_running(v)) {
4022 ret = -ENETDOWN;
4023 goto error;
4024 }
4025
4026 return v;
4027 error:
4028 dev_put(v);
4029 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004030}
4031
Johannes Berg94e860f2014-01-20 23:58:15 +01004032static const struct nla_policy
4033nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004034 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4035 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4036};
4037
Johannes Bergff276692013-02-15 00:09:01 +01004038static int nl80211_parse_sta_wme(struct genl_info *info,
4039 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004040{
Jouni Malinendf881292013-02-14 21:10:54 +02004041 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4042 struct nlattr *nla;
4043 int err;
4044
Jouni Malinendf881292013-02-14 21:10:54 +02004045 /* parse WME attributes if present */
4046 if (!info->attrs[NL80211_ATTR_STA_WME])
4047 return 0;
4048
4049 nla = info->attrs[NL80211_ATTR_STA_WME];
4050 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4051 nl80211_sta_wme_policy);
4052 if (err)
4053 return err;
4054
4055 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4056 params->uapsd_queues = nla_get_u8(
4057 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4058 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4059 return -EINVAL;
4060
4061 if (tb[NL80211_STA_WME_MAX_SP])
4062 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4063
4064 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4065 return -EINVAL;
4066
4067 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4068
4069 return 0;
4070}
4071
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304072static int nl80211_parse_sta_channel_info(struct genl_info *info,
4073 struct station_parameters *params)
4074{
4075 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4076 params->supported_channels =
4077 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4078 params->supported_channels_len =
4079 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4080 /*
4081 * Need to include at least one (first channel, number of
4082 * channels) tuple for each subband, and must have proper
4083 * tuples for the rest of the data as well.
4084 */
4085 if (params->supported_channels_len < 2)
4086 return -EINVAL;
4087 if (params->supported_channels_len % 2)
4088 return -EINVAL;
4089 }
4090
4091 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4092 params->supported_oper_classes =
4093 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4094 params->supported_oper_classes_len =
4095 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4096 /*
4097 * The value of the Length field of the Supported Operating
4098 * Classes element is between 2 and 253.
4099 */
4100 if (params->supported_oper_classes_len < 2 ||
4101 params->supported_oper_classes_len > 253)
4102 return -EINVAL;
4103 }
4104 return 0;
4105}
4106
Johannes Bergff276692013-02-15 00:09:01 +01004107static int nl80211_set_station_tdls(struct genl_info *info,
4108 struct station_parameters *params)
4109{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304110 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004111 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004112 if (info->attrs[NL80211_ATTR_PEER_AID])
4113 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004114 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4115 params->ht_capa =
4116 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4117 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4118 params->vht_capa =
4119 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4120
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304121 err = nl80211_parse_sta_channel_info(info, params);
4122 if (err)
4123 return err;
4124
Johannes Bergff276692013-02-15 00:09:01 +01004125 return nl80211_parse_sta_wme(info, params);
4126}
4127
Johannes Berg5727ef12007-12-19 02:03:34 +01004128static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4129{
Johannes Berg4c476992010-10-04 21:36:35 +02004130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004131 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004132 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004133 u8 *mac_addr;
4134 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004135
4136 memset(&params, 0, sizeof(params));
4137
4138 params.listen_interval = -1;
4139
Johannes Berg77ee7c82013-02-15 00:48:33 +01004140 if (!rdev->ops->change_station)
4141 return -EOPNOTSUPP;
4142
Johannes Berg5727ef12007-12-19 02:03:34 +01004143 if (info->attrs[NL80211_ATTR_STA_AID])
4144 return -EINVAL;
4145
4146 if (!info->attrs[NL80211_ATTR_MAC])
4147 return -EINVAL;
4148
4149 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4150
4151 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4152 params.supported_rates =
4153 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4154 params.supported_rates_len =
4155 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4156 }
4157
Jouni Malinen9d62a982013-02-14 21:10:13 +02004158 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4159 params.capability =
4160 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4161 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4162 }
4163
4164 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4165 params.ext_capab =
4166 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4167 params.ext_capab_len =
4168 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4169 }
4170
Jouni Malinendf881292013-02-14 21:10:54 +02004171 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004172 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004173
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004174 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004175 return -EINVAL;
4176
Johannes Bergf8bacc22013-02-14 23:27:01 +01004177 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004178 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004179 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4180 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4181 return -EINVAL;
4182 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004183
Johannes Bergf8bacc22013-02-14 23:27:01 +01004184 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004185 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004186 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4187 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4188 return -EINVAL;
4189 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4190 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004191
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004192 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4193 enum nl80211_mesh_power_mode pm = nla_get_u32(
4194 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4195
4196 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4197 pm > NL80211_MESH_POWER_MAX)
4198 return -EINVAL;
4199
4200 params.local_pm = pm;
4201 }
4202
Johannes Berg77ee7c82013-02-15 00:48:33 +01004203 /* Include parameters for TDLS peer (will check later) */
4204 err = nl80211_set_station_tdls(info, &params);
4205 if (err)
4206 return err;
4207
4208 params.vlan = get_vlan(info, rdev);
4209 if (IS_ERR(params.vlan))
4210 return PTR_ERR(params.vlan);
4211
Johannes Berga97f4422009-06-18 17:23:43 +02004212 switch (dev->ieee80211_ptr->iftype) {
4213 case NL80211_IFTYPE_AP:
4214 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004215 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004216 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004217 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004218 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004219 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004220 break;
4221 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004222 err = -EOPNOTSUPP;
4223 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004224 }
4225
Johannes Berg77ee7c82013-02-15 00:48:33 +01004226 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004227 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004228
Johannes Berg77ee7c82013-02-15 00:48:33 +01004229 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004230 if (params.vlan)
4231 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004232
Johannes Berg5727ef12007-12-19 02:03:34 +01004233 return err;
4234}
4235
4236static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4237{
Johannes Berg4c476992010-10-04 21:36:35 +02004238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004239 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004240 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004241 struct station_parameters params;
4242 u8 *mac_addr = NULL;
4243
4244 memset(&params, 0, sizeof(params));
4245
Johannes Berg984c3112013-02-14 23:43:25 +01004246 if (!rdev->ops->add_station)
4247 return -EOPNOTSUPP;
4248
Johannes Berg5727ef12007-12-19 02:03:34 +01004249 if (!info->attrs[NL80211_ATTR_MAC])
4250 return -EINVAL;
4251
Johannes Berg5727ef12007-12-19 02:03:34 +01004252 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4253 return -EINVAL;
4254
4255 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4256 return -EINVAL;
4257
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004258 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4259 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004260 return -EINVAL;
4261
Johannes Berg5727ef12007-12-19 02:03:34 +01004262 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4263 params.supported_rates =
4264 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4265 params.supported_rates_len =
4266 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4267 params.listen_interval =
4268 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004269
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004270 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004271 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004272 else
4273 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004274 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4275 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004276
Jouni Malinen9d62a982013-02-14 21:10:13 +02004277 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4278 params.capability =
4279 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4280 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4281 }
4282
4283 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4284 params.ext_capab =
4285 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4286 params.ext_capab_len =
4287 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4288 }
4289
Jouni Malinen36aedc92008-08-25 11:58:58 +03004290 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4291 params.ht_capa =
4292 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004293
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004294 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4295 params.vht_capa =
4296 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4297
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004298 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4299 params.opmode_notif_used = true;
4300 params.opmode_notif =
4301 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4302 }
4303
Johannes Bergf8bacc22013-02-14 23:27:01 +01004304 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004305 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004306 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4307 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4308 return -EINVAL;
4309 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004310
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304311 err = nl80211_parse_sta_channel_info(info, &params);
4312 if (err)
4313 return err;
4314
Johannes Bergff276692013-02-15 00:09:01 +01004315 err = nl80211_parse_sta_wme(info, &params);
4316 if (err)
4317 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004318
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004319 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004320 return -EINVAL;
4321
Johannes Berg77ee7c82013-02-15 00:48:33 +01004322 /* When you run into this, adjust the code below for the new flag */
4323 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4324
Johannes Bergbdd90d52011-12-14 12:20:27 +01004325 switch (dev->ieee80211_ptr->iftype) {
4326 case NL80211_IFTYPE_AP:
4327 case NL80211_IFTYPE_AP_VLAN:
4328 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004329 /* ignore WME attributes if iface/sta is not capable */
4330 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4331 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4332 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004333
Johannes Bergbdd90d52011-12-14 12:20:27 +01004334 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004335 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4336 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004337 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004338 /* but don't bother the driver with it */
4339 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004340
Johannes Bergd582cff2012-10-26 17:53:44 +02004341 /* allow authenticated/associated only if driver handles it */
4342 if (!(rdev->wiphy.features &
4343 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4344 params.sta_flags_mask &
4345 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4346 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4347 return -EINVAL;
4348
Johannes Bergbdd90d52011-12-14 12:20:27 +01004349 /* must be last in here for error handling */
4350 params.vlan = get_vlan(info, rdev);
4351 if (IS_ERR(params.vlan))
4352 return PTR_ERR(params.vlan);
4353 break;
4354 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004355 /* ignore uAPSD data */
4356 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4357
Johannes Bergd582cff2012-10-26 17:53:44 +02004358 /* associated is disallowed */
4359 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4360 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004361 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004362 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4363 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004364 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004365 break;
4366 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004367 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004368 /* ignore uAPSD data */
4369 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4370
Johannes Berg77ee7c82013-02-15 00:48:33 +01004371 /* these are disallowed */
4372 if (params.sta_flags_mask &
4373 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4374 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004375 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004376 /* Only TDLS peers can be added */
4377 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4378 return -EINVAL;
4379 /* Can only add if TDLS ... */
4380 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4381 return -EOPNOTSUPP;
4382 /* ... with external setup is supported */
4383 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4384 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004385 /*
4386 * Older wpa_supplicant versions always mark the TDLS peer
4387 * as authorized, but it shouldn't yet be.
4388 */
4389 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004390 break;
4391 default:
4392 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004393 }
4394
Johannes Bergbdd90d52011-12-14 12:20:27 +01004395 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004396
Hila Gonene35e4d22012-06-27 17:19:42 +03004397 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004398
Johannes Berg5727ef12007-12-19 02:03:34 +01004399 if (params.vlan)
4400 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004401 return err;
4402}
4403
4404static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4405{
Johannes Berg4c476992010-10-04 21:36:35 +02004406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4407 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004408 struct station_del_parameters params;
4409
4410 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004411
4412 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004413 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004414
Johannes Berge80cf852009-05-11 14:43:13 +02004415 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004416 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004417 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004418 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4419 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004420
Johannes Berg4c476992010-10-04 21:36:35 +02004421 if (!rdev->ops->del_station)
4422 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004423
Jouni Malinen98856862014-10-20 13:20:45 +03004424 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4425 params.subtype =
4426 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4427 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4428 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4429 return -EINVAL;
4430 } else {
4431 /* Default to Deauthentication frame */
4432 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4433 }
4434
4435 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4436 params.reason_code =
4437 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4438 if (params.reason_code == 0)
4439 return -EINVAL; /* 0 is reserved */
4440 } else {
4441 /* Default to reason code 2 */
4442 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4443 }
4444
Jouni Malinen89c771e2014-10-10 20:52:40 +03004445 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004446}
4447
Eric W. Biederman15e47302012-09-07 20:12:54 +00004448static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004449 int flags, struct net_device *dev,
4450 u8 *dst, u8 *next_hop,
4451 struct mpath_info *pinfo)
4452{
4453 void *hdr;
4454 struct nlattr *pinfoattr;
4455
Eric W. Biederman15e47302012-09-07 20:12:54 +00004456 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004457 if (!hdr)
4458 return -1;
4459
David S. Miller9360ffd2012-03-29 04:41:26 -04004460 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4461 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4462 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4463 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4464 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004465
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004466 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4467 if (!pinfoattr)
4468 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004469 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4470 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4471 pinfo->frame_qlen))
4472 goto nla_put_failure;
4473 if (((pinfo->filled & MPATH_INFO_SN) &&
4474 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4475 ((pinfo->filled & MPATH_INFO_METRIC) &&
4476 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4477 pinfo->metric)) ||
4478 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4479 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4480 pinfo->exptime)) ||
4481 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4482 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4483 pinfo->flags)) ||
4484 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4485 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4486 pinfo->discovery_timeout)) ||
4487 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4488 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4489 pinfo->discovery_retries)))
4490 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004491
4492 nla_nest_end(msg, pinfoattr);
4493
4494 return genlmsg_end(msg, hdr);
4495
4496 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004497 genlmsg_cancel(msg, hdr);
4498 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004499}
4500
4501static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004502 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004503{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004505 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004506 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004507 u8 dst[ETH_ALEN];
4508 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004509 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004510 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004511
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004512 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004513 if (err)
4514 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004515
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004516 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004517 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004518 goto out_err;
4519 }
4520
Johannes Berg97990a02013-04-19 01:02:55 +02004521 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004522 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004523 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004524 }
4525
Johannes Bergbba95fe2008-07-29 13:22:51 +02004526 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004527 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004528 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004529 if (err == -ENOENT)
4530 break;
4531 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004532 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004533
Eric W. Biederman15e47302012-09-07 20:12:54 +00004534 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004535 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004536 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004537 &pinfo) < 0)
4538 goto out;
4539
4540 path_idx++;
4541 }
4542
4543
4544 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004545 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004546 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004547 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004548 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004549 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004550}
4551
4552static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4553{
Johannes Berg4c476992010-10-04 21:36:35 +02004554 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004555 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004556 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004557 struct mpath_info pinfo;
4558 struct sk_buff *msg;
4559 u8 *dst = NULL;
4560 u8 next_hop[ETH_ALEN];
4561
4562 memset(&pinfo, 0, sizeof(pinfo));
4563
4564 if (!info->attrs[NL80211_ATTR_MAC])
4565 return -EINVAL;
4566
4567 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4568
Johannes Berg4c476992010-10-04 21:36:35 +02004569 if (!rdev->ops->get_mpath)
4570 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004571
Johannes Berg4c476992010-10-04 21:36:35 +02004572 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4573 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004574
Hila Gonene35e4d22012-06-27 17:19:42 +03004575 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004576 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004577 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004578
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004579 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004580 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004581 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004582
Eric W. Biederman15e47302012-09-07 20:12:54 +00004583 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004584 dev, dst, next_hop, &pinfo) < 0) {
4585 nlmsg_free(msg);
4586 return -ENOBUFS;
4587 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004588
Johannes Berg4c476992010-10-04 21:36:35 +02004589 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004590}
4591
4592static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4593{
Johannes Berg4c476992010-10-04 21:36:35 +02004594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4595 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004596 u8 *dst = NULL;
4597 u8 *next_hop = NULL;
4598
4599 if (!info->attrs[NL80211_ATTR_MAC])
4600 return -EINVAL;
4601
4602 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4603 return -EINVAL;
4604
4605 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4606 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4607
Johannes Berg4c476992010-10-04 21:36:35 +02004608 if (!rdev->ops->change_mpath)
4609 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004610
Johannes Berg4c476992010-10-04 21:36:35 +02004611 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4612 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004613
Hila Gonene35e4d22012-06-27 17:19:42 +03004614 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004615}
Johannes Berg4c476992010-10-04 21:36:35 +02004616
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004617static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4618{
Johannes Berg4c476992010-10-04 21:36:35 +02004619 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4620 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004621 u8 *dst = NULL;
4622 u8 *next_hop = NULL;
4623
4624 if (!info->attrs[NL80211_ATTR_MAC])
4625 return -EINVAL;
4626
4627 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4628 return -EINVAL;
4629
4630 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4631 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4632
Johannes Berg4c476992010-10-04 21:36:35 +02004633 if (!rdev->ops->add_mpath)
4634 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004635
Johannes Berg4c476992010-10-04 21:36:35 +02004636 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4637 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004638
Hila Gonene35e4d22012-06-27 17:19:42 +03004639 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004640}
4641
4642static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4643{
Johannes Berg4c476992010-10-04 21:36:35 +02004644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4645 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004646 u8 *dst = NULL;
4647
4648 if (info->attrs[NL80211_ATTR_MAC])
4649 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4650
Johannes Berg4c476992010-10-04 21:36:35 +02004651 if (!rdev->ops->del_mpath)
4652 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004653
Hila Gonene35e4d22012-06-27 17:19:42 +03004654 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004655}
4656
Henning Rogge66be7d22014-09-12 08:58:49 +02004657static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4658{
4659 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4660 int err;
4661 struct net_device *dev = info->user_ptr[1];
4662 struct mpath_info pinfo;
4663 struct sk_buff *msg;
4664 u8 *dst = NULL;
4665 u8 mpp[ETH_ALEN];
4666
4667 memset(&pinfo, 0, sizeof(pinfo));
4668
4669 if (!info->attrs[NL80211_ATTR_MAC])
4670 return -EINVAL;
4671
4672 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4673
4674 if (!rdev->ops->get_mpp)
4675 return -EOPNOTSUPP;
4676
4677 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4678 return -EOPNOTSUPP;
4679
4680 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4681 if (err)
4682 return err;
4683
4684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4685 if (!msg)
4686 return -ENOMEM;
4687
4688 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4689 dev, dst, mpp, &pinfo) < 0) {
4690 nlmsg_free(msg);
4691 return -ENOBUFS;
4692 }
4693
4694 return genlmsg_reply(msg, info);
4695}
4696
4697static int nl80211_dump_mpp(struct sk_buff *skb,
4698 struct netlink_callback *cb)
4699{
4700 struct mpath_info pinfo;
4701 struct cfg80211_registered_device *rdev;
4702 struct wireless_dev *wdev;
4703 u8 dst[ETH_ALEN];
4704 u8 mpp[ETH_ALEN];
4705 int path_idx = cb->args[2];
4706 int err;
4707
4708 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4709 if (err)
4710 return err;
4711
4712 if (!rdev->ops->dump_mpp) {
4713 err = -EOPNOTSUPP;
4714 goto out_err;
4715 }
4716
4717 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4718 err = -EOPNOTSUPP;
4719 goto out_err;
4720 }
4721
4722 while (1) {
4723 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4724 mpp, &pinfo);
4725 if (err == -ENOENT)
4726 break;
4727 if (err)
4728 goto out_err;
4729
4730 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4731 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4732 wdev->netdev, dst, mpp,
4733 &pinfo) < 0)
4734 goto out;
4735
4736 path_idx++;
4737 }
4738
4739 out:
4740 cb->args[2] = path_idx;
4741 err = skb->len;
4742 out_err:
4743 nl80211_finish_wdev_dump(rdev);
4744 return err;
4745}
4746
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004747static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4748{
Johannes Berg4c476992010-10-04 21:36:35 +02004749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4750 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004751 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004752 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004753 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004754
4755 memset(&params, 0, sizeof(params));
4756 /* default to not changing parameters */
4757 params.use_cts_prot = -1;
4758 params.use_short_preamble = -1;
4759 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004760 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004761 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004762 params.p2p_ctwindow = -1;
4763 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004764
4765 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4766 params.use_cts_prot =
4767 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4768 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4769 params.use_short_preamble =
4770 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4771 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4772 params.use_short_slot_time =
4773 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004774 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4775 params.basic_rates =
4776 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4777 params.basic_rates_len =
4778 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4779 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004780 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4781 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004782 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4783 params.ht_opmode =
4784 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004785
Johannes Berg53cabad2012-11-14 15:17:28 +01004786 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4787 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4788 return -EINVAL;
4789 params.p2p_ctwindow =
4790 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4791 if (params.p2p_ctwindow < 0)
4792 return -EINVAL;
4793 if (params.p2p_ctwindow != 0 &&
4794 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4795 return -EINVAL;
4796 }
4797
4798 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4799 u8 tmp;
4800
4801 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4802 return -EINVAL;
4803 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4804 if (tmp > 1)
4805 return -EINVAL;
4806 params.p2p_opp_ps = tmp;
4807 if (params.p2p_opp_ps &&
4808 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4809 return -EINVAL;
4810 }
4811
Johannes Berg4c476992010-10-04 21:36:35 +02004812 if (!rdev->ops->change_bss)
4813 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004814
Johannes Berg074ac8d2010-09-16 14:58:22 +02004815 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004816 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4817 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004818
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004819 wdev_lock(wdev);
4820 err = rdev_change_bss(rdev, dev, &params);
4821 wdev_unlock(wdev);
4822
4823 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004824}
4825
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004826static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004827 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4828 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4829 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4830 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4831 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4832 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004833 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004834};
4835
4836static int parse_reg_rule(struct nlattr *tb[],
4837 struct ieee80211_reg_rule *reg_rule)
4838{
4839 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4840 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4841
4842 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4843 return -EINVAL;
4844 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4845 return -EINVAL;
4846 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4847 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004848 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4849 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004850 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4851 return -EINVAL;
4852
4853 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4854
4855 freq_range->start_freq_khz =
4856 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4857 freq_range->end_freq_khz =
4858 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004859 freq_range->max_bandwidth_khz =
4860 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004861
4862 power_rule->max_eirp =
4863 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4864
4865 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4866 power_rule->max_antenna_gain =
4867 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4868
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004869 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4870 reg_rule->dfs_cac_ms =
4871 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4872
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004873 return 0;
4874}
4875
4876static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4877{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004878 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004879 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004880
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004881 /*
4882 * You should only get this when cfg80211 hasn't yet initialized
4883 * completely when built-in to the kernel right between the time
4884 * window between nl80211_init() and regulatory_init(), if that is
4885 * even possible.
4886 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004887 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004888 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004889
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004890 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4891 user_reg_hint_type =
4892 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4893 else
4894 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4895
4896 switch (user_reg_hint_type) {
4897 case NL80211_USER_REG_HINT_USER:
4898 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004899 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4900 return -EINVAL;
4901
4902 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4903 return regulatory_hint_user(data, user_reg_hint_type);
4904 case NL80211_USER_REG_HINT_INDOOR:
4905 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004906 default:
4907 return -EINVAL;
4908 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004909}
4910
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004911static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004912 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004913{
Johannes Berg4c476992010-10-04 21:36:35 +02004914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004915 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004916 struct wireless_dev *wdev = dev->ieee80211_ptr;
4917 struct mesh_config cur_params;
4918 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004919 void *hdr;
4920 struct nlattr *pinfoattr;
4921 struct sk_buff *msg;
4922
Johannes Berg29cbe682010-12-03 09:20:44 +01004923 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4924 return -EOPNOTSUPP;
4925
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004926 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004927 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004928
Johannes Berg29cbe682010-12-03 09:20:44 +01004929 wdev_lock(wdev);
4930 /* If not connected, get default parameters */
4931 if (!wdev->mesh_id_len)
4932 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4933 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004934 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004935 wdev_unlock(wdev);
4936
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004937 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004938 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004939
4940 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004941 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004942 if (!msg)
4943 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004944 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004945 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004946 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004947 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004948 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004949 if (!pinfoattr)
4950 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004951 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4952 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4953 cur_params.dot11MeshRetryTimeout) ||
4954 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4955 cur_params.dot11MeshConfirmTimeout) ||
4956 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4957 cur_params.dot11MeshHoldingTimeout) ||
4958 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4959 cur_params.dot11MeshMaxPeerLinks) ||
4960 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4961 cur_params.dot11MeshMaxRetries) ||
4962 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4963 cur_params.dot11MeshTTL) ||
4964 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4965 cur_params.element_ttl) ||
4966 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4967 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004968 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4969 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004970 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4971 cur_params.dot11MeshHWMPmaxPREQretries) ||
4972 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4973 cur_params.path_refresh_time) ||
4974 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4975 cur_params.min_discovery_timeout) ||
4976 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4977 cur_params.dot11MeshHWMPactivePathTimeout) ||
4978 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4979 cur_params.dot11MeshHWMPpreqMinInterval) ||
4980 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4981 cur_params.dot11MeshHWMPperrMinInterval) ||
4982 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4983 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4984 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4985 cur_params.dot11MeshHWMPRootMode) ||
4986 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4987 cur_params.dot11MeshHWMPRannInterval) ||
4988 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4989 cur_params.dot11MeshGateAnnouncementProtocol) ||
4990 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4991 cur_params.dot11MeshForwarding) ||
4992 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004993 cur_params.rssi_threshold) ||
4994 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004995 cur_params.ht_opmode) ||
4996 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4997 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4998 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004999 cur_params.dot11MeshHWMProotInterval) ||
5000 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005001 cur_params.dot11MeshHWMPconfirmationInterval) ||
5002 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5003 cur_params.power_mode) ||
5004 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005005 cur_params.dot11MeshAwakeWindowDuration) ||
5006 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5007 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005008 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005009 nla_nest_end(msg, pinfoattr);
5010 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005011 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005012
Johannes Berg3b858752009-03-12 09:55:09 +01005013 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005014 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005015 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005016 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005017 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005018}
5019
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005020static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005021 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5022 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5023 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5024 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5025 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5026 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005027 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005028 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005029 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005030 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5031 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5032 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5033 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5034 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005035 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005036 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005037 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005038 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005039 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005040 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005041 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5042 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005043 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5044 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005045 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005046 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5047 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005048 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005049};
5050
Javier Cardonac80d5452010-12-16 17:37:49 -08005051static const struct nla_policy
5052 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005053 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005054 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5055 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005056 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005057 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005058 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005059 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005060 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005061 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005062};
5063
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005064static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005065 struct mesh_config *cfg,
5066 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005067{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005068 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005069 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005070
Marco Porschea54fba2013-01-07 16:04:48 +01005071#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5072do { \
5073 if (tb[attr]) { \
5074 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5075 return -EINVAL; \
5076 cfg->param = fn(tb[attr]); \
5077 mask |= (1 << (attr - 1)); \
5078 } \
5079} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005080
5081
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005082 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005083 return -EINVAL;
5084 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005085 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005086 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005087 return -EINVAL;
5088
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005089 /* This makes sure that there aren't more than 32 mesh config
5090 * parameters (otherwise our bitfield scheme would not work.) */
5091 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5092
5093 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005094 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005095 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5096 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005097 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005098 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5099 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005100 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005101 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5102 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005103 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005104 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5105 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005106 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005107 mask, NL80211_MESHCONF_MAX_RETRIES,
5108 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005109 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005110 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005111 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005112 mask, NL80211_MESHCONF_ELEMENT_TTL,
5113 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005114 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005115 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5116 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005117 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5118 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005119 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5120 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005121 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005122 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5123 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005124 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005125 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5126 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005127 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005128 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5129 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005130 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5131 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005132 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5133 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005134 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005135 1, 65535, mask,
5136 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005137 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005138 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005139 1, 65535, mask,
5140 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005141 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005142 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005143 dot11MeshHWMPnetDiameterTraversalTime,
5144 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005145 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5146 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005147 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5148 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5149 nla_get_u8);
5150 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5151 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005152 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005153 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005154 dot11MeshGateAnnouncementProtocol, 0, 1,
5155 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005156 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005157 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005158 mask, NL80211_MESHCONF_FORWARDING,
5159 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005160 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005161 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005162 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005163 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005164 mask, NL80211_MESHCONF_HT_OPMODE,
5165 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005166 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005167 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005168 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5169 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005170 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005171 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5172 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005173 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005174 dot11MeshHWMPconfirmationInterval,
5175 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005176 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5177 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005178 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5179 NL80211_MESH_POWER_ACTIVE,
5180 NL80211_MESH_POWER_MAX,
5181 mask, NL80211_MESHCONF_POWER_MODE,
5182 nla_get_u32);
5183 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5184 0, 65535, mask,
5185 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005186 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5187 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5188 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005189 if (mask_out)
5190 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005191
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005192 return 0;
5193
5194#undef FILL_IN_MESH_PARAM_IF_SET
5195}
5196
Javier Cardonac80d5452010-12-16 17:37:49 -08005197static int nl80211_parse_mesh_setup(struct genl_info *info,
5198 struct mesh_setup *setup)
5199{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005201 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5202
5203 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5204 return -EINVAL;
5205 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5206 info->attrs[NL80211_ATTR_MESH_SETUP],
5207 nl80211_mesh_setup_params_policy))
5208 return -EINVAL;
5209
Javier Cardonad299a1f2012-03-31 11:31:33 -07005210 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5211 setup->sync_method =
5212 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5213 IEEE80211_SYNC_METHOD_VENDOR :
5214 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5215
Javier Cardonac80d5452010-12-16 17:37:49 -08005216 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5217 setup->path_sel_proto =
5218 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5219 IEEE80211_PATH_PROTOCOL_VENDOR :
5220 IEEE80211_PATH_PROTOCOL_HWMP;
5221
5222 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5223 setup->path_metric =
5224 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5225 IEEE80211_PATH_METRIC_VENDOR :
5226 IEEE80211_PATH_METRIC_AIRTIME;
5227
Javier Cardona581a8b02011-04-07 15:08:27 -07005228
5229 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005230 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005231 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005232 if (!is_valid_ie_attr(ieattr))
5233 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005234 setup->ie = nla_data(ieattr);
5235 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005236 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005237 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5238 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5239 return -EINVAL;
5240 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005241 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5242 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005243 if (setup->is_secure)
5244 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005245
Colleen Twitty6e16d902013-05-08 11:45:59 -07005246 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5247 if (!setup->user_mpm)
5248 return -EINVAL;
5249 setup->auth_id =
5250 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5251 }
5252
Javier Cardonac80d5452010-12-16 17:37:49 -08005253 return 0;
5254}
5255
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005256static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005257 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005258{
5259 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5260 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005261 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005262 struct mesh_config cfg;
5263 u32 mask;
5264 int err;
5265
Johannes Berg29cbe682010-12-03 09:20:44 +01005266 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5267 return -EOPNOTSUPP;
5268
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005269 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005270 return -EOPNOTSUPP;
5271
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005272 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005273 if (err)
5274 return err;
5275
Johannes Berg29cbe682010-12-03 09:20:44 +01005276 wdev_lock(wdev);
5277 if (!wdev->mesh_id_len)
5278 err = -ENOLINK;
5279
5280 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005281 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005282
5283 wdev_unlock(wdev);
5284
5285 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005286}
5287
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005288static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5289{
Johannes Berg458f4f92012-12-06 15:47:38 +01005290 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005291 struct sk_buff *msg;
5292 void *hdr = NULL;
5293 struct nlattr *nl_reg_rules;
5294 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005295
5296 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005297 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005298
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005299 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005300 if (!msg)
5301 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005302
Eric W. Biederman15e47302012-09-07 20:12:54 +00005303 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005304 NL80211_CMD_GET_REG);
5305 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005306 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005307
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005308 if (reg_last_request_cell_base() &&
5309 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5310 NL80211_USER_REG_HINT_CELL_BASE))
5311 goto nla_put_failure;
5312
Johannes Berg458f4f92012-12-06 15:47:38 +01005313 rcu_read_lock();
5314 regdom = rcu_dereference(cfg80211_regdomain);
5315
5316 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5317 (regdom->dfs_region &&
5318 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5319 goto nla_put_failure_rcu;
5320
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005321 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5322 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005323 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005324
Johannes Berg458f4f92012-12-06 15:47:38 +01005325 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005326 struct nlattr *nl_reg_rule;
5327 const struct ieee80211_reg_rule *reg_rule;
5328 const struct ieee80211_freq_range *freq_range;
5329 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005330 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005331
Johannes Berg458f4f92012-12-06 15:47:38 +01005332 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005333 freq_range = &reg_rule->freq_range;
5334 power_rule = &reg_rule->power_rule;
5335
5336 nl_reg_rule = nla_nest_start(msg, i);
5337 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005338 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005339
Janusz Dziedzic97524822014-01-30 09:52:20 +01005340 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5341 if (!max_bandwidth_khz)
5342 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5343 reg_rule);
5344
David S. Miller9360ffd2012-03-29 04:41:26 -04005345 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5346 reg_rule->flags) ||
5347 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5348 freq_range->start_freq_khz) ||
5349 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5350 freq_range->end_freq_khz) ||
5351 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005352 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005353 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5354 power_rule->max_antenna_gain) ||
5355 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005356 power_rule->max_eirp) ||
5357 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5358 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005359 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005360
5361 nla_nest_end(msg, nl_reg_rule);
5362 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005363 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005364
5365 nla_nest_end(msg, nl_reg_rules);
5366
5367 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005368 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005369
Johannes Berg458f4f92012-12-06 15:47:38 +01005370nla_put_failure_rcu:
5371 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005372nla_put_failure:
5373 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005374put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005375 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005376 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005377}
5378
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005379static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5380{
5381 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5382 struct nlattr *nl_reg_rule;
5383 char *alpha2 = NULL;
5384 int rem_reg_rules = 0, r = 0;
5385 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005386 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005387 struct ieee80211_regdomain *rd = NULL;
5388
5389 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5390 return -EINVAL;
5391
5392 if (!info->attrs[NL80211_ATTR_REG_RULES])
5393 return -EINVAL;
5394
5395 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5396
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005397 if (info->attrs[NL80211_ATTR_DFS_REGION])
5398 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5399
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005400 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005401 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005402 num_rules++;
5403 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005404 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005405 }
5406
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005407 if (!reg_is_valid_request(alpha2))
5408 return -EINVAL;
5409
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005410 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005411 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005412
5413 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005414 if (!rd)
5415 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005416
5417 rd->n_reg_rules = num_rules;
5418 rd->alpha2[0] = alpha2[0];
5419 rd->alpha2[1] = alpha2[1];
5420
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005421 /*
5422 * Disable DFS master mode if the DFS region was
5423 * not supported or known on this kernel.
5424 */
5425 if (reg_supported_dfs_region(dfs_region))
5426 rd->dfs_region = dfs_region;
5427
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005428 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005429 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005430 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5431 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5432 reg_rule_policy);
5433 if (r)
5434 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005435 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5436 if (r)
5437 goto bad_reg;
5438
5439 rule_idx++;
5440
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005441 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5442 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005443 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005444 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005445 }
5446
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005447 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005448 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005449 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005450
Johannes Bergd2372b32008-10-24 20:32:20 +02005451 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005452 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005453 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005454}
5455
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005456static int validate_scan_freqs(struct nlattr *freqs)
5457{
5458 struct nlattr *attr1, *attr2;
5459 int n_channels = 0, tmp1, tmp2;
5460
5461 nla_for_each_nested(attr1, freqs, tmp1) {
5462 n_channels++;
5463 /*
5464 * Some hardware has a limited channel list for
5465 * scanning, and it is pretty much nonsensical
5466 * to scan for a channel twice, so disallow that
5467 * and don't require drivers to check that the
5468 * channel list they get isn't longer than what
5469 * they can scan, as long as they can scan all
5470 * the channels they registered at once.
5471 */
5472 nla_for_each_nested(attr2, freqs, tmp2)
5473 if (attr1 != attr2 &&
5474 nla_get_u32(attr1) == nla_get_u32(attr2))
5475 return 0;
5476 }
5477
5478 return n_channels;
5479}
5480
Johannes Berg2a519312009-02-10 21:25:55 +01005481static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5482{
Johannes Berg4c476992010-10-04 21:36:35 +02005483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005484 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005485 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005486 struct nlattr *attr;
5487 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005488 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005489 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005490
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005491 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5492 return -EINVAL;
5493
Johannes Berg79c97e92009-07-07 03:56:12 +02005494 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005495
Johannes Berg4c476992010-10-04 21:36:35 +02005496 if (!rdev->ops->scan)
5497 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005498
Johannes Bergf9d15d12014-01-22 11:14:19 +02005499 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005500 err = -EBUSY;
5501 goto unlock;
5502 }
Johannes Berg2a519312009-02-10 21:25:55 +01005503
5504 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005505 n_channels = validate_scan_freqs(
5506 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005507 if (!n_channels) {
5508 err = -EINVAL;
5509 goto unlock;
5510 }
Johannes Berg2a519312009-02-10 21:25:55 +01005511 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005512 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005513 }
5514
5515 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5516 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5517 n_ssids++;
5518
Johannes Bergf9f47522013-03-19 15:04:07 +01005519 if (n_ssids > wiphy->max_scan_ssids) {
5520 err = -EINVAL;
5521 goto unlock;
5522 }
Johannes Berg2a519312009-02-10 21:25:55 +01005523
Jouni Malinen70692ad2009-02-16 19:39:13 +02005524 if (info->attrs[NL80211_ATTR_IE])
5525 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5526 else
5527 ie_len = 0;
5528
Johannes Bergf9f47522013-03-19 15:04:07 +01005529 if (ie_len > wiphy->max_scan_ie_len) {
5530 err = -EINVAL;
5531 goto unlock;
5532 }
Johannes Berg18a83652009-03-31 12:12:05 +02005533
Johannes Berg2a519312009-02-10 21:25:55 +01005534 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005535 + sizeof(*request->ssids) * n_ssids
5536 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005537 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005538 if (!request) {
5539 err = -ENOMEM;
5540 goto unlock;
5541 }
Johannes Berg2a519312009-02-10 21:25:55 +01005542
Johannes Berg2a519312009-02-10 21:25:55 +01005543 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005544 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005545 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005546 if (ie_len) {
5547 if (request->ssids)
5548 request->ie = (void *)(request->ssids + n_ssids);
5549 else
5550 request->ie = (void *)(request->channels + n_channels);
5551 }
Johannes Berg2a519312009-02-10 21:25:55 +01005552
Johannes Berg584991d2009-11-02 13:32:03 +01005553 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005554 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5555 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005556 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005557 struct ieee80211_channel *chan;
5558
5559 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5560
5561 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005562 err = -EINVAL;
5563 goto out_free;
5564 }
Johannes Berg584991d2009-11-02 13:32:03 +01005565
5566 /* ignore disabled channels */
5567 if (chan->flags & IEEE80211_CHAN_DISABLED)
5568 continue;
5569
5570 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005571 i++;
5572 }
5573 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005574 enum ieee80211_band band;
5575
Johannes Berg2a519312009-02-10 21:25:55 +01005576 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005577 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5578 int j;
5579 if (!wiphy->bands[band])
5580 continue;
5581 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005582 struct ieee80211_channel *chan;
5583
5584 chan = &wiphy->bands[band]->channels[j];
5585
5586 if (chan->flags & IEEE80211_CHAN_DISABLED)
5587 continue;
5588
5589 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005590 i++;
5591 }
5592 }
5593 }
5594
Johannes Berg584991d2009-11-02 13:32:03 +01005595 if (!i) {
5596 err = -EINVAL;
5597 goto out_free;
5598 }
5599
5600 request->n_channels = i;
5601
Johannes Berg2a519312009-02-10 21:25:55 +01005602 i = 0;
5603 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5604 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005605 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005606 err = -EINVAL;
5607 goto out_free;
5608 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005609 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005610 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005611 i++;
5612 }
5613 }
5614
Jouni Malinen70692ad2009-02-16 19:39:13 +02005615 if (info->attrs[NL80211_ATTR_IE]) {
5616 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005617 memcpy((void *)request->ie,
5618 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005619 request->ie_len);
5620 }
5621
Johannes Berg34850ab2011-07-18 18:08:35 +02005622 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005623 if (wiphy->bands[i])
5624 request->rates[i] =
5625 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005626
5627 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5628 nla_for_each_nested(attr,
5629 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5630 tmp) {
5631 enum ieee80211_band band = nla_type(attr);
5632
Dan Carpenter84404622011-07-29 11:52:18 +03005633 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005634 err = -EINVAL;
5635 goto out_free;
5636 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005637
5638 if (!wiphy->bands[band])
5639 continue;
5640
Johannes Berg34850ab2011-07-18 18:08:35 +02005641 err = ieee80211_get_ratemask(wiphy->bands[band],
5642 nla_data(attr),
5643 nla_len(attr),
5644 &request->rates[band]);
5645 if (err)
5646 goto out_free;
5647 }
5648 }
5649
Sam Leffler46856bb2012-10-11 21:03:32 -07005650 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005651 request->flags = nla_get_u32(
5652 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005653 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5654 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005655 err = -EOPNOTSUPP;
5656 goto out_free;
5657 }
5658 }
Sam Lefflered4737712012-10-11 21:03:31 -07005659
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305660 request->no_cck =
5661 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5662
Johannes Bergfd014282012-06-18 19:17:03 +02005663 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005664 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005665 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005666
Johannes Berg79c97e92009-07-07 03:56:12 +02005667 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005668 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005669
Johannes Berg463d0182009-07-14 00:33:35 +02005670 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005671 nl80211_send_scan_start(rdev, wdev);
5672 if (wdev->netdev)
5673 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005674 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005675 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005676 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005677 kfree(request);
5678 }
Johannes Berg3b858752009-03-12 09:55:09 +01005679
Johannes Bergf9f47522013-03-19 15:04:07 +01005680 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005681 return err;
5682}
5683
Luciano Coelho807f8a82011-05-11 17:09:35 +03005684static int nl80211_start_sched_scan(struct sk_buff *skb,
5685 struct genl_info *info)
5686{
5687 struct cfg80211_sched_scan_request *request;
5688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5689 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005690 struct nlattr *attr;
5691 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005692 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005693 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005694 enum ieee80211_band band;
5695 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005696 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005697 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005698
5699 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5700 !rdev->ops->sched_scan_start)
5701 return -EOPNOTSUPP;
5702
5703 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5704 return -EINVAL;
5705
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005706 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5707 return -EINVAL;
5708
5709 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5710 if (interval == 0)
5711 return -EINVAL;
5712
Luciano Coelho807f8a82011-05-11 17:09:35 +03005713 wiphy = &rdev->wiphy;
5714
5715 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5716 n_channels = validate_scan_freqs(
5717 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5718 if (!n_channels)
5719 return -EINVAL;
5720 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005721 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005722 }
5723
5724 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5725 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5726 tmp)
5727 n_ssids++;
5728
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005729 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005730 return -EINVAL;
5731
Johannes Bergea73cbc2014-01-24 10:53:53 +01005732 /*
5733 * First, count the number of 'real' matchsets. Due to an issue with
5734 * the old implementation, matchsets containing only the RSSI attribute
5735 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5736 * RSSI for all matchsets, rather than their own matchset for reporting
5737 * all APs with a strong RSSI. This is needed to be compatible with
5738 * older userspace that treated a matchset with only the RSSI as the
5739 * global RSSI for all other matchsets - if there are other matchsets.
5740 */
5741 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005742 nla_for_each_nested(attr,
5743 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005744 tmp) {
5745 struct nlattr *rssi;
5746
5747 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5748 nla_data(attr), nla_len(attr),
5749 nl80211_match_policy);
5750 if (err)
5751 return err;
5752 /* add other standalone attributes here */
5753 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5754 n_match_sets++;
5755 continue;
5756 }
5757 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5758 if (rssi)
5759 default_match_rssi = nla_get_s32(rssi);
5760 }
5761 }
5762
5763 /* However, if there's no other matchset, add the RSSI one */
5764 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5765 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005766
5767 if (n_match_sets > wiphy->max_match_sets)
5768 return -EINVAL;
5769
Luciano Coelho807f8a82011-05-11 17:09:35 +03005770 if (info->attrs[NL80211_ATTR_IE])
5771 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5772 else
5773 ie_len = 0;
5774
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005775 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005776 return -EINVAL;
5777
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005778 if (rdev->sched_scan_req) {
5779 err = -EINPROGRESS;
5780 goto out;
5781 }
5782
Luciano Coelho807f8a82011-05-11 17:09:35 +03005783 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005784 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005785 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005786 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005787 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005788 if (!request) {
5789 err = -ENOMEM;
5790 goto out;
5791 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005792
5793 if (n_ssids)
5794 request->ssids = (void *)&request->channels[n_channels];
5795 request->n_ssids = n_ssids;
5796 if (ie_len) {
5797 if (request->ssids)
5798 request->ie = (void *)(request->ssids + n_ssids);
5799 else
5800 request->ie = (void *)(request->channels + n_channels);
5801 }
5802
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005803 if (n_match_sets) {
5804 if (request->ie)
5805 request->match_sets = (void *)(request->ie + ie_len);
5806 else if (request->ssids)
5807 request->match_sets =
5808 (void *)(request->ssids + n_ssids);
5809 else
5810 request->match_sets =
5811 (void *)(request->channels + n_channels);
5812 }
5813 request->n_match_sets = n_match_sets;
5814
Luciano Coelho807f8a82011-05-11 17:09:35 +03005815 i = 0;
5816 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5817 /* user specified, bail out if channel not found */
5818 nla_for_each_nested(attr,
5819 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5820 tmp) {
5821 struct ieee80211_channel *chan;
5822
5823 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5824
5825 if (!chan) {
5826 err = -EINVAL;
5827 goto out_free;
5828 }
5829
5830 /* ignore disabled channels */
5831 if (chan->flags & IEEE80211_CHAN_DISABLED)
5832 continue;
5833
5834 request->channels[i] = chan;
5835 i++;
5836 }
5837 } else {
5838 /* all channels */
5839 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5840 int j;
5841 if (!wiphy->bands[band])
5842 continue;
5843 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5844 struct ieee80211_channel *chan;
5845
5846 chan = &wiphy->bands[band]->channels[j];
5847
5848 if (chan->flags & IEEE80211_CHAN_DISABLED)
5849 continue;
5850
5851 request->channels[i] = chan;
5852 i++;
5853 }
5854 }
5855 }
5856
5857 if (!i) {
5858 err = -EINVAL;
5859 goto out_free;
5860 }
5861
5862 request->n_channels = i;
5863
5864 i = 0;
5865 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5866 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5867 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005868 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005869 err = -EINVAL;
5870 goto out_free;
5871 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005872 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005873 memcpy(request->ssids[i].ssid, nla_data(attr),
5874 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005875 i++;
5876 }
5877 }
5878
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005879 i = 0;
5880 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5881 nla_for_each_nested(attr,
5882 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5883 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005884 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005885
Johannes Bergae811e22014-01-24 10:17:47 +01005886 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5887 nla_data(attr), nla_len(attr),
5888 nl80211_match_policy);
5889 if (err)
5890 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005891 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005892 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005893 if (WARN_ON(i >= n_match_sets)) {
5894 /* this indicates a programming error,
5895 * the loop above should have verified
5896 * things properly
5897 */
5898 err = -EINVAL;
5899 goto out_free;
5900 }
5901
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005902 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5903 err = -EINVAL;
5904 goto out_free;
5905 }
5906 memcpy(request->match_sets[i].ssid.ssid,
5907 nla_data(ssid), nla_len(ssid));
5908 request->match_sets[i].ssid.ssid_len =
5909 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005910 /* special attribute - old implemenation w/a */
5911 request->match_sets[i].rssi_thold =
5912 default_match_rssi;
5913 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5914 if (rssi)
5915 request->match_sets[i].rssi_thold =
5916 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005917 }
5918 i++;
5919 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005920
5921 /* there was no other matchset, so the RSSI one is alone */
5922 if (i == 0)
5923 request->match_sets[0].rssi_thold = default_match_rssi;
5924
5925 request->min_rssi_thold = INT_MAX;
5926 for (i = 0; i < n_match_sets; i++)
5927 request->min_rssi_thold =
5928 min(request->match_sets[i].rssi_thold,
5929 request->min_rssi_thold);
5930 } else {
5931 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005932 }
5933
Johannes Berg9900e482014-02-04 21:01:25 +01005934 if (ie_len) {
5935 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005936 memcpy((void *)request->ie,
5937 nla_data(info->attrs[NL80211_ATTR_IE]),
5938 request->ie_len);
5939 }
5940
Sam Leffler46856bb2012-10-11 21:03:32 -07005941 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005942 request->flags = nla_get_u32(
5943 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005944 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5945 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005946 err = -EOPNOTSUPP;
5947 goto out_free;
5948 }
5949 }
Sam Lefflered4737712012-10-11 21:03:31 -07005950
Luciano Coelho807f8a82011-05-11 17:09:35 +03005951 request->dev = dev;
5952 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005953 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005954 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005955
Hila Gonene35e4d22012-06-27 17:19:42 +03005956 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005957 if (!err) {
5958 rdev->sched_scan_req = request;
5959 nl80211_send_sched_scan(rdev, dev,
5960 NL80211_CMD_START_SCHED_SCAN);
5961 goto out;
5962 }
5963
5964out_free:
5965 kfree(request);
5966out:
5967 return err;
5968}
5969
5970static int nl80211_stop_sched_scan(struct sk_buff *skb,
5971 struct genl_info *info)
5972{
5973 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5974
5975 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5976 !rdev->ops->sched_scan_stop)
5977 return -EOPNOTSUPP;
5978
Johannes Berg5fe231e2013-05-08 21:45:15 +02005979 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005980}
5981
Simon Wunderlich04f39042013-02-08 18:16:19 +01005982static int nl80211_start_radar_detection(struct sk_buff *skb,
5983 struct genl_info *info)
5984{
5985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5986 struct net_device *dev = info->user_ptr[1];
5987 struct wireless_dev *wdev = dev->ieee80211_ptr;
5988 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005989 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005990 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005991 int err;
5992
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005993 dfs_region = reg_get_dfs_region(wdev->wiphy);
5994 if (dfs_region == NL80211_DFS_UNSET)
5995 return -EINVAL;
5996
Simon Wunderlich04f39042013-02-08 18:16:19 +01005997 err = nl80211_parse_chandef(rdev, info, &chandef);
5998 if (err)
5999 return err;
6000
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006001 if (netif_carrier_ok(dev))
6002 return -EBUSY;
6003
Simon Wunderlich04f39042013-02-08 18:16:19 +01006004 if (wdev->cac_started)
6005 return -EBUSY;
6006
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006007 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006008 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006009 if (err < 0)
6010 return err;
6011
6012 if (err == 0)
6013 return -EINVAL;
6014
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006015 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006016 return -EINVAL;
6017
6018 if (!rdev->ops->start_radar_detection)
6019 return -EOPNOTSUPP;
6020
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006021 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6022 if (WARN_ON(!cac_time_ms))
6023 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6024
6025 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6026 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006027 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006028 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006029 wdev->cac_started = true;
6030 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006031 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006032 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006033 return err;
6034}
6035
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006036static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6037{
6038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6039 struct net_device *dev = info->user_ptr[1];
6040 struct wireless_dev *wdev = dev->ieee80211_ptr;
6041 struct cfg80211_csa_settings params;
6042 /* csa_attrs is defined static to avoid waste of stack size - this
6043 * function is called under RTNL lock, so this should not be a problem.
6044 */
6045 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006046 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006047 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006048 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006049 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006050
6051 if (!rdev->ops->channel_switch ||
6052 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6053 return -EOPNOTSUPP;
6054
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006055 switch (dev->ieee80211_ptr->iftype) {
6056 case NL80211_IFTYPE_AP:
6057 case NL80211_IFTYPE_P2P_GO:
6058 need_new_beacon = true;
6059
6060 /* useless if AP is not running */
6061 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006062 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006063 break;
6064 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006065 if (!wdev->ssid_len)
6066 return -ENOTCONN;
6067 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006068 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006069 if (!wdev->mesh_id_len)
6070 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006071 break;
6072 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006073 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006074 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006075
6076 memset(&params, 0, sizeof(params));
6077
6078 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6079 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6080 return -EINVAL;
6081
6082 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006083 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006084 return -EINVAL;
6085
Luciano Coelho252e07c2014-10-08 09:48:34 +03006086 /* Even though the attribute is u32, the specification says
6087 * u8, so let's make sure we don't overflow.
6088 */
6089 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6090 if (cs_count > 255)
6091 return -EINVAL;
6092
6093 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006094
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006095 if (!need_new_beacon)
6096 goto skip_beacons;
6097
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006098 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6099 if (err)
6100 return err;
6101
6102 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6103 info->attrs[NL80211_ATTR_CSA_IES],
6104 nl80211_policy);
6105 if (err)
6106 return err;
6107
6108 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6109 if (err)
6110 return err;
6111
6112 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6113 return -EINVAL;
6114
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006115 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6116 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006117 return -EINVAL;
6118
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006119 params.n_counter_offsets_beacon = len / sizeof(u16);
6120 if (rdev->wiphy.max_num_csa_counters &&
6121 (params.n_counter_offsets_beacon >
6122 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006123 return -EINVAL;
6124
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006125 params.counter_offsets_beacon =
6126 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6127
6128 /* sanity checks - counters should fit and be the same */
6129 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6130 u16 offset = params.counter_offsets_beacon[i];
6131
6132 if (offset >= params.beacon_csa.tail_len)
6133 return -EINVAL;
6134
6135 if (params.beacon_csa.tail[offset] != params.count)
6136 return -EINVAL;
6137 }
6138
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006139 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006140 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6141 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006142 return -EINVAL;
6143
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006144 params.n_counter_offsets_presp = len / sizeof(u16);
6145 if (rdev->wiphy.max_num_csa_counters &&
6146 (params.n_counter_offsets_beacon >
6147 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006148 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006149
6150 params.counter_offsets_presp =
6151 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6152
6153 /* sanity checks - counters should fit and be the same */
6154 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6155 u16 offset = params.counter_offsets_presp[i];
6156
6157 if (offset >= params.beacon_csa.probe_resp_len)
6158 return -EINVAL;
6159
6160 if (params.beacon_csa.probe_resp[offset] !=
6161 params.count)
6162 return -EINVAL;
6163 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006164 }
6165
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006166skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006167 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6168 if (err)
6169 return err;
6170
Ilan Peer174e0cd2014-02-23 09:13:01 +02006171 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6172 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006173 return -EINVAL;
6174
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006175 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6176 &params.chandef,
6177 wdev->iftype);
6178 if (err < 0)
6179 return err;
6180
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006181 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006182 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006183
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006184 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6185 params.block_tx = true;
6186
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006187 wdev_lock(wdev);
6188 err = rdev_channel_switch(rdev, dev, &params);
6189 wdev_unlock(wdev);
6190
6191 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006192}
6193
Johannes Berg9720bb32011-06-21 09:45:33 +02006194static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6195 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006196 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006197 struct wireless_dev *wdev,
6198 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006199{
Johannes Berg48ab9052009-07-10 18:42:31 +02006200 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006201 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006202 void *hdr;
6203 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006204
6205 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006206
Eric W. Biederman15e47302012-09-07 20:12:54 +00006207 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006208 NL80211_CMD_NEW_SCAN_RESULTS);
6209 if (!hdr)
6210 return -1;
6211
Johannes Berg9720bb32011-06-21 09:45:33 +02006212 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6213
Johannes Berg97990a02013-04-19 01:02:55 +02006214 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6215 goto nla_put_failure;
6216 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006217 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6218 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006219 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6220 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006221
6222 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6223 if (!bss)
6224 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006225 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006226 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006227 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006228
6229 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006230 /* indicate whether we have probe response data or not */
6231 if (rcu_access_pointer(res->proberesp_ies) &&
6232 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6233 goto fail_unlock_rcu;
6234
6235 /* this pointer prefers to be pointed to probe response data
6236 * but is always valid
6237 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006238 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006239 if (ies) {
6240 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6241 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006242 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6243 ies->len, ies->data))
6244 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006245 }
Johannes Berg0e227082014-08-12 20:34:30 +02006246
6247 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006248 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006249 if (ies && ies->from_beacon) {
6250 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006251 goto fail_unlock_rcu;
6252 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6253 ies->len, ies->data))
6254 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006255 }
6256 rcu_read_unlock();
6257
David S. Miller9360ffd2012-03-29 04:41:26 -04006258 if (res->beacon_interval &&
6259 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6260 goto nla_put_failure;
6261 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6262 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006263 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006264 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6265 jiffies_to_msecs(jiffies - intbss->ts)))
6266 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006267
Johannes Berg77965c92009-02-18 18:45:06 +01006268 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006269 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006270 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6271 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006272 break;
6273 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006274 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6275 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006276 break;
6277 default:
6278 break;
6279 }
6280
Johannes Berg48ab9052009-07-10 18:42:31 +02006281 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006282 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006283 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006284 if (intbss == wdev->current_bss &&
6285 nla_put_u32(msg, NL80211_BSS_STATUS,
6286 NL80211_BSS_STATUS_ASSOCIATED))
6287 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006288 break;
6289 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006290 if (intbss == wdev->current_bss &&
6291 nla_put_u32(msg, NL80211_BSS_STATUS,
6292 NL80211_BSS_STATUS_IBSS_JOINED))
6293 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006294 break;
6295 default:
6296 break;
6297 }
6298
Johannes Berg2a519312009-02-10 21:25:55 +01006299 nla_nest_end(msg, bss);
6300
6301 return genlmsg_end(msg, hdr);
6302
Johannes Berg8cef2c92013-02-05 16:54:31 +01006303 fail_unlock_rcu:
6304 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006305 nla_put_failure:
6306 genlmsg_cancel(msg, hdr);
6307 return -EMSGSIZE;
6308}
6309
Johannes Berg97990a02013-04-19 01:02:55 +02006310static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006311{
Johannes Berg48ab9052009-07-10 18:42:31 +02006312 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006313 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006314 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006315 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006316 int err;
6317
Johannes Berg97990a02013-04-19 01:02:55 +02006318 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006319 if (err)
6320 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006321
Johannes Berg48ab9052009-07-10 18:42:31 +02006322 wdev_lock(wdev);
6323 spin_lock_bh(&rdev->bss_lock);
6324 cfg80211_bss_expire(rdev);
6325
Johannes Berg9720bb32011-06-21 09:45:33 +02006326 cb->seq = rdev->bss_generation;
6327
Johannes Berg48ab9052009-07-10 18:42:31 +02006328 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006329 if (++idx <= start)
6330 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006331 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006332 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006333 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006334 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006335 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006336 }
6337 }
6338
Johannes Berg48ab9052009-07-10 18:42:31 +02006339 spin_unlock_bh(&rdev->bss_lock);
6340 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006341
Johannes Berg97990a02013-04-19 01:02:55 +02006342 cb->args[2] = idx;
6343 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006344
Johannes Berg67748892010-10-04 21:14:06 +02006345 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006346}
6347
Eric W. Biederman15e47302012-09-07 20:12:54 +00006348static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006349 int flags, struct net_device *dev,
6350 struct survey_info *survey)
6351{
6352 void *hdr;
6353 struct nlattr *infoattr;
6354
Eric W. Biederman15e47302012-09-07 20:12:54 +00006355 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006356 NL80211_CMD_NEW_SURVEY_RESULTS);
6357 if (!hdr)
6358 return -ENOMEM;
6359
David S. Miller9360ffd2012-03-29 04:41:26 -04006360 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6361 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006362
6363 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6364 if (!infoattr)
6365 goto nla_put_failure;
6366
David S. Miller9360ffd2012-03-29 04:41:26 -04006367 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6368 survey->channel->center_freq))
6369 goto nla_put_failure;
6370
6371 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6372 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6373 goto nla_put_failure;
6374 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6375 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6376 goto nla_put_failure;
6377 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6378 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6379 survey->channel_time))
6380 goto nla_put_failure;
6381 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6382 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6383 survey->channel_time_busy))
6384 goto nla_put_failure;
6385 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6386 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6387 survey->channel_time_ext_busy))
6388 goto nla_put_failure;
6389 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6390 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6391 survey->channel_time_rx))
6392 goto nla_put_failure;
6393 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6394 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6395 survey->channel_time_tx))
6396 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006397
6398 nla_nest_end(msg, infoattr);
6399
6400 return genlmsg_end(msg, hdr);
6401
6402 nla_put_failure:
6403 genlmsg_cancel(msg, hdr);
6404 return -EMSGSIZE;
6405}
6406
6407static int nl80211_dump_survey(struct sk_buff *skb,
6408 struct netlink_callback *cb)
6409{
6410 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006411 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006412 struct wireless_dev *wdev;
6413 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006414 int res;
6415
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006416 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006417 if (res)
6418 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006419
Johannes Berg97990a02013-04-19 01:02:55 +02006420 if (!wdev->netdev) {
6421 res = -EINVAL;
6422 goto out_err;
6423 }
6424
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006425 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006426 res = -EOPNOTSUPP;
6427 goto out_err;
6428 }
6429
6430 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006431 struct ieee80211_channel *chan;
6432
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006433 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006434 if (res == -ENOENT)
6435 break;
6436 if (res)
6437 goto out_err;
6438
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006439 /* Survey without a channel doesn't make sense */
6440 if (!survey.channel) {
6441 res = -EINVAL;
6442 goto out;
6443 }
6444
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006445 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006446 survey.channel->center_freq);
6447 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6448 survey_idx++;
6449 continue;
6450 }
6451
Holger Schurig61fa7132009-11-11 12:25:40 +01006452 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006453 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006454 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006455 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006456 goto out;
6457 survey_idx++;
6458 }
6459
6460 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006461 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006462 res = skb->len;
6463 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006464 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006465 return res;
6466}
6467
Samuel Ortizb23aa672009-07-01 21:26:54 +02006468static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6469{
6470 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6471 NL80211_WPA_VERSION_2));
6472}
6473
Jouni Malinen636a5d32009-03-19 13:39:22 +02006474static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6475{
Johannes Berg4c476992010-10-04 21:36:35 +02006476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6477 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006478 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006479 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6480 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006481 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006482 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006483 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006484
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006485 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6486 return -EINVAL;
6487
6488 if (!info->attrs[NL80211_ATTR_MAC])
6489 return -EINVAL;
6490
Jouni Malinen17780922009-03-27 20:52:47 +02006491 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6492 return -EINVAL;
6493
Johannes Berg19957bb2009-07-02 17:20:43 +02006494 if (!info->attrs[NL80211_ATTR_SSID])
6495 return -EINVAL;
6496
6497 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6498 return -EINVAL;
6499
Johannes Bergfffd0932009-07-08 14:22:54 +02006500 err = nl80211_parse_key(info, &key);
6501 if (err)
6502 return err;
6503
6504 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006505 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6506 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006507 if (!key.p.key || !key.p.key_len)
6508 return -EINVAL;
6509 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6510 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6511 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6512 key.p.key_len != WLAN_KEY_LEN_WEP104))
6513 return -EINVAL;
6514 if (key.idx > 4)
6515 return -EINVAL;
6516 } else {
6517 key.p.key_len = 0;
6518 key.p.key = NULL;
6519 }
6520
Johannes Bergafea0b72010-08-10 09:46:42 +02006521 if (key.idx >= 0) {
6522 int i;
6523 bool ok = false;
6524 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6525 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6526 ok = true;
6527 break;
6528 }
6529 }
Johannes Berg4c476992010-10-04 21:36:35 +02006530 if (!ok)
6531 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006532 }
6533
Johannes Berg4c476992010-10-04 21:36:35 +02006534 if (!rdev->ops->auth)
6535 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006536
Johannes Berg074ac8d2010-09-16 14:58:22 +02006537 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006538 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6539 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006540
Johannes Berg19957bb2009-07-02 17:20:43 +02006541 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006542 chan = nl80211_get_valid_chan(&rdev->wiphy,
6543 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6544 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006545 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006546
Johannes Berg19957bb2009-07-02 17:20:43 +02006547 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6548 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6549
6550 if (info->attrs[NL80211_ATTR_IE]) {
6551 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6552 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6553 }
6554
6555 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006556 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006557 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006558
Jouni Malinene39e5b52012-09-30 19:29:39 +03006559 if (auth_type == NL80211_AUTHTYPE_SAE &&
6560 !info->attrs[NL80211_ATTR_SAE_DATA])
6561 return -EINVAL;
6562
6563 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6564 if (auth_type != NL80211_AUTHTYPE_SAE)
6565 return -EINVAL;
6566 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6567 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6568 /* need to include at least Auth Transaction and Status Code */
6569 if (sae_data_len < 4)
6570 return -EINVAL;
6571 }
6572
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006573 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6574
Johannes Berg95de8172012-01-20 13:55:25 +01006575 /*
6576 * Since we no longer track auth state, ignore
6577 * requests to only change local state.
6578 */
6579 if (local_state_change)
6580 return 0;
6581
Johannes Berg91bf9b22013-05-15 17:44:01 +02006582 wdev_lock(dev->ieee80211_ptr);
6583 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6584 ssid, ssid_len, ie, ie_len,
6585 key.p.key, key.p.key_len, key.idx,
6586 sae_data, sae_data_len);
6587 wdev_unlock(dev->ieee80211_ptr);
6588 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006589}
6590
Johannes Bergc0692b82010-08-27 14:26:53 +03006591static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6592 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006593 struct cfg80211_crypto_settings *settings,
6594 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006595{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006596 memset(settings, 0, sizeof(*settings));
6597
Samuel Ortizb23aa672009-07-01 21:26:54 +02006598 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6599
Johannes Bergc0692b82010-08-27 14:26:53 +03006600 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6601 u16 proto;
6602 proto = nla_get_u16(
6603 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6604 settings->control_port_ethertype = cpu_to_be16(proto);
6605 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6606 proto != ETH_P_PAE)
6607 return -EINVAL;
6608 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6609 settings->control_port_no_encrypt = true;
6610 } else
6611 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6612
Samuel Ortizb23aa672009-07-01 21:26:54 +02006613 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6614 void *data;
6615 int len, i;
6616
6617 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6618 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6619 settings->n_ciphers_pairwise = len / sizeof(u32);
6620
6621 if (len % sizeof(u32))
6622 return -EINVAL;
6623
Johannes Berg3dc27d22009-07-02 21:36:37 +02006624 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006625 return -EINVAL;
6626
6627 memcpy(settings->ciphers_pairwise, data, len);
6628
6629 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006630 if (!cfg80211_supported_cipher_suite(
6631 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006632 settings->ciphers_pairwise[i]))
6633 return -EINVAL;
6634 }
6635
6636 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6637 settings->cipher_group =
6638 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006639 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6640 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006641 return -EINVAL;
6642 }
6643
6644 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6645 settings->wpa_versions =
6646 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6647 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6648 return -EINVAL;
6649 }
6650
6651 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6652 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006653 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006654
6655 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6656 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6657 settings->n_akm_suites = len / sizeof(u32);
6658
6659 if (len % sizeof(u32))
6660 return -EINVAL;
6661
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006662 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6663 return -EINVAL;
6664
Samuel Ortizb23aa672009-07-01 21:26:54 +02006665 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006666 }
6667
6668 return 0;
6669}
6670
Jouni Malinen636a5d32009-03-19 13:39:22 +02006671static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6672{
Johannes Berg4c476992010-10-04 21:36:35 +02006673 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6674 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006675 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006676 struct cfg80211_assoc_request req = {};
6677 const u8 *bssid, *ssid;
6678 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006679
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006680 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6681 return -EINVAL;
6682
6683 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006684 !info->attrs[NL80211_ATTR_SSID] ||
6685 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006686 return -EINVAL;
6687
Johannes Berg4c476992010-10-04 21:36:35 +02006688 if (!rdev->ops->assoc)
6689 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006690
Johannes Berg074ac8d2010-09-16 14:58:22 +02006691 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006692 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6693 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006694
Johannes Berg19957bb2009-07-02 17:20:43 +02006695 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006696
Jouni Malinen664834d2014-01-15 00:01:44 +02006697 chan = nl80211_get_valid_chan(&rdev->wiphy,
6698 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6699 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006700 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006701
Johannes Berg19957bb2009-07-02 17:20:43 +02006702 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6703 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006704
6705 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006706 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6707 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006708 }
6709
Jouni Malinendc6382c2009-05-06 22:09:37 +03006710 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006711 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006712 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006713 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006714 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006715 else if (mfp != NL80211_MFP_NO)
6716 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006717 }
6718
Johannes Berg3e5d7642009-07-07 14:37:26 +02006719 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006720 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006721
Ben Greear7e7c8922011-11-18 11:31:59 -08006722 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006723 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006724
6725 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006726 memcpy(&req.ht_capa_mask,
6727 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6728 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006729
6730 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006731 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006732 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006733 memcpy(&req.ht_capa,
6734 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6735 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006736 }
6737
Johannes Bergee2aca32013-02-21 17:36:01 +01006738 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006739 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006740
6741 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006742 memcpy(&req.vht_capa_mask,
6743 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6744 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006745
6746 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006747 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006748 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006749 memcpy(&req.vht_capa,
6750 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6751 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006752 }
6753
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006754 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6755 if (!(rdev->wiphy.features &
6756 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6757 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6758 return -EINVAL;
6759 req.flags |= ASSOC_REQ_USE_RRM;
6760 }
6761
Johannes Bergf62fab72013-02-21 20:09:09 +01006762 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006763 if (!err) {
6764 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006765 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6766 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006767 wdev_unlock(dev->ieee80211_ptr);
6768 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006769
Jouni Malinen636a5d32009-03-19 13:39:22 +02006770 return err;
6771}
6772
6773static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6774{
Johannes Berg4c476992010-10-04 21:36:35 +02006775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6776 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006777 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006778 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006779 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006780 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006781
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006782 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6783 return -EINVAL;
6784
6785 if (!info->attrs[NL80211_ATTR_MAC])
6786 return -EINVAL;
6787
6788 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6789 return -EINVAL;
6790
Johannes Berg4c476992010-10-04 21:36:35 +02006791 if (!rdev->ops->deauth)
6792 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006793
Johannes Berg074ac8d2010-09-16 14:58:22 +02006794 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006795 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6796 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006797
Johannes Berg19957bb2009-07-02 17:20:43 +02006798 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006799
Johannes Berg19957bb2009-07-02 17:20:43 +02006800 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6801 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006802 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006803 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006804 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006805
6806 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006807 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6808 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006809 }
6810
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006811 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6812
Johannes Berg91bf9b22013-05-15 17:44:01 +02006813 wdev_lock(dev->ieee80211_ptr);
6814 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6815 local_state_change);
6816 wdev_unlock(dev->ieee80211_ptr);
6817 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006818}
6819
6820static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6821{
Johannes Berg4c476992010-10-04 21:36:35 +02006822 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6823 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006824 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006825 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006826 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006827 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006828
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006829 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6830 return -EINVAL;
6831
6832 if (!info->attrs[NL80211_ATTR_MAC])
6833 return -EINVAL;
6834
6835 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6836 return -EINVAL;
6837
Johannes Berg4c476992010-10-04 21:36:35 +02006838 if (!rdev->ops->disassoc)
6839 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006840
Johannes Berg074ac8d2010-09-16 14:58:22 +02006841 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006842 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6843 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006844
Johannes Berg19957bb2009-07-02 17:20:43 +02006845 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006846
Johannes Berg19957bb2009-07-02 17:20:43 +02006847 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6848 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006849 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006850 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006851 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006852
6853 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006854 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6855 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006856 }
6857
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006858 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6859
Johannes Berg91bf9b22013-05-15 17:44:01 +02006860 wdev_lock(dev->ieee80211_ptr);
6861 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6862 local_state_change);
6863 wdev_unlock(dev->ieee80211_ptr);
6864 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006865}
6866
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006867static bool
6868nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6869 int mcast_rate[IEEE80211_NUM_BANDS],
6870 int rateval)
6871{
6872 struct wiphy *wiphy = &rdev->wiphy;
6873 bool found = false;
6874 int band, i;
6875
6876 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6877 struct ieee80211_supported_band *sband;
6878
6879 sband = wiphy->bands[band];
6880 if (!sband)
6881 continue;
6882
6883 for (i = 0; i < sband->n_bitrates; i++) {
6884 if (sband->bitrates[i].bitrate == rateval) {
6885 mcast_rate[band] = i + 1;
6886 found = true;
6887 break;
6888 }
6889 }
6890 }
6891
6892 return found;
6893}
6894
Johannes Berg04a773a2009-04-19 21:24:32 +02006895static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6896{
Johannes Berg4c476992010-10-04 21:36:35 +02006897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6898 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006899 struct cfg80211_ibss_params ibss;
6900 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006901 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006902 int err;
6903
Johannes Berg8e30bc52009-04-22 17:45:38 +02006904 memset(&ibss, 0, sizeof(ibss));
6905
Johannes Berg04a773a2009-04-19 21:24:32 +02006906 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6907 return -EINVAL;
6908
Johannes Berg683b6d32012-11-08 21:25:48 +01006909 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006910 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6911 return -EINVAL;
6912
Johannes Berg8e30bc52009-04-22 17:45:38 +02006913 ibss.beacon_interval = 100;
6914
6915 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6916 ibss.beacon_interval =
6917 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6918 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6919 return -EINVAL;
6920 }
6921
Johannes Berg4c476992010-10-04 21:36:35 +02006922 if (!rdev->ops->join_ibss)
6923 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006924
Johannes Berg4c476992010-10-04 21:36:35 +02006925 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6926 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006927
Johannes Berg79c97e92009-07-07 03:56:12 +02006928 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006929
Johannes Berg39193492011-09-16 13:45:25 +02006930 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006931 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006932
6933 if (!is_valid_ether_addr(ibss.bssid))
6934 return -EINVAL;
6935 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006936 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6937 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6938
6939 if (info->attrs[NL80211_ATTR_IE]) {
6940 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6941 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6942 }
6943
Johannes Berg683b6d32012-11-08 21:25:48 +01006944 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6945 if (err)
6946 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006947
Ilan Peer174e0cd2014-02-23 09:13:01 +02006948 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6949 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006950 return -EINVAL;
6951
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006952 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006953 case NL80211_CHAN_WIDTH_5:
6954 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006955 case NL80211_CHAN_WIDTH_20_NOHT:
6956 break;
6957 case NL80211_CHAN_WIDTH_20:
6958 case NL80211_CHAN_WIDTH_40:
6959 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6960 break;
6961 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006962 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006963 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006964
Johannes Berg04a773a2009-04-19 21:24:32 +02006965 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006966 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006967
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006968 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6969 u8 *rates =
6970 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6971 int n_rates =
6972 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6973 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006974 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006975
Johannes Berg34850ab2011-07-18 18:08:35 +02006976 err = ieee80211_get_ratemask(sband, rates, n_rates,
6977 &ibss.basic_rates);
6978 if (err)
6979 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006980 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006981
Simon Wunderlich803768f2013-06-28 10:39:58 +02006982 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6983 memcpy(&ibss.ht_capa_mask,
6984 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6985 sizeof(ibss.ht_capa_mask));
6986
6987 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6988 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6989 return -EINVAL;
6990 memcpy(&ibss.ht_capa,
6991 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6992 sizeof(ibss.ht_capa));
6993 }
6994
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006995 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6996 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6997 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6998 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006999
Johannes Berg4c476992010-10-04 21:36:35 +02007000 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307001 bool no_ht = false;
7002
Johannes Berg4c476992010-10-04 21:36:35 +02007003 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307004 info->attrs[NL80211_ATTR_KEYS],
7005 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007006 if (IS_ERR(connkeys))
7007 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307008
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007009 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7010 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307011 kfree(connkeys);
7012 return -EINVAL;
7013 }
Johannes Berg4c476992010-10-04 21:36:35 +02007014 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007015
Antonio Quartulli267335d2012-01-31 20:25:47 +01007016 ibss.control_port =
7017 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7018
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007019 ibss.userspace_handles_dfs =
7020 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7021
Johannes Berg4c476992010-10-04 21:36:35 +02007022 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007023 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007024 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007025 return err;
7026}
7027
7028static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7029{
Johannes Berg4c476992010-10-04 21:36:35 +02007030 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7031 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007032
Johannes Berg4c476992010-10-04 21:36:35 +02007033 if (!rdev->ops->leave_ibss)
7034 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007035
Johannes Berg4c476992010-10-04 21:36:35 +02007036 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7037 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007038
Johannes Berg4c476992010-10-04 21:36:35 +02007039 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007040}
7041
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007042static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7043{
7044 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7045 struct net_device *dev = info->user_ptr[1];
7046 int mcast_rate[IEEE80211_NUM_BANDS];
7047 u32 nla_rate;
7048 int err;
7049
7050 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7051 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7052 return -EOPNOTSUPP;
7053
7054 if (!rdev->ops->set_mcast_rate)
7055 return -EOPNOTSUPP;
7056
7057 memset(mcast_rate, 0, sizeof(mcast_rate));
7058
7059 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7060 return -EINVAL;
7061
7062 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7063 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7064 return -EINVAL;
7065
7066 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7067
7068 return err;
7069}
7070
Johannes Bergad7e7182013-11-13 13:37:47 +01007071static struct sk_buff *
7072__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7073 int approxlen, u32 portid, u32 seq,
7074 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007075 enum nl80211_attrs attr,
7076 const struct nl80211_vendor_cmd_info *info,
7077 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007078{
7079 struct sk_buff *skb;
7080 void *hdr;
7081 struct nlattr *data;
7082
7083 skb = nlmsg_new(approxlen + 100, gfp);
7084 if (!skb)
7085 return NULL;
7086
7087 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7088 if (!hdr) {
7089 kfree_skb(skb);
7090 return NULL;
7091 }
7092
7093 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7094 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007095
7096 if (info) {
7097 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7098 info->vendor_id))
7099 goto nla_put_failure;
7100 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7101 info->subcmd))
7102 goto nla_put_failure;
7103 }
7104
Johannes Bergad7e7182013-11-13 13:37:47 +01007105 data = nla_nest_start(skb, attr);
7106
7107 ((void **)skb->cb)[0] = rdev;
7108 ((void **)skb->cb)[1] = hdr;
7109 ((void **)skb->cb)[2] = data;
7110
7111 return skb;
7112
7113 nla_put_failure:
7114 kfree_skb(skb);
7115 return NULL;
7116}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007117
Johannes Berge03ad6e2014-01-01 17:22:30 +01007118struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7119 enum nl80211_commands cmd,
7120 enum nl80211_attrs attr,
7121 int vendor_event_idx,
7122 int approxlen, gfp_t gfp)
7123{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007124 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007125 const struct nl80211_vendor_cmd_info *info;
7126
7127 switch (cmd) {
7128 case NL80211_CMD_TESTMODE:
7129 if (WARN_ON(vendor_event_idx != -1))
7130 return NULL;
7131 info = NULL;
7132 break;
7133 case NL80211_CMD_VENDOR:
7134 if (WARN_ON(vendor_event_idx < 0 ||
7135 vendor_event_idx >= wiphy->n_vendor_events))
7136 return NULL;
7137 info = &wiphy->vendor_events[vendor_event_idx];
7138 break;
7139 default:
7140 WARN_ON(1);
7141 return NULL;
7142 }
7143
7144 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7145 cmd, attr, info, gfp);
7146}
7147EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7148
7149void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7150{
7151 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7152 void *hdr = ((void **)skb->cb)[1];
7153 struct nlattr *data = ((void **)skb->cb)[2];
7154 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7155
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007156 /* clear CB data for netlink core to own from now on */
7157 memset(skb->cb, 0, sizeof(skb->cb));
7158
Johannes Berge03ad6e2014-01-01 17:22:30 +01007159 nla_nest_end(skb, data);
7160 genlmsg_end(skb, hdr);
7161
7162 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7163 mcgrp = NL80211_MCGRP_VENDOR;
7164
7165 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7166 mcgrp, gfp);
7167}
7168EXPORT_SYMBOL(__cfg80211_send_event_skb);
7169
Johannes Bergaff89a92009-07-01 21:26:51 +02007170#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007171static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7172{
Johannes Berg4c476992010-10-04 21:36:35 +02007173 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007174 struct wireless_dev *wdev =
7175 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007176 int err;
7177
David Spinadelfc73f112013-07-31 18:04:15 +03007178 if (!rdev->ops->testmode_cmd)
7179 return -EOPNOTSUPP;
7180
7181 if (IS_ERR(wdev)) {
7182 err = PTR_ERR(wdev);
7183 if (err != -EINVAL)
7184 return err;
7185 wdev = NULL;
7186 } else if (wdev->wiphy != &rdev->wiphy) {
7187 return -EINVAL;
7188 }
7189
Johannes Bergaff89a92009-07-01 21:26:51 +02007190 if (!info->attrs[NL80211_ATTR_TESTDATA])
7191 return -EINVAL;
7192
Johannes Bergad7e7182013-11-13 13:37:47 +01007193 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007194 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007195 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7196 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007197 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007198
Johannes Bergaff89a92009-07-01 21:26:51 +02007199 return err;
7200}
7201
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007202static int nl80211_testmode_dump(struct sk_buff *skb,
7203 struct netlink_callback *cb)
7204{
Johannes Berg00918d32011-12-13 17:22:05 +01007205 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007206 int err;
7207 long phy_idx;
7208 void *data = NULL;
7209 int data_len = 0;
7210
Johannes Berg5fe231e2013-05-08 21:45:15 +02007211 rtnl_lock();
7212
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007213 if (cb->args[0]) {
7214 /*
7215 * 0 is a valid index, but not valid for args[0],
7216 * so we need to offset by 1.
7217 */
7218 phy_idx = cb->args[0] - 1;
7219 } else {
7220 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7221 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7222 nl80211_policy);
7223 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007224 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007225
Johannes Berg2bd7e352012-06-15 14:23:16 +02007226 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7227 nl80211_fam.attrbuf);
7228 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007229 err = PTR_ERR(rdev);
7230 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007231 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007232 phy_idx = rdev->wiphy_idx;
7233 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007234
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007235 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7236 cb->args[1] =
7237 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7238 }
7239
7240 if (cb->args[1]) {
7241 data = nla_data((void *)cb->args[1]);
7242 data_len = nla_len((void *)cb->args[1]);
7243 }
7244
Johannes Berg00918d32011-12-13 17:22:05 +01007245 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7246 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007247 err = -ENOENT;
7248 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007249 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007250
Johannes Berg00918d32011-12-13 17:22:05 +01007251 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007252 err = -EOPNOTSUPP;
7253 goto out_err;
7254 }
7255
7256 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007257 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007258 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7259 NL80211_CMD_TESTMODE);
7260 struct nlattr *tmdata;
7261
Dan Carpentercb35fba2013-08-14 14:50:01 +03007262 if (!hdr)
7263 break;
7264
David S. Miller9360ffd2012-03-29 04:41:26 -04007265 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007266 genlmsg_cancel(skb, hdr);
7267 break;
7268 }
7269
7270 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7271 if (!tmdata) {
7272 genlmsg_cancel(skb, hdr);
7273 break;
7274 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007275 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007276 nla_nest_end(skb, tmdata);
7277
7278 if (err == -ENOBUFS || err == -ENOENT) {
7279 genlmsg_cancel(skb, hdr);
7280 break;
7281 } else if (err) {
7282 genlmsg_cancel(skb, hdr);
7283 goto out_err;
7284 }
7285
7286 genlmsg_end(skb, hdr);
7287 }
7288
7289 err = skb->len;
7290 /* see above */
7291 cb->args[0] = phy_idx + 1;
7292 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007293 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007294 return err;
7295}
Johannes Bergaff89a92009-07-01 21:26:51 +02007296#endif
7297
Samuel Ortizb23aa672009-07-01 21:26:54 +02007298static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7299{
Johannes Berg4c476992010-10-04 21:36:35 +02007300 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7301 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007302 struct cfg80211_connect_params connect;
7303 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007304 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007305 int err;
7306
7307 memset(&connect, 0, sizeof(connect));
7308
7309 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7310 return -EINVAL;
7311
7312 if (!info->attrs[NL80211_ATTR_SSID] ||
7313 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7314 return -EINVAL;
7315
7316 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7317 connect.auth_type =
7318 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007319 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7320 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007321 return -EINVAL;
7322 } else
7323 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7324
7325 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7326
Johannes Bergc0692b82010-08-27 14:26:53 +03007327 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007328 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007329 if (err)
7330 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007331
Johannes Berg074ac8d2010-09-16 14:58:22 +02007332 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007333 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7334 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007335
Johannes Berg79c97e92009-07-07 03:56:12 +02007336 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007337
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307338 connect.bg_scan_period = -1;
7339 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7340 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7341 connect.bg_scan_period =
7342 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7343 }
7344
Samuel Ortizb23aa672009-07-01 21:26:54 +02007345 if (info->attrs[NL80211_ATTR_MAC])
7346 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007347 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7348 connect.bssid_hint =
7349 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007350 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7351 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7352
7353 if (info->attrs[NL80211_ATTR_IE]) {
7354 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7355 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7356 }
7357
Jouni Malinencee00a92013-01-15 17:15:57 +02007358 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7359 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7360 if (connect.mfp != NL80211_MFP_REQUIRED &&
7361 connect.mfp != NL80211_MFP_NO)
7362 return -EINVAL;
7363 } else {
7364 connect.mfp = NL80211_MFP_NO;
7365 }
7366
Samuel Ortizb23aa672009-07-01 21:26:54 +02007367 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007368 connect.channel = nl80211_get_valid_chan(
7369 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7370 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007371 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007372 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007373 connect.channel_hint = nl80211_get_valid_chan(
7374 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7375 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007376 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007377 }
7378
Johannes Bergfffd0932009-07-08 14:22:54 +02007379 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7380 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307381 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007382 if (IS_ERR(connkeys))
7383 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007384 }
7385
Ben Greear7e7c8922011-11-18 11:31:59 -08007386 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7387 connect.flags |= ASSOC_REQ_DISABLE_HT;
7388
7389 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7390 memcpy(&connect.ht_capa_mask,
7391 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7392 sizeof(connect.ht_capa_mask));
7393
7394 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007395 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007396 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007397 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007398 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007399 memcpy(&connect.ht_capa,
7400 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7401 sizeof(connect.ht_capa));
7402 }
7403
Johannes Bergee2aca32013-02-21 17:36:01 +01007404 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7405 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7406
7407 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7408 memcpy(&connect.vht_capa_mask,
7409 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7410 sizeof(connect.vht_capa_mask));
7411
7412 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7413 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007414 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007415 return -EINVAL;
7416 }
7417 memcpy(&connect.vht_capa,
7418 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7419 sizeof(connect.vht_capa));
7420 }
7421
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007422 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7423 if (!(rdev->wiphy.features &
7424 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7425 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7426 return -EINVAL;
7427 connect.flags |= ASSOC_REQ_USE_RRM;
7428 }
7429
Johannes Berg83739b02013-05-15 17:44:01 +02007430 wdev_lock(dev->ieee80211_ptr);
7431 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7432 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007433 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007434 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007435 return err;
7436}
7437
7438static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7439{
Johannes Berg4c476992010-10-04 21:36:35 +02007440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7441 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007442 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007443 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007444
7445 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7446 reason = WLAN_REASON_DEAUTH_LEAVING;
7447 else
7448 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7449
7450 if (reason == 0)
7451 return -EINVAL;
7452
Johannes Berg074ac8d2010-09-16 14:58:22 +02007453 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007454 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7455 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007456
Johannes Berg83739b02013-05-15 17:44:01 +02007457 wdev_lock(dev->ieee80211_ptr);
7458 ret = cfg80211_disconnect(rdev, dev, reason, true);
7459 wdev_unlock(dev->ieee80211_ptr);
7460 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007461}
7462
Johannes Berg463d0182009-07-14 00:33:35 +02007463static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7464{
Johannes Berg4c476992010-10-04 21:36:35 +02007465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007466 struct net *net;
7467 int err;
7468 u32 pid;
7469
7470 if (!info->attrs[NL80211_ATTR_PID])
7471 return -EINVAL;
7472
7473 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7474
Johannes Berg463d0182009-07-14 00:33:35 +02007475 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007476 if (IS_ERR(net))
7477 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007478
7479 err = 0;
7480
7481 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007482 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7483 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007484
Johannes Berg463d0182009-07-14 00:33:35 +02007485 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007486 return err;
7487}
7488
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007489static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7490{
Johannes Berg4c476992010-10-04 21:36:35 +02007491 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007492 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7493 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007494 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007495 struct cfg80211_pmksa pmksa;
7496
7497 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7498
7499 if (!info->attrs[NL80211_ATTR_MAC])
7500 return -EINVAL;
7501
7502 if (!info->attrs[NL80211_ATTR_PMKID])
7503 return -EINVAL;
7504
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007505 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7506 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7507
Johannes Berg074ac8d2010-09-16 14:58:22 +02007508 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007509 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7510 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007511
7512 switch (info->genlhdr->cmd) {
7513 case NL80211_CMD_SET_PMKSA:
7514 rdev_ops = rdev->ops->set_pmksa;
7515 break;
7516 case NL80211_CMD_DEL_PMKSA:
7517 rdev_ops = rdev->ops->del_pmksa;
7518 break;
7519 default:
7520 WARN_ON(1);
7521 break;
7522 }
7523
Johannes Berg4c476992010-10-04 21:36:35 +02007524 if (!rdev_ops)
7525 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007526
Johannes Berg4c476992010-10-04 21:36:35 +02007527 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007528}
7529
7530static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7531{
Johannes Berg4c476992010-10-04 21:36:35 +02007532 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7533 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007534
Johannes Berg074ac8d2010-09-16 14:58:22 +02007535 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007536 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7537 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007538
Johannes Berg4c476992010-10-04 21:36:35 +02007539 if (!rdev->ops->flush_pmksa)
7540 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007541
Hila Gonene35e4d22012-06-27 17:19:42 +03007542 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007543}
7544
Arik Nemtsov109086c2011-09-28 14:12:50 +03007545static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7546{
7547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7548 struct net_device *dev = info->user_ptr[1];
7549 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307550 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007551 u16 status_code;
7552 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007553 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007554
7555 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7556 !rdev->ops->tdls_mgmt)
7557 return -EOPNOTSUPP;
7558
7559 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7560 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7561 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7562 !info->attrs[NL80211_ATTR_IE] ||
7563 !info->attrs[NL80211_ATTR_MAC])
7564 return -EINVAL;
7565
7566 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7567 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7568 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7569 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007570 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307571 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7572 peer_capability =
7573 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007574
Hila Gonene35e4d22012-06-27 17:19:42 +03007575 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307576 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007577 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007578 nla_data(info->attrs[NL80211_ATTR_IE]),
7579 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007580}
7581
7582static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7583{
7584 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7585 struct net_device *dev = info->user_ptr[1];
7586 enum nl80211_tdls_operation operation;
7587 u8 *peer;
7588
7589 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7590 !rdev->ops->tdls_oper)
7591 return -EOPNOTSUPP;
7592
7593 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7594 !info->attrs[NL80211_ATTR_MAC])
7595 return -EINVAL;
7596
7597 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7598 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7599
Hila Gonene35e4d22012-06-27 17:19:42 +03007600 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007601}
7602
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007603static int nl80211_remain_on_channel(struct sk_buff *skb,
7604 struct genl_info *info)
7605{
Johannes Berg4c476992010-10-04 21:36:35 +02007606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007607 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007608 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007609 struct sk_buff *msg;
7610 void *hdr;
7611 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007612 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007613 int err;
7614
7615 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7616 !info->attrs[NL80211_ATTR_DURATION])
7617 return -EINVAL;
7618
7619 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7620
Johannes Berg7c4ef712011-11-18 15:33:48 +01007621 if (!rdev->ops->remain_on_channel ||
7622 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007623 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007624
Johannes Bergebf348f2012-06-01 12:50:54 +02007625 /*
7626 * We should be on that channel for at least a minimum amount of
7627 * time (10ms) but no longer than the driver supports.
7628 */
7629 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7630 duration > rdev->wiphy.max_remain_on_channel_duration)
7631 return -EINVAL;
7632
Johannes Berg683b6d32012-11-08 21:25:48 +01007633 err = nl80211_parse_chandef(rdev, info, &chandef);
7634 if (err)
7635 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007636
7637 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007638 if (!msg)
7639 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007640
Eric W. Biederman15e47302012-09-07 20:12:54 +00007641 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007642 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007643 if (!hdr) {
7644 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007645 goto free_msg;
7646 }
7647
Johannes Berg683b6d32012-11-08 21:25:48 +01007648 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7649 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007650
7651 if (err)
7652 goto free_msg;
7653
David S. Miller9360ffd2012-03-29 04:41:26 -04007654 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7655 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007656
7657 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007658
7659 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007660
7661 nla_put_failure:
7662 err = -ENOBUFS;
7663 free_msg:
7664 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007665 return err;
7666}
7667
7668static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7669 struct genl_info *info)
7670{
Johannes Berg4c476992010-10-04 21:36:35 +02007671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007672 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007673 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007674
7675 if (!info->attrs[NL80211_ATTR_COOKIE])
7676 return -EINVAL;
7677
Johannes Berg4c476992010-10-04 21:36:35 +02007678 if (!rdev->ops->cancel_remain_on_channel)
7679 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007680
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007681 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7682
Hila Gonene35e4d22012-06-27 17:19:42 +03007683 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007684}
7685
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007686static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7687 u8 *rates, u8 rates_len)
7688{
7689 u8 i;
7690 u32 mask = 0;
7691
7692 for (i = 0; i < rates_len; i++) {
7693 int rate = (rates[i] & 0x7f) * 5;
7694 int ridx;
7695 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7696 struct ieee80211_rate *srate =
7697 &sband->bitrates[ridx];
7698 if (rate == srate->bitrate) {
7699 mask |= 1 << ridx;
7700 break;
7701 }
7702 }
7703 if (ridx == sband->n_bitrates)
7704 return 0; /* rate not found */
7705 }
7706
7707 return mask;
7708}
7709
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007710static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7711 u8 *rates, u8 rates_len,
7712 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7713{
7714 u8 i;
7715
7716 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7717
7718 for (i = 0; i < rates_len; i++) {
7719 int ridx, rbit;
7720
7721 ridx = rates[i] / 8;
7722 rbit = BIT(rates[i] % 8);
7723
7724 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007725 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007726 return false;
7727
7728 /* check availability */
7729 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7730 mcs[ridx] |= rbit;
7731 else
7732 return false;
7733 }
7734
7735 return true;
7736}
7737
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007738static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7739{
7740 u16 mcs_mask = 0;
7741
7742 switch (vht_mcs_map) {
7743 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7744 break;
7745 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7746 mcs_mask = 0x00FF;
7747 break;
7748 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7749 mcs_mask = 0x01FF;
7750 break;
7751 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7752 mcs_mask = 0x03FF;
7753 break;
7754 default:
7755 break;
7756 }
7757
7758 return mcs_mask;
7759}
7760
7761static void vht_build_mcs_mask(u16 vht_mcs_map,
7762 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7763{
7764 u8 nss;
7765
7766 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7767 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7768 vht_mcs_map >>= 2;
7769 }
7770}
7771
7772static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7773 struct nl80211_txrate_vht *txrate,
7774 u16 mcs[NL80211_VHT_NSS_MAX])
7775{
7776 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7777 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7778 u8 i;
7779
7780 if (!sband->vht_cap.vht_supported)
7781 return false;
7782
7783 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7784
7785 /* Build vht_mcs_mask from VHT capabilities */
7786 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7787
7788 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7789 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7790 mcs[i] = txrate->mcs[i];
7791 else
7792 return false;
7793 }
7794
7795 return true;
7796}
7797
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007798static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007799 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7800 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007801 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7802 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007803 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007804 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007805};
7806
7807static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7808 struct genl_info *info)
7809{
7810 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007812 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007813 int rem, i;
7814 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007815 struct nlattr *tx_rates;
7816 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007817 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007818
Johannes Berg4c476992010-10-04 21:36:35 +02007819 if (!rdev->ops->set_bitrate_mask)
7820 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007821
7822 memset(&mask, 0, sizeof(mask));
7823 /* Default to all rates enabled */
7824 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7825 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007826
7827 if (!sband)
7828 continue;
7829
7830 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007831 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007832 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007833 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007834
7835 if (!sband->vht_cap.vht_supported)
7836 continue;
7837
7838 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7839 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007840 }
7841
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007842 /* if no rates are given set it back to the defaults */
7843 if (!info->attrs[NL80211_ATTR_TX_RATES])
7844 goto out;
7845
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007846 /*
7847 * The nested attribute uses enum nl80211_band as the index. This maps
7848 * directly to the enum ieee80211_band values used in cfg80211.
7849 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007850 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007851 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007852 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007853 int err;
7854
Johannes Berg4c476992010-10-04 21:36:35 +02007855 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7856 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007857 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007858 if (sband == NULL)
7859 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007860 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7861 nla_len(tx_rates), nl80211_txattr_policy);
7862 if (err)
7863 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007864 if (tb[NL80211_TXRATE_LEGACY]) {
7865 mask.control[band].legacy = rateset_to_mask(
7866 sband,
7867 nla_data(tb[NL80211_TXRATE_LEGACY]),
7868 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307869 if ((mask.control[band].legacy == 0) &&
7870 nla_len(tb[NL80211_TXRATE_LEGACY]))
7871 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007872 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007873 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007874 if (!ht_rateset_to_mask(
7875 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007876 nla_data(tb[NL80211_TXRATE_HT]),
7877 nla_len(tb[NL80211_TXRATE_HT]),
7878 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007879 return -EINVAL;
7880 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007881 if (tb[NL80211_TXRATE_VHT]) {
7882 if (!vht_set_mcs_mask(
7883 sband,
7884 nla_data(tb[NL80211_TXRATE_VHT]),
7885 mask.control[band].vht_mcs))
7886 return -EINVAL;
7887 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007888 if (tb[NL80211_TXRATE_GI]) {
7889 mask.control[band].gi =
7890 nla_get_u8(tb[NL80211_TXRATE_GI]);
7891 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7892 return -EINVAL;
7893 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007894
7895 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007896 /* don't allow empty legacy rates if HT or VHT
7897 * are not even supported.
7898 */
7899 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7900 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007901 return -EINVAL;
7902
7903 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007904 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007905 goto out;
7906
7907 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7908 if (mask.control[band].vht_mcs[i])
7909 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007910
7911 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007912 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007913 }
7914 }
7915
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007916out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007917 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007918}
7919
Johannes Berg2e161f72010-08-12 15:38:38 +02007920static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007921{
Johannes Berg4c476992010-10-04 21:36:35 +02007922 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007923 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007924 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007925
7926 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7927 return -EINVAL;
7928
Johannes Berg2e161f72010-08-12 15:38:38 +02007929 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7930 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007931
Johannes Berg71bbc992012-06-15 15:30:18 +02007932 switch (wdev->iftype) {
7933 case NL80211_IFTYPE_STATION:
7934 case NL80211_IFTYPE_ADHOC:
7935 case NL80211_IFTYPE_P2P_CLIENT:
7936 case NL80211_IFTYPE_AP:
7937 case NL80211_IFTYPE_AP_VLAN:
7938 case NL80211_IFTYPE_MESH_POINT:
7939 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007940 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007941 break;
7942 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007943 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007944 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007945
7946 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007947 if (!rdev->ops->mgmt_tx)
7948 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007949
Eric W. Biederman15e47302012-09-07 20:12:54 +00007950 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007951 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7952 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007953}
7954
Johannes Berg2e161f72010-08-12 15:38:38 +02007955static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007956{
Johannes Berg4c476992010-10-04 21:36:35 +02007957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007958 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007959 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007960 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007961 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007962 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007963 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007964 struct cfg80211_mgmt_tx_params params = {
7965 .dont_wait_for_ack =
7966 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7967 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007968
Johannes Berg683b6d32012-11-08 21:25:48 +01007969 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007970 return -EINVAL;
7971
Johannes Berg4c476992010-10-04 21:36:35 +02007972 if (!rdev->ops->mgmt_tx)
7973 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007974
Johannes Berg71bbc992012-06-15 15:30:18 +02007975 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007976 case NL80211_IFTYPE_P2P_DEVICE:
7977 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7978 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007979 case NL80211_IFTYPE_STATION:
7980 case NL80211_IFTYPE_ADHOC:
7981 case NL80211_IFTYPE_P2P_CLIENT:
7982 case NL80211_IFTYPE_AP:
7983 case NL80211_IFTYPE_AP_VLAN:
7984 case NL80211_IFTYPE_MESH_POINT:
7985 case NL80211_IFTYPE_P2P_GO:
7986 break;
7987 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007988 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007989 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007990
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007991 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007992 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007993 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007994 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007995
7996 /*
7997 * We should wait on the channel for at least a minimum amount
7998 * of time (10ms) but no longer than the driver supports.
7999 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008000 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8001 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008002 return -EINVAL;
8003
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008004 }
8005
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008006 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008007
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008008 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008009 return -EINVAL;
8010
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008011 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308012
Antonio Quartulliea141b752013-06-11 14:20:03 +02008013 /* get the channel if any has been specified, otherwise pass NULL to
8014 * the driver. The latter will use the current one
8015 */
8016 chandef.chan = NULL;
8017 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8018 err = nl80211_parse_chandef(rdev, info, &chandef);
8019 if (err)
8020 return err;
8021 }
8022
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008023 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008024 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008025
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008026 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8027 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8028
8029 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8030 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8031 int i;
8032
8033 if (len % sizeof(u16))
8034 return -EINVAL;
8035
8036 params.n_csa_offsets = len / sizeof(u16);
8037 params.csa_offsets =
8038 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8039
8040 /* check that all the offsets fit the frame */
8041 for (i = 0; i < params.n_csa_offsets; i++) {
8042 if (params.csa_offsets[i] >= params.len)
8043 return -EINVAL;
8044 }
8045 }
8046
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008047 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008048 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8049 if (!msg)
8050 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008051
Eric W. Biederman15e47302012-09-07 20:12:54 +00008052 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008053 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008054 if (!hdr) {
8055 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008056 goto free_msg;
8057 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008058 }
Johannes Berge247bd902011-11-04 11:18:21 +01008059
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008060 params.chan = chandef.chan;
8061 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008062 if (err)
8063 goto free_msg;
8064
Johannes Berge247bd902011-11-04 11:18:21 +01008065 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008066 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8067 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008068
Johannes Berge247bd902011-11-04 11:18:21 +01008069 genlmsg_end(msg, hdr);
8070 return genlmsg_reply(msg, info);
8071 }
8072
8073 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008074
8075 nla_put_failure:
8076 err = -ENOBUFS;
8077 free_msg:
8078 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008079 return err;
8080}
8081
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008082static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8083{
8084 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008085 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008086 u64 cookie;
8087
8088 if (!info->attrs[NL80211_ATTR_COOKIE])
8089 return -EINVAL;
8090
8091 if (!rdev->ops->mgmt_tx_cancel_wait)
8092 return -EOPNOTSUPP;
8093
Johannes Berg71bbc992012-06-15 15:30:18 +02008094 switch (wdev->iftype) {
8095 case NL80211_IFTYPE_STATION:
8096 case NL80211_IFTYPE_ADHOC:
8097 case NL80211_IFTYPE_P2P_CLIENT:
8098 case NL80211_IFTYPE_AP:
8099 case NL80211_IFTYPE_AP_VLAN:
8100 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008101 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008102 break;
8103 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008104 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008105 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008106
8107 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8108
Hila Gonene35e4d22012-06-27 17:19:42 +03008109 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008110}
8111
Kalle Valoffb9eb32010-02-17 17:58:10 +02008112static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8113{
Johannes Berg4c476992010-10-04 21:36:35 +02008114 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008115 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008116 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008117 u8 ps_state;
8118 bool state;
8119 int err;
8120
Johannes Berg4c476992010-10-04 21:36:35 +02008121 if (!info->attrs[NL80211_ATTR_PS_STATE])
8122 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008123
8124 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8125
Johannes Berg4c476992010-10-04 21:36:35 +02008126 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8127 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008128
8129 wdev = dev->ieee80211_ptr;
8130
Johannes Berg4c476992010-10-04 21:36:35 +02008131 if (!rdev->ops->set_power_mgmt)
8132 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008133
8134 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8135
8136 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008137 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008138
Hila Gonene35e4d22012-06-27 17:19:42 +03008139 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008140 if (!err)
8141 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008142 return err;
8143}
8144
8145static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8146{
Johannes Berg4c476992010-10-04 21:36:35 +02008147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008148 enum nl80211_ps_state ps_state;
8149 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008150 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008151 struct sk_buff *msg;
8152 void *hdr;
8153 int err;
8154
Kalle Valoffb9eb32010-02-17 17:58:10 +02008155 wdev = dev->ieee80211_ptr;
8156
Johannes Berg4c476992010-10-04 21:36:35 +02008157 if (!rdev->ops->set_power_mgmt)
8158 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008159
8160 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008161 if (!msg)
8162 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008163
Eric W. Biederman15e47302012-09-07 20:12:54 +00008164 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008165 NL80211_CMD_GET_POWER_SAVE);
8166 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008167 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008168 goto free_msg;
8169 }
8170
8171 if (wdev->ps)
8172 ps_state = NL80211_PS_ENABLED;
8173 else
8174 ps_state = NL80211_PS_DISABLED;
8175
David S. Miller9360ffd2012-03-29 04:41:26 -04008176 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8177 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008178
8179 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008180 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008181
Johannes Berg4c476992010-10-04 21:36:35 +02008182 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008183 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008184 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008185 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008186 return err;
8187}
8188
Johannes Berg94e860f2014-01-20 23:58:15 +01008189static const struct nla_policy
8190nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008191 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8192 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8193 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008194 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8195 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8196 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008197};
8198
Thomas Pedersen84f10702012-07-12 16:17:33 -07008199static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008200 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008201{
8202 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008203 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008204 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008205
Johannes Bergd9d8b012012-11-26 12:51:52 +01008206 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008207 return -EINVAL;
8208
Thomas Pedersen84f10702012-07-12 16:17:33 -07008209 if (!rdev->ops->set_cqm_txe_config)
8210 return -EOPNOTSUPP;
8211
8212 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8213 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8214 return -EOPNOTSUPP;
8215
Hila Gonene35e4d22012-06-27 17:19:42 +03008216 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008217}
8218
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008219static int nl80211_set_cqm_rssi(struct genl_info *info,
8220 s32 threshold, u32 hysteresis)
8221{
Johannes Berg4c476992010-10-04 21:36:35 +02008222 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008223 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008224 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008225
8226 if (threshold > 0)
8227 return -EINVAL;
8228
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008229 /* disabling - hysteresis should also be zero then */
8230 if (threshold == 0)
8231 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008232
Johannes Berg4c476992010-10-04 21:36:35 +02008233 if (!rdev->ops->set_cqm_rssi_config)
8234 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008235
Johannes Berg074ac8d2010-09-16 14:58:22 +02008236 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008237 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8238 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008239
Hila Gonene35e4d22012-06-27 17:19:42 +03008240 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008241}
8242
8243static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8244{
8245 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8246 struct nlattr *cqm;
8247 int err;
8248
8249 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008250 if (!cqm)
8251 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008252
8253 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8254 nl80211_attr_cqm_policy);
8255 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008256 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008257
8258 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8259 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008260 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8261 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008262
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008263 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8264 }
8265
8266 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8267 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8268 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8269 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8270 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8271 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8272
8273 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8274 }
8275
8276 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008277}
8278
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008279static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8280{
8281 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8282 struct net_device *dev = info->user_ptr[1];
8283 struct ocb_setup setup = {};
8284 int err;
8285
8286 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8287 if (err)
8288 return err;
8289
8290 return cfg80211_join_ocb(rdev, dev, &setup);
8291}
8292
8293static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8294{
8295 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8296 struct net_device *dev = info->user_ptr[1];
8297
8298 return cfg80211_leave_ocb(rdev, dev);
8299}
8300
Johannes Berg29cbe682010-12-03 09:20:44 +01008301static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8302{
8303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8304 struct net_device *dev = info->user_ptr[1];
8305 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008306 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008307 int err;
8308
8309 /* start with default */
8310 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008311 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008312
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008313 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008314 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008315 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008316 if (err)
8317 return err;
8318 }
8319
8320 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8321 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8322 return -EINVAL;
8323
Javier Cardonac80d5452010-12-16 17:37:49 -08008324 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8325 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8326
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008327 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8328 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8329 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8330 return -EINVAL;
8331
Marco Porsch9bdbf042013-01-07 16:04:51 +01008332 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8333 setup.beacon_interval =
8334 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8335 if (setup.beacon_interval < 10 ||
8336 setup.beacon_interval > 10000)
8337 return -EINVAL;
8338 }
8339
8340 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8341 setup.dtim_period =
8342 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8343 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8344 return -EINVAL;
8345 }
8346
Javier Cardonac80d5452010-12-16 17:37:49 -08008347 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8348 /* parse additional setup parameters if given */
8349 err = nl80211_parse_mesh_setup(info, &setup);
8350 if (err)
8351 return err;
8352 }
8353
Thomas Pedersend37bb182013-03-04 13:06:13 -08008354 if (setup.user_mpm)
8355 cfg.auto_open_plinks = false;
8356
Johannes Bergcc1d2802012-05-16 23:50:20 +02008357 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008358 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8359 if (err)
8360 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008361 } else {
8362 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008363 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008364 }
8365
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008366 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8367 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8368 int n_rates =
8369 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8370 struct ieee80211_supported_band *sband;
8371
8372 if (!setup.chandef.chan)
8373 return -EINVAL;
8374
8375 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8376
8377 err = ieee80211_get_ratemask(sband, rates, n_rates,
8378 &setup.basic_rates);
8379 if (err)
8380 return err;
8381 }
8382
Javier Cardonac80d5452010-12-16 17:37:49 -08008383 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008384}
8385
8386static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8387{
8388 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8389 struct net_device *dev = info->user_ptr[1];
8390
8391 return cfg80211_leave_mesh(rdev, dev);
8392}
8393
Johannes Bergdfb89c52012-06-27 09:23:48 +02008394#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008395static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8396 struct cfg80211_registered_device *rdev)
8397{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008398 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008399 struct nlattr *nl_pats, *nl_pat;
8400 int i, pat_len;
8401
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008402 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008403 return 0;
8404
8405 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8406 if (!nl_pats)
8407 return -ENOBUFS;
8408
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008409 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008410 nl_pat = nla_nest_start(msg, i + 1);
8411 if (!nl_pat)
8412 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008413 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008414 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008415 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008416 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8417 wowlan->patterns[i].pattern) ||
8418 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008419 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008420 return -ENOBUFS;
8421 nla_nest_end(msg, nl_pat);
8422 }
8423 nla_nest_end(msg, nl_pats);
8424
8425 return 0;
8426}
8427
Johannes Berg2a0e0472013-01-23 22:57:40 +01008428static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8429 struct cfg80211_wowlan_tcp *tcp)
8430{
8431 struct nlattr *nl_tcp;
8432
8433 if (!tcp)
8434 return 0;
8435
8436 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8437 if (!nl_tcp)
8438 return -ENOBUFS;
8439
8440 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8441 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8442 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8443 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8444 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8445 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8446 tcp->payload_len, tcp->payload) ||
8447 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8448 tcp->data_interval) ||
8449 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8450 tcp->wake_len, tcp->wake_data) ||
8451 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8452 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8453 return -ENOBUFS;
8454
8455 if (tcp->payload_seq.len &&
8456 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8457 sizeof(tcp->payload_seq), &tcp->payload_seq))
8458 return -ENOBUFS;
8459
8460 if (tcp->payload_tok.len &&
8461 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8462 sizeof(tcp->payload_tok) + tcp->tokens_size,
8463 &tcp->payload_tok))
8464 return -ENOBUFS;
8465
Johannes Berge248ad32013-05-16 10:24:28 +02008466 nla_nest_end(msg, nl_tcp);
8467
Johannes Berg2a0e0472013-01-23 22:57:40 +01008468 return 0;
8469}
8470
Johannes Bergff1b6e62011-05-04 15:37:28 +02008471static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8472{
8473 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8474 struct sk_buff *msg;
8475 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008476 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008477
Johannes Berg964dc9e2013-06-03 17:25:34 +02008478 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008479 return -EOPNOTSUPP;
8480
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008481 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008482 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008483 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8484 rdev->wiphy.wowlan_config->tcp->payload_len +
8485 rdev->wiphy.wowlan_config->tcp->wake_len +
8486 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008487 }
8488
8489 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008490 if (!msg)
8491 return -ENOMEM;
8492
Eric W. Biederman15e47302012-09-07 20:12:54 +00008493 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008494 NL80211_CMD_GET_WOWLAN);
8495 if (!hdr)
8496 goto nla_put_failure;
8497
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008498 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008499 struct nlattr *nl_wowlan;
8500
8501 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8502 if (!nl_wowlan)
8503 goto nla_put_failure;
8504
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008505 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008506 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008507 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008508 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008509 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008510 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008511 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008512 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008513 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008514 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008515 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008516 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008517 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008518 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8519 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008520
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008521 if (nl80211_send_wowlan_patterns(msg, rdev))
8522 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008523
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008524 if (nl80211_send_wowlan_tcp(msg,
8525 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008526 goto nla_put_failure;
8527
Johannes Bergff1b6e62011-05-04 15:37:28 +02008528 nla_nest_end(msg, nl_wowlan);
8529 }
8530
8531 genlmsg_end(msg, hdr);
8532 return genlmsg_reply(msg, info);
8533
8534nla_put_failure:
8535 nlmsg_free(msg);
8536 return -ENOBUFS;
8537}
8538
Johannes Berg2a0e0472013-01-23 22:57:40 +01008539static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8540 struct nlattr *attr,
8541 struct cfg80211_wowlan *trig)
8542{
8543 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8544 struct cfg80211_wowlan_tcp *cfg;
8545 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8546 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8547 u32 size;
8548 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8549 int err, port;
8550
Johannes Berg964dc9e2013-06-03 17:25:34 +02008551 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008552 return -EINVAL;
8553
8554 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8555 nla_data(attr), nla_len(attr),
8556 nl80211_wowlan_tcp_policy);
8557 if (err)
8558 return err;
8559
8560 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8561 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8562 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8563 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8564 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8565 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8566 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8567 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8568 return -EINVAL;
8569
8570 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008571 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008572 return -EINVAL;
8573
8574 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008575 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008576 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008577 return -EINVAL;
8578
8579 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008580 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008581 return -EINVAL;
8582
8583 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8584 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8585 return -EINVAL;
8586
8587 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8588 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8589
8590 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8591 tokens_size = tokln - sizeof(*tok);
8592
8593 if (!tok->len || tokens_size % tok->len)
8594 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008595 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008596 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008597 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008598 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008599 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008600 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008601 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008602 return -EINVAL;
8603 if (tok->offset + tok->len > data_size)
8604 return -EINVAL;
8605 }
8606
8607 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8608 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008609 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008610 return -EINVAL;
8611 if (seq->len == 0 || seq->len > 4)
8612 return -EINVAL;
8613 if (seq->len + seq->offset > data_size)
8614 return -EINVAL;
8615 }
8616
8617 size = sizeof(*cfg);
8618 size += data_size;
8619 size += wake_size + wake_mask_size;
8620 size += tokens_size;
8621
8622 cfg = kzalloc(size, GFP_KERNEL);
8623 if (!cfg)
8624 return -ENOMEM;
8625 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8626 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8627 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8628 ETH_ALEN);
8629 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8630 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8631 else
8632 port = 0;
8633#ifdef CONFIG_INET
8634 /* allocate a socket and port for it and use it */
8635 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8636 IPPROTO_TCP, &cfg->sock, 1);
8637 if (err) {
8638 kfree(cfg);
8639 return err;
8640 }
8641 if (inet_csk_get_port(cfg->sock->sk, port)) {
8642 sock_release(cfg->sock);
8643 kfree(cfg);
8644 return -EADDRINUSE;
8645 }
8646 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8647#else
8648 if (!port) {
8649 kfree(cfg);
8650 return -EINVAL;
8651 }
8652 cfg->src_port = port;
8653#endif
8654
8655 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8656 cfg->payload_len = data_size;
8657 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8658 memcpy((void *)cfg->payload,
8659 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8660 data_size);
8661 if (seq)
8662 cfg->payload_seq = *seq;
8663 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8664 cfg->wake_len = wake_size;
8665 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8666 memcpy((void *)cfg->wake_data,
8667 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8668 wake_size);
8669 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8670 data_size + wake_size;
8671 memcpy((void *)cfg->wake_mask,
8672 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8673 wake_mask_size);
8674 if (tok) {
8675 cfg->tokens_size = tokens_size;
8676 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8677 }
8678
8679 trig->tcp = cfg;
8680
8681 return 0;
8682}
8683
Johannes Bergff1b6e62011-05-04 15:37:28 +02008684static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8685{
8686 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8687 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008688 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008689 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008690 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008691 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008692 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008693
Johannes Berg964dc9e2013-06-03 17:25:34 +02008694 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008695 return -EOPNOTSUPP;
8696
Johannes Bergae33bd82012-07-12 16:25:02 +02008697 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8698 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008699 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008700 goto set_wakeup;
8701 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008702
8703 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8704 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8705 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8706 nl80211_wowlan_policy);
8707 if (err)
8708 return err;
8709
8710 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8711 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8712 return -EINVAL;
8713 new_triggers.any = true;
8714 }
8715
8716 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8717 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8718 return -EINVAL;
8719 new_triggers.disconnect = true;
8720 }
8721
8722 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8723 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8724 return -EINVAL;
8725 new_triggers.magic_pkt = true;
8726 }
8727
Johannes Berg77dbbb12011-07-13 10:48:55 +02008728 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8729 return -EINVAL;
8730
8731 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8732 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8733 return -EINVAL;
8734 new_triggers.gtk_rekey_failure = true;
8735 }
8736
8737 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8738 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8739 return -EINVAL;
8740 new_triggers.eap_identity_req = true;
8741 }
8742
8743 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8744 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8745 return -EINVAL;
8746 new_triggers.four_way_handshake = true;
8747 }
8748
8749 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8750 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8751 return -EINVAL;
8752 new_triggers.rfkill_release = true;
8753 }
8754
Johannes Bergff1b6e62011-05-04 15:37:28 +02008755 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8756 struct nlattr *pat;
8757 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008758 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008759 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008760
8761 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8762 rem)
8763 n_patterns++;
8764 if (n_patterns > wowlan->n_patterns)
8765 return -EINVAL;
8766
8767 new_triggers.patterns = kcalloc(n_patterns,
8768 sizeof(new_triggers.patterns[0]),
8769 GFP_KERNEL);
8770 if (!new_triggers.patterns)
8771 return -ENOMEM;
8772
8773 new_triggers.n_patterns = n_patterns;
8774 i = 0;
8775
8776 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8777 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008778 u8 *mask_pat;
8779
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008780 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8781 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008782 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008783 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8784 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008785 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008786 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008787 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008788 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008789 goto error;
8790 if (pat_len > wowlan->pattern_max_len ||
8791 pat_len < wowlan->pattern_min_len)
8792 goto error;
8793
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008794 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008795 pkt_offset = 0;
8796 else
8797 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008798 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008799 if (pkt_offset > wowlan->max_pkt_offset)
8800 goto error;
8801 new_triggers.patterns[i].pkt_offset = pkt_offset;
8802
Johannes Berg922bd802014-05-19 17:59:50 +02008803 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8804 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008805 err = -ENOMEM;
8806 goto error;
8807 }
Johannes Berg922bd802014-05-19 17:59:50 +02008808 new_triggers.patterns[i].mask = mask_pat;
8809 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008810 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008811 mask_pat += mask_len;
8812 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008813 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008814 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008815 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008816 pat_len);
8817 i++;
8818 }
8819 }
8820
Johannes Berg2a0e0472013-01-23 22:57:40 +01008821 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8822 err = nl80211_parse_wowlan_tcp(
8823 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8824 &new_triggers);
8825 if (err)
8826 goto error;
8827 }
8828
Johannes Bergae33bd82012-07-12 16:25:02 +02008829 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8830 if (!ntrig) {
8831 err = -ENOMEM;
8832 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008833 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008834 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008835 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008836
Johannes Bergae33bd82012-07-12 16:25:02 +02008837 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008838 if (rdev->ops->set_wakeup &&
8839 prev_enabled != !!rdev->wiphy.wowlan_config)
8840 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008841
Johannes Bergff1b6e62011-05-04 15:37:28 +02008842 return 0;
8843 error:
8844 for (i = 0; i < new_triggers.n_patterns; i++)
8845 kfree(new_triggers.patterns[i].mask);
8846 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008847 if (new_triggers.tcp && new_triggers.tcp->sock)
8848 sock_release(new_triggers.tcp->sock);
8849 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008850 return err;
8851}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008852#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008853
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008854static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8855 struct cfg80211_registered_device *rdev)
8856{
8857 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8858 int i, j, pat_len;
8859 struct cfg80211_coalesce_rules *rule;
8860
8861 if (!rdev->coalesce->n_rules)
8862 return 0;
8863
8864 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8865 if (!nl_rules)
8866 return -ENOBUFS;
8867
8868 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8869 nl_rule = nla_nest_start(msg, i + 1);
8870 if (!nl_rule)
8871 return -ENOBUFS;
8872
8873 rule = &rdev->coalesce->rules[i];
8874 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8875 rule->delay))
8876 return -ENOBUFS;
8877
8878 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8879 rule->condition))
8880 return -ENOBUFS;
8881
8882 nl_pats = nla_nest_start(msg,
8883 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8884 if (!nl_pats)
8885 return -ENOBUFS;
8886
8887 for (j = 0; j < rule->n_patterns; j++) {
8888 nl_pat = nla_nest_start(msg, j + 1);
8889 if (!nl_pat)
8890 return -ENOBUFS;
8891 pat_len = rule->patterns[j].pattern_len;
8892 if (nla_put(msg, NL80211_PKTPAT_MASK,
8893 DIV_ROUND_UP(pat_len, 8),
8894 rule->patterns[j].mask) ||
8895 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8896 rule->patterns[j].pattern) ||
8897 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8898 rule->patterns[j].pkt_offset))
8899 return -ENOBUFS;
8900 nla_nest_end(msg, nl_pat);
8901 }
8902 nla_nest_end(msg, nl_pats);
8903 nla_nest_end(msg, nl_rule);
8904 }
8905 nla_nest_end(msg, nl_rules);
8906
8907 return 0;
8908}
8909
8910static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8911{
8912 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8913 struct sk_buff *msg;
8914 void *hdr;
8915
8916 if (!rdev->wiphy.coalesce)
8917 return -EOPNOTSUPP;
8918
8919 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8920 if (!msg)
8921 return -ENOMEM;
8922
8923 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8924 NL80211_CMD_GET_COALESCE);
8925 if (!hdr)
8926 goto nla_put_failure;
8927
8928 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8929 goto nla_put_failure;
8930
8931 genlmsg_end(msg, hdr);
8932 return genlmsg_reply(msg, info);
8933
8934nla_put_failure:
8935 nlmsg_free(msg);
8936 return -ENOBUFS;
8937}
8938
8939void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8940{
8941 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8942 int i, j;
8943 struct cfg80211_coalesce_rules *rule;
8944
8945 if (!coalesce)
8946 return;
8947
8948 for (i = 0; i < coalesce->n_rules; i++) {
8949 rule = &coalesce->rules[i];
8950 for (j = 0; j < rule->n_patterns; j++)
8951 kfree(rule->patterns[j].mask);
8952 kfree(rule->patterns);
8953 }
8954 kfree(coalesce->rules);
8955 kfree(coalesce);
8956 rdev->coalesce = NULL;
8957}
8958
8959static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8960 struct nlattr *rule,
8961 struct cfg80211_coalesce_rules *new_rule)
8962{
8963 int err, i;
8964 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8965 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8966 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8967 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8968
8969 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8970 nla_len(rule), nl80211_coalesce_policy);
8971 if (err)
8972 return err;
8973
8974 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8975 new_rule->delay =
8976 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8977 if (new_rule->delay > coalesce->max_delay)
8978 return -EINVAL;
8979
8980 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8981 new_rule->condition =
8982 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8983 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8984 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8985 return -EINVAL;
8986
8987 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8988 return -EINVAL;
8989
8990 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8991 rem)
8992 n_patterns++;
8993 if (n_patterns > coalesce->n_patterns)
8994 return -EINVAL;
8995
8996 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8997 GFP_KERNEL);
8998 if (!new_rule->patterns)
8999 return -ENOMEM;
9000
9001 new_rule->n_patterns = n_patterns;
9002 i = 0;
9003
9004 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9005 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009006 u8 *mask_pat;
9007
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009008 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9009 nla_len(pat), NULL);
9010 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9011 !pat_tb[NL80211_PKTPAT_PATTERN])
9012 return -EINVAL;
9013 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9014 mask_len = DIV_ROUND_UP(pat_len, 8);
9015 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9016 return -EINVAL;
9017 if (pat_len > coalesce->pattern_max_len ||
9018 pat_len < coalesce->pattern_min_len)
9019 return -EINVAL;
9020
9021 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9022 pkt_offset = 0;
9023 else
9024 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9025 if (pkt_offset > coalesce->max_pkt_offset)
9026 return -EINVAL;
9027 new_rule->patterns[i].pkt_offset = pkt_offset;
9028
Johannes Berg922bd802014-05-19 17:59:50 +02009029 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9030 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009031 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009032
9033 new_rule->patterns[i].mask = mask_pat;
9034 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9035 mask_len);
9036
9037 mask_pat += mask_len;
9038 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009039 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009040 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9041 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009042 i++;
9043 }
9044
9045 return 0;
9046}
9047
9048static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9049{
9050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9051 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9052 struct cfg80211_coalesce new_coalesce = {};
9053 struct cfg80211_coalesce *n_coalesce;
9054 int err, rem_rule, n_rules = 0, i, j;
9055 struct nlattr *rule;
9056 struct cfg80211_coalesce_rules *tmp_rule;
9057
9058 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9059 return -EOPNOTSUPP;
9060
9061 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9062 cfg80211_rdev_free_coalesce(rdev);
9063 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9064 return 0;
9065 }
9066
9067 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9068 rem_rule)
9069 n_rules++;
9070 if (n_rules > coalesce->n_rules)
9071 return -EINVAL;
9072
9073 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9074 GFP_KERNEL);
9075 if (!new_coalesce.rules)
9076 return -ENOMEM;
9077
9078 new_coalesce.n_rules = n_rules;
9079 i = 0;
9080
9081 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9082 rem_rule) {
9083 err = nl80211_parse_coalesce_rule(rdev, rule,
9084 &new_coalesce.rules[i]);
9085 if (err)
9086 goto error;
9087
9088 i++;
9089 }
9090
9091 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9092 if (err)
9093 goto error;
9094
9095 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9096 if (!n_coalesce) {
9097 err = -ENOMEM;
9098 goto error;
9099 }
9100 cfg80211_rdev_free_coalesce(rdev);
9101 rdev->coalesce = n_coalesce;
9102
9103 return 0;
9104error:
9105 for (i = 0; i < new_coalesce.n_rules; i++) {
9106 tmp_rule = &new_coalesce.rules[i];
9107 for (j = 0; j < tmp_rule->n_patterns; j++)
9108 kfree(tmp_rule->patterns[j].mask);
9109 kfree(tmp_rule->patterns);
9110 }
9111 kfree(new_coalesce.rules);
9112
9113 return err;
9114}
9115
Johannes Berge5497d72011-07-05 16:35:40 +02009116static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9117{
9118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9119 struct net_device *dev = info->user_ptr[1];
9120 struct wireless_dev *wdev = dev->ieee80211_ptr;
9121 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9122 struct cfg80211_gtk_rekey_data rekey_data;
9123 int err;
9124
9125 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9126 return -EINVAL;
9127
9128 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9129 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9130 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9131 nl80211_rekey_policy);
9132 if (err)
9133 return err;
9134
9135 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9136 return -ERANGE;
9137 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9138 return -ERANGE;
9139 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9140 return -ERANGE;
9141
Johannes Berg78f686c2014-09-10 22:28:06 +03009142 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9143 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9144 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009145
9146 wdev_lock(wdev);
9147 if (!wdev->current_bss) {
9148 err = -ENOTCONN;
9149 goto out;
9150 }
9151
9152 if (!rdev->ops->set_rekey_data) {
9153 err = -EOPNOTSUPP;
9154 goto out;
9155 }
9156
Hila Gonene35e4d22012-06-27 17:19:42 +03009157 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009158 out:
9159 wdev_unlock(wdev);
9160 return err;
9161}
9162
Johannes Berg28946da2011-11-04 11:18:12 +01009163static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9164 struct genl_info *info)
9165{
9166 struct net_device *dev = info->user_ptr[1];
9167 struct wireless_dev *wdev = dev->ieee80211_ptr;
9168
9169 if (wdev->iftype != NL80211_IFTYPE_AP &&
9170 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9171 return -EINVAL;
9172
Eric W. Biederman15e47302012-09-07 20:12:54 +00009173 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009174 return -EBUSY;
9175
Eric W. Biederman15e47302012-09-07 20:12:54 +00009176 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009177 return 0;
9178}
9179
Johannes Berg7f6cf312011-11-04 11:18:15 +01009180static int nl80211_probe_client(struct sk_buff *skb,
9181 struct genl_info *info)
9182{
9183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9184 struct net_device *dev = info->user_ptr[1];
9185 struct wireless_dev *wdev = dev->ieee80211_ptr;
9186 struct sk_buff *msg;
9187 void *hdr;
9188 const u8 *addr;
9189 u64 cookie;
9190 int err;
9191
9192 if (wdev->iftype != NL80211_IFTYPE_AP &&
9193 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9194 return -EOPNOTSUPP;
9195
9196 if (!info->attrs[NL80211_ATTR_MAC])
9197 return -EINVAL;
9198
9199 if (!rdev->ops->probe_client)
9200 return -EOPNOTSUPP;
9201
9202 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9203 if (!msg)
9204 return -ENOMEM;
9205
Eric W. Biederman15e47302012-09-07 20:12:54 +00009206 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009207 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009208 if (!hdr) {
9209 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009210 goto free_msg;
9211 }
9212
9213 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9214
Hila Gonene35e4d22012-06-27 17:19:42 +03009215 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009216 if (err)
9217 goto free_msg;
9218
David S. Miller9360ffd2012-03-29 04:41:26 -04009219 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9220 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009221
9222 genlmsg_end(msg, hdr);
9223
9224 return genlmsg_reply(msg, info);
9225
9226 nla_put_failure:
9227 err = -ENOBUFS;
9228 free_msg:
9229 nlmsg_free(msg);
9230 return err;
9231}
9232
Johannes Berg5e760232011-11-04 11:18:17 +01009233static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9234{
9235 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009236 struct cfg80211_beacon_registration *reg, *nreg;
9237 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009238
9239 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9240 return -EOPNOTSUPP;
9241
Ben Greear37c73b52012-10-26 14:49:25 -07009242 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9243 if (!nreg)
9244 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009245
Ben Greear37c73b52012-10-26 14:49:25 -07009246 /* First, check if already registered. */
9247 spin_lock_bh(&rdev->beacon_registrations_lock);
9248 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9249 if (reg->nlportid == info->snd_portid) {
9250 rv = -EALREADY;
9251 goto out_err;
9252 }
9253 }
9254 /* Add it to the list */
9255 nreg->nlportid = info->snd_portid;
9256 list_add(&nreg->list, &rdev->beacon_registrations);
9257
9258 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009259
9260 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009261out_err:
9262 spin_unlock_bh(&rdev->beacon_registrations_lock);
9263 kfree(nreg);
9264 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009265}
9266
Johannes Berg98104fde2012-06-16 00:19:54 +02009267static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9268{
9269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9270 struct wireless_dev *wdev = info->user_ptr[1];
9271 int err;
9272
9273 if (!rdev->ops->start_p2p_device)
9274 return -EOPNOTSUPP;
9275
9276 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9277 return -EOPNOTSUPP;
9278
9279 if (wdev->p2p_started)
9280 return 0;
9281
Luciano Coelhob6a55012014-02-27 11:07:21 +02009282 if (rfkill_blocked(rdev->rfkill))
9283 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009284
Johannes Bergeeb126e2012-10-23 15:16:50 +02009285 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009286 if (err)
9287 return err;
9288
9289 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009290 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009291
9292 return 0;
9293}
9294
9295static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9296{
9297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9298 struct wireless_dev *wdev = info->user_ptr[1];
9299
9300 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9301 return -EOPNOTSUPP;
9302
9303 if (!rdev->ops->stop_p2p_device)
9304 return -EOPNOTSUPP;
9305
Johannes Bergf9f47522013-03-19 15:04:07 +01009306 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009307
9308 return 0;
9309}
9310
Johannes Berg3713b4e2013-02-14 16:19:38 +01009311static int nl80211_get_protocol_features(struct sk_buff *skb,
9312 struct genl_info *info)
9313{
9314 void *hdr;
9315 struct sk_buff *msg;
9316
9317 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9318 if (!msg)
9319 return -ENOMEM;
9320
9321 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9322 NL80211_CMD_GET_PROTOCOL_FEATURES);
9323 if (!hdr)
9324 goto nla_put_failure;
9325
9326 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9327 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9328 goto nla_put_failure;
9329
9330 genlmsg_end(msg, hdr);
9331 return genlmsg_reply(msg, info);
9332
9333 nla_put_failure:
9334 kfree_skb(msg);
9335 return -ENOBUFS;
9336}
9337
Jouni Malinen355199e2013-02-27 17:14:27 +02009338static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9339{
9340 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9341 struct cfg80211_update_ft_ies_params ft_params;
9342 struct net_device *dev = info->user_ptr[1];
9343
9344 if (!rdev->ops->update_ft_ies)
9345 return -EOPNOTSUPP;
9346
9347 if (!info->attrs[NL80211_ATTR_MDID] ||
9348 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9349 return -EINVAL;
9350
9351 memset(&ft_params, 0, sizeof(ft_params));
9352 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9353 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9354 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9355
9356 return rdev_update_ft_ies(rdev, dev, &ft_params);
9357}
9358
Arend van Spriel5de17982013-04-18 15:49:00 +02009359static int nl80211_crit_protocol_start(struct sk_buff *skb,
9360 struct genl_info *info)
9361{
9362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9363 struct wireless_dev *wdev = info->user_ptr[1];
9364 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9365 u16 duration;
9366 int ret;
9367
9368 if (!rdev->ops->crit_proto_start)
9369 return -EOPNOTSUPP;
9370
9371 if (WARN_ON(!rdev->ops->crit_proto_stop))
9372 return -EINVAL;
9373
9374 if (rdev->crit_proto_nlportid)
9375 return -EBUSY;
9376
9377 /* determine protocol if provided */
9378 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9379 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9380
9381 if (proto >= NUM_NL80211_CRIT_PROTO)
9382 return -EINVAL;
9383
9384 /* timeout must be provided */
9385 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9386 return -EINVAL;
9387
9388 duration =
9389 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9390
9391 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9392 return -ERANGE;
9393
9394 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9395 if (!ret)
9396 rdev->crit_proto_nlportid = info->snd_portid;
9397
9398 return ret;
9399}
9400
9401static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9402 struct genl_info *info)
9403{
9404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9405 struct wireless_dev *wdev = info->user_ptr[1];
9406
9407 if (!rdev->ops->crit_proto_stop)
9408 return -EOPNOTSUPP;
9409
9410 if (rdev->crit_proto_nlportid) {
9411 rdev->crit_proto_nlportid = 0;
9412 rdev_crit_proto_stop(rdev, wdev);
9413 }
9414 return 0;
9415}
9416
Johannes Bergad7e7182013-11-13 13:37:47 +01009417static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9418{
9419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9420 struct wireless_dev *wdev =
9421 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9422 int i, err;
9423 u32 vid, subcmd;
9424
9425 if (!rdev->wiphy.vendor_commands)
9426 return -EOPNOTSUPP;
9427
9428 if (IS_ERR(wdev)) {
9429 err = PTR_ERR(wdev);
9430 if (err != -EINVAL)
9431 return err;
9432 wdev = NULL;
9433 } else if (wdev->wiphy != &rdev->wiphy) {
9434 return -EINVAL;
9435 }
9436
9437 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9438 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9439 return -EINVAL;
9440
9441 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9442 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9443 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9444 const struct wiphy_vendor_command *vcmd;
9445 void *data = NULL;
9446 int len = 0;
9447
9448 vcmd = &rdev->wiphy.vendor_commands[i];
9449
9450 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9451 continue;
9452
9453 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9454 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9455 if (!wdev)
9456 return -EINVAL;
9457 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9458 !wdev->netdev)
9459 return -EINVAL;
9460
9461 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9462 if (wdev->netdev &&
9463 !netif_running(wdev->netdev))
9464 return -ENETDOWN;
9465 if (!wdev->netdev && !wdev->p2p_started)
9466 return -ENETDOWN;
9467 }
9468 } else {
9469 wdev = NULL;
9470 }
9471
9472 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9473 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9474 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9475 }
9476
9477 rdev->cur_cmd_info = info;
9478 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9479 data, len);
9480 rdev->cur_cmd_info = NULL;
9481 return err;
9482 }
9483
9484 return -EOPNOTSUPP;
9485}
9486
9487struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9488 enum nl80211_commands cmd,
9489 enum nl80211_attrs attr,
9490 int approxlen)
9491{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009492 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009493
9494 if (WARN_ON(!rdev->cur_cmd_info))
9495 return NULL;
9496
9497 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9498 rdev->cur_cmd_info->snd_portid,
9499 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009500 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009501}
9502EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9503
9504int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9505{
9506 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9507 void *hdr = ((void **)skb->cb)[1];
9508 struct nlattr *data = ((void **)skb->cb)[2];
9509
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009510 /* clear CB data for netlink core to own from now on */
9511 memset(skb->cb, 0, sizeof(skb->cb));
9512
Johannes Bergad7e7182013-11-13 13:37:47 +01009513 if (WARN_ON(!rdev->cur_cmd_info)) {
9514 kfree_skb(skb);
9515 return -EINVAL;
9516 }
9517
9518 nla_nest_end(skb, data);
9519 genlmsg_end(skb, hdr);
9520 return genlmsg_reply(skb, rdev->cur_cmd_info);
9521}
9522EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9523
9524
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009525static int nl80211_set_qos_map(struct sk_buff *skb,
9526 struct genl_info *info)
9527{
9528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9529 struct cfg80211_qos_map *qos_map = NULL;
9530 struct net_device *dev = info->user_ptr[1];
9531 u8 *pos, len, num_des, des_len, des;
9532 int ret;
9533
9534 if (!rdev->ops->set_qos_map)
9535 return -EOPNOTSUPP;
9536
9537 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9538 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9539 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9540
9541 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9542 len > IEEE80211_QOS_MAP_LEN_MAX)
9543 return -EINVAL;
9544
9545 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9546 if (!qos_map)
9547 return -ENOMEM;
9548
9549 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9550 if (num_des) {
9551 des_len = num_des *
9552 sizeof(struct cfg80211_dscp_exception);
9553 memcpy(qos_map->dscp_exception, pos, des_len);
9554 qos_map->num_des = num_des;
9555 for (des = 0; des < num_des; des++) {
9556 if (qos_map->dscp_exception[des].up > 7) {
9557 kfree(qos_map);
9558 return -EINVAL;
9559 }
9560 }
9561 pos += des_len;
9562 }
9563 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9564 }
9565
9566 wdev_lock(dev->ieee80211_ptr);
9567 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9568 if (!ret)
9569 ret = rdev_set_qos_map(rdev, dev, qos_map);
9570 wdev_unlock(dev->ieee80211_ptr);
9571
9572 kfree(qos_map);
9573 return ret;
9574}
9575
Johannes Berg960d01a2014-09-09 22:55:35 +03009576static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9577{
9578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9579 struct net_device *dev = info->user_ptr[1];
9580 struct wireless_dev *wdev = dev->ieee80211_ptr;
9581 const u8 *peer;
9582 u8 tsid, up;
9583 u16 admitted_time = 0;
9584 int err;
9585
Johannes Berg723e73a2014-10-22 09:25:06 +02009586 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009587 return -EOPNOTSUPP;
9588
9589 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9590 !info->attrs[NL80211_ATTR_USER_PRIO])
9591 return -EINVAL;
9592
9593 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9594 if (tsid >= IEEE80211_NUM_TIDS)
9595 return -EINVAL;
9596
9597 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9598 if (up >= IEEE80211_NUM_UPS)
9599 return -EINVAL;
9600
9601 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009602 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009603 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009604 * need more attributes for that (e.g. BA session requirement);
9605 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009606 */
9607 return -EINVAL;
9608 }
9609
9610 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9611
9612 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9613 admitted_time =
9614 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9615 if (!admitted_time)
9616 return -EINVAL;
9617 }
9618
9619 wdev_lock(wdev);
9620 switch (wdev->iftype) {
9621 case NL80211_IFTYPE_STATION:
9622 case NL80211_IFTYPE_P2P_CLIENT:
9623 if (wdev->current_bss)
9624 break;
9625 err = -ENOTCONN;
9626 goto out;
9627 default:
9628 err = -EOPNOTSUPP;
9629 goto out;
9630 }
9631
9632 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9633
9634 out:
9635 wdev_unlock(wdev);
9636 return err;
9637}
9638
9639static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9640{
9641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9642 struct net_device *dev = info->user_ptr[1];
9643 struct wireless_dev *wdev = dev->ieee80211_ptr;
9644 const u8 *peer;
9645 u8 tsid;
9646 int err;
9647
9648 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9649 return -EINVAL;
9650
9651 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9652 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9653
9654 wdev_lock(wdev);
9655 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9656 wdev_unlock(wdev);
9657
9658 return err;
9659}
9660
Johannes Berg4c476992010-10-04 21:36:35 +02009661#define NL80211_FLAG_NEED_WIPHY 0x01
9662#define NL80211_FLAG_NEED_NETDEV 0x02
9663#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009664#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9665#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9666 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009667#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009668/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009669#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9670 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +03009671#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +02009672
Johannes Bergf84f7712013-11-14 17:14:45 +01009673static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009674 struct genl_info *info)
9675{
9676 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009677 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009678 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009679 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9680
9681 if (rtnl)
9682 rtnl_lock();
9683
9684 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009685 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009686 if (IS_ERR(rdev)) {
9687 if (rtnl)
9688 rtnl_unlock();
9689 return PTR_ERR(rdev);
9690 }
9691 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009692 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9693 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009694 ASSERT_RTNL();
9695
Johannes Berg89a54e42012-06-15 14:33:17 +02009696 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9697 info->attrs);
9698 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009699 if (rtnl)
9700 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009701 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009702 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009703
Johannes Berg89a54e42012-06-15 14:33:17 +02009704 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009705 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009706
Johannes Berg1bf614e2012-06-15 15:23:36 +02009707 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9708 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009709 if (rtnl)
9710 rtnl_unlock();
9711 return -EINVAL;
9712 }
9713
9714 info->user_ptr[1] = dev;
9715 } else {
9716 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009717 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009718
Johannes Berg1bf614e2012-06-15 15:23:36 +02009719 if (dev) {
9720 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9721 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009722 if (rtnl)
9723 rtnl_unlock();
9724 return -ENETDOWN;
9725 }
9726
9727 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009728 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9729 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009730 if (rtnl)
9731 rtnl_unlock();
9732 return -ENETDOWN;
9733 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009734 }
9735
Johannes Berg4c476992010-10-04 21:36:35 +02009736 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009737 }
9738
9739 return 0;
9740}
9741
Johannes Bergf84f7712013-11-14 17:14:45 +01009742static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009743 struct genl_info *info)
9744{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009745 if (info->user_ptr[1]) {
9746 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9747 struct wireless_dev *wdev = info->user_ptr[1];
9748
9749 if (wdev->netdev)
9750 dev_put(wdev->netdev);
9751 } else {
9752 dev_put(info->user_ptr[1]);
9753 }
9754 }
Johannes Berg5393b912014-09-10 15:00:16 +03009755
Johannes Berg4c476992010-10-04 21:36:35 +02009756 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9757 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +03009758
9759 /* If needed, clear the netlink message payload from the SKB
9760 * as it might contain key data that shouldn't stick around on
9761 * the heap after the SKB is freed. The netlink message header
9762 * is still needed for further processing, so leave it intact.
9763 */
9764 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
9765 struct nlmsghdr *nlh = nlmsg_hdr(skb);
9766
9767 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
9768 }
Johannes Berg4c476992010-10-04 21:36:35 +02009769}
9770
Johannes Berg4534de82013-11-14 17:14:46 +01009771static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009772 {
9773 .cmd = NL80211_CMD_GET_WIPHY,
9774 .doit = nl80211_get_wiphy,
9775 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009776 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009777 .policy = nl80211_policy,
9778 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009779 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9780 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009781 },
9782 {
9783 .cmd = NL80211_CMD_SET_WIPHY,
9784 .doit = nl80211_set_wiphy,
9785 .policy = nl80211_policy,
9786 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009787 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009788 },
9789 {
9790 .cmd = NL80211_CMD_GET_INTERFACE,
9791 .doit = nl80211_get_interface,
9792 .dumpit = nl80211_dump_interface,
9793 .policy = nl80211_policy,
9794 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009795 .internal_flags = NL80211_FLAG_NEED_WDEV |
9796 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009797 },
9798 {
9799 .cmd = NL80211_CMD_SET_INTERFACE,
9800 .doit = nl80211_set_interface,
9801 .policy = nl80211_policy,
9802 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009803 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9804 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009805 },
9806 {
9807 .cmd = NL80211_CMD_NEW_INTERFACE,
9808 .doit = nl80211_new_interface,
9809 .policy = nl80211_policy,
9810 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009811 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9812 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009813 },
9814 {
9815 .cmd = NL80211_CMD_DEL_INTERFACE,
9816 .doit = nl80211_del_interface,
9817 .policy = nl80211_policy,
9818 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009819 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009820 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009821 },
Johannes Berg41ade002007-12-19 02:03:29 +01009822 {
9823 .cmd = NL80211_CMD_GET_KEY,
9824 .doit = nl80211_get_key,
9825 .policy = nl80211_policy,
9826 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009827 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009828 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009829 },
9830 {
9831 .cmd = NL80211_CMD_SET_KEY,
9832 .doit = nl80211_set_key,
9833 .policy = nl80211_policy,
9834 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009836 NL80211_FLAG_NEED_RTNL |
9837 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009838 },
9839 {
9840 .cmd = NL80211_CMD_NEW_KEY,
9841 .doit = nl80211_new_key,
9842 .policy = nl80211_policy,
9843 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009844 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009845 NL80211_FLAG_NEED_RTNL |
9846 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009847 },
9848 {
9849 .cmd = NL80211_CMD_DEL_KEY,
9850 .doit = nl80211_del_key,
9851 .policy = nl80211_policy,
9852 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009854 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009855 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009856 {
9857 .cmd = NL80211_CMD_SET_BEACON,
9858 .policy = nl80211_policy,
9859 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009860 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009861 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009862 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009863 },
9864 {
Johannes Berg88600202012-02-13 15:17:18 +01009865 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009866 .policy = nl80211_policy,
9867 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009868 .doit = nl80211_start_ap,
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 Berged1b6cc2007-12-19 02:03:32 +01009871 },
9872 {
Johannes Berg88600202012-02-13 15:17:18 +01009873 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009874 .policy = nl80211_policy,
9875 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009876 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009877 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009878 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009879 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009880 {
9881 .cmd = NL80211_CMD_GET_STATION,
9882 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009883 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009884 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009885 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9886 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009887 },
9888 {
9889 .cmd = NL80211_CMD_SET_STATION,
9890 .doit = nl80211_set_station,
9891 .policy = nl80211_policy,
9892 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009893 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009894 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009895 },
9896 {
9897 .cmd = NL80211_CMD_NEW_STATION,
9898 .doit = nl80211_new_station,
9899 .policy = nl80211_policy,
9900 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009901 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009902 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009903 },
9904 {
9905 .cmd = NL80211_CMD_DEL_STATION,
9906 .doit = nl80211_del_station,
9907 .policy = nl80211_policy,
9908 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009909 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009910 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009911 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009912 {
9913 .cmd = NL80211_CMD_GET_MPATH,
9914 .doit = nl80211_get_mpath,
9915 .dumpit = nl80211_dump_mpath,
9916 .policy = nl80211_policy,
9917 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009918 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009919 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009920 },
9921 {
Henning Rogge66be7d22014-09-12 08:58:49 +02009922 .cmd = NL80211_CMD_GET_MPP,
9923 .doit = nl80211_get_mpp,
9924 .dumpit = nl80211_dump_mpp,
9925 .policy = nl80211_policy,
9926 .flags = GENL_ADMIN_PERM,
9927 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9928 NL80211_FLAG_NEED_RTNL,
9929 },
9930 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009931 .cmd = NL80211_CMD_SET_MPATH,
9932 .doit = nl80211_set_mpath,
9933 .policy = nl80211_policy,
9934 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009936 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009937 },
9938 {
9939 .cmd = NL80211_CMD_NEW_MPATH,
9940 .doit = nl80211_new_mpath,
9941 .policy = nl80211_policy,
9942 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009943 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009944 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009945 },
9946 {
9947 .cmd = NL80211_CMD_DEL_MPATH,
9948 .doit = nl80211_del_mpath,
9949 .policy = nl80211_policy,
9950 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009951 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009952 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009953 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009954 {
9955 .cmd = NL80211_CMD_SET_BSS,
9956 .doit = nl80211_set_bss,
9957 .policy = nl80211_policy,
9958 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009960 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009961 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009962 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009963 .cmd = NL80211_CMD_GET_REG,
9964 .doit = nl80211_get_reg,
9965 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009966 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009967 /* can be retrieved by unprivileged users */
9968 },
9969 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009970 .cmd = NL80211_CMD_SET_REG,
9971 .doit = nl80211_set_reg,
9972 .policy = nl80211_policy,
9973 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009974 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009975 },
9976 {
9977 .cmd = NL80211_CMD_REQ_SET_REG,
9978 .doit = nl80211_req_set_reg,
9979 .policy = nl80211_policy,
9980 .flags = GENL_ADMIN_PERM,
9981 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009982 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009983 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9984 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009985 .policy = nl80211_policy,
9986 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009987 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009988 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009989 },
9990 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009991 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9992 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009993 .policy = nl80211_policy,
9994 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009995 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009996 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009997 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009998 {
Johannes Berg2a519312009-02-10 21:25:55 +01009999 .cmd = NL80211_CMD_TRIGGER_SCAN,
10000 .doit = nl80211_trigger_scan,
10001 .policy = nl80211_policy,
10002 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010003 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010004 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010005 },
10006 {
10007 .cmd = NL80211_CMD_GET_SCAN,
10008 .policy = nl80211_policy,
10009 .dumpit = nl80211_dump_scan,
10010 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010011 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010012 .cmd = NL80211_CMD_START_SCHED_SCAN,
10013 .doit = nl80211_start_sched_scan,
10014 .policy = nl80211_policy,
10015 .flags = GENL_ADMIN_PERM,
10016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10017 NL80211_FLAG_NEED_RTNL,
10018 },
10019 {
10020 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10021 .doit = nl80211_stop_sched_scan,
10022 .policy = nl80211_policy,
10023 .flags = GENL_ADMIN_PERM,
10024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10025 NL80211_FLAG_NEED_RTNL,
10026 },
10027 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010028 .cmd = NL80211_CMD_AUTHENTICATE,
10029 .doit = nl80211_authenticate,
10030 .policy = nl80211_policy,
10031 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010033 NL80211_FLAG_NEED_RTNL |
10034 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010035 },
10036 {
10037 .cmd = NL80211_CMD_ASSOCIATE,
10038 .doit = nl80211_associate,
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,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010043 },
10044 {
10045 .cmd = NL80211_CMD_DEAUTHENTICATE,
10046 .doit = nl80211_deauthenticate,
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,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010051 },
10052 {
10053 .cmd = NL80211_CMD_DISASSOCIATE,
10054 .doit = nl80211_disassociate,
10055 .policy = nl80211_policy,
10056 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010058 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010059 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010060 {
10061 .cmd = NL80211_CMD_JOIN_IBSS,
10062 .doit = nl80211_join_ibss,
10063 .policy = nl80211_policy,
10064 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010066 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010067 },
10068 {
10069 .cmd = NL80211_CMD_LEAVE_IBSS,
10070 .doit = nl80211_leave_ibss,
10071 .policy = nl80211_policy,
10072 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010073 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010074 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010075 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010076#ifdef CONFIG_NL80211_TESTMODE
10077 {
10078 .cmd = NL80211_CMD_TESTMODE,
10079 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010080 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010081 .policy = nl80211_policy,
10082 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010083 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10084 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010085 },
10086#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010087 {
10088 .cmd = NL80211_CMD_CONNECT,
10089 .doit = nl80211_connect,
10090 .policy = nl80211_policy,
10091 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010092 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010093 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010094 },
10095 {
10096 .cmd = NL80211_CMD_DISCONNECT,
10097 .doit = nl80211_disconnect,
10098 .policy = nl80211_policy,
10099 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010101 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010102 },
Johannes Berg463d0182009-07-14 00:33:35 +020010103 {
10104 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10105 .doit = nl80211_wiphy_netns,
10106 .policy = nl80211_policy,
10107 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010108 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10109 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010110 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010111 {
10112 .cmd = NL80211_CMD_GET_SURVEY,
10113 .policy = nl80211_policy,
10114 .dumpit = nl80211_dump_survey,
10115 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010116 {
10117 .cmd = NL80211_CMD_SET_PMKSA,
10118 .doit = nl80211_setdel_pmksa,
10119 .policy = nl80211_policy,
10120 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010121 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010122 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010123 },
10124 {
10125 .cmd = NL80211_CMD_DEL_PMKSA,
10126 .doit = nl80211_setdel_pmksa,
10127 .policy = nl80211_policy,
10128 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010129 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010130 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010131 },
10132 {
10133 .cmd = NL80211_CMD_FLUSH_PMKSA,
10134 .doit = nl80211_flush_pmksa,
10135 .policy = nl80211_policy,
10136 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010137 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010138 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010139 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010140 {
10141 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10142 .doit = nl80211_remain_on_channel,
10143 .policy = nl80211_policy,
10144 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010145 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010146 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010147 },
10148 {
10149 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10150 .doit = nl80211_cancel_remain_on_channel,
10151 .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 Malinen9588bbd2009-12-23 13:15:41 +010010155 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010156 {
10157 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10158 .doit = nl80211_set_tx_bitrate_mask,
10159 .policy = nl80211_policy,
10160 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010161 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10162 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010163 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010164 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010165 .cmd = NL80211_CMD_REGISTER_FRAME,
10166 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010167 .policy = nl80211_policy,
10168 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010169 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010170 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010171 },
10172 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010173 .cmd = NL80211_CMD_FRAME,
10174 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010175 .policy = nl80211_policy,
10176 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010177 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010178 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010179 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010180 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010181 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10182 .doit = nl80211_tx_mgmt_cancel_wait,
10183 .policy = nl80211_policy,
10184 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010185 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010186 NL80211_FLAG_NEED_RTNL,
10187 },
10188 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010189 .cmd = NL80211_CMD_SET_POWER_SAVE,
10190 .doit = nl80211_set_power_save,
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,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010195 },
10196 {
10197 .cmd = NL80211_CMD_GET_POWER_SAVE,
10198 .doit = nl80211_get_power_save,
10199 .policy = nl80211_policy,
10200 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010201 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10202 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010203 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010204 {
10205 .cmd = NL80211_CMD_SET_CQM,
10206 .doit = nl80211_set_cqm,
10207 .policy = nl80211_policy,
10208 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010209 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10210 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010211 },
Johannes Bergf444de02010-05-05 15:25:02 +020010212 {
10213 .cmd = NL80211_CMD_SET_CHANNEL,
10214 .doit = nl80211_set_channel,
10215 .policy = nl80211_policy,
10216 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010217 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10218 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010219 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010220 {
10221 .cmd = NL80211_CMD_SET_WDS_PEER,
10222 .doit = nl80211_set_wds_peer,
10223 .policy = nl80211_policy,
10224 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010225 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10226 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010227 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010228 {
10229 .cmd = NL80211_CMD_JOIN_MESH,
10230 .doit = nl80211_join_mesh,
10231 .policy = nl80211_policy,
10232 .flags = GENL_ADMIN_PERM,
10233 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10234 NL80211_FLAG_NEED_RTNL,
10235 },
10236 {
10237 .cmd = NL80211_CMD_LEAVE_MESH,
10238 .doit = nl80211_leave_mesh,
10239 .policy = nl80211_policy,
10240 .flags = GENL_ADMIN_PERM,
10241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10242 NL80211_FLAG_NEED_RTNL,
10243 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010244 {
10245 .cmd = NL80211_CMD_JOIN_OCB,
10246 .doit = nl80211_join_ocb,
10247 .policy = nl80211_policy,
10248 .flags = GENL_ADMIN_PERM,
10249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10250 NL80211_FLAG_NEED_RTNL,
10251 },
10252 {
10253 .cmd = NL80211_CMD_LEAVE_OCB,
10254 .doit = nl80211_leave_ocb,
10255 .policy = nl80211_policy,
10256 .flags = GENL_ADMIN_PERM,
10257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10258 NL80211_FLAG_NEED_RTNL,
10259 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010260#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010261 {
10262 .cmd = NL80211_CMD_GET_WOWLAN,
10263 .doit = nl80211_get_wowlan,
10264 .policy = nl80211_policy,
10265 /* can be retrieved by unprivileged users */
10266 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10267 NL80211_FLAG_NEED_RTNL,
10268 },
10269 {
10270 .cmd = NL80211_CMD_SET_WOWLAN,
10271 .doit = nl80211_set_wowlan,
10272 .policy = nl80211_policy,
10273 .flags = GENL_ADMIN_PERM,
10274 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10275 NL80211_FLAG_NEED_RTNL,
10276 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010277#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010278 {
10279 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10280 .doit = nl80211_set_rekey_data,
10281 .policy = nl80211_policy,
10282 .flags = GENL_ADMIN_PERM,
10283 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010284 NL80211_FLAG_NEED_RTNL |
10285 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010286 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010287 {
10288 .cmd = NL80211_CMD_TDLS_MGMT,
10289 .doit = nl80211_tdls_mgmt,
10290 .policy = nl80211_policy,
10291 .flags = GENL_ADMIN_PERM,
10292 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10293 NL80211_FLAG_NEED_RTNL,
10294 },
10295 {
10296 .cmd = NL80211_CMD_TDLS_OPER,
10297 .doit = nl80211_tdls_oper,
10298 .policy = nl80211_policy,
10299 .flags = GENL_ADMIN_PERM,
10300 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10301 NL80211_FLAG_NEED_RTNL,
10302 },
Johannes Berg28946da2011-11-04 11:18:12 +010010303 {
10304 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10305 .doit = nl80211_register_unexpected_frame,
10306 .policy = nl80211_policy,
10307 .flags = GENL_ADMIN_PERM,
10308 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10309 NL80211_FLAG_NEED_RTNL,
10310 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010311 {
10312 .cmd = NL80211_CMD_PROBE_CLIENT,
10313 .doit = nl80211_probe_client,
10314 .policy = nl80211_policy,
10315 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010317 NL80211_FLAG_NEED_RTNL,
10318 },
Johannes Berg5e760232011-11-04 11:18:17 +010010319 {
10320 .cmd = NL80211_CMD_REGISTER_BEACONS,
10321 .doit = nl80211_register_beacons,
10322 .policy = nl80211_policy,
10323 .flags = GENL_ADMIN_PERM,
10324 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10325 NL80211_FLAG_NEED_RTNL,
10326 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010327 {
10328 .cmd = NL80211_CMD_SET_NOACK_MAP,
10329 .doit = nl80211_set_noack_map,
10330 .policy = nl80211_policy,
10331 .flags = GENL_ADMIN_PERM,
10332 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10333 NL80211_FLAG_NEED_RTNL,
10334 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010335 {
10336 .cmd = NL80211_CMD_START_P2P_DEVICE,
10337 .doit = nl80211_start_p2p_device,
10338 .policy = nl80211_policy,
10339 .flags = GENL_ADMIN_PERM,
10340 .internal_flags = NL80211_FLAG_NEED_WDEV |
10341 NL80211_FLAG_NEED_RTNL,
10342 },
10343 {
10344 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10345 .doit = nl80211_stop_p2p_device,
10346 .policy = nl80211_policy,
10347 .flags = GENL_ADMIN_PERM,
10348 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10349 NL80211_FLAG_NEED_RTNL,
10350 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010351 {
10352 .cmd = NL80211_CMD_SET_MCAST_RATE,
10353 .doit = nl80211_set_mcast_rate,
10354 .policy = nl80211_policy,
10355 .flags = GENL_ADMIN_PERM,
10356 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10357 NL80211_FLAG_NEED_RTNL,
10358 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010359 {
10360 .cmd = NL80211_CMD_SET_MAC_ACL,
10361 .doit = nl80211_set_mac_acl,
10362 .policy = nl80211_policy,
10363 .flags = GENL_ADMIN_PERM,
10364 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10365 NL80211_FLAG_NEED_RTNL,
10366 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010367 {
10368 .cmd = NL80211_CMD_RADAR_DETECT,
10369 .doit = nl80211_start_radar_detection,
10370 .policy = nl80211_policy,
10371 .flags = GENL_ADMIN_PERM,
10372 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10373 NL80211_FLAG_NEED_RTNL,
10374 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010375 {
10376 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10377 .doit = nl80211_get_protocol_features,
10378 .policy = nl80211_policy,
10379 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010380 {
10381 .cmd = NL80211_CMD_UPDATE_FT_IES,
10382 .doit = nl80211_update_ft_ies,
10383 .policy = nl80211_policy,
10384 .flags = GENL_ADMIN_PERM,
10385 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10386 NL80211_FLAG_NEED_RTNL,
10387 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010388 {
10389 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10390 .doit = nl80211_crit_protocol_start,
10391 .policy = nl80211_policy,
10392 .flags = GENL_ADMIN_PERM,
10393 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10394 NL80211_FLAG_NEED_RTNL,
10395 },
10396 {
10397 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10398 .doit = nl80211_crit_protocol_stop,
10399 .policy = nl80211_policy,
10400 .flags = GENL_ADMIN_PERM,
10401 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10402 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010403 },
10404 {
10405 .cmd = NL80211_CMD_GET_COALESCE,
10406 .doit = nl80211_get_coalesce,
10407 .policy = nl80211_policy,
10408 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10409 NL80211_FLAG_NEED_RTNL,
10410 },
10411 {
10412 .cmd = NL80211_CMD_SET_COALESCE,
10413 .doit = nl80211_set_coalesce,
10414 .policy = nl80211_policy,
10415 .flags = GENL_ADMIN_PERM,
10416 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10417 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010418 },
10419 {
10420 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10421 .doit = nl80211_channel_switch,
10422 .policy = nl80211_policy,
10423 .flags = GENL_ADMIN_PERM,
10424 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10425 NL80211_FLAG_NEED_RTNL,
10426 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010427 {
10428 .cmd = NL80211_CMD_VENDOR,
10429 .doit = nl80211_vendor_cmd,
10430 .policy = nl80211_policy,
10431 .flags = GENL_ADMIN_PERM,
10432 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10433 NL80211_FLAG_NEED_RTNL,
10434 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010435 {
10436 .cmd = NL80211_CMD_SET_QOS_MAP,
10437 .doit = nl80211_set_qos_map,
10438 .policy = nl80211_policy,
10439 .flags = GENL_ADMIN_PERM,
10440 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10441 NL80211_FLAG_NEED_RTNL,
10442 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010443 {
10444 .cmd = NL80211_CMD_ADD_TX_TS,
10445 .doit = nl80211_add_tx_ts,
10446 .policy = nl80211_policy,
10447 .flags = GENL_ADMIN_PERM,
10448 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10449 NL80211_FLAG_NEED_RTNL,
10450 },
10451 {
10452 .cmd = NL80211_CMD_DEL_TX_TS,
10453 .doit = nl80211_del_tx_ts,
10454 .policy = nl80211_policy,
10455 .flags = GENL_ADMIN_PERM,
10456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10457 NL80211_FLAG_NEED_RTNL,
10458 },
Johannes Berg55682962007-09-20 13:09:35 -040010459};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010460
Johannes Berg55682962007-09-20 13:09:35 -040010461/* notification functions */
10462
Johannes Berg3bb20552014-05-26 13:52:25 +020010463void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10464 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010465{
10466 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010467 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010468
Johannes Berg3bb20552014-05-26 13:52:25 +020010469 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10470 cmd != NL80211_CMD_DEL_WIPHY);
10471
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010472 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010473 if (!msg)
10474 return;
10475
Johannes Berg3bb20552014-05-26 13:52:25 +020010476 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010477 nlmsg_free(msg);
10478 return;
10479 }
10480
Johannes Berg68eb5502013-11-19 15:19:38 +010010481 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010482 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010483}
10484
Johannes Berg362a4152009-05-24 16:43:15 +020010485static int nl80211_add_scan_req(struct sk_buff *msg,
10486 struct cfg80211_registered_device *rdev)
10487{
10488 struct cfg80211_scan_request *req = rdev->scan_req;
10489 struct nlattr *nest;
10490 int i;
10491
10492 if (WARN_ON(!req))
10493 return 0;
10494
10495 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10496 if (!nest)
10497 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010498 for (i = 0; i < req->n_ssids; i++) {
10499 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10500 goto nla_put_failure;
10501 }
Johannes Berg362a4152009-05-24 16:43:15 +020010502 nla_nest_end(msg, nest);
10503
10504 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10505 if (!nest)
10506 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010507 for (i = 0; i < req->n_channels; i++) {
10508 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10509 goto nla_put_failure;
10510 }
Johannes Berg362a4152009-05-24 16:43:15 +020010511 nla_nest_end(msg, nest);
10512
David S. Miller9360ffd2012-03-29 04:41:26 -040010513 if (req->ie &&
10514 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10515 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010516
Johannes Bergae917c92013-10-25 11:05:22 +020010517 if (req->flags &&
10518 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10519 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010520
Johannes Berg362a4152009-05-24 16:43:15 +020010521 return 0;
10522 nla_put_failure:
10523 return -ENOBUFS;
10524}
10525
Johannes Berga538e2d2009-06-16 19:56:42 +020010526static int nl80211_send_scan_msg(struct sk_buff *msg,
10527 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010528 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010529 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010530 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010531{
10532 void *hdr;
10533
Eric W. Biederman15e47302012-09-07 20:12:54 +000010534 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010535 if (!hdr)
10536 return -1;
10537
David S. Miller9360ffd2012-03-29 04:41:26 -040010538 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010539 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10540 wdev->netdev->ifindex)) ||
10541 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010542 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010543
Johannes Berg362a4152009-05-24 16:43:15 +020010544 /* ignore errors and send incomplete event anyway */
10545 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010546
10547 return genlmsg_end(msg, hdr);
10548
10549 nla_put_failure:
10550 genlmsg_cancel(msg, hdr);
10551 return -EMSGSIZE;
10552}
10553
Luciano Coelho807f8a82011-05-11 17:09:35 +030010554static int
10555nl80211_send_sched_scan_msg(struct sk_buff *msg,
10556 struct cfg80211_registered_device *rdev,
10557 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010558 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010559{
10560 void *hdr;
10561
Eric W. Biederman15e47302012-09-07 20:12:54 +000010562 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010563 if (!hdr)
10564 return -1;
10565
David S. Miller9360ffd2012-03-29 04:41:26 -040010566 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10567 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10568 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010569
10570 return genlmsg_end(msg, hdr);
10571
10572 nla_put_failure:
10573 genlmsg_cancel(msg, hdr);
10574 return -EMSGSIZE;
10575}
10576
Johannes Berga538e2d2009-06-16 19:56:42 +020010577void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010578 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010579{
10580 struct sk_buff *msg;
10581
Thomas Graf58050fc2012-06-28 03:57:45 +000010582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010583 if (!msg)
10584 return;
10585
Johannes Bergfd014282012-06-18 19:17:03 +020010586 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010587 NL80211_CMD_TRIGGER_SCAN) < 0) {
10588 nlmsg_free(msg);
10589 return;
10590 }
10591
Johannes Berg68eb5502013-11-19 15:19:38 +010010592 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010593 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010594}
10595
Johannes Bergf9d15d12014-01-22 11:14:19 +020010596struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10597 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010598{
10599 struct sk_buff *msg;
10600
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010601 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010602 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010603 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010604
Johannes Bergfd014282012-06-18 19:17:03 +020010605 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010606 aborted ? NL80211_CMD_SCAN_ABORTED :
10607 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010608 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010609 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010610 }
10611
Johannes Bergf9d15d12014-01-22 11:14:19 +020010612 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010613}
10614
Johannes Bergf9d15d12014-01-22 11:14:19 +020010615void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10616 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010617{
Johannes Berg2a519312009-02-10 21:25:55 +010010618 if (!msg)
10619 return;
10620
Johannes Berg68eb5502013-11-19 15:19:38 +010010621 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010622 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010623}
10624
Luciano Coelho807f8a82011-05-11 17:09:35 +030010625void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10626 struct net_device *netdev)
10627{
10628 struct sk_buff *msg;
10629
10630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10631 if (!msg)
10632 return;
10633
10634 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10635 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10636 nlmsg_free(msg);
10637 return;
10638 }
10639
Johannes Berg68eb5502013-11-19 15:19:38 +010010640 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010641 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010642}
10643
10644void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10645 struct net_device *netdev, u32 cmd)
10646{
10647 struct sk_buff *msg;
10648
Thomas Graf58050fc2012-06-28 03:57:45 +000010649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010650 if (!msg)
10651 return;
10652
10653 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10654 nlmsg_free(msg);
10655 return;
10656 }
10657
Johannes Berg68eb5502013-11-19 15:19:38 +010010658 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010659 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010660}
10661
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010662/*
10663 * This can happen on global regulatory changes or device specific settings
10664 * based on custom world regulatory domains.
10665 */
10666void nl80211_send_reg_change_event(struct regulatory_request *request)
10667{
10668 struct sk_buff *msg;
10669 void *hdr;
10670
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010671 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010672 if (!msg)
10673 return;
10674
10675 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10676 if (!hdr) {
10677 nlmsg_free(msg);
10678 return;
10679 }
10680
10681 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010682 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10683 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010684
David S. Miller9360ffd2012-03-29 04:41:26 -040010685 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10686 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10687 NL80211_REGDOM_TYPE_WORLD))
10688 goto nla_put_failure;
10689 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10690 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10691 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10692 goto nla_put_failure;
10693 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10694 request->intersect) {
10695 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10696 NL80211_REGDOM_TYPE_INTERSECTION))
10697 goto nla_put_failure;
10698 } else {
10699 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10700 NL80211_REGDOM_TYPE_COUNTRY) ||
10701 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10702 request->alpha2))
10703 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010704 }
10705
Johannes Bergf4173762012-12-03 18:23:37 +010010706 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010707 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10708 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010709
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010710 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010711
Johannes Bergbc43b282009-07-25 10:54:13 +020010712 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010713 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010714 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010715 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010716
10717 return;
10718
10719nla_put_failure:
10720 genlmsg_cancel(msg, hdr);
10721 nlmsg_free(msg);
10722}
10723
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010724static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10725 struct net_device *netdev,
10726 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010727 enum nl80211_commands cmd, gfp_t gfp,
10728 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010729{
10730 struct sk_buff *msg;
10731 void *hdr;
10732
Johannes Berge6d6e342009-07-01 21:26:47 +020010733 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010734 if (!msg)
10735 return;
10736
10737 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10738 if (!hdr) {
10739 nlmsg_free(msg);
10740 return;
10741 }
10742
David S. Miller9360ffd2012-03-29 04:41:26 -040010743 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10744 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10745 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10746 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010747
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010748 if (uapsd_queues >= 0) {
10749 struct nlattr *nla_wmm =
10750 nla_nest_start(msg, NL80211_ATTR_STA_WME);
10751 if (!nla_wmm)
10752 goto nla_put_failure;
10753
10754 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
10755 uapsd_queues))
10756 goto nla_put_failure;
10757
10758 nla_nest_end(msg, nla_wmm);
10759 }
10760
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010761 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010762
Johannes Berg68eb5502013-11-19 15:19:38 +010010763 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010764 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010765 return;
10766
10767 nla_put_failure:
10768 genlmsg_cancel(msg, hdr);
10769 nlmsg_free(msg);
10770}
10771
10772void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010773 struct net_device *netdev, const u8 *buf,
10774 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010775{
10776 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010777 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010778}
10779
10780void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10781 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010782 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010783{
Johannes Berge6d6e342009-07-01 21:26:47 +020010784 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010785 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010786}
10787
Jouni Malinen53b46b82009-03-27 20:53:56 +020010788void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010789 struct net_device *netdev, const u8 *buf,
10790 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010791{
10792 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010793 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010794}
10795
Jouni Malinen53b46b82009-03-27 20:53:56 +020010796void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10797 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010798 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010799{
10800 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010801 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010802}
10803
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010804void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10805 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010806{
Johannes Berg947add32013-02-22 22:05:20 +010010807 struct wireless_dev *wdev = dev->ieee80211_ptr;
10808 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010809 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010810 const struct ieee80211_mgmt *mgmt = (void *)buf;
10811 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010812
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010813 if (WARN_ON(len < 2))
10814 return;
10815
10816 if (ieee80211_is_deauth(mgmt->frame_control))
10817 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10818 else
10819 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10820
10821 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010822 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010823}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010824EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010825
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010826static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10827 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010828 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010829{
10830 struct sk_buff *msg;
10831 void *hdr;
10832
Johannes Berge6d6e342009-07-01 21:26:47 +020010833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010834 if (!msg)
10835 return;
10836
10837 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10838 if (!hdr) {
10839 nlmsg_free(msg);
10840 return;
10841 }
10842
David S. Miller9360ffd2012-03-29 04:41:26 -040010843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10844 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10845 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10846 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10847 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010848
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010849 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010850
Johannes Berg68eb5502013-11-19 15:19:38 +010010851 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010852 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010853 return;
10854
10855 nla_put_failure:
10856 genlmsg_cancel(msg, hdr);
10857 nlmsg_free(msg);
10858}
10859
10860void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010861 struct net_device *netdev, const u8 *addr,
10862 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010863{
10864 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010865 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010866}
10867
10868void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010869 struct net_device *netdev, const u8 *addr,
10870 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010871{
Johannes Berge6d6e342009-07-01 21:26:47 +020010872 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10873 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010874}
10875
Samuel Ortizb23aa672009-07-01 21:26:54 +020010876void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10877 struct net_device *netdev, const u8 *bssid,
10878 const u8 *req_ie, size_t req_ie_len,
10879 const u8 *resp_ie, size_t resp_ie_len,
10880 u16 status, 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_CONNECT);
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 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10898 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10899 (req_ie &&
10900 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10901 (resp_ie &&
10902 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10903 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010904
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010905 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010906
Johannes Berg68eb5502013-11-19 15:19:38 +010010907 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010908 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010909 return;
10910
10911 nla_put_failure:
10912 genlmsg_cancel(msg, hdr);
10913 nlmsg_free(msg);
10914
10915}
10916
10917void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10918 struct net_device *netdev, const u8 *bssid,
10919 const u8 *req_ie, size_t req_ie_len,
10920 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10921{
10922 struct sk_buff *msg;
10923 void *hdr;
10924
Thomas Graf58050fc2012-06-28 03:57:45 +000010925 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010926 if (!msg)
10927 return;
10928
10929 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10930 if (!hdr) {
10931 nlmsg_free(msg);
10932 return;
10933 }
10934
David S. Miller9360ffd2012-03-29 04:41:26 -040010935 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10936 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10937 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10938 (req_ie &&
10939 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10940 (resp_ie &&
10941 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10942 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010943
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010944 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010945
Johannes Berg68eb5502013-11-19 15:19:38 +010010946 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010947 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010948 return;
10949
10950 nla_put_failure:
10951 genlmsg_cancel(msg, hdr);
10952 nlmsg_free(msg);
10953
10954}
10955
10956void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10957 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010958 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010959{
10960 struct sk_buff *msg;
10961 void *hdr;
10962
Thomas Graf58050fc2012-06-28 03:57:45 +000010963 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010964 if (!msg)
10965 return;
10966
10967 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10968 if (!hdr) {
10969 nlmsg_free(msg);
10970 return;
10971 }
10972
David S. Miller9360ffd2012-03-29 04:41:26 -040010973 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10974 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10975 (from_ap && reason &&
10976 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10977 (from_ap &&
10978 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10979 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10980 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010981
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010982 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010983
Johannes Berg68eb5502013-11-19 15:19:38 +010010984 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010985 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010986 return;
10987
10988 nla_put_failure:
10989 genlmsg_cancel(msg, hdr);
10990 nlmsg_free(msg);
10991
10992}
10993
Johannes Berg04a773a2009-04-19 21:24:32 +020010994void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10995 struct net_device *netdev, const u8 *bssid,
10996 gfp_t gfp)
10997{
10998 struct sk_buff *msg;
10999 void *hdr;
11000
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011001 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011002 if (!msg)
11003 return;
11004
11005 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11006 if (!hdr) {
11007 nlmsg_free(msg);
11008 return;
11009 }
11010
David S. Miller9360ffd2012-03-29 04:41:26 -040011011 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11012 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11013 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11014 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011015
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011016 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011017
Johannes Berg68eb5502013-11-19 15:19:38 +010011018 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011019 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011020 return;
11021
11022 nla_put_failure:
11023 genlmsg_cancel(msg, hdr);
11024 nlmsg_free(msg);
11025}
11026
Johannes Berg947add32013-02-22 22:05:20 +010011027void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11028 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011029{
Johannes Berg947add32013-02-22 22:05:20 +010011030 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011031 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011032 struct sk_buff *msg;
11033 void *hdr;
11034
Johannes Berg947add32013-02-22 22:05:20 +010011035 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11036 return;
11037
11038 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11039
Javier Cardonac93b5e72011-04-07 15:08:34 -070011040 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11041 if (!msg)
11042 return;
11043
11044 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11045 if (!hdr) {
11046 nlmsg_free(msg);
11047 return;
11048 }
11049
David S. Miller9360ffd2012-03-29 04:41:26 -040011050 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011051 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11052 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011053 (ie_len && ie &&
11054 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11055 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011056
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011057 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011058
Johannes Berg68eb5502013-11-19 15:19:38 +010011059 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011060 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011061 return;
11062
11063 nla_put_failure:
11064 genlmsg_cancel(msg, hdr);
11065 nlmsg_free(msg);
11066}
Johannes Berg947add32013-02-22 22:05:20 +010011067EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011068
Jouni Malinena3b8b052009-03-27 21:59:49 +020011069void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11070 struct net_device *netdev, const u8 *addr,
11071 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011072 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011073{
11074 struct sk_buff *msg;
11075 void *hdr;
11076
Johannes Berge6d6e342009-07-01 21:26:47 +020011077 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011078 if (!msg)
11079 return;
11080
11081 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11082 if (!hdr) {
11083 nlmsg_free(msg);
11084 return;
11085 }
11086
David S. Miller9360ffd2012-03-29 04:41:26 -040011087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11088 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11089 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11090 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11091 (key_id != -1 &&
11092 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11093 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11094 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011095
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011096 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011097
Johannes Berg68eb5502013-11-19 15:19:38 +010011098 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011099 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011100 return;
11101
11102 nla_put_failure:
11103 genlmsg_cancel(msg, hdr);
11104 nlmsg_free(msg);
11105}
11106
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011107void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11108 struct ieee80211_channel *channel_before,
11109 struct ieee80211_channel *channel_after)
11110{
11111 struct sk_buff *msg;
11112 void *hdr;
11113 struct nlattr *nl_freq;
11114
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011115 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011116 if (!msg)
11117 return;
11118
11119 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11120 if (!hdr) {
11121 nlmsg_free(msg);
11122 return;
11123 }
11124
11125 /*
11126 * Since we are applying the beacon hint to a wiphy we know its
11127 * wiphy_idx is valid
11128 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011129 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11130 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011131
11132 /* Before */
11133 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11134 if (!nl_freq)
11135 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011136 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011137 goto nla_put_failure;
11138 nla_nest_end(msg, nl_freq);
11139
11140 /* After */
11141 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11142 if (!nl_freq)
11143 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011144 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011145 goto nla_put_failure;
11146 nla_nest_end(msg, nl_freq);
11147
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011148 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011149
Johannes Berg463d0182009-07-14 00:33:35 +020011150 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011151 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011152 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011153 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011154
11155 return;
11156
11157nla_put_failure:
11158 genlmsg_cancel(msg, hdr);
11159 nlmsg_free(msg);
11160}
11161
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011162static void nl80211_send_remain_on_chan_event(
11163 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011164 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011165 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011166 unsigned int duration, gfp_t gfp)
11167{
11168 struct sk_buff *msg;
11169 void *hdr;
11170
11171 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11172 if (!msg)
11173 return;
11174
11175 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11176 if (!hdr) {
11177 nlmsg_free(msg);
11178 return;
11179 }
11180
David S. Miller9360ffd2012-03-29 04:41:26 -040011181 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011182 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11183 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011184 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011185 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011186 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11187 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011188 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11189 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011190
David S. Miller9360ffd2012-03-29 04:41:26 -040011191 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11192 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11193 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011194
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011195 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011196
Johannes Berg68eb5502013-11-19 15:19:38 +010011197 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011198 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011199 return;
11200
11201 nla_put_failure:
11202 genlmsg_cancel(msg, hdr);
11203 nlmsg_free(msg);
11204}
11205
Johannes Berg947add32013-02-22 22:05:20 +010011206void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11207 struct ieee80211_channel *chan,
11208 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011209{
Johannes Berg947add32013-02-22 22:05:20 +010011210 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011211 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011212
11213 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011214 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011215 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011216 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011217}
Johannes Berg947add32013-02-22 22:05:20 +010011218EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011219
Johannes Berg947add32013-02-22 22:05:20 +010011220void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11221 struct ieee80211_channel *chan,
11222 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011223{
Johannes Berg947add32013-02-22 22:05:20 +010011224 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011225 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011226
11227 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011228 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011229 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011230}
Johannes Berg947add32013-02-22 22:05:20 +010011231EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011232
Johannes Berg947add32013-02-22 22:05:20 +010011233void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11234 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011235{
Johannes Berg947add32013-02-22 22:05:20 +010011236 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011237 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011238 struct sk_buff *msg;
11239
Johannes Berg947add32013-02-22 22:05:20 +010011240 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11241
Thomas Graf58050fc2012-06-28 03:57:45 +000011242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011243 if (!msg)
11244 return;
11245
John W. Linville66266b32012-03-15 13:25:41 -040011246 if (nl80211_send_station(msg, 0, 0, 0,
11247 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011248 nlmsg_free(msg);
11249 return;
11250 }
11251
Johannes Berg68eb5502013-11-19 15:19:38 +010011252 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011253 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011254}
Johannes Berg947add32013-02-22 22:05:20 +010011255EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011256
Johannes Berg947add32013-02-22 22:05:20 +010011257void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011258{
Johannes Berg947add32013-02-22 22:05:20 +010011259 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011260 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011261 struct sk_buff *msg;
11262 void *hdr;
11263
Johannes Berg947add32013-02-22 22:05:20 +010011264 trace_cfg80211_del_sta(dev, mac_addr);
11265
Thomas Graf58050fc2012-06-28 03:57:45 +000011266 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011267 if (!msg)
11268 return;
11269
11270 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11271 if (!hdr) {
11272 nlmsg_free(msg);
11273 return;
11274 }
11275
David S. Miller9360ffd2012-03-29 04:41:26 -040011276 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11277 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11278 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011279
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011280 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011281
Johannes Berg68eb5502013-11-19 15:19:38 +010011282 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011283 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011284 return;
11285
11286 nla_put_failure:
11287 genlmsg_cancel(msg, hdr);
11288 nlmsg_free(msg);
11289}
Johannes Berg947add32013-02-22 22:05:20 +010011290EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011291
Johannes Berg947add32013-02-22 22:05:20 +010011292void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11293 enum nl80211_connect_failed_reason reason,
11294 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011295{
Johannes Berg947add32013-02-22 22:05:20 +010011296 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011297 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011298 struct sk_buff *msg;
11299 void *hdr;
11300
11301 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11302 if (!msg)
11303 return;
11304
11305 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11306 if (!hdr) {
11307 nlmsg_free(msg);
11308 return;
11309 }
11310
11311 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11312 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11313 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11314 goto nla_put_failure;
11315
11316 genlmsg_end(msg, hdr);
11317
Johannes Berg68eb5502013-11-19 15:19:38 +010011318 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011319 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011320 return;
11321
11322 nla_put_failure:
11323 genlmsg_cancel(msg, hdr);
11324 nlmsg_free(msg);
11325}
Johannes Berg947add32013-02-22 22:05:20 +010011326EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011327
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011328static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11329 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011330{
11331 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011332 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011333 struct sk_buff *msg;
11334 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011335 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011336
Eric W. Biederman15e47302012-09-07 20:12:54 +000011337 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011338 return false;
11339
11340 msg = nlmsg_new(100, gfp);
11341 if (!msg)
11342 return true;
11343
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011344 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011345 if (!hdr) {
11346 nlmsg_free(msg);
11347 return true;
11348 }
11349
David S. Miller9360ffd2012-03-29 04:41:26 -040011350 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11351 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11352 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11353 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011354
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011355 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011356 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011357 return true;
11358
11359 nla_put_failure:
11360 genlmsg_cancel(msg, hdr);
11361 nlmsg_free(msg);
11362 return true;
11363}
11364
Johannes Berg947add32013-02-22 22:05:20 +010011365bool cfg80211_rx_spurious_frame(struct net_device *dev,
11366 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011367{
Johannes Berg947add32013-02-22 22:05:20 +010011368 struct wireless_dev *wdev = dev->ieee80211_ptr;
11369 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011370
Johannes Berg947add32013-02-22 22:05:20 +010011371 trace_cfg80211_rx_spurious_frame(dev, addr);
11372
11373 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11374 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11375 trace_cfg80211_return_bool(false);
11376 return false;
11377 }
11378 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11379 addr, gfp);
11380 trace_cfg80211_return_bool(ret);
11381 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011382}
Johannes Berg947add32013-02-22 22:05:20 +010011383EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11384
11385bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11386 const u8 *addr, gfp_t gfp)
11387{
11388 struct wireless_dev *wdev = dev->ieee80211_ptr;
11389 bool ret;
11390
11391 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11392
11393 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11394 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11395 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11396 trace_cfg80211_return_bool(false);
11397 return false;
11398 }
11399 ret = __nl80211_unexpected_frame(dev,
11400 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11401 addr, gfp);
11402 trace_cfg80211_return_bool(ret);
11403 return ret;
11404}
11405EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011406
Johannes Berg2e161f72010-08-12 15:38:38 +020011407int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011408 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011409 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011410 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011411{
Johannes Berg71bbc992012-06-15 15:30:18 +020011412 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011413 struct sk_buff *msg;
11414 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011415
11416 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11417 if (!msg)
11418 return -ENOMEM;
11419
Johannes Berg2e161f72010-08-12 15:38:38 +020011420 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011421 if (!hdr) {
11422 nlmsg_free(msg);
11423 return -ENOMEM;
11424 }
11425
David S. Miller9360ffd2012-03-29 04:41:26 -040011426 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011427 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11428 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011429 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011430 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11431 (sig_dbm &&
11432 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011433 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11434 (flags &&
11435 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011436 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
Eric W. Biederman15e47302012-09-07 20:12:54 +000011440 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011441
11442 nla_put_failure:
11443 genlmsg_cancel(msg, hdr);
11444 nlmsg_free(msg);
11445 return -ENOBUFS;
11446}
11447
Johannes Berg947add32013-02-22 22:05:20 +010011448void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11449 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011450{
Johannes Berg947add32013-02-22 22:05:20 +010011451 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011452 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011453 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011454 struct sk_buff *msg;
11455 void *hdr;
11456
Johannes Berg947add32013-02-22 22:05:20 +010011457 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11458
Jouni Malinen026331c2010-02-15 12:53:10 +020011459 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11460 if (!msg)
11461 return;
11462
Johannes Berg2e161f72010-08-12 15:38:38 +020011463 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011464 if (!hdr) {
11465 nlmsg_free(msg);
11466 return;
11467 }
11468
David S. Miller9360ffd2012-03-29 04:41:26 -040011469 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011470 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11471 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011472 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011473 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11474 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11475 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11476 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011477
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011478 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011479
Johannes Berg68eb5502013-11-19 15:19:38 +010011480 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011481 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011482 return;
11483
11484 nla_put_failure:
11485 genlmsg_cancel(msg, hdr);
11486 nlmsg_free(msg);
11487}
Johannes Berg947add32013-02-22 22:05:20 +010011488EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011489
Johannes Berg947add32013-02-22 22:05:20 +010011490void cfg80211_cqm_rssi_notify(struct net_device *dev,
11491 enum nl80211_cqm_rssi_threshold_event rssi_event,
11492 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011493{
Johannes Berg947add32013-02-22 22:05:20 +010011494 struct wireless_dev *wdev = dev->ieee80211_ptr;
11495 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011496 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011497 struct sk_buff *msg;
11498 struct nlattr *pinfoattr;
11499 void *hdr;
11500
Johannes Berg947add32013-02-22 22:05:20 +010011501 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11502
Thomas Graf58050fc2012-06-28 03:57:45 +000011503 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011504 if (!msg)
11505 return;
11506
11507 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11508 if (!hdr) {
11509 nlmsg_free(msg);
11510 return;
11511 }
11512
David S. Miller9360ffd2012-03-29 04:41:26 -040011513 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011514 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011515 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011516
11517 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11518 if (!pinfoattr)
11519 goto nla_put_failure;
11520
David S. Miller9360ffd2012-03-29 04:41:26 -040011521 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11522 rssi_event))
11523 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011524
11525 nla_nest_end(msg, pinfoattr);
11526
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011527 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011528
Johannes Berg68eb5502013-11-19 15:19:38 +010011529 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011530 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011531 return;
11532
11533 nla_put_failure:
11534 genlmsg_cancel(msg, hdr);
11535 nlmsg_free(msg);
11536}
Johannes Berg947add32013-02-22 22:05:20 +010011537EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011538
Johannes Berg947add32013-02-22 22:05:20 +010011539static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11540 struct net_device *netdev, const u8 *bssid,
11541 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011542{
11543 struct sk_buff *msg;
11544 struct nlattr *rekey_attr;
11545 void *hdr;
11546
Thomas Graf58050fc2012-06-28 03:57:45 +000011547 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011548 if (!msg)
11549 return;
11550
11551 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11552 if (!hdr) {
11553 nlmsg_free(msg);
11554 return;
11555 }
11556
David S. Miller9360ffd2012-03-29 04:41:26 -040011557 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11558 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11559 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11560 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011561
11562 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11563 if (!rekey_attr)
11564 goto nla_put_failure;
11565
David S. Miller9360ffd2012-03-29 04:41:26 -040011566 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11567 NL80211_REPLAY_CTR_LEN, replay_ctr))
11568 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011569
11570 nla_nest_end(msg, rekey_attr);
11571
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011572 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011573
Johannes Berg68eb5502013-11-19 15:19:38 +010011574 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011575 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011576 return;
11577
11578 nla_put_failure:
11579 genlmsg_cancel(msg, hdr);
11580 nlmsg_free(msg);
11581}
11582
Johannes Berg947add32013-02-22 22:05:20 +010011583void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11584 const u8 *replay_ctr, gfp_t gfp)
11585{
11586 struct wireless_dev *wdev = dev->ieee80211_ptr;
11587 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011588 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011589
11590 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11591 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11592}
11593EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11594
11595static void
11596nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11597 struct net_device *netdev, int index,
11598 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011599{
11600 struct sk_buff *msg;
11601 struct nlattr *attr;
11602 void *hdr;
11603
Thomas Graf58050fc2012-06-28 03:57:45 +000011604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011605 if (!msg)
11606 return;
11607
11608 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11609 if (!hdr) {
11610 nlmsg_free(msg);
11611 return;
11612 }
11613
David S. Miller9360ffd2012-03-29 04:41:26 -040011614 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11615 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11616 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011617
11618 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11619 if (!attr)
11620 goto nla_put_failure;
11621
David S. Miller9360ffd2012-03-29 04:41:26 -040011622 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11623 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11624 (preauth &&
11625 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11626 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011627
11628 nla_nest_end(msg, attr);
11629
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011630 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011631
Johannes Berg68eb5502013-11-19 15:19:38 +010011632 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011633 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011634 return;
11635
11636 nla_put_failure:
11637 genlmsg_cancel(msg, hdr);
11638 nlmsg_free(msg);
11639}
11640
Johannes Berg947add32013-02-22 22:05:20 +010011641void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11642 const u8 *bssid, bool preauth, gfp_t gfp)
11643{
11644 struct wireless_dev *wdev = dev->ieee80211_ptr;
11645 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011646 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011647
11648 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11649 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11650}
11651EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11652
11653static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11654 struct net_device *netdev,
11655 struct cfg80211_chan_def *chandef,
11656 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011657{
11658 struct sk_buff *msg;
11659 void *hdr;
11660
Thomas Graf58050fc2012-06-28 03:57:45 +000011661 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011662 if (!msg)
11663 return;
11664
11665 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11666 if (!hdr) {
11667 nlmsg_free(msg);
11668 return;
11669 }
11670
Johannes Berg683b6d32012-11-08 21:25:48 +010011671 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11672 goto nla_put_failure;
11673
11674 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011675 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011676
11677 genlmsg_end(msg, hdr);
11678
Johannes Berg68eb5502013-11-19 15:19:38 +010011679 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011680 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011681 return;
11682
11683 nla_put_failure:
11684 genlmsg_cancel(msg, hdr);
11685 nlmsg_free(msg);
11686}
11687
Johannes Berg947add32013-02-22 22:05:20 +010011688void cfg80211_ch_switch_notify(struct net_device *dev,
11689 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011690{
Johannes Berg947add32013-02-22 22:05:20 +010011691 struct wireless_dev *wdev = dev->ieee80211_ptr;
11692 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011693 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011694
Simon Wunderliche487eae2013-11-21 18:19:51 +010011695 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011696
Simon Wunderliche487eae2013-11-21 18:19:51 +010011697 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011698
11699 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011700 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011701 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11702 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011703 return;
Johannes Berg947add32013-02-22 22:05:20 +010011704
Michal Kazior9e0e2962014-01-29 14:22:27 +010011705 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011706 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011707 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011708}
11709EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11710
11711void cfg80211_cqm_txe_notify(struct net_device *dev,
11712 const u8 *peer, u32 num_packets,
11713 u32 rate, u32 intvl, gfp_t gfp)
11714{
11715 struct wireless_dev *wdev = dev->ieee80211_ptr;
11716 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011717 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011718 struct sk_buff *msg;
11719 struct nlattr *pinfoattr;
11720 void *hdr;
11721
11722 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11723 if (!msg)
11724 return;
11725
11726 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11727 if (!hdr) {
11728 nlmsg_free(msg);
11729 return;
11730 }
11731
11732 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011733 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011734 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11735 goto nla_put_failure;
11736
11737 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11738 if (!pinfoattr)
11739 goto nla_put_failure;
11740
11741 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11742 goto nla_put_failure;
11743
11744 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11745 goto nla_put_failure;
11746
11747 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11748 goto nla_put_failure;
11749
11750 nla_nest_end(msg, pinfoattr);
11751
11752 genlmsg_end(msg, hdr);
11753
Johannes Berg68eb5502013-11-19 15:19:38 +010011754 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011755 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011756 return;
11757
11758 nla_put_failure:
11759 genlmsg_cancel(msg, hdr);
11760 nlmsg_free(msg);
11761}
Johannes Berg947add32013-02-22 22:05:20 +010011762EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011763
11764void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011765nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011766 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011767 enum nl80211_radar_event event,
11768 struct net_device *netdev, gfp_t gfp)
11769{
11770 struct sk_buff *msg;
11771 void *hdr;
11772
11773 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11774 if (!msg)
11775 return;
11776
11777 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11778 if (!hdr) {
11779 nlmsg_free(msg);
11780 return;
11781 }
11782
11783 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11784 goto nla_put_failure;
11785
11786 /* NOP and radar events don't need a netdev parameter */
11787 if (netdev) {
11788 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11789
11790 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11791 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11792 goto nla_put_failure;
11793 }
11794
11795 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11796 goto nla_put_failure;
11797
11798 if (nl80211_send_chandef(msg, chandef))
11799 goto nla_put_failure;
11800
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011801 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011802
Johannes Berg68eb5502013-11-19 15:19:38 +010011803 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011804 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011805 return;
11806
11807 nla_put_failure:
11808 genlmsg_cancel(msg, hdr);
11809 nlmsg_free(msg);
11810}
11811
Johannes Berg947add32013-02-22 22:05:20 +010011812void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11813 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011814{
Johannes Berg947add32013-02-22 22:05:20 +010011815 struct wireless_dev *wdev = dev->ieee80211_ptr;
11816 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011817 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011818 struct sk_buff *msg;
11819 struct nlattr *pinfoattr;
11820 void *hdr;
11821
Johannes Berg947add32013-02-22 22:05:20 +010011822 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11823
Thomas Graf58050fc2012-06-28 03:57:45 +000011824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011825 if (!msg)
11826 return;
11827
11828 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11829 if (!hdr) {
11830 nlmsg_free(msg);
11831 return;
11832 }
11833
David S. Miller9360ffd2012-03-29 04:41:26 -040011834 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011835 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011836 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11837 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011838
11839 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11840 if (!pinfoattr)
11841 goto nla_put_failure;
11842
David S. Miller9360ffd2012-03-29 04:41:26 -040011843 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11844 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011845
11846 nla_nest_end(msg, pinfoattr);
11847
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011848 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +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 Bergc063dbf2010-11-24 08:10:05 +010011852 return;
11853
11854 nla_put_failure:
11855 genlmsg_cancel(msg, hdr);
11856 nlmsg_free(msg);
11857}
Johannes Berg947add32013-02-22 22:05:20 +010011858EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011859
Johannes Berg7f6cf312011-11-04 11:18:15 +010011860void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11861 u64 cookie, bool acked, gfp_t gfp)
11862{
11863 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011864 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011865 struct sk_buff *msg;
11866 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011867
Beni Lev4ee3e062012-08-27 12:49:39 +030011868 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11869
Thomas Graf58050fc2012-06-28 03:57:45 +000011870 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011871
Johannes Berg7f6cf312011-11-04 11:18:15 +010011872 if (!msg)
11873 return;
11874
11875 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11876 if (!hdr) {
11877 nlmsg_free(msg);
11878 return;
11879 }
11880
David S. Miller9360ffd2012-03-29 04:41:26 -040011881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11882 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11883 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11884 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11885 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11886 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011887
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011888 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011889
Johannes Berg68eb5502013-11-19 15:19:38 +010011890 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011891 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011892 return;
11893
11894 nla_put_failure:
11895 genlmsg_cancel(msg, hdr);
11896 nlmsg_free(msg);
11897}
11898EXPORT_SYMBOL(cfg80211_probe_status);
11899
Johannes Berg5e760232011-11-04 11:18:17 +010011900void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11901 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011902 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011903{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011904 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011905 struct sk_buff *msg;
11906 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011907 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011908
Beni Lev4ee3e062012-08-27 12:49:39 +030011909 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11910
Ben Greear37c73b52012-10-26 14:49:25 -070011911 spin_lock_bh(&rdev->beacon_registrations_lock);
11912 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11913 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11914 if (!msg) {
11915 spin_unlock_bh(&rdev->beacon_registrations_lock);
11916 return;
11917 }
Johannes Berg5e760232011-11-04 11:18:17 +010011918
Ben Greear37c73b52012-10-26 14:49:25 -070011919 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11920 if (!hdr)
11921 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011922
Ben Greear37c73b52012-10-26 14:49:25 -070011923 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11924 (freq &&
11925 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11926 (sig_dbm &&
11927 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11928 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11929 goto nla_put_failure;
11930
11931 genlmsg_end(msg, hdr);
11932
11933 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011934 }
Ben Greear37c73b52012-10-26 14:49:25 -070011935 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011936 return;
11937
11938 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011939 spin_unlock_bh(&rdev->beacon_registrations_lock);
11940 if (hdr)
11941 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011942 nlmsg_free(msg);
11943}
11944EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11945
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011946#ifdef CONFIG_PM
11947void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11948 struct cfg80211_wowlan_wakeup *wakeup,
11949 gfp_t gfp)
11950{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011951 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011952 struct sk_buff *msg;
11953 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011954 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011955
11956 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11957
11958 if (wakeup)
11959 size += wakeup->packet_present_len;
11960
11961 msg = nlmsg_new(size, gfp);
11962 if (!msg)
11963 return;
11964
11965 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11966 if (!hdr)
11967 goto free_msg;
11968
11969 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11970 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11971 goto free_msg;
11972
11973 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11974 wdev->netdev->ifindex))
11975 goto free_msg;
11976
11977 if (wakeup) {
11978 struct nlattr *reasons;
11979
11980 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011981 if (!reasons)
11982 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011983
11984 if (wakeup->disconnect &&
11985 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11986 goto free_msg;
11987 if (wakeup->magic_pkt &&
11988 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11989 goto free_msg;
11990 if (wakeup->gtk_rekey_failure &&
11991 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11992 goto free_msg;
11993 if (wakeup->eap_identity_req &&
11994 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11995 goto free_msg;
11996 if (wakeup->four_way_handshake &&
11997 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11998 goto free_msg;
11999 if (wakeup->rfkill_release &&
12000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12001 goto free_msg;
12002
12003 if (wakeup->pattern_idx >= 0 &&
12004 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12005 wakeup->pattern_idx))
12006 goto free_msg;
12007
Johannes Bergae917c92013-10-25 11:05:22 +020012008 if (wakeup->tcp_match &&
12009 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12010 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012011
Johannes Bergae917c92013-10-25 11:05:22 +020012012 if (wakeup->tcp_connlost &&
12013 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12014 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012015
Johannes Bergae917c92013-10-25 11:05:22 +020012016 if (wakeup->tcp_nomoretokens &&
12017 nla_put_flag(msg,
12018 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12019 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012020
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012021 if (wakeup->packet) {
12022 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12023 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12024
12025 if (!wakeup->packet_80211) {
12026 pkt_attr =
12027 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12028 len_attr =
12029 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12030 }
12031
12032 if (wakeup->packet_len &&
12033 nla_put_u32(msg, len_attr, wakeup->packet_len))
12034 goto free_msg;
12035
12036 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12037 wakeup->packet))
12038 goto free_msg;
12039 }
12040
12041 nla_nest_end(msg, reasons);
12042 }
12043
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012044 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012045
Johannes Berg68eb5502013-11-19 15:19:38 +010012046 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012047 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012048 return;
12049
12050 free_msg:
12051 nlmsg_free(msg);
12052}
12053EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12054#endif
12055
Jouni Malinen3475b092012-11-16 22:49:57 +020012056void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12057 enum nl80211_tdls_operation oper,
12058 u16 reason_code, gfp_t gfp)
12059{
12060 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012061 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012062 struct sk_buff *msg;
12063 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012064
12065 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12066 reason_code);
12067
12068 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12069 if (!msg)
12070 return;
12071
12072 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12073 if (!hdr) {
12074 nlmsg_free(msg);
12075 return;
12076 }
12077
12078 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12079 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12080 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12081 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12082 (reason_code > 0 &&
12083 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12084 goto nla_put_failure;
12085
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012086 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012087
Johannes Berg68eb5502013-11-19 15:19:38 +010012088 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012089 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012090 return;
12091
12092 nla_put_failure:
12093 genlmsg_cancel(msg, hdr);
12094 nlmsg_free(msg);
12095}
12096EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12097
Jouni Malinen026331c2010-02-15 12:53:10 +020012098static int nl80211_netlink_notify(struct notifier_block * nb,
12099 unsigned long state,
12100 void *_notify)
12101{
12102 struct netlink_notify *notify = _notify;
12103 struct cfg80211_registered_device *rdev;
12104 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012105 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012106
12107 if (state != NETLINK_URELEASE)
12108 return NOTIFY_DONE;
12109
12110 rcu_read_lock();
12111
Johannes Berg5e760232011-11-04 11:18:17 +010012112 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012113 bool schedule_destroy_work = false;
12114
12115 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012116 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012117
Johannes Berg78f22b62014-03-24 17:57:27 +010012118 if (wdev->owner_nlportid == notify->portid)
12119 schedule_destroy_work = true;
12120 }
12121
Ben Greear37c73b52012-10-26 14:49:25 -070012122 spin_lock_bh(&rdev->beacon_registrations_lock);
12123 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12124 list) {
12125 if (reg->nlportid == notify->portid) {
12126 list_del(&reg->list);
12127 kfree(reg);
12128 break;
12129 }
12130 }
12131 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012132
12133 if (schedule_destroy_work) {
12134 struct cfg80211_iface_destroy *destroy;
12135
12136 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12137 if (destroy) {
12138 destroy->nlportid = notify->portid;
12139 spin_lock(&rdev->destroy_list_lock);
12140 list_add(&destroy->list, &rdev->destroy_list);
12141 spin_unlock(&rdev->destroy_list_lock);
12142 schedule_work(&rdev->destroy_work);
12143 }
12144 }
Johannes Berg5e760232011-11-04 11:18:17 +010012145 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012146
12147 rcu_read_unlock();
12148
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012149 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012150}
12151
12152static struct notifier_block nl80211_netlink_notifier = {
12153 .notifier_call = nl80211_netlink_notify,
12154};
12155
Jouni Malinen355199e2013-02-27 17:14:27 +020012156void cfg80211_ft_event(struct net_device *netdev,
12157 struct cfg80211_ft_event_params *ft_event)
12158{
12159 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012161 struct sk_buff *msg;
12162 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012163
12164 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12165
12166 if (!ft_event->target_ap)
12167 return;
12168
12169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12170 if (!msg)
12171 return;
12172
12173 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012174 if (!hdr)
12175 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012176
Johannes Bergae917c92013-10-25 11:05:22 +020012177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12178 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12179 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12180 goto out;
12181
12182 if (ft_event->ies &&
12183 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12184 goto out;
12185 if (ft_event->ric_ies &&
12186 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12187 ft_event->ric_ies))
12188 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012189
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012190 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012191
Johannes Berg68eb5502013-11-19 15:19:38 +010012192 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012193 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012194 return;
12195 out:
12196 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012197}
12198EXPORT_SYMBOL(cfg80211_ft_event);
12199
Arend van Spriel5de17982013-04-18 15:49:00 +020012200void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12201{
12202 struct cfg80211_registered_device *rdev;
12203 struct sk_buff *msg;
12204 void *hdr;
12205 u32 nlportid;
12206
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012207 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012208 if (!rdev->crit_proto_nlportid)
12209 return;
12210
12211 nlportid = rdev->crit_proto_nlportid;
12212 rdev->crit_proto_nlportid = 0;
12213
12214 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12215 if (!msg)
12216 return;
12217
12218 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12219 if (!hdr)
12220 goto nla_put_failure;
12221
12222 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12223 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12224 goto nla_put_failure;
12225
12226 genlmsg_end(msg, hdr);
12227
12228 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12229 return;
12230
12231 nla_put_failure:
12232 if (hdr)
12233 genlmsg_cancel(msg, hdr);
12234 nlmsg_free(msg);
12235
12236}
12237EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12238
Johannes Berg348baf02014-01-24 14:06:29 +010012239void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12240{
12241 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012242 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012243 struct sk_buff *msg;
12244 void *hdr;
12245
12246 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12247 if (!msg)
12248 return;
12249
12250 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12251 if (!hdr)
12252 goto out;
12253
12254 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12255 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12256 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12257 goto out;
12258
12259 genlmsg_end(msg, hdr);
12260
12261 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12262 NL80211_MCGRP_MLME, GFP_KERNEL);
12263 return;
12264 out:
12265 nlmsg_free(msg);
12266}
12267
Johannes Berg55682962007-09-20 13:09:35 -040012268/* initialisation/exit functions */
12269
12270int nl80211_init(void)
12271{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012272 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012273
Johannes Berg2a94fe42013-11-19 15:19:39 +010012274 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12275 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012276 if (err)
12277 return err;
12278
Jouni Malinen026331c2010-02-15 12:53:10 +020012279 err = netlink_register_notifier(&nl80211_netlink_notifier);
12280 if (err)
12281 goto err_out;
12282
Johannes Berg55682962007-09-20 13:09:35 -040012283 return 0;
12284 err_out:
12285 genl_unregister_family(&nl80211_fam);
12286 return err;
12287}
12288
12289void nl80211_exit(void)
12290{
Jouni Malinen026331c2010-02-15 12:53:10 +020012291 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012292 genl_unregister_family(&nl80211_fam);
12293}