blob: cf178d2b621da5f7c6838684267505f7889bb192 [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 Malinen36aedc902008-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 Berg55682962007-09-20 13:09:35 -0400394};
395
Johannes Berge31b8212010-10-05 19:39:30 +0200396/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000397static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200398 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200399 [NL80211_KEY_IDX] = { .type = NLA_U8 },
400 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200401 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200402 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
403 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200404 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100405 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
406};
407
408/* policy for the key default flags */
409static const struct nla_policy
410nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
411 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
412 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200413};
414
Johannes Bergff1b6e62011-05-04 15:37:28 +0200415/* policy for WoWLAN attributes */
416static const struct nla_policy
417nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
418 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
419 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
420 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
421 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200422 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
423 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
424 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100426 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
427};
428
429static const struct nla_policy
430nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
431 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
432 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
433 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
434 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
435 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
436 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
437 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
438 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
439 },
440 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
441 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
442 },
443 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
444 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
445 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200446};
447
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700448/* policy for coalesce rule attributes */
449static const struct nla_policy
450nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
451 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
452 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
453 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
454};
455
Johannes Berge5497d72011-07-05 16:35:40 +0200456/* policy for GTK rekey offload attributes */
457static const struct nla_policy
458nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
459 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
460 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
461 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
462};
463
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300464static const struct nla_policy
465nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200466 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300467 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700468 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300469};
470
Johannes Berg97990a02013-04-19 01:02:55 +0200471static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
472 struct netlink_callback *cb,
473 struct cfg80211_registered_device **rdev,
474 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100475{
Johannes Berg67748892010-10-04 21:14:06 +0200476 int err;
477
Johannes Berg67748892010-10-04 21:14:06 +0200478 rtnl_lock();
479
Johannes Berg97990a02013-04-19 01:02:55 +0200480 if (!cb->args[0]) {
481 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
482 nl80211_fam.attrbuf, nl80211_fam.maxattr,
483 nl80211_policy);
484 if (err)
485 goto out_unlock;
486
487 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
488 nl80211_fam.attrbuf);
489 if (IS_ERR(*wdev)) {
490 err = PTR_ERR(*wdev);
491 goto out_unlock;
492 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800493 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200494 /* 0 is the first index - add 1 to parse only once */
495 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200496 cb->args[1] = (*wdev)->identifier;
497 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200498 /* subtract the 1 again here */
499 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200500 struct wireless_dev *tmp;
501
502 if (!wiphy) {
503 err = -ENODEV;
504 goto out_unlock;
505 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800506 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200507 *wdev = NULL;
508
Johannes Berg97990a02013-04-19 01:02:55 +0200509 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
510 if (tmp->identifier == cb->args[1]) {
511 *wdev = tmp;
512 break;
513 }
514 }
Johannes Berg97990a02013-04-19 01:02:55 +0200515
516 if (!*wdev) {
517 err = -ENODEV;
518 goto out_unlock;
519 }
Johannes Berg67748892010-10-04 21:14:06 +0200520 }
521
Johannes Berg67748892010-10-04 21:14:06 +0200522 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200523 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200524 rtnl_unlock();
525 return err;
526}
527
Johannes Berg97990a02013-04-19 01:02:55 +0200528static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200529{
Johannes Berg67748892010-10-04 21:14:06 +0200530 rtnl_unlock();
531}
532
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100533/* IE validation */
534static bool is_valid_ie_attr(const struct nlattr *attr)
535{
536 const u8 *pos;
537 int len;
538
539 if (!attr)
540 return true;
541
542 pos = nla_data(attr);
543 len = nla_len(attr);
544
545 while (len) {
546 u8 elemlen;
547
548 if (len < 2)
549 return false;
550 len -= 2;
551
552 elemlen = pos[1];
553 if (elemlen > len)
554 return false;
555
556 len -= elemlen;
557 pos += 2 + elemlen;
558 }
559
560 return true;
561}
562
Johannes Berg55682962007-09-20 13:09:35 -0400563/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000564static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400565 int flags, u8 cmd)
566{
567 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000568 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400569}
570
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400571static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100572 struct ieee80211_channel *chan,
573 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400574{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200575 /* Some channels must be completely excluded from the
576 * list to protect old user-space tools from breaking
577 */
578 if (!large && chan->flags &
579 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
580 return 0;
581
David S. Miller9360ffd2012-03-29 04:41:26 -0400582 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
583 chan->center_freq))
584 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400585
David S. Miller9360ffd2012-03-29 04:41:26 -0400586 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
587 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
588 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200589 if (chan->flags & IEEE80211_CHAN_NO_IR) {
590 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
591 goto nla_put_failure;
592 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
593 goto nla_put_failure;
594 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100595 if (chan->flags & IEEE80211_CHAN_RADAR) {
596 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
597 goto nla_put_failure;
598 if (large) {
599 u32 time;
600
601 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
602
603 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
604 chan->dfs_state))
605 goto nla_put_failure;
606 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
607 time))
608 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100609 if (nla_put_u32(msg,
610 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
611 chan->dfs_cac_ms))
612 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100613 }
614 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400615
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100616 if (large) {
617 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
618 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
619 goto nla_put_failure;
620 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
621 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
622 goto nla_put_failure;
623 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
624 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
625 goto nla_put_failure;
626 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
627 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
628 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200629 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
630 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
631 goto nla_put_failure;
632 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
633 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
634 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200635 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
636 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
637 goto nla_put_failure;
638 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
639 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
640 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100641 }
642
David S. Miller9360ffd2012-03-29 04:41:26 -0400643 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
644 DBM_TO_MBM(chan->max_power)))
645 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400646
647 return 0;
648
649 nla_put_failure:
650 return -ENOBUFS;
651}
652
Johannes Berg55682962007-09-20 13:09:35 -0400653/* netlink command implementations */
654
Johannes Bergb9454e82009-07-08 13:29:08 +0200655struct key_parse {
656 struct key_params p;
657 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200658 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200659 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100660 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200661};
662
663static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
664{
665 struct nlattr *tb[NL80211_KEY_MAX + 1];
666 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
667 nl80211_key_policy);
668 if (err)
669 return err;
670
671 k->def = !!tb[NL80211_KEY_DEFAULT];
672 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
673
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100674 if (k->def) {
675 k->def_uni = true;
676 k->def_multi = true;
677 }
678 if (k->defmgmt)
679 k->def_multi = true;
680
Johannes Bergb9454e82009-07-08 13:29:08 +0200681 if (tb[NL80211_KEY_IDX])
682 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
683
684 if (tb[NL80211_KEY_DATA]) {
685 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
686 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
687 }
688
689 if (tb[NL80211_KEY_SEQ]) {
690 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
691 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
692 }
693
694 if (tb[NL80211_KEY_CIPHER])
695 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
696
Johannes Berge31b8212010-10-05 19:39:30 +0200697 if (tb[NL80211_KEY_TYPE]) {
698 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
699 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
700 return -EINVAL;
701 }
702
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100703 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
704 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100705 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
706 tb[NL80211_KEY_DEFAULT_TYPES],
707 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100708 if (err)
709 return err;
710
711 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
712 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
713 }
714
Johannes Bergb9454e82009-07-08 13:29:08 +0200715 return 0;
716}
717
718static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
719{
720 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
721 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
722 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
723 }
724
725 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
726 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
727 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
728 }
729
730 if (info->attrs[NL80211_ATTR_KEY_IDX])
731 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
732
733 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
734 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
735
736 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
737 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
738
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100739 if (k->def) {
740 k->def_uni = true;
741 k->def_multi = true;
742 }
743 if (k->defmgmt)
744 k->def_multi = true;
745
Johannes Berge31b8212010-10-05 19:39:30 +0200746 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
747 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
748 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
749 return -EINVAL;
750 }
751
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100752 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
753 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
754 int err = nla_parse_nested(
755 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
756 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
757 nl80211_key_default_policy);
758 if (err)
759 return err;
760
761 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
762 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
763 }
764
Johannes Bergb9454e82009-07-08 13:29:08 +0200765 return 0;
766}
767
768static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
769{
770 int err;
771
772 memset(k, 0, sizeof(*k));
773 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200774 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200775
776 if (info->attrs[NL80211_ATTR_KEY])
777 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
778 else
779 err = nl80211_parse_key_old(info, k);
780
781 if (err)
782 return err;
783
784 if (k->def && k->defmgmt)
785 return -EINVAL;
786
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100787 if (k->defmgmt) {
788 if (k->def_uni || !k->def_multi)
789 return -EINVAL;
790 }
791
Johannes Bergb9454e82009-07-08 13:29:08 +0200792 if (k->idx != -1) {
793 if (k->defmgmt) {
794 if (k->idx < 4 || k->idx > 5)
795 return -EINVAL;
796 } else if (k->def) {
797 if (k->idx < 0 || k->idx > 3)
798 return -EINVAL;
799 } else {
800 if (k->idx < 0 || k->idx > 5)
801 return -EINVAL;
802 }
803 }
804
805 return 0;
806}
807
Johannes Bergfffd0932009-07-08 14:22:54 +0200808static struct cfg80211_cached_keys *
809nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530810 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200811{
812 struct key_parse parse;
813 struct nlattr *key;
814 struct cfg80211_cached_keys *result;
815 int rem, err, def = 0;
816
817 result = kzalloc(sizeof(*result), GFP_KERNEL);
818 if (!result)
819 return ERR_PTR(-ENOMEM);
820
821 result->def = -1;
822 result->defmgmt = -1;
823
824 nla_for_each_nested(key, keys, rem) {
825 memset(&parse, 0, sizeof(parse));
826 parse.idx = -1;
827
828 err = nl80211_parse_key_new(key, &parse);
829 if (err)
830 goto error;
831 err = -EINVAL;
832 if (!parse.p.key)
833 goto error;
834 if (parse.idx < 0 || parse.idx > 4)
835 goto error;
836 if (parse.def) {
837 if (def)
838 goto error;
839 def = 1;
840 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100841 if (!parse.def_uni || !parse.def_multi)
842 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200843 } else if (parse.defmgmt)
844 goto error;
845 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200846 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200847 if (err)
848 goto error;
849 result->params[parse.idx].cipher = parse.p.cipher;
850 result->params[parse.idx].key_len = parse.p.key_len;
851 result->params[parse.idx].key = result->data[parse.idx];
852 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530853
854 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
855 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
856 if (no_ht)
857 *no_ht = true;
858 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200859 }
860
861 return result;
862 error:
863 kfree(result);
864 return ERR_PTR(err);
865}
866
867static int nl80211_key_allowed(struct wireless_dev *wdev)
868{
869 ASSERT_WDEV_LOCK(wdev);
870
Johannes Bergfffd0932009-07-08 14:22:54 +0200871 switch (wdev->iftype) {
872 case NL80211_IFTYPE_AP:
873 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200874 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700875 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 break;
877 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200878 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200879 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200880 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200881 return -ENOLINK;
882 break;
883 default:
884 return -EINVAL;
885 }
886
887 return 0;
888}
889
Jouni Malinen664834d2014-01-15 00:01:44 +0200890static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
891 struct nlattr *tb)
892{
893 struct ieee80211_channel *chan;
894
895 if (tb == NULL)
896 return NULL;
897 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
898 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
899 return NULL;
900 return chan;
901}
902
Johannes Berg7527a782011-05-13 10:58:57 +0200903static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
904{
905 struct nlattr *nl_modes = nla_nest_start(msg, attr);
906 int i;
907
908 if (!nl_modes)
909 goto nla_put_failure;
910
911 i = 0;
912 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400913 if ((ifmodes & 1) && nla_put_flag(msg, i))
914 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200915 ifmodes >>= 1;
916 i++;
917 }
918
919 nla_nest_end(msg, nl_modes);
920 return 0;
921
922nla_put_failure:
923 return -ENOBUFS;
924}
925
926static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100927 struct sk_buff *msg,
928 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200929{
930 struct nlattr *nl_combis;
931 int i, j;
932
933 nl_combis = nla_nest_start(msg,
934 NL80211_ATTR_INTERFACE_COMBINATIONS);
935 if (!nl_combis)
936 goto nla_put_failure;
937
938 for (i = 0; i < wiphy->n_iface_combinations; i++) {
939 const struct ieee80211_iface_combination *c;
940 struct nlattr *nl_combi, *nl_limits;
941
942 c = &wiphy->iface_combinations[i];
943
944 nl_combi = nla_nest_start(msg, i + 1);
945 if (!nl_combi)
946 goto nla_put_failure;
947
948 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
949 if (!nl_limits)
950 goto nla_put_failure;
951
952 for (j = 0; j < c->n_limits; j++) {
953 struct nlattr *nl_limit;
954
955 nl_limit = nla_nest_start(msg, j + 1);
956 if (!nl_limit)
957 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400958 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
959 c->limits[j].max))
960 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200961 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
962 c->limits[j].types))
963 goto nla_put_failure;
964 nla_nest_end(msg, nl_limit);
965 }
966
967 nla_nest_end(msg, nl_limits);
968
David S. Miller9360ffd2012-03-29 04:41:26 -0400969 if (c->beacon_int_infra_match &&
970 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
971 goto nla_put_failure;
972 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
973 c->num_different_channels) ||
974 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
975 c->max_interfaces))
976 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100977 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200978 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
979 c->radar_detect_widths) ||
980 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
981 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100982 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200983
984 nla_nest_end(msg, nl_combi);
985 }
986
987 nla_nest_end(msg, nl_combis);
988
989 return 0;
990nla_put_failure:
991 return -ENOBUFS;
992}
993
Johannes Berg3713b4e2013-02-14 16:19:38 +0100994#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100995static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
996 struct sk_buff *msg)
997{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200998 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100999 struct nlattr *nl_tcp;
1000
1001 if (!tcp)
1002 return 0;
1003
1004 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1005 if (!nl_tcp)
1006 return -ENOBUFS;
1007
1008 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1009 tcp->data_payload_max))
1010 return -ENOBUFS;
1011
1012 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1013 tcp->data_payload_max))
1014 return -ENOBUFS;
1015
1016 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1017 return -ENOBUFS;
1018
1019 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1020 sizeof(*tcp->tok), tcp->tok))
1021 return -ENOBUFS;
1022
1023 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1024 tcp->data_interval_max))
1025 return -ENOBUFS;
1026
1027 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1028 tcp->wake_payload_max))
1029 return -ENOBUFS;
1030
1031 nla_nest_end(msg, nl_tcp);
1032 return 0;
1033}
1034
Johannes Berg3713b4e2013-02-14 16:19:38 +01001035static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001036 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001037 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001038{
1039 struct nlattr *nl_wowlan;
1040
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001041 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001042 return 0;
1043
1044 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1045 if (!nl_wowlan)
1046 return -ENOBUFS;
1047
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001048 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001049 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001050 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001054 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001055 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001058 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001060 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1064 return -ENOBUFS;
1065
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001067 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001068 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1069 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1070 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1071 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 };
1073
1074 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1075 sizeof(pat), &pat))
1076 return -ENOBUFS;
1077 }
1078
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001079 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001080 return -ENOBUFS;
1081
Johannes Berg3713b4e2013-02-14 16:19:38 +01001082 nla_nest_end(msg, nl_wowlan);
1083
1084 return 0;
1085}
1086#endif
1087
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001088static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001089 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001090{
1091 struct nl80211_coalesce_rule_support rule;
1092
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001093 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001094 return 0;
1095
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001096 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1097 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1098 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1099 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1100 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1101 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001102
1103 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1104 return -ENOBUFS;
1105
1106 return 0;
1107}
1108
Johannes Berg3713b4e2013-02-14 16:19:38 +01001109static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1110 struct ieee80211_supported_band *sband)
1111{
1112 struct nlattr *nl_rates, *nl_rate;
1113 struct ieee80211_rate *rate;
1114 int i;
1115
1116 /* add HT info */
1117 if (sband->ht_cap.ht_supported &&
1118 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1119 sizeof(sband->ht_cap.mcs),
1120 &sband->ht_cap.mcs) ||
1121 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1122 sband->ht_cap.cap) ||
1123 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1124 sband->ht_cap.ampdu_factor) ||
1125 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1126 sband->ht_cap.ampdu_density)))
1127 return -ENOBUFS;
1128
1129 /* add VHT info */
1130 if (sband->vht_cap.vht_supported &&
1131 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1132 sizeof(sband->vht_cap.vht_mcs),
1133 &sband->vht_cap.vht_mcs) ||
1134 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1135 sband->vht_cap.cap)))
1136 return -ENOBUFS;
1137
1138 /* add bitrates */
1139 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1140 if (!nl_rates)
1141 return -ENOBUFS;
1142
1143 for (i = 0; i < sband->n_bitrates; i++) {
1144 nl_rate = nla_nest_start(msg, i);
1145 if (!nl_rate)
1146 return -ENOBUFS;
1147
1148 rate = &sband->bitrates[i];
1149 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1150 rate->bitrate))
1151 return -ENOBUFS;
1152 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1153 nla_put_flag(msg,
1154 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1155 return -ENOBUFS;
1156
1157 nla_nest_end(msg, nl_rate);
1158 }
1159
1160 nla_nest_end(msg, nl_rates);
1161
1162 return 0;
1163}
1164
1165static int
1166nl80211_send_mgmt_stypes(struct sk_buff *msg,
1167 const struct ieee80211_txrx_stypes *mgmt_stypes)
1168{
1169 u16 stypes;
1170 struct nlattr *nl_ftypes, *nl_ifs;
1171 enum nl80211_iftype ift;
1172 int i;
1173
1174 if (!mgmt_stypes)
1175 return 0;
1176
1177 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1178 if (!nl_ifs)
1179 return -ENOBUFS;
1180
1181 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1182 nl_ftypes = nla_nest_start(msg, ift);
1183 if (!nl_ftypes)
1184 return -ENOBUFS;
1185 i = 0;
1186 stypes = mgmt_stypes[ift].tx;
1187 while (stypes) {
1188 if ((stypes & 1) &&
1189 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1190 (i << 4) | IEEE80211_FTYPE_MGMT))
1191 return -ENOBUFS;
1192 stypes >>= 1;
1193 i++;
1194 }
1195 nla_nest_end(msg, nl_ftypes);
1196 }
1197
1198 nla_nest_end(msg, nl_ifs);
1199
1200 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1201 if (!nl_ifs)
1202 return -ENOBUFS;
1203
1204 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1205 nl_ftypes = nla_nest_start(msg, ift);
1206 if (!nl_ftypes)
1207 return -ENOBUFS;
1208 i = 0;
1209 stypes = mgmt_stypes[ift].rx;
1210 while (stypes) {
1211 if ((stypes & 1) &&
1212 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1213 (i << 4) | IEEE80211_FTYPE_MGMT))
1214 return -ENOBUFS;
1215 stypes >>= 1;
1216 i++;
1217 }
1218 nla_nest_end(msg, nl_ftypes);
1219 }
1220 nla_nest_end(msg, nl_ifs);
1221
1222 return 0;
1223}
1224
Johannes Berg86e8cf92013-06-19 10:57:22 +02001225struct nl80211_dump_wiphy_state {
1226 s64 filter_wiphy;
1227 long start;
1228 long split_start, band_start, chan_start;
1229 bool split;
1230};
1231
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001232static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001233 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001234 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001235 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001236{
1237 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001238 struct nlattr *nl_bands, *nl_band;
1239 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001240 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001241 enum ieee80211_band band;
1242 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001243 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001244 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001245 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001246 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001247
Johannes Berg3bb20552014-05-26 13:52:25 +02001248 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001249 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001250 return -ENOBUFS;
1251
Johannes Berg86e8cf92013-06-19 10:57:22 +02001252 if (WARN_ON(!state))
1253 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001254
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001255 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001256 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001257 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001258 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001259 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001260 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001261
Johannes Berg3bb20552014-05-26 13:52:25 +02001262 if (cmd != NL80211_CMD_NEW_WIPHY)
1263 goto finish;
1264
Johannes Berg86e8cf92013-06-19 10:57:22 +02001265 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001266 case 0:
1267 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001268 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001269 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001270 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001272 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001274 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001276 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001280 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001287 goto nla_put_failure;
1288
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001289 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1291 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1294 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1297 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1300 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1303 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001306 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001307 state->split_start++;
1308 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 break;
1310 case 1:
1311 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001312 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1313 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001314 goto nla_put_failure;
1315
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001318 goto nla_put_failure;
1319
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001320 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1322 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001323
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001327 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001329
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001330 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001331 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001334
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001335 if ((rdev->wiphy.available_antennas_tx ||
1336 rdev->wiphy.available_antennas_rx) &&
1337 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 u32 tx_ant = 0, rx_ant = 0;
1339 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 if (!res) {
1342 if (nla_put_u32(msg,
1343 NL80211_ATTR_WIPHY_ANTENNA_TX,
1344 tx_ant) ||
1345 nla_put_u32(msg,
1346 NL80211_ATTR_WIPHY_ANTENNA_RX,
1347 rx_ant))
1348 goto nla_put_failure;
1349 }
Johannes Bergee688b002008-01-24 19:38:39 +01001350 }
1351
Johannes Berg86e8cf92013-06-19 10:57:22 +02001352 state->split_start++;
1353 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 break;
1355 case 2:
1356 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001357 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001359 state->split_start++;
1360 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 break;
1362 case 3:
1363 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1364 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001365 goto nla_put_failure;
1366
Johannes Berg86e8cf92013-06-19 10:57:22 +02001367 for (band = state->band_start;
1368 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001369 struct ieee80211_supported_band *sband;
1370
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001371 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372
1373 if (!sband)
1374 continue;
1375
1376 nl_band = nla_nest_start(msg, band);
1377 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001378 goto nla_put_failure;
1379
Johannes Berg86e8cf92013-06-19 10:57:22 +02001380 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 case 0:
1382 if (nl80211_send_band_rateinfo(msg, sband))
1383 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001384 state->chan_start++;
1385 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001386 break;
1387 default:
1388 /* add frequencies */
1389 nl_freqs = nla_nest_start(
1390 msg, NL80211_BAND_ATTR_FREQS);
1391 if (!nl_freqs)
1392 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001393
Johannes Berg86e8cf92013-06-19 10:57:22 +02001394 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 i < sband->n_channels;
1396 i++) {
1397 nl_freq = nla_nest_start(msg, i);
1398 if (!nl_freq)
1399 goto nla_put_failure;
1400
1401 chan = &sband->channels[i];
1402
Johannes Berg86e8cf92013-06-19 10:57:22 +02001403 if (nl80211_msg_put_channel(
1404 msg, chan,
1405 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 goto nla_put_failure;
1407
1408 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001409 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 break;
1411 }
1412 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001413 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001415 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001416 nla_nest_end(msg, nl_freqs);
1417 }
1418
1419 nla_nest_end(msg, nl_band);
1420
Johannes Berg86e8cf92013-06-19 10:57:22 +02001421 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001423 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001424 band--;
1425 break;
1426 }
Johannes Bergee688b002008-01-24 19:38:39 +01001427 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001429
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001431 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001433 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001434
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 if (state->band_start == 0 && state->chan_start == 0)
1437 state->split_start++;
1438 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 break;
1440 case 4:
1441 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1442 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001443 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444
1445 i = 0;
1446#define CMD(op, n) \
1447 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001448 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 i++; \
1450 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1451 goto nla_put_failure; \
1452 } \
1453 } while (0)
1454
1455 CMD(add_virtual_intf, NEW_INTERFACE);
1456 CMD(change_virtual_intf, SET_INTERFACE);
1457 CMD(add_key, NEW_KEY);
1458 CMD(start_ap, START_AP);
1459 CMD(add_station, NEW_STATION);
1460 CMD(add_mpath, NEW_MPATH);
1461 CMD(update_mesh_config, SET_MESH_CONFIG);
1462 CMD(change_bss, SET_BSS);
1463 CMD(auth, AUTHENTICATE);
1464 CMD(assoc, ASSOCIATE);
1465 CMD(deauth, DEAUTHENTICATE);
1466 CMD(disassoc, DISASSOCIATE);
1467 CMD(join_ibss, JOIN_IBSS);
1468 CMD(join_mesh, JOIN_MESH);
1469 CMD(set_pmksa, SET_PMKSA);
1470 CMD(del_pmksa, DEL_PMKSA);
1471 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001472 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1474 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1475 CMD(mgmt_tx, FRAME);
1476 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001477 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478 i++;
1479 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1480 goto nla_put_failure;
1481 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001482 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1483 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001484 i++;
1485 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1486 goto nla_put_failure;
1487 }
1488 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001489 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001490 CMD(tdls_mgmt, TDLS_MGMT);
1491 CMD(tdls_oper, TDLS_OPER);
1492 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 CMD(sched_scan_start, START_SCHED_SCAN);
1495 CMD(probe_client, PROBE_CLIENT);
1496 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 i++;
1499 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1500 goto nla_put_failure;
1501 }
1502 CMD(start_p2p_device, START_P2P_DEVICE);
1503 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001504#ifdef CONFIG_NL80211_TESTMODE
1505 CMD(testmode_cmd, TESTMODE);
1506#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001507 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001508 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1509 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001511 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001512 CMD(set_qos_map, SET_QOS_MAP);
Arend van Spriel5de17982013-04-18 15:49:00 +02001513 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001514 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001515#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001516
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 i++;
1519 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001520 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001521 }
1522
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524 i++;
1525 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1526 goto nla_put_failure;
1527 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001528
Johannes Berg3713b4e2013-02-14 16:19:38 +01001529 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001530 state->split_start++;
1531 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 break;
1533 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001534 if (rdev->ops->remain_on_channel &&
1535 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 nla_put_u32(msg,
1537 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001539 goto nla_put_failure;
1540
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1543 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001544
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1546 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001547 state->split_start++;
1548 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 break;
1550 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001551#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001552 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001554 state->split_start++;
1555 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 break;
1557#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001558 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559#endif
1560 case 7:
1561 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001563 goto nla_put_failure;
1564
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001567 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001568
Johannes Berg86e8cf92013-06-19 10:57:22 +02001569 state->split_start++;
1570 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001571 break;
1572 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001573 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576 goto nla_put_failure;
1577
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001579 /*
1580 * We can only add the per-channel limit information if the
1581 * dump is split, otherwise it makes it too big. Therefore
1582 * only advertise it in that case.
1583 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001584 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001585 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1586 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 goto nla_put_failure;
1588
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001591 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1592 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 goto nla_put_failure;
1594
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001595 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1596 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 goto nla_put_failure;
1600
1601 /*
1602 * Any information below this point is only available to
1603 * applications that can deal with it being split. This
1604 * helps ensure that newly added capabilities don't break
1605 * older tools by overrunning their buffers.
1606 *
1607 * We still increment split_start so that in the split
1608 * case we'll continue with more data in the next round,
1609 * but break unconditionally so unsplit data stops here.
1610 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001611 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612 break;
1613 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001615 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001616 rdev->wiphy.extended_capabilities_len,
1617 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001618 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001619 rdev->wiphy.extended_capabilities_len,
1620 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001621 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001624 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001625 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1626 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001627 goto nla_put_failure;
1628
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001629 state->split_start++;
1630 break;
1631 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001633 goto nla_put_failure;
1634
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001635 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001636 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1637 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1638 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001639
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001641 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001643 goto nla_put_failure;
1644
Johannes Bergad7e7182013-11-13 13:37:47 +01001645 state->split_start++;
1646 break;
1647 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001649 const struct nl80211_vendor_cmd_info *info;
1650 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001651
Johannes Berg567ffc32013-12-18 14:43:31 +01001652 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1653 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001654 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001655
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001656 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1657 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001658 if (nla_put(msg, i + 1, sizeof(*info), info))
1659 goto nla_put_failure;
1660 }
1661 nla_nest_end(msg, nested);
1662 }
1663
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001665 const struct nl80211_vendor_cmd_info *info;
1666 struct nlattr *nested;
1667
1668 nested = nla_nest_start(msg,
1669 NL80211_ATTR_VENDOR_EVENTS);
1670 if (!nested)
1671 goto nla_put_failure;
1672
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1674 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001675 if (nla_put(msg, i + 1, sizeof(*info), info))
1676 goto nla_put_failure;
1677 }
1678 nla_nest_end(msg, nested);
1679 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001680 state->split_start++;
1681 break;
1682 case 12:
1683 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1684 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1685 rdev->wiphy.max_num_csa_counters))
1686 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001687
Johannes Berg3713b4e2013-02-14 16:19:38 +01001688 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001689 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001690 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001691 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001692 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001693 return genlmsg_end(msg, hdr);
1694
1695 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001696 genlmsg_cancel(msg, hdr);
1697 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001698}
1699
Johannes Berg86e8cf92013-06-19 10:57:22 +02001700static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1701 struct netlink_callback *cb,
1702 struct nl80211_dump_wiphy_state *state)
1703{
1704 struct nlattr **tb = nl80211_fam.attrbuf;
1705 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1706 tb, nl80211_fam.maxattr, nl80211_policy);
1707 /* ignore parse errors for backward compatibility */
1708 if (ret)
1709 return 0;
1710
1711 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1712 if (tb[NL80211_ATTR_WIPHY])
1713 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1714 if (tb[NL80211_ATTR_WDEV])
1715 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1716 if (tb[NL80211_ATTR_IFINDEX]) {
1717 struct net_device *netdev;
1718 struct cfg80211_registered_device *rdev;
1719 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1720
Ying Xue7f2b8562014-01-15 10:23:45 +08001721 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001722 if (!netdev)
1723 return -ENODEV;
1724 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001725 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001726 netdev->ieee80211_ptr->wiphy);
1727 state->filter_wiphy = rdev->wiphy_idx;
1728 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001729 }
1730
1731 return 0;
1732}
1733
Johannes Berg55682962007-09-20 13:09:35 -04001734static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1735{
Johannes Berg645e77d2013-03-01 14:03:49 +01001736 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001737 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001738 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001739
Johannes Berg5fe231e2013-05-08 21:45:15 +02001740 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001741 if (!state) {
1742 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001743 if (!state) {
1744 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001745 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001746 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001747 state->filter_wiphy = -1;
1748 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1749 if (ret) {
1750 kfree(state);
1751 rtnl_unlock();
1752 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001754 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001755 }
1756
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001757 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1758 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001759 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001760 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001761 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001763 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001764 continue;
1765 /* attempt to fit multiple wiphy data chunks into the skb */
1766 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001767 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1768 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 NETLINK_CB(cb->skb).portid,
1770 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001771 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001772 if (ret < 0) {
1773 /*
1774 * If sending the wiphy data didn't fit (ENOBUFS
1775 * or EMSGSIZE returned), this SKB is still
1776 * empty (so it's not too big because another
1777 * wiphy dataset is already in the skb) and
1778 * we've not tried to adjust the dump allocation
1779 * yet ... then adjust the alloc size to be
1780 * bigger, and return 1 but with the empty skb.
1781 * This results in an empty message being RX'ed
1782 * in userspace, but that is ignored.
1783 *
1784 * We can then retry with the larger buffer.
1785 */
1786 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001787 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 cb->min_dump_alloc < 4096) {
1789 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001790 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001791 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001792 return 1;
1793 }
1794 idx--;
1795 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001796 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001797 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001798 break;
Johannes Berg55682962007-09-20 13:09:35 -04001799 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001800 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001801
Johannes Berg86e8cf92013-06-19 10:57:22 +02001802 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001803
1804 return skb->len;
1805}
1806
Johannes Berg86e8cf92013-06-19 10:57:22 +02001807static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1808{
1809 kfree((void *)cb->args[0]);
1810 return 0;
1811}
1812
Johannes Berg55682962007-09-20 13:09:35 -04001813static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1814{
1815 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001817 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001818
Johannes Berg645e77d2013-03-01 14:03:49 +01001819 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001820 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001821 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001822
Johannes Berg3bb20552014-05-26 13:52:25 +02001823 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1824 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001825 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001826 nlmsg_free(msg);
1827 return -ENOBUFS;
1828 }
Johannes Berg55682962007-09-20 13:09:35 -04001829
Johannes Berg134e6372009-07-10 09:51:34 +00001830 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001831}
1832
Jouni Malinen31888482008-10-30 16:59:24 +02001833static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1834 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1835 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1836 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1837 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1838 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1839};
1840
1841static int parse_txq_params(struct nlattr *tb[],
1842 struct ieee80211_txq_params *txq_params)
1843{
Johannes Berga3304b02012-03-28 11:04:24 +02001844 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001845 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1846 !tb[NL80211_TXQ_ATTR_AIFS])
1847 return -EINVAL;
1848
Johannes Berga3304b02012-03-28 11:04:24 +02001849 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001850 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1851 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1852 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1853 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1854
Johannes Berga3304b02012-03-28 11:04:24 +02001855 if (txq_params->ac >= NL80211_NUM_ACS)
1856 return -EINVAL;
1857
Jouni Malinen31888482008-10-30 16:59:24 +02001858 return 0;
1859}
1860
Johannes Bergf444de02010-05-05 15:25:02 +02001861static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1862{
1863 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001864 * You can only set the channel explicitly for WDS interfaces,
1865 * all others have their channel managed via their respective
1866 * "establish a connection" command (connect, join, ...)
1867 *
1868 * For AP/GO and mesh mode, the channel can be set with the
1869 * channel userspace API, but is only stored and passed to the
1870 * low-level driver when the AP starts or the mesh is joined.
1871 * This is for backward compatibility, userspace can also give
1872 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001873 *
1874 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001875 * whatever else is going on, so they have their own special
1876 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001877 */
1878 return !wdev ||
1879 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001880 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001881 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1882 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001883}
1884
Johannes Berg683b6d32012-11-08 21:25:48 +01001885static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1886 struct genl_info *info,
1887 struct cfg80211_chan_def *chandef)
1888{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301889 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001890
1891 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1892 return -EINVAL;
1893
1894 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1895
1896 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001897 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1898 chandef->center_freq1 = control_freq;
1899 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001900
1901 /* Primary channel not allowed */
1902 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1903 return -EINVAL;
1904
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001905 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1906 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001907
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001908 chantype = nla_get_u32(
1909 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1910
1911 switch (chantype) {
1912 case NL80211_CHAN_NO_HT:
1913 case NL80211_CHAN_HT20:
1914 case NL80211_CHAN_HT40PLUS:
1915 case NL80211_CHAN_HT40MINUS:
1916 cfg80211_chandef_create(chandef, chandef->chan,
1917 chantype);
1918 break;
1919 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001920 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001921 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001922 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1923 chandef->width =
1924 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1925 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1926 chandef->center_freq1 =
1927 nla_get_u32(
1928 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1929 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1930 chandef->center_freq2 =
1931 nla_get_u32(
1932 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1933 }
1934
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001935 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001936 return -EINVAL;
1937
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001938 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1939 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001940 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001941
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001942 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1943 chandef->width == NL80211_CHAN_WIDTH_10) &&
1944 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1945 return -EINVAL;
1946
Johannes Berg683b6d32012-11-08 21:25:48 +01001947 return 0;
1948}
1949
Johannes Bergf444de02010-05-05 15:25:02 +02001950static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001951 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001952 struct genl_info *info)
1953{
Johannes Berg683b6d32012-11-08 21:25:48 +01001954 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001955 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001956 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001957 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001958
Jouni Malinene16821b2014-04-28 11:22:08 +03001959 if (dev)
1960 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001961 if (!nl80211_can_set_dev_channel(wdev))
1962 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001963 if (wdev)
1964 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001965
Johannes Berg683b6d32012-11-08 21:25:48 +01001966 result = nl80211_parse_chandef(rdev, info, &chandef);
1967 if (result)
1968 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001969
Johannes Berge8c9bd52012-06-06 08:18:22 +02001970 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001971 case NL80211_IFTYPE_AP:
1972 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001973 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001974 result = -EINVAL;
1975 break;
1976 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001977 if (wdev->beacon_interval) {
1978 if (!dev || !rdev->ops->set_ap_chanwidth ||
1979 !(rdev->wiphy.features &
1980 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1981 result = -EBUSY;
1982 break;
1983 }
1984
1985 /* Only allow dynamic channel width changes */
1986 if (chandef.chan != wdev->preset_chandef.chan) {
1987 result = -EBUSY;
1988 break;
1989 }
1990 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1991 if (result)
1992 break;
1993 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001994 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001995 result = 0;
1996 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001997 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001998 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001999 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002000 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002001 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002002 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002003 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002004 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002005 }
Johannes Bergf444de02010-05-05 15:25:02 +02002006
2007 return result;
2008}
2009
2010static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2011{
Johannes Berg4c476992010-10-04 21:36:35 +02002012 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2013 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002014
Jouni Malinene16821b2014-04-28 11:22:08 +03002015 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002016}
2017
Bill Jordane8347eb2010-10-01 13:54:28 -04002018static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2019{
Johannes Berg43b19952010-10-07 13:10:30 +02002020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2021 struct net_device *dev = info->user_ptr[1];
2022 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002023 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002024
2025 if (!info->attrs[NL80211_ATTR_MAC])
2026 return -EINVAL;
2027
Johannes Berg43b19952010-10-07 13:10:30 +02002028 if (netif_running(dev))
2029 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002030
Johannes Berg43b19952010-10-07 13:10:30 +02002031 if (!rdev->ops->set_wds_peer)
2032 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002033
Johannes Berg43b19952010-10-07 13:10:30 +02002034 if (wdev->iftype != NL80211_IFTYPE_WDS)
2035 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002036
2037 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002038 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002039}
2040
2041
Johannes Berg55682962007-09-20 13:09:35 -04002042static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2043{
2044 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002045 struct net_device *netdev = NULL;
2046 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002047 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002048 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002049 u32 changed;
2050 u8 retry_short = 0, retry_long = 0;
2051 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002052 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002053
Johannes Berg5fe231e2013-05-08 21:45:15 +02002054 ASSERT_RTNL();
2055
Johannes Bergf444de02010-05-05 15:25:02 +02002056 /*
2057 * Try to find the wiphy and netdev. Normally this
2058 * function shouldn't need the netdev, but this is
2059 * done for backward compatibility -- previously
2060 * setting the channel was done per wiphy, but now
2061 * it is per netdev. Previous userland like hostapd
2062 * also passed a netdev to set_wiphy, so that it is
2063 * possible to let that go to the right netdev!
2064 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002065
Johannes Bergf444de02010-05-05 15:25:02 +02002066 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2067 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2068
Ying Xue7f2b8562014-01-15 10:23:45 +08002069 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002070 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002071 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002072 else
Johannes Bergf444de02010-05-05 15:25:02 +02002073 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002074 }
2075
Johannes Bergf444de02010-05-05 15:25:02 +02002076 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002077 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2078 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002079 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002080 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002081 wdev = NULL;
2082 netdev = NULL;
2083 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002084 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002085 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002086
2087 /*
2088 * end workaround code, by now the rdev is available
2089 * and locked, and wdev may or may not be NULL.
2090 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002091
2092 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002093 result = cfg80211_dev_rename(
2094 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002095
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002096 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002097 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002098
Jouni Malinen31888482008-10-30 16:59:24 +02002099 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2100 struct ieee80211_txq_params txq_params;
2101 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2102
Ying Xue7f2b8562014-01-15 10:23:45 +08002103 if (!rdev->ops->set_txq_params)
2104 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002105
Ying Xue7f2b8562014-01-15 10:23:45 +08002106 if (!netdev)
2107 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002108
Johannes Berg133a3ff2011-11-03 14:50:13 +01002109 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002110 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2111 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002112
Ying Xue7f2b8562014-01-15 10:23:45 +08002113 if (!netif_running(netdev))
2114 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002115
Jouni Malinen31888482008-10-30 16:59:24 +02002116 nla_for_each_nested(nl_txq_params,
2117 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2118 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002119 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2120 nla_data(nl_txq_params),
2121 nla_len(nl_txq_params),
2122 txq_params_policy);
2123 if (result)
2124 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002125 result = parse_txq_params(tb, &txq_params);
2126 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002127 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002128
Hila Gonene35e4d22012-06-27 17:19:42 +03002129 result = rdev_set_txq_params(rdev, netdev,
2130 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002131 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002132 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002133 }
2134 }
2135
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002136 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002137 result = __nl80211_set_channel(
2138 rdev,
2139 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2140 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002141 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002142 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002143 }
2144
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002145 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002146 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002147 enum nl80211_tx_power_setting type;
2148 int idx, mbm = 0;
2149
Johannes Bergc8442112012-10-24 10:17:18 +02002150 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2151 txp_wdev = NULL;
2152
Ying Xue7f2b8562014-01-15 10:23:45 +08002153 if (!rdev->ops->set_tx_power)
2154 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002155
2156 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2157 type = nla_get_u32(info->attrs[idx]);
2158
2159 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002160 (type != NL80211_TX_POWER_AUTOMATIC))
2161 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002162
2163 if (type != NL80211_TX_POWER_AUTOMATIC) {
2164 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2165 mbm = nla_get_u32(info->attrs[idx]);
2166 }
2167
Johannes Bergc8442112012-10-24 10:17:18 +02002168 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002169 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002170 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002171 }
2172
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002173 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2174 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2175 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002176 if ((!rdev->wiphy.available_antennas_tx &&
2177 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002178 !rdev->ops->set_antenna)
2179 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002180
2181 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2182 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2183
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002184 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002185 * available antenna masks, except for the "all" mask */
2186 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002187 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2188 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002189
Bruno Randolf7f531e02010-12-16 11:30:22 +09002190 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2191 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002192
Hila Gonene35e4d22012-06-27 17:19:42 +03002193 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002194 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002195 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002196 }
2197
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002198 changed = 0;
2199
2200 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2201 retry_short = nla_get_u8(
2202 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002203 if (retry_short == 0)
2204 return -EINVAL;
2205
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002206 changed |= WIPHY_PARAM_RETRY_SHORT;
2207 }
2208
2209 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2210 retry_long = nla_get_u8(
2211 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002212 if (retry_long == 0)
2213 return -EINVAL;
2214
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002215 changed |= WIPHY_PARAM_RETRY_LONG;
2216 }
2217
2218 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2219 frag_threshold = nla_get_u32(
2220 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002221 if (frag_threshold < 256)
2222 return -EINVAL;
2223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002224 if (frag_threshold != (u32) -1) {
2225 /*
2226 * Fragments (apart from the last one) are required to
2227 * have even length. Make the fragmentation code
2228 * simpler by stripping LSB should someone try to use
2229 * odd threshold value.
2230 */
2231 frag_threshold &= ~0x1;
2232 }
2233 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2234 }
2235
2236 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2237 rts_threshold = nla_get_u32(
2238 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2239 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2240 }
2241
Lukáš Turek81077e82009-12-21 22:50:47 +01002242 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002243 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2244 return -EINVAL;
2245
Lukáš Turek81077e82009-12-21 22:50:47 +01002246 coverage_class = nla_get_u8(
2247 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2248 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2249 }
2250
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002251 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2252 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2253 return -EOPNOTSUPP;
2254
2255 changed |= WIPHY_PARAM_DYN_ACK;
2256 }
2257
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002258 if (changed) {
2259 u8 old_retry_short, old_retry_long;
2260 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002261 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002262
Ying Xue7f2b8562014-01-15 10:23:45 +08002263 if (!rdev->ops->set_wiphy_params)
2264 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002265
2266 old_retry_short = rdev->wiphy.retry_short;
2267 old_retry_long = rdev->wiphy.retry_long;
2268 old_frag_threshold = rdev->wiphy.frag_threshold;
2269 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002270 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002271
2272 if (changed & WIPHY_PARAM_RETRY_SHORT)
2273 rdev->wiphy.retry_short = retry_short;
2274 if (changed & WIPHY_PARAM_RETRY_LONG)
2275 rdev->wiphy.retry_long = retry_long;
2276 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2277 rdev->wiphy.frag_threshold = frag_threshold;
2278 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2279 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002280 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2281 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002282
Hila Gonene35e4d22012-06-27 17:19:42 +03002283 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002284 if (result) {
2285 rdev->wiphy.retry_short = old_retry_short;
2286 rdev->wiphy.retry_long = old_retry_long;
2287 rdev->wiphy.frag_threshold = old_frag_threshold;
2288 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002289 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002290 }
2291 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002292 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002293}
2294
Johannes Berg71bbc992012-06-15 15:30:18 +02002295static inline u64 wdev_id(struct wireless_dev *wdev)
2296{
2297 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002298 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002299}
Johannes Berg55682962007-09-20 13:09:35 -04002300
Johannes Berg683b6d32012-11-08 21:25:48 +01002301static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002302 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002303{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002304 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002305
Johannes Berg683b6d32012-11-08 21:25:48 +01002306 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2307 chandef->chan->center_freq))
2308 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002309 switch (chandef->width) {
2310 case NL80211_CHAN_WIDTH_20_NOHT:
2311 case NL80211_CHAN_WIDTH_20:
2312 case NL80211_CHAN_WIDTH_40:
2313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2314 cfg80211_get_chandef_type(chandef)))
2315 return -ENOBUFS;
2316 break;
2317 default:
2318 break;
2319 }
2320 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2321 return -ENOBUFS;
2322 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2323 return -ENOBUFS;
2324 if (chandef->center_freq2 &&
2325 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002326 return -ENOBUFS;
2327 return 0;
2328}
2329
Eric W. Biederman15e47302012-09-07 20:12:54 +00002330static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002331 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002332 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002333{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002334 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002335 void *hdr;
2336
Eric W. Biederman15e47302012-09-07 20:12:54 +00002337 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002338 if (!hdr)
2339 return -1;
2340
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002341 if (dev &&
2342 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002343 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002344 goto nla_put_failure;
2345
2346 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2347 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002348 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002349 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002350 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2351 rdev->devlist_generation ^
2352 (cfg80211_rdev_list_generation << 2)))
2353 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002354
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002355 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002356 int ret;
2357 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002358
Johannes Berg683b6d32012-11-08 21:25:48 +01002359 ret = rdev_get_channel(rdev, wdev, &chandef);
2360 if (ret == 0) {
2361 if (nl80211_send_chandef(msg, &chandef))
2362 goto nla_put_failure;
2363 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002364 }
2365
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002366 if (wdev->ssid_len) {
2367 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2368 goto nla_put_failure;
2369 }
2370
Johannes Berg55682962007-09-20 13:09:35 -04002371 return genlmsg_end(msg, hdr);
2372
2373 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002374 genlmsg_cancel(msg, hdr);
2375 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002376}
2377
2378static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2379{
2380 int wp_idx = 0;
2381 int if_idx = 0;
2382 int wp_start = cb->args[0];
2383 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002384 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002385 struct wireless_dev *wdev;
2386
Johannes Berg5fe231e2013-05-08 21:45:15 +02002387 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002388 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2389 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002390 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002391 if (wp_idx < wp_start) {
2392 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002393 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002394 }
Johannes Berg55682962007-09-20 13:09:35 -04002395 if_idx = 0;
2396
Johannes Berg89a54e42012-06-15 14:33:17 +02002397 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002398 if (if_idx < if_start) {
2399 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002400 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002401 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002402 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002403 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002404 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002405 goto out;
2406 }
2407 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002408 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002409
2410 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002411 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002412 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002413 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002414
2415 cb->args[0] = wp_idx;
2416 cb->args[1] = if_idx;
2417
2418 return skb->len;
2419}
2420
2421static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2422{
2423 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002425 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002426
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002428 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002429 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002430
Eric W. Biederman15e47302012-09-07 20:12:54 +00002431 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002432 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002433 nlmsg_free(msg);
2434 return -ENOBUFS;
2435 }
Johannes Berg55682962007-09-20 13:09:35 -04002436
Johannes Berg134e6372009-07-10 09:51:34 +00002437 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002438}
2439
Michael Wu66f7ac52008-01-31 19:48:22 +01002440static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2441 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2442 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2443 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2444 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2445 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002446 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002447};
2448
2449static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2450{
2451 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2452 int flag;
2453
2454 *mntrflags = 0;
2455
2456 if (!nla)
2457 return -EINVAL;
2458
2459 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2460 nla, mntr_flags_policy))
2461 return -EINVAL;
2462
2463 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2464 if (flags[flag])
2465 *mntrflags |= (1<<flag);
2466
2467 return 0;
2468}
2469
Johannes Berg9bc383d2009-11-19 11:55:19 +01002470static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002471 struct net_device *netdev, u8 use_4addr,
2472 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002473{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002474 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002475 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002476 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002477 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002478 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002479
2480 switch (iftype) {
2481 case NL80211_IFTYPE_AP_VLAN:
2482 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2483 return 0;
2484 break;
2485 case NL80211_IFTYPE_STATION:
2486 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2487 return 0;
2488 break;
2489 default:
2490 break;
2491 }
2492
2493 return -EOPNOTSUPP;
2494}
2495
Johannes Berg55682962007-09-20 13:09:35 -04002496static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2497{
Johannes Berg4c476992010-10-04 21:36:35 +02002498 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002499 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002500 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002501 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002502 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002503 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002504 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002505
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002506 memset(&params, 0, sizeof(params));
2507
Johannes Berg04a773a2009-04-19 21:24:32 +02002508 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002509
Johannes Berg723b0382008-09-16 20:22:09 +02002510 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002511 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002512 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002513 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002514 if (ntype > NL80211_IFTYPE_MAX)
2515 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002516 }
2517
Johannes Berg92ffe052008-09-16 20:39:36 +02002518 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002519 struct wireless_dev *wdev = dev->ieee80211_ptr;
2520
Johannes Berg4c476992010-10-04 21:36:35 +02002521 if (ntype != NL80211_IFTYPE_MESH_POINT)
2522 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002523 if (netif_running(dev))
2524 return -EBUSY;
2525
2526 wdev_lock(wdev);
2527 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2528 IEEE80211_MAX_MESH_ID_LEN);
2529 wdev->mesh_id_up_len =
2530 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2531 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2532 wdev->mesh_id_up_len);
2533 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002534 }
2535
Felix Fietkau8b787642009-11-10 18:53:10 +01002536 if (info->attrs[NL80211_ATTR_4ADDR]) {
2537 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2538 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002539 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002540 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002541 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002542 } else {
2543 params.use_4addr = -1;
2544 }
2545
Johannes Berg92ffe052008-09-16 20:39:36 +02002546 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002547 if (ntype != NL80211_IFTYPE_MONITOR)
2548 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002549 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2550 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002551 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002552 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002553
2554 flags = &_flags;
2555 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002556 }
Johannes Berg3b858752009-03-12 09:55:09 +01002557
Luciano Coelho18003292013-08-29 13:26:57 +03002558 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002559 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2560 return -EOPNOTSUPP;
2561
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002562 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002563 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002564 else
2565 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002566
Johannes Berg9bc383d2009-11-19 11:55:19 +01002567 if (!err && params.use_4addr != -1)
2568 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2569
Johannes Berg55682962007-09-20 13:09:35 -04002570 return err;
2571}
2572
2573static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2574{
Johannes Berg4c476992010-10-04 21:36:35 +02002575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002576 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002577 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002578 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002579 int err;
2580 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002581 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002582
Johannes Berg78f22b62014-03-24 17:57:27 +01002583 /* to avoid failing a new interface creation due to pending removal */
2584 cfg80211_destroy_ifaces(rdev);
2585
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002586 memset(&params, 0, sizeof(params));
2587
Johannes Berg55682962007-09-20 13:09:35 -04002588 if (!info->attrs[NL80211_ATTR_IFNAME])
2589 return -EINVAL;
2590
2591 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2592 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2593 if (type > NL80211_IFTYPE_MAX)
2594 return -EINVAL;
2595 }
2596
Johannes Berg79c97e92009-07-07 03:56:12 +02002597 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002598 !(rdev->wiphy.interface_modes & (1 << type)))
2599 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002600
Arend van Spriel1c18f142013-01-08 10:17:27 +01002601 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2602 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2603 ETH_ALEN);
2604 if (!is_valid_ether_addr(params.macaddr))
2605 return -EADDRNOTAVAIL;
2606 }
2607
Johannes Berg9bc383d2009-11-19 11:55:19 +01002608 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002609 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002610 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002611 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002612 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002613 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002614
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002615 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2616 if (!msg)
2617 return -ENOMEM;
2618
Michael Wu66f7ac52008-01-31 19:48:22 +01002619 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2620 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2621 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002622
Luciano Coelho18003292013-08-29 13:26:57 +03002623 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002624 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2625 return -EOPNOTSUPP;
2626
Hila Gonene35e4d22012-06-27 17:19:42 +03002627 wdev = rdev_add_virtual_intf(rdev,
2628 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2629 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002630 if (IS_ERR(wdev)) {
2631 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002632 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002633 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002634
Johannes Berg78f22b62014-03-24 17:57:27 +01002635 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2636 wdev->owner_nlportid = info->snd_portid;
2637
Johannes Berg98104fde2012-06-16 00:19:54 +02002638 switch (type) {
2639 case NL80211_IFTYPE_MESH_POINT:
2640 if (!info->attrs[NL80211_ATTR_MESH_ID])
2641 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002642 wdev_lock(wdev);
2643 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2644 IEEE80211_MAX_MESH_ID_LEN);
2645 wdev->mesh_id_up_len =
2646 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2647 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2648 wdev->mesh_id_up_len);
2649 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002650 break;
2651 case NL80211_IFTYPE_P2P_DEVICE:
2652 /*
2653 * P2P Device doesn't have a netdev, so doesn't go
2654 * through the netdev notifier and must be added here
2655 */
2656 mutex_init(&wdev->mtx);
2657 INIT_LIST_HEAD(&wdev->event_list);
2658 spin_lock_init(&wdev->event_lock);
2659 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2660 spin_lock_init(&wdev->mgmt_registrations_lock);
2661
Johannes Berg98104fde2012-06-16 00:19:54 +02002662 wdev->identifier = ++rdev->wdev_id;
2663 list_add_rcu(&wdev->list, &rdev->wdev_list);
2664 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002665 break;
2666 default:
2667 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002668 }
2669
Eric W. Biederman15e47302012-09-07 20:12:54 +00002670 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002671 rdev, wdev) < 0) {
2672 nlmsg_free(msg);
2673 return -ENOBUFS;
2674 }
2675
2676 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002677}
2678
2679static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2680{
Johannes Berg4c476992010-10-04 21:36:35 +02002681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002682 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002683
Johannes Berg4c476992010-10-04 21:36:35 +02002684 if (!rdev->ops->del_virtual_intf)
2685 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002686
Johannes Berg84efbb82012-06-16 00:00:26 +02002687 /*
2688 * If we remove a wireless device without a netdev then clear
2689 * user_ptr[1] so that nl80211_post_doit won't dereference it
2690 * to check if it needs to do dev_put(). Otherwise it crashes
2691 * since the wdev has been freed, unlike with a netdev where
2692 * we need the dev_put() for the netdev to really be freed.
2693 */
2694 if (!wdev->netdev)
2695 info->user_ptr[1] = NULL;
2696
Hila Gonene35e4d22012-06-27 17:19:42 +03002697 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002698}
2699
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002700static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2701{
2702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2703 struct net_device *dev = info->user_ptr[1];
2704 u16 noack_map;
2705
2706 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2707 return -EINVAL;
2708
2709 if (!rdev->ops->set_noack_map)
2710 return -EOPNOTSUPP;
2711
2712 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2713
Hila Gonene35e4d22012-06-27 17:19:42 +03002714 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002715}
2716
Johannes Berg41ade002007-12-19 02:03:29 +01002717struct get_key_cookie {
2718 struct sk_buff *msg;
2719 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002720 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002721};
2722
2723static void get_key_callback(void *c, struct key_params *params)
2724{
Johannes Bergb9454e82009-07-08 13:29:08 +02002725 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002726 struct get_key_cookie *cookie = c;
2727
David S. Miller9360ffd2012-03-29 04:41:26 -04002728 if ((params->key &&
2729 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2730 params->key_len, params->key)) ||
2731 (params->seq &&
2732 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2733 params->seq_len, params->seq)) ||
2734 (params->cipher &&
2735 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2736 params->cipher)))
2737 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002738
Johannes Bergb9454e82009-07-08 13:29:08 +02002739 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2740 if (!key)
2741 goto nla_put_failure;
2742
David S. Miller9360ffd2012-03-29 04:41:26 -04002743 if ((params->key &&
2744 nla_put(cookie->msg, NL80211_KEY_DATA,
2745 params->key_len, params->key)) ||
2746 (params->seq &&
2747 nla_put(cookie->msg, NL80211_KEY_SEQ,
2748 params->seq_len, params->seq)) ||
2749 (params->cipher &&
2750 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2751 params->cipher)))
2752 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002753
David S. Miller9360ffd2012-03-29 04:41:26 -04002754 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2755 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002756
2757 nla_nest_end(cookie->msg, key);
2758
Johannes Berg41ade002007-12-19 02:03:29 +01002759 return;
2760 nla_put_failure:
2761 cookie->error = 1;
2762}
2763
2764static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2765{
Johannes Berg4c476992010-10-04 21:36:35 +02002766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002767 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002768 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002769 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002770 const u8 *mac_addr = NULL;
2771 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002772 struct get_key_cookie cookie = {
2773 .error = 0,
2774 };
2775 void *hdr;
2776 struct sk_buff *msg;
2777
2778 if (info->attrs[NL80211_ATTR_KEY_IDX])
2779 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2780
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002781 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002782 return -EINVAL;
2783
2784 if (info->attrs[NL80211_ATTR_MAC])
2785 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2786
Johannes Berge31b8212010-10-05 19:39:30 +02002787 pairwise = !!mac_addr;
2788 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2789 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2790 if (kt >= NUM_NL80211_KEYTYPES)
2791 return -EINVAL;
2792 if (kt != NL80211_KEYTYPE_GROUP &&
2793 kt != NL80211_KEYTYPE_PAIRWISE)
2794 return -EINVAL;
2795 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2796 }
2797
Johannes Berg4c476992010-10-04 21:36:35 +02002798 if (!rdev->ops->get_key)
2799 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002800
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002801 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002802 if (!msg)
2803 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002804
Eric W. Biederman15e47302012-09-07 20:12:54 +00002805 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002806 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002807 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002808 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002809
2810 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002811 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002812
David S. Miller9360ffd2012-03-29 04:41:26 -04002813 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2814 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2815 goto nla_put_failure;
2816 if (mac_addr &&
2817 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2818 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002819
Johannes Berge31b8212010-10-05 19:39:30 +02002820 if (pairwise && mac_addr &&
2821 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2822 return -ENOENT;
2823
Hila Gonene35e4d22012-06-27 17:19:42 +03002824 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2825 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002826
2827 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002828 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002829
2830 if (cookie.error)
2831 goto nla_put_failure;
2832
2833 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002834 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002835
2836 nla_put_failure:
2837 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002838 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002839 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002840 return err;
2841}
2842
2843static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2844{
Johannes Berg4c476992010-10-04 21:36:35 +02002845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002846 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002847 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002848 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002849
Johannes Bergb9454e82009-07-08 13:29:08 +02002850 err = nl80211_parse_key(info, &key);
2851 if (err)
2852 return err;
2853
2854 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002855 return -EINVAL;
2856
Johannes Bergb9454e82009-07-08 13:29:08 +02002857 /* only support setting default key */
2858 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002859 return -EINVAL;
2860
Johannes Bergfffd0932009-07-08 14:22:54 +02002861 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002862
2863 if (key.def) {
2864 if (!rdev->ops->set_default_key) {
2865 err = -EOPNOTSUPP;
2866 goto out;
2867 }
2868
2869 err = nl80211_key_allowed(dev->ieee80211_ptr);
2870 if (err)
2871 goto out;
2872
Hila Gonene35e4d22012-06-27 17:19:42 +03002873 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002874 key.def_uni, key.def_multi);
2875
2876 if (err)
2877 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002878
Johannes Berg3d23e342009-09-29 23:27:28 +02002879#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002880 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002881#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002882 } else {
2883 if (key.def_uni || !key.def_multi) {
2884 err = -EINVAL;
2885 goto out;
2886 }
2887
2888 if (!rdev->ops->set_default_mgmt_key) {
2889 err = -EOPNOTSUPP;
2890 goto out;
2891 }
2892
2893 err = nl80211_key_allowed(dev->ieee80211_ptr);
2894 if (err)
2895 goto out;
2896
Hila Gonene35e4d22012-06-27 17:19:42 +03002897 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002898 if (err)
2899 goto out;
2900
2901#ifdef CONFIG_CFG80211_WEXT
2902 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2903#endif
2904 }
2905
2906 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002907 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002908
Johannes Berg41ade002007-12-19 02:03:29 +01002909 return err;
2910}
2911
2912static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2913{
Johannes Berg4c476992010-10-04 21:36:35 +02002914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002915 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002916 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002917 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002918 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002919
Johannes Bergb9454e82009-07-08 13:29:08 +02002920 err = nl80211_parse_key(info, &key);
2921 if (err)
2922 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002923
Johannes Bergb9454e82009-07-08 13:29:08 +02002924 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002925 return -EINVAL;
2926
Johannes Berg41ade002007-12-19 02:03:29 +01002927 if (info->attrs[NL80211_ATTR_MAC])
2928 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2929
Johannes Berge31b8212010-10-05 19:39:30 +02002930 if (key.type == -1) {
2931 if (mac_addr)
2932 key.type = NL80211_KEYTYPE_PAIRWISE;
2933 else
2934 key.type = NL80211_KEYTYPE_GROUP;
2935 }
2936
2937 /* for now */
2938 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2939 key.type != NL80211_KEYTYPE_GROUP)
2940 return -EINVAL;
2941
Johannes Berg4c476992010-10-04 21:36:35 +02002942 if (!rdev->ops->add_key)
2943 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002944
Johannes Berge31b8212010-10-05 19:39:30 +02002945 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2946 key.type == NL80211_KEYTYPE_PAIRWISE,
2947 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002948 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002949
2950 wdev_lock(dev->ieee80211_ptr);
2951 err = nl80211_key_allowed(dev->ieee80211_ptr);
2952 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002953 err = rdev_add_key(rdev, dev, key.idx,
2954 key.type == NL80211_KEYTYPE_PAIRWISE,
2955 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002956 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002957
Johannes Berg41ade002007-12-19 02:03:29 +01002958 return err;
2959}
2960
2961static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2962{
Johannes Berg4c476992010-10-04 21:36:35 +02002963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002964 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002965 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002966 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002967 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002968
Johannes Bergb9454e82009-07-08 13:29:08 +02002969 err = nl80211_parse_key(info, &key);
2970 if (err)
2971 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002972
2973 if (info->attrs[NL80211_ATTR_MAC])
2974 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2975
Johannes Berge31b8212010-10-05 19:39:30 +02002976 if (key.type == -1) {
2977 if (mac_addr)
2978 key.type = NL80211_KEYTYPE_PAIRWISE;
2979 else
2980 key.type = NL80211_KEYTYPE_GROUP;
2981 }
2982
2983 /* for now */
2984 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2985 key.type != NL80211_KEYTYPE_GROUP)
2986 return -EINVAL;
2987
Johannes Berg4c476992010-10-04 21:36:35 +02002988 if (!rdev->ops->del_key)
2989 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002990
Johannes Bergfffd0932009-07-08 14:22:54 +02002991 wdev_lock(dev->ieee80211_ptr);
2992 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002993
2994 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2995 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2996 err = -ENOENT;
2997
Johannes Bergfffd0932009-07-08 14:22:54 +02002998 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002999 err = rdev_del_key(rdev, dev, key.idx,
3000 key.type == NL80211_KEYTYPE_PAIRWISE,
3001 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003002
Johannes Berg3d23e342009-09-29 23:27:28 +02003003#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003004 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003005 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003006 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003007 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003008 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3009 }
3010#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003011 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003012
Johannes Berg41ade002007-12-19 02:03:29 +01003013 return err;
3014}
3015
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303016/* This function returns an error or the number of nested attributes */
3017static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3018{
3019 struct nlattr *attr;
3020 int n_entries = 0, tmp;
3021
3022 nla_for_each_nested(attr, nl_attr, tmp) {
3023 if (nla_len(attr) != ETH_ALEN)
3024 return -EINVAL;
3025
3026 n_entries++;
3027 }
3028
3029 return n_entries;
3030}
3031
3032/*
3033 * This function parses ACL information and allocates memory for ACL data.
3034 * On successful return, the calling function is responsible to free the
3035 * ACL buffer returned by this function.
3036 */
3037static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3038 struct genl_info *info)
3039{
3040 enum nl80211_acl_policy acl_policy;
3041 struct nlattr *attr;
3042 struct cfg80211_acl_data *acl;
3043 int i = 0, n_entries, tmp;
3044
3045 if (!wiphy->max_acl_mac_addrs)
3046 return ERR_PTR(-EOPNOTSUPP);
3047
3048 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3049 return ERR_PTR(-EINVAL);
3050
3051 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3052 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3053 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3054 return ERR_PTR(-EINVAL);
3055
3056 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3057 return ERR_PTR(-EINVAL);
3058
3059 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3060 if (n_entries < 0)
3061 return ERR_PTR(n_entries);
3062
3063 if (n_entries > wiphy->max_acl_mac_addrs)
3064 return ERR_PTR(-ENOTSUPP);
3065
3066 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3067 GFP_KERNEL);
3068 if (!acl)
3069 return ERR_PTR(-ENOMEM);
3070
3071 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3072 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3073 i++;
3074 }
3075
3076 acl->n_acl_entries = n_entries;
3077 acl->acl_policy = acl_policy;
3078
3079 return acl;
3080}
3081
3082static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3083{
3084 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3085 struct net_device *dev = info->user_ptr[1];
3086 struct cfg80211_acl_data *acl;
3087 int err;
3088
3089 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3090 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3091 return -EOPNOTSUPP;
3092
3093 if (!dev->ieee80211_ptr->beacon_interval)
3094 return -EINVAL;
3095
3096 acl = parse_acl_data(&rdev->wiphy, info);
3097 if (IS_ERR(acl))
3098 return PTR_ERR(acl);
3099
3100 err = rdev_set_mac_acl(rdev, dev, acl);
3101
3102 kfree(acl);
3103
3104 return err;
3105}
3106
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003107static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003108 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003109{
Johannes Berg88600202012-02-13 15:17:18 +01003110 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003111
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003112 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3113 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3114 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3115 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003116 return -EINVAL;
3117
Johannes Berg88600202012-02-13 15:17:18 +01003118 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003119
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003120 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3121 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3122 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003123 if (!bcn->head_len)
3124 return -EINVAL;
3125 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003126 }
3127
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003128 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3129 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3130 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003131 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003132 }
3133
Johannes Berg4c476992010-10-04 21:36:35 +02003134 if (!haveinfo)
3135 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003136
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003137 if (attrs[NL80211_ATTR_IE]) {
3138 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3139 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003140 }
3141
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003142 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003143 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003144 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003145 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003146 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003147 }
3148
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003149 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003150 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003151 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003152 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003153 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003154 }
3155
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003156 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3157 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3158 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003159 }
3160
Johannes Berg88600202012-02-13 15:17:18 +01003161 return 0;
3162}
3163
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003164static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3165 struct cfg80211_ap_settings *params)
3166{
3167 struct wireless_dev *wdev;
3168 bool ret = false;
3169
Johannes Berg89a54e42012-06-15 14:33:17 +02003170 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003171 if (wdev->iftype != NL80211_IFTYPE_AP &&
3172 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3173 continue;
3174
Johannes Berg683b6d32012-11-08 21:25:48 +01003175 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003176 continue;
3177
Johannes Berg683b6d32012-11-08 21:25:48 +01003178 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003179 ret = true;
3180 break;
3181 }
3182
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003183 return ret;
3184}
3185
Jouni Malinene39e5b52012-09-30 19:29:39 +03003186static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3187 enum nl80211_auth_type auth_type,
3188 enum nl80211_commands cmd)
3189{
3190 if (auth_type > NL80211_AUTHTYPE_MAX)
3191 return false;
3192
3193 switch (cmd) {
3194 case NL80211_CMD_AUTHENTICATE:
3195 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3196 auth_type == NL80211_AUTHTYPE_SAE)
3197 return false;
3198 return true;
3199 case NL80211_CMD_CONNECT:
3200 case NL80211_CMD_START_AP:
3201 /* SAE not supported yet */
3202 if (auth_type == NL80211_AUTHTYPE_SAE)
3203 return false;
3204 return true;
3205 default:
3206 return false;
3207 }
3208}
3209
Johannes Berg88600202012-02-13 15:17:18 +01003210static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3211{
3212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3213 struct net_device *dev = info->user_ptr[1];
3214 struct wireless_dev *wdev = dev->ieee80211_ptr;
3215 struct cfg80211_ap_settings params;
3216 int err;
3217
3218 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3219 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3220 return -EOPNOTSUPP;
3221
3222 if (!rdev->ops->start_ap)
3223 return -EOPNOTSUPP;
3224
3225 if (wdev->beacon_interval)
3226 return -EALREADY;
3227
3228 memset(&params, 0, sizeof(params));
3229
3230 /* these are required for START_AP */
3231 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3232 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3233 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3234 return -EINVAL;
3235
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003236 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003237 if (err)
3238 return err;
3239
3240 params.beacon_interval =
3241 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3242 params.dtim_period =
3243 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3244
3245 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3246 if (err)
3247 return err;
3248
3249 /*
3250 * In theory, some of these attributes should be required here
3251 * but since they were not used when the command was originally
3252 * added, keep them optional for old user space programs to let
3253 * them continue to work with drivers that do not need the
3254 * additional information -- drivers must check!
3255 */
3256 if (info->attrs[NL80211_ATTR_SSID]) {
3257 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3258 params.ssid_len =
3259 nla_len(info->attrs[NL80211_ATTR_SSID]);
3260 if (params.ssid_len == 0 ||
3261 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3262 return -EINVAL;
3263 }
3264
3265 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3266 params.hidden_ssid = nla_get_u32(
3267 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3268 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3269 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3270 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3271 return -EINVAL;
3272 }
3273
3274 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3275
3276 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3277 params.auth_type = nla_get_u32(
3278 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003279 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3280 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003281 return -EINVAL;
3282 } else
3283 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3284
3285 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3286 NL80211_MAX_NR_CIPHER_SUITES);
3287 if (err)
3288 return err;
3289
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303290 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3291 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3292 return -EOPNOTSUPP;
3293 params.inactivity_timeout = nla_get_u16(
3294 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3295 }
3296
Johannes Berg53cabad2012-11-14 15:17:28 +01003297 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3298 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3299 return -EINVAL;
3300 params.p2p_ctwindow =
3301 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3302 if (params.p2p_ctwindow > 127)
3303 return -EINVAL;
3304 if (params.p2p_ctwindow != 0 &&
3305 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3306 return -EINVAL;
3307 }
3308
3309 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3310 u8 tmp;
3311
3312 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3313 return -EINVAL;
3314 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3315 if (tmp > 1)
3316 return -EINVAL;
3317 params.p2p_opp_ps = tmp;
3318 if (params.p2p_opp_ps != 0 &&
3319 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3320 return -EINVAL;
3321 }
3322
Johannes Bergaa430da2012-05-16 23:50:18 +02003323 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003324 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3325 if (err)
3326 return err;
3327 } else if (wdev->preset_chandef.chan) {
3328 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003329 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003330 return -EINVAL;
3331
Ilan Peer174e0cd2014-02-23 09:13:01 +02003332 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3333 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003334 return -EINVAL;
3335
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303336 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3337 params.acl = parse_acl_data(&rdev->wiphy, info);
3338 if (IS_ERR(params.acl))
3339 return PTR_ERR(params.acl);
3340 }
3341
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003342 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003343 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003344 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003345 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003346 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003347 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003348 wdev->ssid_len = params.ssid_len;
3349 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003350 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003351 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303352
3353 kfree(params.acl);
3354
Johannes Berg56d18932011-05-09 18:41:15 +02003355 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003356}
3357
Johannes Berg88600202012-02-13 15:17:18 +01003358static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3359{
3360 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3361 struct net_device *dev = info->user_ptr[1];
3362 struct wireless_dev *wdev = dev->ieee80211_ptr;
3363 struct cfg80211_beacon_data params;
3364 int err;
3365
3366 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3367 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3368 return -EOPNOTSUPP;
3369
3370 if (!rdev->ops->change_beacon)
3371 return -EOPNOTSUPP;
3372
3373 if (!wdev->beacon_interval)
3374 return -EINVAL;
3375
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003376 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003377 if (err)
3378 return err;
3379
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003380 wdev_lock(wdev);
3381 err = rdev_change_beacon(rdev, dev, &params);
3382 wdev_unlock(wdev);
3383
3384 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003385}
3386
3387static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003388{
Johannes Berg4c476992010-10-04 21:36:35 +02003389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3390 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003391
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003392 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003393}
3394
Johannes Berg5727ef12007-12-19 02:03:34 +01003395static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3396 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3397 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3398 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003399 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003400 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003401 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003402};
3403
Johannes Bergeccb8e82009-05-11 21:57:56 +03003404static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003405 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003406 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003407{
3408 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003409 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003410 int flag;
3411
Johannes Bergeccb8e82009-05-11 21:57:56 +03003412 /*
3413 * Try parsing the new attribute first so userspace
3414 * can specify both for older kernels.
3415 */
3416 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3417 if (nla) {
3418 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003419
Johannes Bergeccb8e82009-05-11 21:57:56 +03003420 sta_flags = nla_data(nla);
3421 params->sta_flags_mask = sta_flags->mask;
3422 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003423 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003424 if ((params->sta_flags_mask |
3425 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3426 return -EINVAL;
3427 return 0;
3428 }
3429
3430 /* if present, parse the old attribute */
3431
3432 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003433 if (!nla)
3434 return 0;
3435
3436 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3437 nla, sta_flags_policy))
3438 return -EINVAL;
3439
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003440 /*
3441 * Only allow certain flags for interface types so that
3442 * other attributes are silently ignored. Remember that
3443 * this is backward compatibility code with old userspace
3444 * and shouldn't be hit in other cases anyway.
3445 */
3446 switch (iftype) {
3447 case NL80211_IFTYPE_AP:
3448 case NL80211_IFTYPE_AP_VLAN:
3449 case NL80211_IFTYPE_P2P_GO:
3450 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3451 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3452 BIT(NL80211_STA_FLAG_WME) |
3453 BIT(NL80211_STA_FLAG_MFP);
3454 break;
3455 case NL80211_IFTYPE_P2P_CLIENT:
3456 case NL80211_IFTYPE_STATION:
3457 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3458 BIT(NL80211_STA_FLAG_TDLS_PEER);
3459 break;
3460 case NL80211_IFTYPE_MESH_POINT:
3461 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3462 BIT(NL80211_STA_FLAG_MFP) |
3463 BIT(NL80211_STA_FLAG_AUTHORIZED);
3464 default:
3465 return -EINVAL;
3466 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003467
Johannes Berg3383b5a2012-05-10 20:14:43 +02003468 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3469 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003470 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003471
Johannes Berg3383b5a2012-05-10 20:14:43 +02003472 /* no longer support new API additions in old API */
3473 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3474 return -EINVAL;
3475 }
3476 }
3477
Johannes Berg5727ef12007-12-19 02:03:34 +01003478 return 0;
3479}
3480
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003481static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3482 int attr)
3483{
3484 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003485 u32 bitrate;
3486 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003487
3488 rate = nla_nest_start(msg, attr);
3489 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003490 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003491
3492 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3493 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003494 /* report 16-bit bitrate only if we can */
3495 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003496 if (bitrate > 0 &&
3497 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3498 return false;
3499 if (bitrate_compat > 0 &&
3500 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3501 return false;
3502
3503 if (info->flags & RATE_INFO_FLAGS_MCS) {
3504 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3505 return false;
3506 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3507 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3508 return false;
3509 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3510 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3511 return false;
3512 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3513 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3514 return false;
3515 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3516 return false;
3517 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3518 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3519 return false;
3520 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3521 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3522 return false;
3523 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3524 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3525 return false;
3526 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3527 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3528 return false;
3529 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3530 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3531 return false;
3532 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003533
3534 nla_nest_end(msg, rate);
3535 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003536}
3537
Felix Fietkau119363c2013-04-22 16:29:30 +02003538static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3539 int id)
3540{
3541 void *attr;
3542 int i = 0;
3543
3544 if (!mask)
3545 return true;
3546
3547 attr = nla_nest_start(msg, id);
3548 if (!attr)
3549 return false;
3550
3551 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3552 if (!(mask & BIT(i)))
3553 continue;
3554
3555 if (nla_put_u8(msg, i, signal[i]))
3556 return false;
3557 }
3558
3559 nla_nest_end(msg, attr);
3560
3561 return true;
3562}
3563
Eric W. Biederman15e47302012-09-07 20:12:54 +00003564static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003565 int flags,
3566 struct cfg80211_registered_device *rdev,
3567 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003568 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003569{
3570 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003571 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003572
Eric W. Biederman15e47302012-09-07 20:12:54 +00003573 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003574 if (!hdr)
3575 return -1;
3576
David S. Miller9360ffd2012-03-29 04:41:26 -04003577 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3578 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3579 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3580 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003581
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003582 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3583 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003584 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003585 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3586 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3587 sinfo->connected_time))
3588 goto nla_put_failure;
3589 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3590 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3591 sinfo->inactive_time))
3592 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003593 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3594 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003595 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003596 (u32)sinfo->rx_bytes))
3597 goto nla_put_failure;
3598 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003599 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003600 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3601 (u32)sinfo->tx_bytes))
3602 goto nla_put_failure;
3603 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3604 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003605 sinfo->rx_bytes))
3606 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003607 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3608 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003609 sinfo->tx_bytes))
3610 goto nla_put_failure;
3611 if ((sinfo->filled & STATION_INFO_LLID) &&
3612 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3613 goto nla_put_failure;
3614 if ((sinfo->filled & STATION_INFO_PLID) &&
3615 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3616 goto nla_put_failure;
3617 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3618 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3619 sinfo->plink_state))
3620 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003621 switch (rdev->wiphy.signal_type) {
3622 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003623 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3624 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3625 sinfo->signal))
3626 goto nla_put_failure;
3627 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3628 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3629 sinfo->signal_avg))
3630 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003631 break;
3632 default:
3633 break;
3634 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003635 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3636 if (!nl80211_put_signal(msg, sinfo->chains,
3637 sinfo->chain_signal,
3638 NL80211_STA_INFO_CHAIN_SIGNAL))
3639 goto nla_put_failure;
3640 }
3641 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3642 if (!nl80211_put_signal(msg, sinfo->chains,
3643 sinfo->chain_signal_avg,
3644 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3645 goto nla_put_failure;
3646 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003647 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003648 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3649 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003650 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003651 }
3652 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3653 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3654 NL80211_STA_INFO_RX_BITRATE))
3655 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003656 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003657 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3658 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3659 sinfo->rx_packets))
3660 goto nla_put_failure;
3661 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3662 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3663 sinfo->tx_packets))
3664 goto nla_put_failure;
3665 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3666 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3667 sinfo->tx_retries))
3668 goto nla_put_failure;
3669 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3670 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3671 sinfo->tx_failed))
3672 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003673 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3674 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3675 sinfo->expected_throughput))
3676 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003677 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3678 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3679 sinfo->beacon_loss_count))
3680 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003681 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3682 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3683 sinfo->local_pm))
3684 goto nla_put_failure;
3685 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3686 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3687 sinfo->peer_pm))
3688 goto nla_put_failure;
3689 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3690 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3691 sinfo->nonpeer_pm))
3692 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003693 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3694 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3695 if (!bss_param)
3696 goto nla_put_failure;
3697
David S. Miller9360ffd2012-03-29 04:41:26 -04003698 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3699 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3700 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3701 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3702 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3703 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3704 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3705 sinfo->bss_param.dtim_period) ||
3706 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3707 sinfo->bss_param.beacon_interval))
3708 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003709
3710 nla_nest_end(msg, bss_param);
3711 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003712 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3713 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3714 sizeof(struct nl80211_sta_flag_update),
3715 &sinfo->sta_flags))
3716 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003717 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3718 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3719 sinfo->t_offset))
3720 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003721 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003722
David S. Miller9360ffd2012-03-29 04:41:26 -04003723 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3724 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3725 sinfo->assoc_req_ies))
3726 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003727
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003728 return genlmsg_end(msg, hdr);
3729
3730 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003731 genlmsg_cancel(msg, hdr);
3732 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003733}
3734
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003735static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003736 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003737{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003738 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003739 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003740 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003741 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003742 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003743 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003744
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003745 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003746 if (err)
3747 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003748
Johannes Berg97990a02013-04-19 01:02:55 +02003749 if (!wdev->netdev) {
3750 err = -EINVAL;
3751 goto out_err;
3752 }
3753
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003754 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003755 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003756 goto out_err;
3757 }
3758
Johannes Bergbba95fe2008-07-29 13:22:51 +02003759 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003760 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003761 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003762 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003763 if (err == -ENOENT)
3764 break;
3765 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003766 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003767
3768 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003769 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003770 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003771 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003772 &sinfo) < 0)
3773 goto out;
3774
3775 sta_idx++;
3776 }
3777
3778
3779 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003780 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003781 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003782 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003783 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003784
3785 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003786}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003787
Johannes Berg5727ef12007-12-19 02:03:34 +01003788static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3789{
Johannes Berg4c476992010-10-04 21:36:35 +02003790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3791 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003792 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003793 struct sk_buff *msg;
3794 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003795 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003796
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003797 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003798
3799 if (!info->attrs[NL80211_ATTR_MAC])
3800 return -EINVAL;
3801
3802 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3803
Johannes Berg4c476992010-10-04 21:36:35 +02003804 if (!rdev->ops->get_station)
3805 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003806
Hila Gonene35e4d22012-06-27 17:19:42 +03003807 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003808 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003809 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003810
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003811 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003812 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003813 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003814
Eric W. Biederman15e47302012-09-07 20:12:54 +00003815 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003816 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003817 nlmsg_free(msg);
3818 return -ENOBUFS;
3819 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003820
Johannes Berg4c476992010-10-04 21:36:35 +02003821 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003822}
3823
Johannes Berg77ee7c82013-02-15 00:48:33 +01003824int cfg80211_check_station_change(struct wiphy *wiphy,
3825 struct station_parameters *params,
3826 enum cfg80211_station_type statype)
3827{
3828 if (params->listen_interval != -1)
3829 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003830 if (params->aid &&
3831 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003832 return -EINVAL;
3833
3834 /* When you run into this, adjust the code below for the new flag */
3835 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3836
3837 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003838 case CFG80211_STA_MESH_PEER_KERNEL:
3839 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003840 /*
3841 * No ignoring the TDLS flag here -- the userspace mesh
3842 * code doesn't have the bug of including TDLS in the
3843 * mask everywhere.
3844 */
3845 if (params->sta_flags_mask &
3846 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3847 BIT(NL80211_STA_FLAG_MFP) |
3848 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3849 return -EINVAL;
3850 break;
3851 case CFG80211_STA_TDLS_PEER_SETUP:
3852 case CFG80211_STA_TDLS_PEER_ACTIVE:
3853 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3854 return -EINVAL;
3855 /* ignore since it can't change */
3856 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3857 break;
3858 default:
3859 /* disallow mesh-specific things */
3860 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3861 return -EINVAL;
3862 if (params->local_pm)
3863 return -EINVAL;
3864 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3865 return -EINVAL;
3866 }
3867
3868 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3869 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3870 /* TDLS can't be set, ... */
3871 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3872 return -EINVAL;
3873 /*
3874 * ... but don't bother the driver with it. This works around
3875 * a hostapd/wpa_supplicant issue -- it always includes the
3876 * TLDS_PEER flag in the mask even for AP mode.
3877 */
3878 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3879 }
3880
3881 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3882 /* reject other things that can't change */
3883 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3884 return -EINVAL;
3885 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3886 return -EINVAL;
3887 if (params->supported_rates)
3888 return -EINVAL;
3889 if (params->ext_capab || params->ht_capa || params->vht_capa)
3890 return -EINVAL;
3891 }
3892
3893 if (statype != CFG80211_STA_AP_CLIENT) {
3894 if (params->vlan)
3895 return -EINVAL;
3896 }
3897
3898 switch (statype) {
3899 case CFG80211_STA_AP_MLME_CLIENT:
3900 /* Use this only for authorizing/unauthorizing a station */
3901 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3902 return -EOPNOTSUPP;
3903 break;
3904 case CFG80211_STA_AP_CLIENT:
3905 /* accept only the listed bits */
3906 if (params->sta_flags_mask &
3907 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3908 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3909 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3910 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3911 BIT(NL80211_STA_FLAG_WME) |
3912 BIT(NL80211_STA_FLAG_MFP)))
3913 return -EINVAL;
3914
3915 /* but authenticated/associated only if driver handles it */
3916 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3917 params->sta_flags_mask &
3918 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3919 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3920 return -EINVAL;
3921 break;
3922 case CFG80211_STA_IBSS:
3923 case CFG80211_STA_AP_STA:
3924 /* reject any changes other than AUTHORIZED */
3925 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3926 return -EINVAL;
3927 break;
3928 case CFG80211_STA_TDLS_PEER_SETUP:
3929 /* reject any changes other than AUTHORIZED or WME */
3930 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3931 BIT(NL80211_STA_FLAG_WME)))
3932 return -EINVAL;
3933 /* force (at least) rates when authorizing */
3934 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3935 !params->supported_rates)
3936 return -EINVAL;
3937 break;
3938 case CFG80211_STA_TDLS_PEER_ACTIVE:
3939 /* reject any changes */
3940 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003941 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003942 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3943 return -EINVAL;
3944 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003945 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003946 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3947 return -EINVAL;
3948 break;
3949 }
3950
3951 return 0;
3952}
3953EXPORT_SYMBOL(cfg80211_check_station_change);
3954
Johannes Berg5727ef12007-12-19 02:03:34 +01003955/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003956 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003957 */
Johannes Berg80b99892011-11-18 16:23:01 +01003958static struct net_device *get_vlan(struct genl_info *info,
3959 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003960{
Johannes Berg463d0182009-07-14 00:33:35 +02003961 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003962 struct net_device *v;
3963 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003964
Johannes Berg80b99892011-11-18 16:23:01 +01003965 if (!vlanattr)
3966 return NULL;
3967
3968 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3969 if (!v)
3970 return ERR_PTR(-ENODEV);
3971
3972 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3973 ret = -EINVAL;
3974 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003975 }
Johannes Berg80b99892011-11-18 16:23:01 +01003976
Johannes Berg77ee7c82013-02-15 00:48:33 +01003977 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3978 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3979 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3980 ret = -EINVAL;
3981 goto error;
3982 }
3983
Johannes Berg80b99892011-11-18 16:23:01 +01003984 if (!netif_running(v)) {
3985 ret = -ENETDOWN;
3986 goto error;
3987 }
3988
3989 return v;
3990 error:
3991 dev_put(v);
3992 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003993}
3994
Johannes Berg94e860f2014-01-20 23:58:15 +01003995static const struct nla_policy
3996nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003997 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3998 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3999};
4000
Johannes Bergff276692013-02-15 00:09:01 +01004001static int nl80211_parse_sta_wme(struct genl_info *info,
4002 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004003{
Jouni Malinendf881292013-02-14 21:10:54 +02004004 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4005 struct nlattr *nla;
4006 int err;
4007
Jouni Malinendf881292013-02-14 21:10:54 +02004008 /* parse WME attributes if present */
4009 if (!info->attrs[NL80211_ATTR_STA_WME])
4010 return 0;
4011
4012 nla = info->attrs[NL80211_ATTR_STA_WME];
4013 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4014 nl80211_sta_wme_policy);
4015 if (err)
4016 return err;
4017
4018 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4019 params->uapsd_queues = nla_get_u8(
4020 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4021 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4022 return -EINVAL;
4023
4024 if (tb[NL80211_STA_WME_MAX_SP])
4025 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4026
4027 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4028 return -EINVAL;
4029
4030 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4031
4032 return 0;
4033}
4034
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304035static int nl80211_parse_sta_channel_info(struct genl_info *info,
4036 struct station_parameters *params)
4037{
4038 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4039 params->supported_channels =
4040 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4041 params->supported_channels_len =
4042 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4043 /*
4044 * Need to include at least one (first channel, number of
4045 * channels) tuple for each subband, and must have proper
4046 * tuples for the rest of the data as well.
4047 */
4048 if (params->supported_channels_len < 2)
4049 return -EINVAL;
4050 if (params->supported_channels_len % 2)
4051 return -EINVAL;
4052 }
4053
4054 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4055 params->supported_oper_classes =
4056 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4057 params->supported_oper_classes_len =
4058 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4059 /*
4060 * The value of the Length field of the Supported Operating
4061 * Classes element is between 2 and 253.
4062 */
4063 if (params->supported_oper_classes_len < 2 ||
4064 params->supported_oper_classes_len > 253)
4065 return -EINVAL;
4066 }
4067 return 0;
4068}
4069
Johannes Bergff276692013-02-15 00:09:01 +01004070static int nl80211_set_station_tdls(struct genl_info *info,
4071 struct station_parameters *params)
4072{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304073 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004074 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004075 if (info->attrs[NL80211_ATTR_PEER_AID])
4076 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004077 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4078 params->ht_capa =
4079 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4080 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4081 params->vht_capa =
4082 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4083
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304084 err = nl80211_parse_sta_channel_info(info, params);
4085 if (err)
4086 return err;
4087
Johannes Bergff276692013-02-15 00:09:01 +01004088 return nl80211_parse_sta_wme(info, params);
4089}
4090
Johannes Berg5727ef12007-12-19 02:03:34 +01004091static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4092{
Johannes Berg4c476992010-10-04 21:36:35 +02004093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004094 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004095 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004096 u8 *mac_addr;
4097 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004098
4099 memset(&params, 0, sizeof(params));
4100
4101 params.listen_interval = -1;
4102
Johannes Berg77ee7c82013-02-15 00:48:33 +01004103 if (!rdev->ops->change_station)
4104 return -EOPNOTSUPP;
4105
Johannes Berg5727ef12007-12-19 02:03:34 +01004106 if (info->attrs[NL80211_ATTR_STA_AID])
4107 return -EINVAL;
4108
4109 if (!info->attrs[NL80211_ATTR_MAC])
4110 return -EINVAL;
4111
4112 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4113
4114 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4115 params.supported_rates =
4116 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4117 params.supported_rates_len =
4118 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4119 }
4120
Jouni Malinen9d62a982013-02-14 21:10:13 +02004121 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4122 params.capability =
4123 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4124 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4125 }
4126
4127 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4128 params.ext_capab =
4129 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4130 params.ext_capab_len =
4131 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4132 }
4133
Jouni Malinendf881292013-02-14 21:10:54 +02004134 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004135 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004136
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004137 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004138 return -EINVAL;
4139
Johannes Bergf8bacc22013-02-14 23:27:01 +01004140 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004141 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004142 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4143 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4144 return -EINVAL;
4145 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004146
Johannes Bergf8bacc22013-02-14 23:27:01 +01004147 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004148 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004149 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4150 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4151 return -EINVAL;
4152 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4153 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004154
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004155 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4156 enum nl80211_mesh_power_mode pm = nla_get_u32(
4157 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4158
4159 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4160 pm > NL80211_MESH_POWER_MAX)
4161 return -EINVAL;
4162
4163 params.local_pm = pm;
4164 }
4165
Johannes Berg77ee7c82013-02-15 00:48:33 +01004166 /* Include parameters for TDLS peer (will check later) */
4167 err = nl80211_set_station_tdls(info, &params);
4168 if (err)
4169 return err;
4170
4171 params.vlan = get_vlan(info, rdev);
4172 if (IS_ERR(params.vlan))
4173 return PTR_ERR(params.vlan);
4174
Johannes Berga97f4422009-06-18 17:23:43 +02004175 switch (dev->ieee80211_ptr->iftype) {
4176 case NL80211_IFTYPE_AP:
4177 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004178 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004179 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004180 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004181 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004182 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004183 break;
4184 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004185 err = -EOPNOTSUPP;
4186 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004187 }
4188
Johannes Berg77ee7c82013-02-15 00:48:33 +01004189 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004190 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004191
Johannes Berg77ee7c82013-02-15 00:48:33 +01004192 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004193 if (params.vlan)
4194 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004195
Johannes Berg5727ef12007-12-19 02:03:34 +01004196 return err;
4197}
4198
4199static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4200{
Johannes Berg4c476992010-10-04 21:36:35 +02004201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004202 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004203 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004204 struct station_parameters params;
4205 u8 *mac_addr = NULL;
4206
4207 memset(&params, 0, sizeof(params));
4208
Johannes Berg984c3112013-02-14 23:43:25 +01004209 if (!rdev->ops->add_station)
4210 return -EOPNOTSUPP;
4211
Johannes Berg5727ef12007-12-19 02:03:34 +01004212 if (!info->attrs[NL80211_ATTR_MAC])
4213 return -EINVAL;
4214
Johannes Berg5727ef12007-12-19 02:03:34 +01004215 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4216 return -EINVAL;
4217
4218 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4219 return -EINVAL;
4220
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004221 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4222 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004223 return -EINVAL;
4224
Johannes Berg5727ef12007-12-19 02:03:34 +01004225 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4226 params.supported_rates =
4227 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4228 params.supported_rates_len =
4229 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4230 params.listen_interval =
4231 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004232
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004233 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004234 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004235 else
4236 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004237 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4238 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004239
Jouni Malinen9d62a982013-02-14 21:10:13 +02004240 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4241 params.capability =
4242 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4243 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4244 }
4245
4246 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4247 params.ext_capab =
4248 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4249 params.ext_capab_len =
4250 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4251 }
4252
Jouni Malinen36aedc902008-08-25 11:58:58 +03004253 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4254 params.ht_capa =
4255 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004256
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004257 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4258 params.vht_capa =
4259 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4260
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004261 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4262 params.opmode_notif_used = true;
4263 params.opmode_notif =
4264 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4265 }
4266
Johannes Bergf8bacc22013-02-14 23:27:01 +01004267 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004268 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004269 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4270 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4271 return -EINVAL;
4272 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004273
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304274 err = nl80211_parse_sta_channel_info(info, &params);
4275 if (err)
4276 return err;
4277
Johannes Bergff276692013-02-15 00:09:01 +01004278 err = nl80211_parse_sta_wme(info, &params);
4279 if (err)
4280 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004281
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004282 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004283 return -EINVAL;
4284
Johannes Berg77ee7c82013-02-15 00:48:33 +01004285 /* When you run into this, adjust the code below for the new flag */
4286 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4287
Johannes Bergbdd90d52011-12-14 12:20:27 +01004288 switch (dev->ieee80211_ptr->iftype) {
4289 case NL80211_IFTYPE_AP:
4290 case NL80211_IFTYPE_AP_VLAN:
4291 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004292 /* ignore WME attributes if iface/sta is not capable */
4293 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4294 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4295 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004296
Johannes Bergbdd90d52011-12-14 12:20:27 +01004297 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004298 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4299 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004300 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004301 /* but don't bother the driver with it */
4302 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004303
Johannes Bergd582cff2012-10-26 17:53:44 +02004304 /* allow authenticated/associated only if driver handles it */
4305 if (!(rdev->wiphy.features &
4306 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4307 params.sta_flags_mask &
4308 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4309 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4310 return -EINVAL;
4311
Johannes Bergbdd90d52011-12-14 12:20:27 +01004312 /* must be last in here for error handling */
4313 params.vlan = get_vlan(info, rdev);
4314 if (IS_ERR(params.vlan))
4315 return PTR_ERR(params.vlan);
4316 break;
4317 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004318 /* ignore uAPSD data */
4319 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4320
Johannes Bergd582cff2012-10-26 17:53:44 +02004321 /* associated is disallowed */
4322 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4323 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004324 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004325 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4326 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004327 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004328 break;
4329 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004330 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004331 /* ignore uAPSD data */
4332 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4333
Johannes Berg77ee7c82013-02-15 00:48:33 +01004334 /* these are disallowed */
4335 if (params.sta_flags_mask &
4336 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4337 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004338 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004339 /* Only TDLS peers can be added */
4340 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4341 return -EINVAL;
4342 /* Can only add if TDLS ... */
4343 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4344 return -EOPNOTSUPP;
4345 /* ... with external setup is supported */
4346 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4347 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004348 /*
4349 * Older wpa_supplicant versions always mark the TDLS peer
4350 * as authorized, but it shouldn't yet be.
4351 */
4352 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004353 break;
4354 default:
4355 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004356 }
4357
Johannes Bergbdd90d52011-12-14 12:20:27 +01004358 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004359
Hila Gonene35e4d22012-06-27 17:19:42 +03004360 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004361
Johannes Berg5727ef12007-12-19 02:03:34 +01004362 if (params.vlan)
4363 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004364 return err;
4365}
4366
4367static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4368{
Johannes Berg4c476992010-10-04 21:36:35 +02004369 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4370 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004371 u8 *mac_addr = NULL;
4372
4373 if (info->attrs[NL80211_ATTR_MAC])
4374 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4375
Johannes Berge80cf852009-05-11 14:43:13 +02004376 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004377 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004378 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004379 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4380 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004381
Johannes Berg4c476992010-10-04 21:36:35 +02004382 if (!rdev->ops->del_station)
4383 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004384
Hila Gonene35e4d22012-06-27 17:19:42 +03004385 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004386}
4387
Eric W. Biederman15e47302012-09-07 20:12:54 +00004388static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004389 int flags, struct net_device *dev,
4390 u8 *dst, u8 *next_hop,
4391 struct mpath_info *pinfo)
4392{
4393 void *hdr;
4394 struct nlattr *pinfoattr;
4395
Eric W. Biederman15e47302012-09-07 20:12:54 +00004396 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004397 if (!hdr)
4398 return -1;
4399
David S. Miller9360ffd2012-03-29 04:41:26 -04004400 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4401 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4402 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4403 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4404 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004405
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004406 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4407 if (!pinfoattr)
4408 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004409 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4410 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4411 pinfo->frame_qlen))
4412 goto nla_put_failure;
4413 if (((pinfo->filled & MPATH_INFO_SN) &&
4414 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4415 ((pinfo->filled & MPATH_INFO_METRIC) &&
4416 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4417 pinfo->metric)) ||
4418 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4419 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4420 pinfo->exptime)) ||
4421 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4422 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4423 pinfo->flags)) ||
4424 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4425 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4426 pinfo->discovery_timeout)) ||
4427 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4428 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4429 pinfo->discovery_retries)))
4430 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004431
4432 nla_nest_end(msg, pinfoattr);
4433
4434 return genlmsg_end(msg, hdr);
4435
4436 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004437 genlmsg_cancel(msg, hdr);
4438 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439}
4440
4441static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004442 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004443{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004444 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004445 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004446 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004447 u8 dst[ETH_ALEN];
4448 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004449 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004450 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004451
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004452 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004453 if (err)
4454 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004455
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004456 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004457 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004458 goto out_err;
4459 }
4460
Johannes Berg97990a02013-04-19 01:02:55 +02004461 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004462 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004463 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004464 }
4465
Johannes Bergbba95fe2008-07-29 13:22:51 +02004466 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004467 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004468 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004469 if (err == -ENOENT)
4470 break;
4471 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004472 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004473
Eric W. Biederman15e47302012-09-07 20:12:54 +00004474 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004475 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004476 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004477 &pinfo) < 0)
4478 goto out;
4479
4480 path_idx++;
4481 }
4482
4483
4484 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004485 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004486 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004487 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004488 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004489 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004490}
4491
4492static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4493{
Johannes Berg4c476992010-10-04 21:36:35 +02004494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004495 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004496 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004497 struct mpath_info pinfo;
4498 struct sk_buff *msg;
4499 u8 *dst = NULL;
4500 u8 next_hop[ETH_ALEN];
4501
4502 memset(&pinfo, 0, sizeof(pinfo));
4503
4504 if (!info->attrs[NL80211_ATTR_MAC])
4505 return -EINVAL;
4506
4507 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4508
Johannes Berg4c476992010-10-04 21:36:35 +02004509 if (!rdev->ops->get_mpath)
4510 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004511
Johannes Berg4c476992010-10-04 21:36:35 +02004512 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4513 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004514
Hila Gonene35e4d22012-06-27 17:19:42 +03004515 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004516 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004517 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004518
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004520 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004521 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004522
Eric W. Biederman15e47302012-09-07 20:12:54 +00004523 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004524 dev, dst, next_hop, &pinfo) < 0) {
4525 nlmsg_free(msg);
4526 return -ENOBUFS;
4527 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004528
Johannes Berg4c476992010-10-04 21:36:35 +02004529 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004530}
4531
4532static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4533{
Johannes Berg4c476992010-10-04 21:36:35 +02004534 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4535 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004536 u8 *dst = NULL;
4537 u8 *next_hop = NULL;
4538
4539 if (!info->attrs[NL80211_ATTR_MAC])
4540 return -EINVAL;
4541
4542 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4543 return -EINVAL;
4544
4545 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4546 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4547
Johannes Berg4c476992010-10-04 21:36:35 +02004548 if (!rdev->ops->change_mpath)
4549 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004550
Johannes Berg4c476992010-10-04 21:36:35 +02004551 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4552 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004553
Hila Gonene35e4d22012-06-27 17:19:42 +03004554 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004555}
Johannes Berg4c476992010-10-04 21:36:35 +02004556
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004557static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4558{
Johannes Berg4c476992010-10-04 21:36:35 +02004559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4560 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004561 u8 *dst = NULL;
4562 u8 *next_hop = NULL;
4563
4564 if (!info->attrs[NL80211_ATTR_MAC])
4565 return -EINVAL;
4566
4567 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4568 return -EINVAL;
4569
4570 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4571 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4572
Johannes Berg4c476992010-10-04 21:36:35 +02004573 if (!rdev->ops->add_mpath)
4574 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004575
Johannes Berg4c476992010-10-04 21:36:35 +02004576 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4577 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004578
Hila Gonene35e4d22012-06-27 17:19:42 +03004579 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004580}
4581
4582static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4583{
Johannes Berg4c476992010-10-04 21:36:35 +02004584 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4585 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004586 u8 *dst = NULL;
4587
4588 if (info->attrs[NL80211_ATTR_MAC])
4589 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4590
Johannes Berg4c476992010-10-04 21:36:35 +02004591 if (!rdev->ops->del_mpath)
4592 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004593
Hila Gonene35e4d22012-06-27 17:19:42 +03004594 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004595}
4596
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004597static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4598{
Johannes Berg4c476992010-10-04 21:36:35 +02004599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4600 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004601 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004602 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004603 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004604
4605 memset(&params, 0, sizeof(params));
4606 /* default to not changing parameters */
4607 params.use_cts_prot = -1;
4608 params.use_short_preamble = -1;
4609 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004610 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004611 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004612 params.p2p_ctwindow = -1;
4613 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004614
4615 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4616 params.use_cts_prot =
4617 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4618 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4619 params.use_short_preamble =
4620 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4621 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4622 params.use_short_slot_time =
4623 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004624 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4625 params.basic_rates =
4626 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4627 params.basic_rates_len =
4628 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4629 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004630 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4631 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004632 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4633 params.ht_opmode =
4634 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004635
Johannes Berg53cabad2012-11-14 15:17:28 +01004636 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4637 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4638 return -EINVAL;
4639 params.p2p_ctwindow =
4640 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4641 if (params.p2p_ctwindow < 0)
4642 return -EINVAL;
4643 if (params.p2p_ctwindow != 0 &&
4644 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4645 return -EINVAL;
4646 }
4647
4648 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4649 u8 tmp;
4650
4651 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4652 return -EINVAL;
4653 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4654 if (tmp > 1)
4655 return -EINVAL;
4656 params.p2p_opp_ps = tmp;
4657 if (params.p2p_opp_ps &&
4658 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4659 return -EINVAL;
4660 }
4661
Johannes Berg4c476992010-10-04 21:36:35 +02004662 if (!rdev->ops->change_bss)
4663 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004664
Johannes Berg074ac8d2010-09-16 14:58:22 +02004665 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004666 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4667 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004668
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004669 wdev_lock(wdev);
4670 err = rdev_change_bss(rdev, dev, &params);
4671 wdev_unlock(wdev);
4672
4673 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004674}
4675
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004676static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004677 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4678 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4679 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4680 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4681 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4682 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004683 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004684};
4685
4686static int parse_reg_rule(struct nlattr *tb[],
4687 struct ieee80211_reg_rule *reg_rule)
4688{
4689 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4690 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4691
4692 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4693 return -EINVAL;
4694 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4695 return -EINVAL;
4696 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4697 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004698 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4699 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004700 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4701 return -EINVAL;
4702
4703 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4704
4705 freq_range->start_freq_khz =
4706 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4707 freq_range->end_freq_khz =
4708 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004709 freq_range->max_bandwidth_khz =
4710 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004711
4712 power_rule->max_eirp =
4713 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4714
4715 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4716 power_rule->max_antenna_gain =
4717 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4718
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004719 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4720 reg_rule->dfs_cac_ms =
4721 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4722
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004723 return 0;
4724}
4725
4726static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4727{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004728 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004729 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004730
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004731 /*
4732 * You should only get this when cfg80211 hasn't yet initialized
4733 * completely when built-in to the kernel right between the time
4734 * window between nl80211_init() and regulatory_init(), if that is
4735 * even possible.
4736 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004737 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004738 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004739
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004740 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4741 user_reg_hint_type =
4742 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4743 else
4744 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4745
4746 switch (user_reg_hint_type) {
4747 case NL80211_USER_REG_HINT_USER:
4748 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004749 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4750 return -EINVAL;
4751
4752 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4753 return regulatory_hint_user(data, user_reg_hint_type);
4754 case NL80211_USER_REG_HINT_INDOOR:
4755 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004756 default:
4757 return -EINVAL;
4758 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004759}
4760
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004761static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004762 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004763{
Johannes Berg4c476992010-10-04 21:36:35 +02004764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004765 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004766 struct wireless_dev *wdev = dev->ieee80211_ptr;
4767 struct mesh_config cur_params;
4768 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004769 void *hdr;
4770 struct nlattr *pinfoattr;
4771 struct sk_buff *msg;
4772
Johannes Berg29cbe682010-12-03 09:20:44 +01004773 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4774 return -EOPNOTSUPP;
4775
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004776 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004777 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004778
Johannes Berg29cbe682010-12-03 09:20:44 +01004779 wdev_lock(wdev);
4780 /* If not connected, get default parameters */
4781 if (!wdev->mesh_id_len)
4782 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4783 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004784 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004785 wdev_unlock(wdev);
4786
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004787 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004788 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004789
4790 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004791 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004792 if (!msg)
4793 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004794 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004795 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004796 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004797 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004798 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004799 if (!pinfoattr)
4800 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004801 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4802 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4803 cur_params.dot11MeshRetryTimeout) ||
4804 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4805 cur_params.dot11MeshConfirmTimeout) ||
4806 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4807 cur_params.dot11MeshHoldingTimeout) ||
4808 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4809 cur_params.dot11MeshMaxPeerLinks) ||
4810 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4811 cur_params.dot11MeshMaxRetries) ||
4812 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4813 cur_params.dot11MeshTTL) ||
4814 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4815 cur_params.element_ttl) ||
4816 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4817 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004818 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4819 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004820 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4821 cur_params.dot11MeshHWMPmaxPREQretries) ||
4822 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4823 cur_params.path_refresh_time) ||
4824 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4825 cur_params.min_discovery_timeout) ||
4826 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4827 cur_params.dot11MeshHWMPactivePathTimeout) ||
4828 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4829 cur_params.dot11MeshHWMPpreqMinInterval) ||
4830 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4831 cur_params.dot11MeshHWMPperrMinInterval) ||
4832 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4833 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4834 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4835 cur_params.dot11MeshHWMPRootMode) ||
4836 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4837 cur_params.dot11MeshHWMPRannInterval) ||
4838 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4839 cur_params.dot11MeshGateAnnouncementProtocol) ||
4840 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4841 cur_params.dot11MeshForwarding) ||
4842 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004843 cur_params.rssi_threshold) ||
4844 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004845 cur_params.ht_opmode) ||
4846 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4847 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4848 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004849 cur_params.dot11MeshHWMProotInterval) ||
4850 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004851 cur_params.dot11MeshHWMPconfirmationInterval) ||
4852 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4853 cur_params.power_mode) ||
4854 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004855 cur_params.dot11MeshAwakeWindowDuration) ||
4856 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4857 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004858 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004859 nla_nest_end(msg, pinfoattr);
4860 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004861 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004862
Johannes Berg3b858752009-03-12 09:55:09 +01004863 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004864 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004865 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004866 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004867 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004868}
4869
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004870static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004871 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4872 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4873 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4874 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4875 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4876 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004877 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004878 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004879 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004880 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4881 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4882 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4883 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4884 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004885 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004886 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004887 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004888 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004889 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004890 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004891 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4892 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004893 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4894 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004895 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004896 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4897 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004898 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004899};
4900
Javier Cardonac80d5452010-12-16 17:37:49 -08004901static const struct nla_policy
4902 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004903 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004904 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4905 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004906 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004907 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004908 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004909 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004910 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004911 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004912};
4913
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004914static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004915 struct mesh_config *cfg,
4916 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004917{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004918 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004919 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004920
Marco Porschea54fba2013-01-07 16:04:48 +01004921#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4922do { \
4923 if (tb[attr]) { \
4924 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4925 return -EINVAL; \
4926 cfg->param = fn(tb[attr]); \
4927 mask |= (1 << (attr - 1)); \
4928 } \
4929} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004930
4931
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004932 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004933 return -EINVAL;
4934 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004935 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004936 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004937 return -EINVAL;
4938
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004939 /* This makes sure that there aren't more than 32 mesh config
4940 * parameters (otherwise our bitfield scheme would not work.) */
4941 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4942
4943 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004944 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004945 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4946 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004948 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4949 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004950 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004951 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4952 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004953 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004954 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4955 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004957 mask, NL80211_MESHCONF_MAX_RETRIES,
4958 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004960 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004961 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004962 mask, NL80211_MESHCONF_ELEMENT_TTL,
4963 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004965 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4966 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4968 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004969 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4970 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004971 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004972 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4973 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004974 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004975 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4976 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004977 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004978 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4979 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004980 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4981 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004982 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4983 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004984 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004985 1, 65535, mask,
4986 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004987 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004988 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004989 1, 65535, mask,
4990 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004991 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004992 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004993 dot11MeshHWMPnetDiameterTraversalTime,
4994 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004995 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4996 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004997 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4998 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4999 nla_get_u8);
5000 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5001 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005002 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005003 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005004 dot11MeshGateAnnouncementProtocol, 0, 1,
5005 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005006 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005007 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005008 mask, NL80211_MESHCONF_FORWARDING,
5009 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005010 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005011 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005012 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005013 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005014 mask, NL80211_MESHCONF_HT_OPMODE,
5015 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005016 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005017 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005018 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5019 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005020 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005021 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5022 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005023 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005024 dot11MeshHWMPconfirmationInterval,
5025 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005026 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5027 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005028 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5029 NL80211_MESH_POWER_ACTIVE,
5030 NL80211_MESH_POWER_MAX,
5031 mask, NL80211_MESHCONF_POWER_MODE,
5032 nla_get_u32);
5033 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5034 0, 65535, mask,
5035 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005036 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5037 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5038 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005039 if (mask_out)
5040 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005041
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005042 return 0;
5043
5044#undef FILL_IN_MESH_PARAM_IF_SET
5045}
5046
Javier Cardonac80d5452010-12-16 17:37:49 -08005047static int nl80211_parse_mesh_setup(struct genl_info *info,
5048 struct mesh_setup *setup)
5049{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005051 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5052
5053 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5054 return -EINVAL;
5055 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5056 info->attrs[NL80211_ATTR_MESH_SETUP],
5057 nl80211_mesh_setup_params_policy))
5058 return -EINVAL;
5059
Javier Cardonad299a1f2012-03-31 11:31:33 -07005060 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5061 setup->sync_method =
5062 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5063 IEEE80211_SYNC_METHOD_VENDOR :
5064 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5065
Javier Cardonac80d5452010-12-16 17:37:49 -08005066 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5067 setup->path_sel_proto =
5068 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5069 IEEE80211_PATH_PROTOCOL_VENDOR :
5070 IEEE80211_PATH_PROTOCOL_HWMP;
5071
5072 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5073 setup->path_metric =
5074 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5075 IEEE80211_PATH_METRIC_VENDOR :
5076 IEEE80211_PATH_METRIC_AIRTIME;
5077
Javier Cardona581a8b02011-04-07 15:08:27 -07005078
5079 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005080 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005081 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005082 if (!is_valid_ie_attr(ieattr))
5083 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005084 setup->ie = nla_data(ieattr);
5085 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005086 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005087 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5088 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5089 return -EINVAL;
5090 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005091 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5092 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005093 if (setup->is_secure)
5094 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005095
Colleen Twitty6e16d902013-05-08 11:45:59 -07005096 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5097 if (!setup->user_mpm)
5098 return -EINVAL;
5099 setup->auth_id =
5100 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5101 }
5102
Javier Cardonac80d5452010-12-16 17:37:49 -08005103 return 0;
5104}
5105
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005106static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005107 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005108{
5109 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5110 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005111 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005112 struct mesh_config cfg;
5113 u32 mask;
5114 int err;
5115
Johannes Berg29cbe682010-12-03 09:20:44 +01005116 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5117 return -EOPNOTSUPP;
5118
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005119 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005120 return -EOPNOTSUPP;
5121
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005122 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005123 if (err)
5124 return err;
5125
Johannes Berg29cbe682010-12-03 09:20:44 +01005126 wdev_lock(wdev);
5127 if (!wdev->mesh_id_len)
5128 err = -ENOLINK;
5129
5130 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005131 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005132
5133 wdev_unlock(wdev);
5134
5135 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005136}
5137
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005138static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5139{
Johannes Berg458f4f92012-12-06 15:47:38 +01005140 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005141 struct sk_buff *msg;
5142 void *hdr = NULL;
5143 struct nlattr *nl_reg_rules;
5144 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005145
5146 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005147 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005148
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005149 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005150 if (!msg)
5151 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005152
Eric W. Biederman15e47302012-09-07 20:12:54 +00005153 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005154 NL80211_CMD_GET_REG);
5155 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005156 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005157
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005158 if (reg_last_request_cell_base() &&
5159 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5160 NL80211_USER_REG_HINT_CELL_BASE))
5161 goto nla_put_failure;
5162
Johannes Berg458f4f92012-12-06 15:47:38 +01005163 rcu_read_lock();
5164 regdom = rcu_dereference(cfg80211_regdomain);
5165
5166 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5167 (regdom->dfs_region &&
5168 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5169 goto nla_put_failure_rcu;
5170
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005171 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5172 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005173 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005174
Johannes Berg458f4f92012-12-06 15:47:38 +01005175 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005176 struct nlattr *nl_reg_rule;
5177 const struct ieee80211_reg_rule *reg_rule;
5178 const struct ieee80211_freq_range *freq_range;
5179 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005180 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005181
Johannes Berg458f4f92012-12-06 15:47:38 +01005182 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005183 freq_range = &reg_rule->freq_range;
5184 power_rule = &reg_rule->power_rule;
5185
5186 nl_reg_rule = nla_nest_start(msg, i);
5187 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005188 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005189
Janusz Dziedzic97524822014-01-30 09:52:20 +01005190 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5191 if (!max_bandwidth_khz)
5192 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5193 reg_rule);
5194
David S. Miller9360ffd2012-03-29 04:41:26 -04005195 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5196 reg_rule->flags) ||
5197 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5198 freq_range->start_freq_khz) ||
5199 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5200 freq_range->end_freq_khz) ||
5201 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005202 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005203 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5204 power_rule->max_antenna_gain) ||
5205 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005206 power_rule->max_eirp) ||
5207 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5208 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005209 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005210
5211 nla_nest_end(msg, nl_reg_rule);
5212 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005213 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005214
5215 nla_nest_end(msg, nl_reg_rules);
5216
5217 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005218 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005219
Johannes Berg458f4f92012-12-06 15:47:38 +01005220nla_put_failure_rcu:
5221 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005222nla_put_failure:
5223 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005224put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005225 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005226 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005227}
5228
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005229static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5230{
5231 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5232 struct nlattr *nl_reg_rule;
5233 char *alpha2 = NULL;
5234 int rem_reg_rules = 0, r = 0;
5235 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005236 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005237 struct ieee80211_regdomain *rd = NULL;
5238
5239 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5240 return -EINVAL;
5241
5242 if (!info->attrs[NL80211_ATTR_REG_RULES])
5243 return -EINVAL;
5244
5245 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5246
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005247 if (info->attrs[NL80211_ATTR_DFS_REGION])
5248 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5249
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005250 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005251 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005252 num_rules++;
5253 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005254 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005255 }
5256
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005257 if (!reg_is_valid_request(alpha2))
5258 return -EINVAL;
5259
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005260 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005261 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005262
5263 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005264 if (!rd)
5265 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005266
5267 rd->n_reg_rules = num_rules;
5268 rd->alpha2[0] = alpha2[0];
5269 rd->alpha2[1] = alpha2[1];
5270
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005271 /*
5272 * Disable DFS master mode if the DFS region was
5273 * not supported or known on this kernel.
5274 */
5275 if (reg_supported_dfs_region(dfs_region))
5276 rd->dfs_region = dfs_region;
5277
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005278 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005279 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005280 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5281 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5282 reg_rule_policy);
5283 if (r)
5284 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005285 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5286 if (r)
5287 goto bad_reg;
5288
5289 rule_idx++;
5290
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005291 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5292 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005293 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005294 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005295 }
5296
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005297 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005298 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005299 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005300
Johannes Bergd2372b32008-10-24 20:32:20 +02005301 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005302 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005303 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005304}
5305
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005306static int validate_scan_freqs(struct nlattr *freqs)
5307{
5308 struct nlattr *attr1, *attr2;
5309 int n_channels = 0, tmp1, tmp2;
5310
5311 nla_for_each_nested(attr1, freqs, tmp1) {
5312 n_channels++;
5313 /*
5314 * Some hardware has a limited channel list for
5315 * scanning, and it is pretty much nonsensical
5316 * to scan for a channel twice, so disallow that
5317 * and don't require drivers to check that the
5318 * channel list they get isn't longer than what
5319 * they can scan, as long as they can scan all
5320 * the channels they registered at once.
5321 */
5322 nla_for_each_nested(attr2, freqs, tmp2)
5323 if (attr1 != attr2 &&
5324 nla_get_u32(attr1) == nla_get_u32(attr2))
5325 return 0;
5326 }
5327
5328 return n_channels;
5329}
5330
Johannes Berg2a519312009-02-10 21:25:55 +01005331static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5332{
Johannes Berg4c476992010-10-04 21:36:35 +02005333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005334 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005335 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005336 struct nlattr *attr;
5337 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005338 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005339 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005340
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005341 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5342 return -EINVAL;
5343
Johannes Berg79c97e92009-07-07 03:56:12 +02005344 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005345
Johannes Berg4c476992010-10-04 21:36:35 +02005346 if (!rdev->ops->scan)
5347 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005348
Johannes Bergf9d15d12014-01-22 11:14:19 +02005349 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005350 err = -EBUSY;
5351 goto unlock;
5352 }
Johannes Berg2a519312009-02-10 21:25:55 +01005353
5354 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005355 n_channels = validate_scan_freqs(
5356 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005357 if (!n_channels) {
5358 err = -EINVAL;
5359 goto unlock;
5360 }
Johannes Berg2a519312009-02-10 21:25:55 +01005361 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005362 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005363 }
5364
5365 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5366 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5367 n_ssids++;
5368
Johannes Bergf9f47522013-03-19 15:04:07 +01005369 if (n_ssids > wiphy->max_scan_ssids) {
5370 err = -EINVAL;
5371 goto unlock;
5372 }
Johannes Berg2a519312009-02-10 21:25:55 +01005373
Jouni Malinen70692ad2009-02-16 19:39:13 +02005374 if (info->attrs[NL80211_ATTR_IE])
5375 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5376 else
5377 ie_len = 0;
5378
Johannes Bergf9f47522013-03-19 15:04:07 +01005379 if (ie_len > wiphy->max_scan_ie_len) {
5380 err = -EINVAL;
5381 goto unlock;
5382 }
Johannes Berg18a83652009-03-31 12:12:05 +02005383
Johannes Berg2a519312009-02-10 21:25:55 +01005384 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005385 + sizeof(*request->ssids) * n_ssids
5386 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005387 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005388 if (!request) {
5389 err = -ENOMEM;
5390 goto unlock;
5391 }
Johannes Berg2a519312009-02-10 21:25:55 +01005392
Johannes Berg2a519312009-02-10 21:25:55 +01005393 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005394 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005395 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005396 if (ie_len) {
5397 if (request->ssids)
5398 request->ie = (void *)(request->ssids + n_ssids);
5399 else
5400 request->ie = (void *)(request->channels + n_channels);
5401 }
Johannes Berg2a519312009-02-10 21:25:55 +01005402
Johannes Berg584991d2009-11-02 13:32:03 +01005403 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005404 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5405 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005406 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005407 struct ieee80211_channel *chan;
5408
5409 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5410
5411 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005412 err = -EINVAL;
5413 goto out_free;
5414 }
Johannes Berg584991d2009-11-02 13:32:03 +01005415
5416 /* ignore disabled channels */
5417 if (chan->flags & IEEE80211_CHAN_DISABLED)
5418 continue;
5419
5420 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005421 i++;
5422 }
5423 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005424 enum ieee80211_band band;
5425
Johannes Berg2a519312009-02-10 21:25:55 +01005426 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005427 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5428 int j;
5429 if (!wiphy->bands[band])
5430 continue;
5431 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005432 struct ieee80211_channel *chan;
5433
5434 chan = &wiphy->bands[band]->channels[j];
5435
5436 if (chan->flags & IEEE80211_CHAN_DISABLED)
5437 continue;
5438
5439 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005440 i++;
5441 }
5442 }
5443 }
5444
Johannes Berg584991d2009-11-02 13:32:03 +01005445 if (!i) {
5446 err = -EINVAL;
5447 goto out_free;
5448 }
5449
5450 request->n_channels = i;
5451
Johannes Berg2a519312009-02-10 21:25:55 +01005452 i = 0;
5453 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5454 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005455 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005456 err = -EINVAL;
5457 goto out_free;
5458 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005459 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005460 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005461 i++;
5462 }
5463 }
5464
Jouni Malinen70692ad2009-02-16 19:39:13 +02005465 if (info->attrs[NL80211_ATTR_IE]) {
5466 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005467 memcpy((void *)request->ie,
5468 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005469 request->ie_len);
5470 }
5471
Johannes Berg34850ab2011-07-18 18:08:35 +02005472 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005473 if (wiphy->bands[i])
5474 request->rates[i] =
5475 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005476
5477 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5478 nla_for_each_nested(attr,
5479 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5480 tmp) {
5481 enum ieee80211_band band = nla_type(attr);
5482
Dan Carpenter84404622011-07-29 11:52:18 +03005483 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005484 err = -EINVAL;
5485 goto out_free;
5486 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005487
5488 if (!wiphy->bands[band])
5489 continue;
5490
Johannes Berg34850ab2011-07-18 18:08:35 +02005491 err = ieee80211_get_ratemask(wiphy->bands[band],
5492 nla_data(attr),
5493 nla_len(attr),
5494 &request->rates[band]);
5495 if (err)
5496 goto out_free;
5497 }
5498 }
5499
Sam Leffler46856bb2012-10-11 21:03:32 -07005500 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005501 request->flags = nla_get_u32(
5502 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005503 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5504 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005505 err = -EOPNOTSUPP;
5506 goto out_free;
5507 }
5508 }
Sam Lefflered4737712012-10-11 21:03:31 -07005509
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305510 request->no_cck =
5511 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5512
Johannes Bergfd014282012-06-18 19:17:03 +02005513 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005514 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005515 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005516
Johannes Berg79c97e92009-07-07 03:56:12 +02005517 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005518 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005519
Johannes Berg463d0182009-07-14 00:33:35 +02005520 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005521 nl80211_send_scan_start(rdev, wdev);
5522 if (wdev->netdev)
5523 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005524 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005525 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005526 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005527 kfree(request);
5528 }
Johannes Berg3b858752009-03-12 09:55:09 +01005529
Johannes Bergf9f47522013-03-19 15:04:07 +01005530 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005531 return err;
5532}
5533
Luciano Coelho807f8a82011-05-11 17:09:35 +03005534static int nl80211_start_sched_scan(struct sk_buff *skb,
5535 struct genl_info *info)
5536{
5537 struct cfg80211_sched_scan_request *request;
5538 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5539 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005540 struct nlattr *attr;
5541 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005542 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005543 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005544 enum ieee80211_band band;
5545 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005546 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005547 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005548
5549 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5550 !rdev->ops->sched_scan_start)
5551 return -EOPNOTSUPP;
5552
5553 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5554 return -EINVAL;
5555
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005556 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5557 return -EINVAL;
5558
5559 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5560 if (interval == 0)
5561 return -EINVAL;
5562
Luciano Coelho807f8a82011-05-11 17:09:35 +03005563 wiphy = &rdev->wiphy;
5564
5565 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5566 n_channels = validate_scan_freqs(
5567 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5568 if (!n_channels)
5569 return -EINVAL;
5570 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005571 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005572 }
5573
5574 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5575 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5576 tmp)
5577 n_ssids++;
5578
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005579 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005580 return -EINVAL;
5581
Johannes Bergea73cbc2014-01-24 10:53:53 +01005582 /*
5583 * First, count the number of 'real' matchsets. Due to an issue with
5584 * the old implementation, matchsets containing only the RSSI attribute
5585 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5586 * RSSI for all matchsets, rather than their own matchset for reporting
5587 * all APs with a strong RSSI. This is needed to be compatible with
5588 * older userspace that treated a matchset with only the RSSI as the
5589 * global RSSI for all other matchsets - if there are other matchsets.
5590 */
5591 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005592 nla_for_each_nested(attr,
5593 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005594 tmp) {
5595 struct nlattr *rssi;
5596
5597 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5598 nla_data(attr), nla_len(attr),
5599 nl80211_match_policy);
5600 if (err)
5601 return err;
5602 /* add other standalone attributes here */
5603 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5604 n_match_sets++;
5605 continue;
5606 }
5607 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5608 if (rssi)
5609 default_match_rssi = nla_get_s32(rssi);
5610 }
5611 }
5612
5613 /* However, if there's no other matchset, add the RSSI one */
5614 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5615 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005616
5617 if (n_match_sets > wiphy->max_match_sets)
5618 return -EINVAL;
5619
Luciano Coelho807f8a82011-05-11 17:09:35 +03005620 if (info->attrs[NL80211_ATTR_IE])
5621 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5622 else
5623 ie_len = 0;
5624
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005625 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005626 return -EINVAL;
5627
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005628 if (rdev->sched_scan_req) {
5629 err = -EINPROGRESS;
5630 goto out;
5631 }
5632
Luciano Coelho807f8a82011-05-11 17:09:35 +03005633 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005634 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005635 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005636 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005637 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005638 if (!request) {
5639 err = -ENOMEM;
5640 goto out;
5641 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005642
5643 if (n_ssids)
5644 request->ssids = (void *)&request->channels[n_channels];
5645 request->n_ssids = n_ssids;
5646 if (ie_len) {
5647 if (request->ssids)
5648 request->ie = (void *)(request->ssids + n_ssids);
5649 else
5650 request->ie = (void *)(request->channels + n_channels);
5651 }
5652
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005653 if (n_match_sets) {
5654 if (request->ie)
5655 request->match_sets = (void *)(request->ie + ie_len);
5656 else if (request->ssids)
5657 request->match_sets =
5658 (void *)(request->ssids + n_ssids);
5659 else
5660 request->match_sets =
5661 (void *)(request->channels + n_channels);
5662 }
5663 request->n_match_sets = n_match_sets;
5664
Luciano Coelho807f8a82011-05-11 17:09:35 +03005665 i = 0;
5666 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5667 /* user specified, bail out if channel not found */
5668 nla_for_each_nested(attr,
5669 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5670 tmp) {
5671 struct ieee80211_channel *chan;
5672
5673 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5674
5675 if (!chan) {
5676 err = -EINVAL;
5677 goto out_free;
5678 }
5679
5680 /* ignore disabled channels */
5681 if (chan->flags & IEEE80211_CHAN_DISABLED)
5682 continue;
5683
5684 request->channels[i] = chan;
5685 i++;
5686 }
5687 } else {
5688 /* all channels */
5689 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5690 int j;
5691 if (!wiphy->bands[band])
5692 continue;
5693 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5694 struct ieee80211_channel *chan;
5695
5696 chan = &wiphy->bands[band]->channels[j];
5697
5698 if (chan->flags & IEEE80211_CHAN_DISABLED)
5699 continue;
5700
5701 request->channels[i] = chan;
5702 i++;
5703 }
5704 }
5705 }
5706
5707 if (!i) {
5708 err = -EINVAL;
5709 goto out_free;
5710 }
5711
5712 request->n_channels = i;
5713
5714 i = 0;
5715 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5716 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5717 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005718 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005719 err = -EINVAL;
5720 goto out_free;
5721 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005722 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005723 memcpy(request->ssids[i].ssid, nla_data(attr),
5724 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005725 i++;
5726 }
5727 }
5728
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005729 i = 0;
5730 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5731 nla_for_each_nested(attr,
5732 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5733 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005734 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005735
Johannes Bergae811e22014-01-24 10:17:47 +01005736 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5737 nla_data(attr), nla_len(attr),
5738 nl80211_match_policy);
5739 if (err)
5740 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005741 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005742 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005743 if (WARN_ON(i >= n_match_sets)) {
5744 /* this indicates a programming error,
5745 * the loop above should have verified
5746 * things properly
5747 */
5748 err = -EINVAL;
5749 goto out_free;
5750 }
5751
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005752 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5753 err = -EINVAL;
5754 goto out_free;
5755 }
5756 memcpy(request->match_sets[i].ssid.ssid,
5757 nla_data(ssid), nla_len(ssid));
5758 request->match_sets[i].ssid.ssid_len =
5759 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005760 /* special attribute - old implemenation w/a */
5761 request->match_sets[i].rssi_thold =
5762 default_match_rssi;
5763 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5764 if (rssi)
5765 request->match_sets[i].rssi_thold =
5766 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005767 }
5768 i++;
5769 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005770
5771 /* there was no other matchset, so the RSSI one is alone */
5772 if (i == 0)
5773 request->match_sets[0].rssi_thold = default_match_rssi;
5774
5775 request->min_rssi_thold = INT_MAX;
5776 for (i = 0; i < n_match_sets; i++)
5777 request->min_rssi_thold =
5778 min(request->match_sets[i].rssi_thold,
5779 request->min_rssi_thold);
5780 } else {
5781 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005782 }
5783
Johannes Berg9900e482014-02-04 21:01:25 +01005784 if (ie_len) {
5785 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005786 memcpy((void *)request->ie,
5787 nla_data(info->attrs[NL80211_ATTR_IE]),
5788 request->ie_len);
5789 }
5790
Sam Leffler46856bb2012-10-11 21:03:32 -07005791 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005792 request->flags = nla_get_u32(
5793 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005794 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5795 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005796 err = -EOPNOTSUPP;
5797 goto out_free;
5798 }
5799 }
Sam Lefflered4737712012-10-11 21:03:31 -07005800
Luciano Coelho807f8a82011-05-11 17:09:35 +03005801 request->dev = dev;
5802 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005803 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005804 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005805
Hila Gonene35e4d22012-06-27 17:19:42 +03005806 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005807 if (!err) {
5808 rdev->sched_scan_req = request;
5809 nl80211_send_sched_scan(rdev, dev,
5810 NL80211_CMD_START_SCHED_SCAN);
5811 goto out;
5812 }
5813
5814out_free:
5815 kfree(request);
5816out:
5817 return err;
5818}
5819
5820static int nl80211_stop_sched_scan(struct sk_buff *skb,
5821 struct genl_info *info)
5822{
5823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5824
5825 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5826 !rdev->ops->sched_scan_stop)
5827 return -EOPNOTSUPP;
5828
Johannes Berg5fe231e2013-05-08 21:45:15 +02005829 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005830}
5831
Simon Wunderlich04f39042013-02-08 18:16:19 +01005832static int nl80211_start_radar_detection(struct sk_buff *skb,
5833 struct genl_info *info)
5834{
5835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5836 struct net_device *dev = info->user_ptr[1];
5837 struct wireless_dev *wdev = dev->ieee80211_ptr;
5838 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005839 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005840 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005841 int err;
5842
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005843 dfs_region = reg_get_dfs_region(wdev->wiphy);
5844 if (dfs_region == NL80211_DFS_UNSET)
5845 return -EINVAL;
5846
Simon Wunderlich04f39042013-02-08 18:16:19 +01005847 err = nl80211_parse_chandef(rdev, info, &chandef);
5848 if (err)
5849 return err;
5850
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005851 if (netif_carrier_ok(dev))
5852 return -EBUSY;
5853
Simon Wunderlich04f39042013-02-08 18:16:19 +01005854 if (wdev->cac_started)
5855 return -EBUSY;
5856
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02005857 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03005858 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005859 if (err < 0)
5860 return err;
5861
5862 if (err == 0)
5863 return -EINVAL;
5864
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005865 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005866 return -EINVAL;
5867
5868 if (!rdev->ops->start_radar_detection)
5869 return -EOPNOTSUPP;
5870
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005871 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5872 if (WARN_ON(!cac_time_ms))
5873 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5874
5875 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5876 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005877 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005878 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005879 wdev->cac_started = true;
5880 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005881 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005882 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005883 return err;
5884}
5885
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005886static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5887{
5888 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5889 struct net_device *dev = info->user_ptr[1];
5890 struct wireless_dev *wdev = dev->ieee80211_ptr;
5891 struct cfg80211_csa_settings params;
5892 /* csa_attrs is defined static to avoid waste of stack size - this
5893 * function is called under RTNL lock, so this should not be a problem.
5894 */
5895 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5896 u8 radar_detect_width = 0;
5897 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005898 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005899 int len, i;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005900
5901 if (!rdev->ops->channel_switch ||
5902 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5903 return -EOPNOTSUPP;
5904
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005905 switch (dev->ieee80211_ptr->iftype) {
5906 case NL80211_IFTYPE_AP:
5907 case NL80211_IFTYPE_P2P_GO:
5908 need_new_beacon = true;
5909
5910 /* useless if AP is not running */
5911 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005912 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005913 break;
5914 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005915 if (!wdev->ssid_len)
5916 return -ENOTCONN;
5917 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005918 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005919 if (!wdev->mesh_id_len)
5920 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005921 break;
5922 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005923 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005924 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005925
5926 memset(&params, 0, sizeof(params));
5927
5928 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5929 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5930 return -EINVAL;
5931
5932 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005933 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005934 return -EINVAL;
5935
5936 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5937
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005938 if (!need_new_beacon)
5939 goto skip_beacons;
5940
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005941 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5942 if (err)
5943 return err;
5944
5945 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5946 info->attrs[NL80211_ATTR_CSA_IES],
5947 nl80211_policy);
5948 if (err)
5949 return err;
5950
5951 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5952 if (err)
5953 return err;
5954
5955 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5956 return -EINVAL;
5957
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005958 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5959 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005960 return -EINVAL;
5961
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005962 params.n_counter_offsets_beacon = len / sizeof(u16);
5963 if (rdev->wiphy.max_num_csa_counters &&
5964 (params.n_counter_offsets_beacon >
5965 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005966 return -EINVAL;
5967
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005968 params.counter_offsets_beacon =
5969 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5970
5971 /* sanity checks - counters should fit and be the same */
5972 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
5973 u16 offset = params.counter_offsets_beacon[i];
5974
5975 if (offset >= params.beacon_csa.tail_len)
5976 return -EINVAL;
5977
5978 if (params.beacon_csa.tail[offset] != params.count)
5979 return -EINVAL;
5980 }
5981
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005982 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005983 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5984 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005985 return -EINVAL;
5986
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005987 params.n_counter_offsets_presp = len / sizeof(u16);
5988 if (rdev->wiphy.max_num_csa_counters &&
5989 (params.n_counter_offsets_beacon >
5990 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005991 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005992
5993 params.counter_offsets_presp =
5994 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5995
5996 /* sanity checks - counters should fit and be the same */
5997 for (i = 0; i < params.n_counter_offsets_presp; i++) {
5998 u16 offset = params.counter_offsets_presp[i];
5999
6000 if (offset >= params.beacon_csa.probe_resp_len)
6001 return -EINVAL;
6002
6003 if (params.beacon_csa.probe_resp[offset] !=
6004 params.count)
6005 return -EINVAL;
6006 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006007 }
6008
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006009skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006010 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6011 if (err)
6012 return err;
6013
Ilan Peer174e0cd2014-02-23 09:13:01 +02006014 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6015 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006016 return -EINVAL;
6017
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006018 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6019 &params.chandef,
6020 wdev->iftype);
6021 if (err < 0)
6022 return err;
6023
6024 if (err > 0) {
6025 radar_detect_width = BIT(params.chandef.width);
6026 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006027 }
6028
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006029 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6030 params.block_tx = true;
6031
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006032 wdev_lock(wdev);
6033 err = rdev_channel_switch(rdev, dev, &params);
6034 wdev_unlock(wdev);
6035
6036 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006037}
6038
Johannes Berg9720bb32011-06-21 09:45:33 +02006039static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6040 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006041 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006042 struct wireless_dev *wdev,
6043 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006044{
Johannes Berg48ab9052009-07-10 18:42:31 +02006045 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006046 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006047 void *hdr;
6048 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006049
6050 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006051
Eric W. Biederman15e47302012-09-07 20:12:54 +00006052 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006053 NL80211_CMD_NEW_SCAN_RESULTS);
6054 if (!hdr)
6055 return -1;
6056
Johannes Berg9720bb32011-06-21 09:45:33 +02006057 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6058
Johannes Berg97990a02013-04-19 01:02:55 +02006059 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6060 goto nla_put_failure;
6061 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006062 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6063 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006064 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6065 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006066
6067 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6068 if (!bss)
6069 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006070 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006071 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006072 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006073
6074 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006075 /* indicate whether we have probe response data or not */
6076 if (rcu_access_pointer(res->proberesp_ies) &&
6077 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6078 goto fail_unlock_rcu;
6079
6080 /* this pointer prefers to be pointed to probe response data
6081 * but is always valid
6082 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006083 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006084 if (ies) {
6085 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6086 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006087 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6088 ies->len, ies->data))
6089 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006090 }
Johannes Berg0e227082014-08-12 20:34:30 +02006091
6092 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006093 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006094 if (ies && ies->from_beacon) {
6095 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006096 goto fail_unlock_rcu;
6097 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6098 ies->len, ies->data))
6099 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006100 }
6101 rcu_read_unlock();
6102
David S. Miller9360ffd2012-03-29 04:41:26 -04006103 if (res->beacon_interval &&
6104 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6105 goto nla_put_failure;
6106 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6107 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006108 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006109 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6110 jiffies_to_msecs(jiffies - intbss->ts)))
6111 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006112
Johannes Berg77965c92009-02-18 18:45:06 +01006113 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006114 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006115 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6116 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006117 break;
6118 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006119 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6120 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006121 break;
6122 default:
6123 break;
6124 }
6125
Johannes Berg48ab9052009-07-10 18:42:31 +02006126 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006127 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006128 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006129 if (intbss == wdev->current_bss &&
6130 nla_put_u32(msg, NL80211_BSS_STATUS,
6131 NL80211_BSS_STATUS_ASSOCIATED))
6132 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006133 break;
6134 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006135 if (intbss == wdev->current_bss &&
6136 nla_put_u32(msg, NL80211_BSS_STATUS,
6137 NL80211_BSS_STATUS_IBSS_JOINED))
6138 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006139 break;
6140 default:
6141 break;
6142 }
6143
Johannes Berg2a519312009-02-10 21:25:55 +01006144 nla_nest_end(msg, bss);
6145
6146 return genlmsg_end(msg, hdr);
6147
Johannes Berg8cef2c92013-02-05 16:54:31 +01006148 fail_unlock_rcu:
6149 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006150 nla_put_failure:
6151 genlmsg_cancel(msg, hdr);
6152 return -EMSGSIZE;
6153}
6154
Johannes Berg97990a02013-04-19 01:02:55 +02006155static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006156{
Johannes Berg48ab9052009-07-10 18:42:31 +02006157 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006158 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006159 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006160 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006161 int err;
6162
Johannes Berg97990a02013-04-19 01:02:55 +02006163 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006164 if (err)
6165 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006166
Johannes Berg48ab9052009-07-10 18:42:31 +02006167 wdev_lock(wdev);
6168 spin_lock_bh(&rdev->bss_lock);
6169 cfg80211_bss_expire(rdev);
6170
Johannes Berg9720bb32011-06-21 09:45:33 +02006171 cb->seq = rdev->bss_generation;
6172
Johannes Berg48ab9052009-07-10 18:42:31 +02006173 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006174 if (++idx <= start)
6175 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006176 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006177 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006178 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006179 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006180 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006181 }
6182 }
6183
Johannes Berg48ab9052009-07-10 18:42:31 +02006184 spin_unlock_bh(&rdev->bss_lock);
6185 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006186
Johannes Berg97990a02013-04-19 01:02:55 +02006187 cb->args[2] = idx;
6188 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006189
Johannes Berg67748892010-10-04 21:14:06 +02006190 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006191}
6192
Eric W. Biederman15e47302012-09-07 20:12:54 +00006193static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006194 int flags, struct net_device *dev,
6195 struct survey_info *survey)
6196{
6197 void *hdr;
6198 struct nlattr *infoattr;
6199
Eric W. Biederman15e47302012-09-07 20:12:54 +00006200 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006201 NL80211_CMD_NEW_SURVEY_RESULTS);
6202 if (!hdr)
6203 return -ENOMEM;
6204
David S. Miller9360ffd2012-03-29 04:41:26 -04006205 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6206 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006207
6208 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6209 if (!infoattr)
6210 goto nla_put_failure;
6211
David S. Miller9360ffd2012-03-29 04:41:26 -04006212 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6213 survey->channel->center_freq))
6214 goto nla_put_failure;
6215
6216 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6217 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6218 goto nla_put_failure;
6219 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6220 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6221 goto nla_put_failure;
6222 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6223 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6224 survey->channel_time))
6225 goto nla_put_failure;
6226 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6227 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6228 survey->channel_time_busy))
6229 goto nla_put_failure;
6230 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6231 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6232 survey->channel_time_ext_busy))
6233 goto nla_put_failure;
6234 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6235 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6236 survey->channel_time_rx))
6237 goto nla_put_failure;
6238 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6239 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6240 survey->channel_time_tx))
6241 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006242
6243 nla_nest_end(msg, infoattr);
6244
6245 return genlmsg_end(msg, hdr);
6246
6247 nla_put_failure:
6248 genlmsg_cancel(msg, hdr);
6249 return -EMSGSIZE;
6250}
6251
6252static int nl80211_dump_survey(struct sk_buff *skb,
6253 struct netlink_callback *cb)
6254{
6255 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006256 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006257 struct wireless_dev *wdev;
6258 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006259 int res;
6260
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006261 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006262 if (res)
6263 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006264
Johannes Berg97990a02013-04-19 01:02:55 +02006265 if (!wdev->netdev) {
6266 res = -EINVAL;
6267 goto out_err;
6268 }
6269
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006270 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006271 res = -EOPNOTSUPP;
6272 goto out_err;
6273 }
6274
6275 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006276 struct ieee80211_channel *chan;
6277
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006278 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006279 if (res == -ENOENT)
6280 break;
6281 if (res)
6282 goto out_err;
6283
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006284 /* Survey without a channel doesn't make sense */
6285 if (!survey.channel) {
6286 res = -EINVAL;
6287 goto out;
6288 }
6289
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006290 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006291 survey.channel->center_freq);
6292 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6293 survey_idx++;
6294 continue;
6295 }
6296
Holger Schurig61fa7132009-11-11 12:25:40 +01006297 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006298 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006299 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006300 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006301 goto out;
6302 survey_idx++;
6303 }
6304
6305 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006306 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006307 res = skb->len;
6308 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006309 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006310 return res;
6311}
6312
Samuel Ortizb23aa672009-07-01 21:26:54 +02006313static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6314{
6315 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6316 NL80211_WPA_VERSION_2));
6317}
6318
Jouni Malinen636a5d32009-03-19 13:39:22 +02006319static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6320{
Johannes Berg4c476992010-10-04 21:36:35 +02006321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6322 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006323 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006324 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6325 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006326 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006327 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006328 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006329
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006330 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6331 return -EINVAL;
6332
6333 if (!info->attrs[NL80211_ATTR_MAC])
6334 return -EINVAL;
6335
Jouni Malinen17780922009-03-27 20:52:47 +02006336 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6337 return -EINVAL;
6338
Johannes Berg19957bb2009-07-02 17:20:43 +02006339 if (!info->attrs[NL80211_ATTR_SSID])
6340 return -EINVAL;
6341
6342 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6343 return -EINVAL;
6344
Johannes Bergfffd0932009-07-08 14:22:54 +02006345 err = nl80211_parse_key(info, &key);
6346 if (err)
6347 return err;
6348
6349 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006350 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6351 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006352 if (!key.p.key || !key.p.key_len)
6353 return -EINVAL;
6354 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6355 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6356 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6357 key.p.key_len != WLAN_KEY_LEN_WEP104))
6358 return -EINVAL;
6359 if (key.idx > 4)
6360 return -EINVAL;
6361 } else {
6362 key.p.key_len = 0;
6363 key.p.key = NULL;
6364 }
6365
Johannes Bergafea0b72010-08-10 09:46:42 +02006366 if (key.idx >= 0) {
6367 int i;
6368 bool ok = false;
6369 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6370 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6371 ok = true;
6372 break;
6373 }
6374 }
Johannes Berg4c476992010-10-04 21:36:35 +02006375 if (!ok)
6376 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006377 }
6378
Johannes Berg4c476992010-10-04 21:36:35 +02006379 if (!rdev->ops->auth)
6380 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006381
Johannes Berg074ac8d2010-09-16 14:58:22 +02006382 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006383 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6384 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006385
Johannes Berg19957bb2009-07-02 17:20:43 +02006386 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006387 chan = nl80211_get_valid_chan(&rdev->wiphy,
6388 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6389 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006390 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006391
Johannes Berg19957bb2009-07-02 17:20:43 +02006392 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6393 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6394
6395 if (info->attrs[NL80211_ATTR_IE]) {
6396 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6397 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6398 }
6399
6400 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006401 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006402 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006403
Jouni Malinene39e5b52012-09-30 19:29:39 +03006404 if (auth_type == NL80211_AUTHTYPE_SAE &&
6405 !info->attrs[NL80211_ATTR_SAE_DATA])
6406 return -EINVAL;
6407
6408 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6409 if (auth_type != NL80211_AUTHTYPE_SAE)
6410 return -EINVAL;
6411 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6412 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6413 /* need to include at least Auth Transaction and Status Code */
6414 if (sae_data_len < 4)
6415 return -EINVAL;
6416 }
6417
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006418 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6419
Johannes Berg95de8172012-01-20 13:55:25 +01006420 /*
6421 * Since we no longer track auth state, ignore
6422 * requests to only change local state.
6423 */
6424 if (local_state_change)
6425 return 0;
6426
Johannes Berg91bf9b22013-05-15 17:44:01 +02006427 wdev_lock(dev->ieee80211_ptr);
6428 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6429 ssid, ssid_len, ie, ie_len,
6430 key.p.key, key.p.key_len, key.idx,
6431 sae_data, sae_data_len);
6432 wdev_unlock(dev->ieee80211_ptr);
6433 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006434}
6435
Johannes Bergc0692b82010-08-27 14:26:53 +03006436static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6437 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006438 struct cfg80211_crypto_settings *settings,
6439 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006440{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006441 memset(settings, 0, sizeof(*settings));
6442
Samuel Ortizb23aa672009-07-01 21:26:54 +02006443 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6444
Johannes Bergc0692b82010-08-27 14:26:53 +03006445 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6446 u16 proto;
6447 proto = nla_get_u16(
6448 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6449 settings->control_port_ethertype = cpu_to_be16(proto);
6450 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6451 proto != ETH_P_PAE)
6452 return -EINVAL;
6453 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6454 settings->control_port_no_encrypt = true;
6455 } else
6456 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6457
Samuel Ortizb23aa672009-07-01 21:26:54 +02006458 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6459 void *data;
6460 int len, i;
6461
6462 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6463 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6464 settings->n_ciphers_pairwise = len / sizeof(u32);
6465
6466 if (len % sizeof(u32))
6467 return -EINVAL;
6468
Johannes Berg3dc27d22009-07-02 21:36:37 +02006469 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006470 return -EINVAL;
6471
6472 memcpy(settings->ciphers_pairwise, data, len);
6473
6474 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006475 if (!cfg80211_supported_cipher_suite(
6476 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006477 settings->ciphers_pairwise[i]))
6478 return -EINVAL;
6479 }
6480
6481 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6482 settings->cipher_group =
6483 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006484 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6485 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006486 return -EINVAL;
6487 }
6488
6489 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6490 settings->wpa_versions =
6491 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6492 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6493 return -EINVAL;
6494 }
6495
6496 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6497 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006498 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006499
6500 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6501 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6502 settings->n_akm_suites = len / sizeof(u32);
6503
6504 if (len % sizeof(u32))
6505 return -EINVAL;
6506
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006507 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6508 return -EINVAL;
6509
Samuel Ortizb23aa672009-07-01 21:26:54 +02006510 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006511 }
6512
6513 return 0;
6514}
6515
Jouni Malinen636a5d32009-03-19 13:39:22 +02006516static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6517{
Johannes Berg4c476992010-10-04 21:36:35 +02006518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6519 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006520 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006521 struct cfg80211_assoc_request req = {};
6522 const u8 *bssid, *ssid;
6523 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006524
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006525 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6526 return -EINVAL;
6527
6528 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006529 !info->attrs[NL80211_ATTR_SSID] ||
6530 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006531 return -EINVAL;
6532
Johannes Berg4c476992010-10-04 21:36:35 +02006533 if (!rdev->ops->assoc)
6534 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006535
Johannes Berg074ac8d2010-09-16 14:58:22 +02006536 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006537 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6538 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006539
Johannes Berg19957bb2009-07-02 17:20:43 +02006540 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006541
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]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006549
6550 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006551 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6552 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006553 }
6554
Jouni Malinendc6382c2009-05-06 22:09:37 +03006555 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006556 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006557 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006558 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006559 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006560 else if (mfp != NL80211_MFP_NO)
6561 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006562 }
6563
Johannes Berg3e5d7642009-07-07 14:37:26 +02006564 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006565 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006566
Ben Greear7e7c8922011-11-18 11:31:59 -08006567 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006568 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006569
6570 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006571 memcpy(&req.ht_capa_mask,
6572 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6573 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006574
6575 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006576 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006577 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006578 memcpy(&req.ht_capa,
6579 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6580 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006581 }
6582
Johannes Bergee2aca32013-02-21 17:36:01 +01006583 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006584 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006585
6586 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006587 memcpy(&req.vht_capa_mask,
6588 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6589 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006590
6591 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006592 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006593 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006594 memcpy(&req.vht_capa,
6595 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6596 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006597 }
6598
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006599 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6600 if (!(rdev->wiphy.features &
6601 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6602 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6603 return -EINVAL;
6604 req.flags |= ASSOC_REQ_USE_RRM;
6605 }
6606
Johannes Bergf62fab72013-02-21 20:09:09 +01006607 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006608 if (!err) {
6609 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006610 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6611 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006612 wdev_unlock(dev->ieee80211_ptr);
6613 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006614
Jouni Malinen636a5d32009-03-19 13:39:22 +02006615 return err;
6616}
6617
6618static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6619{
Johannes Berg4c476992010-10-04 21:36:35 +02006620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6621 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006622 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006623 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006624 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006625 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006626
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006627 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6628 return -EINVAL;
6629
6630 if (!info->attrs[NL80211_ATTR_MAC])
6631 return -EINVAL;
6632
6633 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6634 return -EINVAL;
6635
Johannes Berg4c476992010-10-04 21:36:35 +02006636 if (!rdev->ops->deauth)
6637 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006638
Johannes Berg074ac8d2010-09-16 14:58:22 +02006639 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006640 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6641 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006642
Johannes Berg19957bb2009-07-02 17:20:43 +02006643 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006644
Johannes Berg19957bb2009-07-02 17:20:43 +02006645 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6646 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006647 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006648 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006649 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006650
6651 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006652 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6653 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006654 }
6655
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006656 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6657
Johannes Berg91bf9b22013-05-15 17:44:01 +02006658 wdev_lock(dev->ieee80211_ptr);
6659 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6660 local_state_change);
6661 wdev_unlock(dev->ieee80211_ptr);
6662 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006663}
6664
6665static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6666{
Johannes Berg4c476992010-10-04 21:36:35 +02006667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6668 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006669 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006670 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006671 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006672 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006673
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006674 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6675 return -EINVAL;
6676
6677 if (!info->attrs[NL80211_ATTR_MAC])
6678 return -EINVAL;
6679
6680 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6681 return -EINVAL;
6682
Johannes Berg4c476992010-10-04 21:36:35 +02006683 if (!rdev->ops->disassoc)
6684 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006685
Johannes Berg074ac8d2010-09-16 14:58:22 +02006686 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006687 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6688 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006689
Johannes Berg19957bb2009-07-02 17:20:43 +02006690 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006691
Johannes Berg19957bb2009-07-02 17:20:43 +02006692 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6693 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006694 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006695 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006696 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006697
6698 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006699 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6700 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006701 }
6702
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006703 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6704
Johannes Berg91bf9b22013-05-15 17:44:01 +02006705 wdev_lock(dev->ieee80211_ptr);
6706 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6707 local_state_change);
6708 wdev_unlock(dev->ieee80211_ptr);
6709 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006710}
6711
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006712static bool
6713nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6714 int mcast_rate[IEEE80211_NUM_BANDS],
6715 int rateval)
6716{
6717 struct wiphy *wiphy = &rdev->wiphy;
6718 bool found = false;
6719 int band, i;
6720
6721 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6722 struct ieee80211_supported_band *sband;
6723
6724 sband = wiphy->bands[band];
6725 if (!sband)
6726 continue;
6727
6728 for (i = 0; i < sband->n_bitrates; i++) {
6729 if (sband->bitrates[i].bitrate == rateval) {
6730 mcast_rate[band] = i + 1;
6731 found = true;
6732 break;
6733 }
6734 }
6735 }
6736
6737 return found;
6738}
6739
Johannes Berg04a773a2009-04-19 21:24:32 +02006740static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6741{
Johannes Berg4c476992010-10-04 21:36:35 +02006742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6743 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006744 struct cfg80211_ibss_params ibss;
6745 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006746 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006747 int err;
6748
Johannes Berg8e30bc52009-04-22 17:45:38 +02006749 memset(&ibss, 0, sizeof(ibss));
6750
Johannes Berg04a773a2009-04-19 21:24:32 +02006751 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6752 return -EINVAL;
6753
Johannes Berg683b6d32012-11-08 21:25:48 +01006754 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006755 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6756 return -EINVAL;
6757
Johannes Berg8e30bc52009-04-22 17:45:38 +02006758 ibss.beacon_interval = 100;
6759
6760 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6761 ibss.beacon_interval =
6762 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6763 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6764 return -EINVAL;
6765 }
6766
Johannes Berg4c476992010-10-04 21:36:35 +02006767 if (!rdev->ops->join_ibss)
6768 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006769
Johannes Berg4c476992010-10-04 21:36:35 +02006770 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6771 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006772
Johannes Berg79c97e92009-07-07 03:56:12 +02006773 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006774
Johannes Berg39193492011-09-16 13:45:25 +02006775 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006776 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006777
6778 if (!is_valid_ether_addr(ibss.bssid))
6779 return -EINVAL;
6780 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006781 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6782 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6783
6784 if (info->attrs[NL80211_ATTR_IE]) {
6785 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6786 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6787 }
6788
Johannes Berg683b6d32012-11-08 21:25:48 +01006789 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6790 if (err)
6791 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006792
Ilan Peer174e0cd2014-02-23 09:13:01 +02006793 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6794 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006795 return -EINVAL;
6796
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006797 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006798 case NL80211_CHAN_WIDTH_5:
6799 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006800 case NL80211_CHAN_WIDTH_20_NOHT:
6801 break;
6802 case NL80211_CHAN_WIDTH_20:
6803 case NL80211_CHAN_WIDTH_40:
6804 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6805 break;
6806 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006807 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006808 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006809
Johannes Berg04a773a2009-04-19 21:24:32 +02006810 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006811 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006812
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006813 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6814 u8 *rates =
6815 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6816 int n_rates =
6817 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6818 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006819 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006820
Johannes Berg34850ab2011-07-18 18:08:35 +02006821 err = ieee80211_get_ratemask(sband, rates, n_rates,
6822 &ibss.basic_rates);
6823 if (err)
6824 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006825 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006826
Simon Wunderlich803768f2013-06-28 10:39:58 +02006827 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6828 memcpy(&ibss.ht_capa_mask,
6829 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6830 sizeof(ibss.ht_capa_mask));
6831
6832 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6833 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6834 return -EINVAL;
6835 memcpy(&ibss.ht_capa,
6836 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6837 sizeof(ibss.ht_capa));
6838 }
6839
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006840 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6841 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6842 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6843 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006844
Johannes Berg4c476992010-10-04 21:36:35 +02006845 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306846 bool no_ht = false;
6847
Johannes Berg4c476992010-10-04 21:36:35 +02006848 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306849 info->attrs[NL80211_ATTR_KEYS],
6850 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006851 if (IS_ERR(connkeys))
6852 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306853
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006854 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6855 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306856 kfree(connkeys);
6857 return -EINVAL;
6858 }
Johannes Berg4c476992010-10-04 21:36:35 +02006859 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006860
Antonio Quartulli267335d2012-01-31 20:25:47 +01006861 ibss.control_port =
6862 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6863
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006864 ibss.userspace_handles_dfs =
6865 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6866
Johannes Berg4c476992010-10-04 21:36:35 +02006867 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006868 if (err)
6869 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006870 return err;
6871}
6872
6873static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6874{
Johannes Berg4c476992010-10-04 21:36:35 +02006875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6876 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006877
Johannes Berg4c476992010-10-04 21:36:35 +02006878 if (!rdev->ops->leave_ibss)
6879 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006880
Johannes Berg4c476992010-10-04 21:36:35 +02006881 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6882 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006883
Johannes Berg4c476992010-10-04 21:36:35 +02006884 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006885}
6886
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006887static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6888{
6889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6890 struct net_device *dev = info->user_ptr[1];
6891 int mcast_rate[IEEE80211_NUM_BANDS];
6892 u32 nla_rate;
6893 int err;
6894
6895 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6896 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6897 return -EOPNOTSUPP;
6898
6899 if (!rdev->ops->set_mcast_rate)
6900 return -EOPNOTSUPP;
6901
6902 memset(mcast_rate, 0, sizeof(mcast_rate));
6903
6904 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6905 return -EINVAL;
6906
6907 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6908 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6909 return -EINVAL;
6910
6911 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6912
6913 return err;
6914}
6915
Johannes Bergad7e7182013-11-13 13:37:47 +01006916static struct sk_buff *
6917__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6918 int approxlen, u32 portid, u32 seq,
6919 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006920 enum nl80211_attrs attr,
6921 const struct nl80211_vendor_cmd_info *info,
6922 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006923{
6924 struct sk_buff *skb;
6925 void *hdr;
6926 struct nlattr *data;
6927
6928 skb = nlmsg_new(approxlen + 100, gfp);
6929 if (!skb)
6930 return NULL;
6931
6932 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6933 if (!hdr) {
6934 kfree_skb(skb);
6935 return NULL;
6936 }
6937
6938 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6939 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006940
6941 if (info) {
6942 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6943 info->vendor_id))
6944 goto nla_put_failure;
6945 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6946 info->subcmd))
6947 goto nla_put_failure;
6948 }
6949
Johannes Bergad7e7182013-11-13 13:37:47 +01006950 data = nla_nest_start(skb, attr);
6951
6952 ((void **)skb->cb)[0] = rdev;
6953 ((void **)skb->cb)[1] = hdr;
6954 ((void **)skb->cb)[2] = data;
6955
6956 return skb;
6957
6958 nla_put_failure:
6959 kfree_skb(skb);
6960 return NULL;
6961}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006962
Johannes Berge03ad6e2014-01-01 17:22:30 +01006963struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6964 enum nl80211_commands cmd,
6965 enum nl80211_attrs attr,
6966 int vendor_event_idx,
6967 int approxlen, gfp_t gfp)
6968{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006969 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006970 const struct nl80211_vendor_cmd_info *info;
6971
6972 switch (cmd) {
6973 case NL80211_CMD_TESTMODE:
6974 if (WARN_ON(vendor_event_idx != -1))
6975 return NULL;
6976 info = NULL;
6977 break;
6978 case NL80211_CMD_VENDOR:
6979 if (WARN_ON(vendor_event_idx < 0 ||
6980 vendor_event_idx >= wiphy->n_vendor_events))
6981 return NULL;
6982 info = &wiphy->vendor_events[vendor_event_idx];
6983 break;
6984 default:
6985 WARN_ON(1);
6986 return NULL;
6987 }
6988
6989 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6990 cmd, attr, info, gfp);
6991}
6992EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6993
6994void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6995{
6996 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6997 void *hdr = ((void **)skb->cb)[1];
6998 struct nlattr *data = ((void **)skb->cb)[2];
6999 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7000
7001 nla_nest_end(skb, data);
7002 genlmsg_end(skb, hdr);
7003
7004 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7005 mcgrp = NL80211_MCGRP_VENDOR;
7006
7007 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7008 mcgrp, gfp);
7009}
7010EXPORT_SYMBOL(__cfg80211_send_event_skb);
7011
Johannes Bergaff89a92009-07-01 21:26:51 +02007012#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007013static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7014{
Johannes Berg4c476992010-10-04 21:36:35 +02007015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007016 struct wireless_dev *wdev =
7017 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007018 int err;
7019
David Spinadelfc73f112013-07-31 18:04:15 +03007020 if (!rdev->ops->testmode_cmd)
7021 return -EOPNOTSUPP;
7022
7023 if (IS_ERR(wdev)) {
7024 err = PTR_ERR(wdev);
7025 if (err != -EINVAL)
7026 return err;
7027 wdev = NULL;
7028 } else if (wdev->wiphy != &rdev->wiphy) {
7029 return -EINVAL;
7030 }
7031
Johannes Bergaff89a92009-07-01 21:26:51 +02007032 if (!info->attrs[NL80211_ATTR_TESTDATA])
7033 return -EINVAL;
7034
Johannes Bergad7e7182013-11-13 13:37:47 +01007035 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007036 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007037 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7038 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007039 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007040
Johannes Bergaff89a92009-07-01 21:26:51 +02007041 return err;
7042}
7043
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007044static int nl80211_testmode_dump(struct sk_buff *skb,
7045 struct netlink_callback *cb)
7046{
Johannes Berg00918d32011-12-13 17:22:05 +01007047 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007048 int err;
7049 long phy_idx;
7050 void *data = NULL;
7051 int data_len = 0;
7052
Johannes Berg5fe231e2013-05-08 21:45:15 +02007053 rtnl_lock();
7054
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007055 if (cb->args[0]) {
7056 /*
7057 * 0 is a valid index, but not valid for args[0],
7058 * so we need to offset by 1.
7059 */
7060 phy_idx = cb->args[0] - 1;
7061 } else {
7062 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7063 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7064 nl80211_policy);
7065 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007066 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007067
Johannes Berg2bd7e352012-06-15 14:23:16 +02007068 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7069 nl80211_fam.attrbuf);
7070 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007071 err = PTR_ERR(rdev);
7072 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007073 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007074 phy_idx = rdev->wiphy_idx;
7075 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007076
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007077 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7078 cb->args[1] =
7079 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7080 }
7081
7082 if (cb->args[1]) {
7083 data = nla_data((void *)cb->args[1]);
7084 data_len = nla_len((void *)cb->args[1]);
7085 }
7086
Johannes Berg00918d32011-12-13 17:22:05 +01007087 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7088 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007089 err = -ENOENT;
7090 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007091 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007092
Johannes Berg00918d32011-12-13 17:22:05 +01007093 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007094 err = -EOPNOTSUPP;
7095 goto out_err;
7096 }
7097
7098 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007099 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007100 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7101 NL80211_CMD_TESTMODE);
7102 struct nlattr *tmdata;
7103
Dan Carpentercb35fba2013-08-14 14:50:01 +03007104 if (!hdr)
7105 break;
7106
David S. Miller9360ffd2012-03-29 04:41:26 -04007107 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007108 genlmsg_cancel(skb, hdr);
7109 break;
7110 }
7111
7112 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7113 if (!tmdata) {
7114 genlmsg_cancel(skb, hdr);
7115 break;
7116 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007117 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007118 nla_nest_end(skb, tmdata);
7119
7120 if (err == -ENOBUFS || err == -ENOENT) {
7121 genlmsg_cancel(skb, hdr);
7122 break;
7123 } else if (err) {
7124 genlmsg_cancel(skb, hdr);
7125 goto out_err;
7126 }
7127
7128 genlmsg_end(skb, hdr);
7129 }
7130
7131 err = skb->len;
7132 /* see above */
7133 cb->args[0] = phy_idx + 1;
7134 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007135 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007136 return err;
7137}
Johannes Bergaff89a92009-07-01 21:26:51 +02007138#endif
7139
Samuel Ortizb23aa672009-07-01 21:26:54 +02007140static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7141{
Johannes Berg4c476992010-10-04 21:36:35 +02007142 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7143 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007144 struct cfg80211_connect_params connect;
7145 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007146 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007147 int err;
7148
7149 memset(&connect, 0, sizeof(connect));
7150
7151 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7152 return -EINVAL;
7153
7154 if (!info->attrs[NL80211_ATTR_SSID] ||
7155 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7156 return -EINVAL;
7157
7158 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7159 connect.auth_type =
7160 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007161 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7162 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007163 return -EINVAL;
7164 } else
7165 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7166
7167 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7168
Johannes Bergc0692b82010-08-27 14:26:53 +03007169 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007170 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007171 if (err)
7172 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007173
Johannes Berg074ac8d2010-09-16 14:58:22 +02007174 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007175 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7176 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007177
Johannes Berg79c97e92009-07-07 03:56:12 +02007178 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007179
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307180 connect.bg_scan_period = -1;
7181 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7182 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7183 connect.bg_scan_period =
7184 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7185 }
7186
Samuel Ortizb23aa672009-07-01 21:26:54 +02007187 if (info->attrs[NL80211_ATTR_MAC])
7188 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007189 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7190 connect.bssid_hint =
7191 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007192 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7193 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7194
7195 if (info->attrs[NL80211_ATTR_IE]) {
7196 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7197 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7198 }
7199
Jouni Malinencee00a92013-01-15 17:15:57 +02007200 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7201 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7202 if (connect.mfp != NL80211_MFP_REQUIRED &&
7203 connect.mfp != NL80211_MFP_NO)
7204 return -EINVAL;
7205 } else {
7206 connect.mfp = NL80211_MFP_NO;
7207 }
7208
Samuel Ortizb23aa672009-07-01 21:26:54 +02007209 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007210 connect.channel = nl80211_get_valid_chan(
7211 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7212 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007213 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007214 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007215 connect.channel_hint = nl80211_get_valid_chan(
7216 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7217 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007218 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007219 }
7220
Johannes Bergfffd0932009-07-08 14:22:54 +02007221 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7222 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307223 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007224 if (IS_ERR(connkeys))
7225 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007226 }
7227
Ben Greear7e7c8922011-11-18 11:31:59 -08007228 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7229 connect.flags |= ASSOC_REQ_DISABLE_HT;
7230
7231 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7232 memcpy(&connect.ht_capa_mask,
7233 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7234 sizeof(connect.ht_capa_mask));
7235
7236 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007237 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7238 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007239 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007240 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007241 memcpy(&connect.ht_capa,
7242 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7243 sizeof(connect.ht_capa));
7244 }
7245
Johannes Bergee2aca32013-02-21 17:36:01 +01007246 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7247 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7248
7249 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7250 memcpy(&connect.vht_capa_mask,
7251 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7252 sizeof(connect.vht_capa_mask));
7253
7254 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7255 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7256 kfree(connkeys);
7257 return -EINVAL;
7258 }
7259 memcpy(&connect.vht_capa,
7260 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7261 sizeof(connect.vht_capa));
7262 }
7263
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007264 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7265 if (!(rdev->wiphy.features &
7266 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7267 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7268 return -EINVAL;
7269 connect.flags |= ASSOC_REQ_USE_RRM;
7270 }
7271
Johannes Berg83739b02013-05-15 17:44:01 +02007272 wdev_lock(dev->ieee80211_ptr);
7273 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7274 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007275 if (err)
7276 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007277 return err;
7278}
7279
7280static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7281{
Johannes Berg4c476992010-10-04 21:36:35 +02007282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7283 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007284 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007285 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007286
7287 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7288 reason = WLAN_REASON_DEAUTH_LEAVING;
7289 else
7290 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7291
7292 if (reason == 0)
7293 return -EINVAL;
7294
Johannes Berg074ac8d2010-09-16 14:58:22 +02007295 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007296 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7297 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007298
Johannes Berg83739b02013-05-15 17:44:01 +02007299 wdev_lock(dev->ieee80211_ptr);
7300 ret = cfg80211_disconnect(rdev, dev, reason, true);
7301 wdev_unlock(dev->ieee80211_ptr);
7302 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007303}
7304
Johannes Berg463d0182009-07-14 00:33:35 +02007305static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7306{
Johannes Berg4c476992010-10-04 21:36:35 +02007307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007308 struct net *net;
7309 int err;
7310 u32 pid;
7311
7312 if (!info->attrs[NL80211_ATTR_PID])
7313 return -EINVAL;
7314
7315 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7316
Johannes Berg463d0182009-07-14 00:33:35 +02007317 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007318 if (IS_ERR(net))
7319 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007320
7321 err = 0;
7322
7323 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007324 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7325 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007326
Johannes Berg463d0182009-07-14 00:33:35 +02007327 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007328 return err;
7329}
7330
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007331static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7332{
Johannes Berg4c476992010-10-04 21:36:35 +02007333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007334 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7335 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007336 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007337 struct cfg80211_pmksa pmksa;
7338
7339 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7340
7341 if (!info->attrs[NL80211_ATTR_MAC])
7342 return -EINVAL;
7343
7344 if (!info->attrs[NL80211_ATTR_PMKID])
7345 return -EINVAL;
7346
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007347 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7348 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7349
Johannes Berg074ac8d2010-09-16 14:58:22 +02007350 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007351 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7352 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007353
7354 switch (info->genlhdr->cmd) {
7355 case NL80211_CMD_SET_PMKSA:
7356 rdev_ops = rdev->ops->set_pmksa;
7357 break;
7358 case NL80211_CMD_DEL_PMKSA:
7359 rdev_ops = rdev->ops->del_pmksa;
7360 break;
7361 default:
7362 WARN_ON(1);
7363 break;
7364 }
7365
Johannes Berg4c476992010-10-04 21:36:35 +02007366 if (!rdev_ops)
7367 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007368
Johannes Berg4c476992010-10-04 21:36:35 +02007369 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007370}
7371
7372static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7373{
Johannes Berg4c476992010-10-04 21:36:35 +02007374 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7375 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007376
Johannes Berg074ac8d2010-09-16 14:58:22 +02007377 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007378 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7379 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007380
Johannes Berg4c476992010-10-04 21:36:35 +02007381 if (!rdev->ops->flush_pmksa)
7382 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007383
Hila Gonene35e4d22012-06-27 17:19:42 +03007384 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007385}
7386
Arik Nemtsov109086c2011-09-28 14:12:50 +03007387static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7388{
7389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7390 struct net_device *dev = info->user_ptr[1];
7391 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307392 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007393 u16 status_code;
7394 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007395 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007396
7397 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7398 !rdev->ops->tdls_mgmt)
7399 return -EOPNOTSUPP;
7400
7401 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7402 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7403 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7404 !info->attrs[NL80211_ATTR_IE] ||
7405 !info->attrs[NL80211_ATTR_MAC])
7406 return -EINVAL;
7407
7408 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7409 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7410 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7411 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007412 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307413 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7414 peer_capability =
7415 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007416
Hila Gonene35e4d22012-06-27 17:19:42 +03007417 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307418 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007419 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007420 nla_data(info->attrs[NL80211_ATTR_IE]),
7421 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007422}
7423
7424static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7425{
7426 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7427 struct net_device *dev = info->user_ptr[1];
7428 enum nl80211_tdls_operation operation;
7429 u8 *peer;
7430
7431 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7432 !rdev->ops->tdls_oper)
7433 return -EOPNOTSUPP;
7434
7435 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7436 !info->attrs[NL80211_ATTR_MAC])
7437 return -EINVAL;
7438
7439 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7440 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7441
Hila Gonene35e4d22012-06-27 17:19:42 +03007442 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007443}
7444
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007445static int nl80211_remain_on_channel(struct sk_buff *skb,
7446 struct genl_info *info)
7447{
Johannes Berg4c476992010-10-04 21:36:35 +02007448 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007449 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007450 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007451 struct sk_buff *msg;
7452 void *hdr;
7453 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007454 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007455 int err;
7456
7457 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7458 !info->attrs[NL80211_ATTR_DURATION])
7459 return -EINVAL;
7460
7461 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7462
Johannes Berg7c4ef712011-11-18 15:33:48 +01007463 if (!rdev->ops->remain_on_channel ||
7464 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007465 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007466
Johannes Bergebf348f2012-06-01 12:50:54 +02007467 /*
7468 * We should be on that channel for at least a minimum amount of
7469 * time (10ms) but no longer than the driver supports.
7470 */
7471 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7472 duration > rdev->wiphy.max_remain_on_channel_duration)
7473 return -EINVAL;
7474
Johannes Berg683b6d32012-11-08 21:25:48 +01007475 err = nl80211_parse_chandef(rdev, info, &chandef);
7476 if (err)
7477 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007478
7479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007480 if (!msg)
7481 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007482
Eric W. Biederman15e47302012-09-07 20:12:54 +00007483 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007484 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007485 if (!hdr) {
7486 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007487 goto free_msg;
7488 }
7489
Johannes Berg683b6d32012-11-08 21:25:48 +01007490 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7491 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007492
7493 if (err)
7494 goto free_msg;
7495
David S. Miller9360ffd2012-03-29 04:41:26 -04007496 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7497 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007498
7499 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007500
7501 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007502
7503 nla_put_failure:
7504 err = -ENOBUFS;
7505 free_msg:
7506 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007507 return err;
7508}
7509
7510static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7511 struct genl_info *info)
7512{
Johannes Berg4c476992010-10-04 21:36:35 +02007513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007514 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007515 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007516
7517 if (!info->attrs[NL80211_ATTR_COOKIE])
7518 return -EINVAL;
7519
Johannes Berg4c476992010-10-04 21:36:35 +02007520 if (!rdev->ops->cancel_remain_on_channel)
7521 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007522
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007523 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7524
Hila Gonene35e4d22012-06-27 17:19:42 +03007525 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007526}
7527
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007528static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7529 u8 *rates, u8 rates_len)
7530{
7531 u8 i;
7532 u32 mask = 0;
7533
7534 for (i = 0; i < rates_len; i++) {
7535 int rate = (rates[i] & 0x7f) * 5;
7536 int ridx;
7537 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7538 struct ieee80211_rate *srate =
7539 &sband->bitrates[ridx];
7540 if (rate == srate->bitrate) {
7541 mask |= 1 << ridx;
7542 break;
7543 }
7544 }
7545 if (ridx == sband->n_bitrates)
7546 return 0; /* rate not found */
7547 }
7548
7549 return mask;
7550}
7551
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007552static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7553 u8 *rates, u8 rates_len,
7554 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7555{
7556 u8 i;
7557
7558 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7559
7560 for (i = 0; i < rates_len; i++) {
7561 int ridx, rbit;
7562
7563 ridx = rates[i] / 8;
7564 rbit = BIT(rates[i] % 8);
7565
7566 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007567 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007568 return false;
7569
7570 /* check availability */
7571 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7572 mcs[ridx] |= rbit;
7573 else
7574 return false;
7575 }
7576
7577 return true;
7578}
7579
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007580static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7581{
7582 u16 mcs_mask = 0;
7583
7584 switch (vht_mcs_map) {
7585 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7586 break;
7587 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7588 mcs_mask = 0x00FF;
7589 break;
7590 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7591 mcs_mask = 0x01FF;
7592 break;
7593 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7594 mcs_mask = 0x03FF;
7595 break;
7596 default:
7597 break;
7598 }
7599
7600 return mcs_mask;
7601}
7602
7603static void vht_build_mcs_mask(u16 vht_mcs_map,
7604 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7605{
7606 u8 nss;
7607
7608 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7609 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7610 vht_mcs_map >>= 2;
7611 }
7612}
7613
7614static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7615 struct nl80211_txrate_vht *txrate,
7616 u16 mcs[NL80211_VHT_NSS_MAX])
7617{
7618 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7619 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7620 u8 i;
7621
7622 if (!sband->vht_cap.vht_supported)
7623 return false;
7624
7625 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7626
7627 /* Build vht_mcs_mask from VHT capabilities */
7628 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7629
7630 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7631 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7632 mcs[i] = txrate->mcs[i];
7633 else
7634 return false;
7635 }
7636
7637 return true;
7638}
7639
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007640static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007641 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7642 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007643 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7644 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007645 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007646 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007647};
7648
7649static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7650 struct genl_info *info)
7651{
7652 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007654 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007655 int rem, i;
7656 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007657 struct nlattr *tx_rates;
7658 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007659 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007660
Johannes Berg4c476992010-10-04 21:36:35 +02007661 if (!rdev->ops->set_bitrate_mask)
7662 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007663
7664 memset(&mask, 0, sizeof(mask));
7665 /* Default to all rates enabled */
7666 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7667 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007668
7669 if (!sband)
7670 continue;
7671
7672 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007673 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007674 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007675 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007676
7677 if (!sband->vht_cap.vht_supported)
7678 continue;
7679
7680 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7681 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007682 }
7683
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007684 /* if no rates are given set it back to the defaults */
7685 if (!info->attrs[NL80211_ATTR_TX_RATES])
7686 goto out;
7687
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007688 /*
7689 * The nested attribute uses enum nl80211_band as the index. This maps
7690 * directly to the enum ieee80211_band values used in cfg80211.
7691 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007692 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007693 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007694 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007695 int err;
7696
Johannes Berg4c476992010-10-04 21:36:35 +02007697 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7698 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007699 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007700 if (sband == NULL)
7701 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007702 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7703 nla_len(tx_rates), nl80211_txattr_policy);
7704 if (err)
7705 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007706 if (tb[NL80211_TXRATE_LEGACY]) {
7707 mask.control[band].legacy = rateset_to_mask(
7708 sband,
7709 nla_data(tb[NL80211_TXRATE_LEGACY]),
7710 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307711 if ((mask.control[band].legacy == 0) &&
7712 nla_len(tb[NL80211_TXRATE_LEGACY]))
7713 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007714 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007715 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007716 if (!ht_rateset_to_mask(
7717 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007718 nla_data(tb[NL80211_TXRATE_HT]),
7719 nla_len(tb[NL80211_TXRATE_HT]),
7720 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007721 return -EINVAL;
7722 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007723 if (tb[NL80211_TXRATE_VHT]) {
7724 if (!vht_set_mcs_mask(
7725 sband,
7726 nla_data(tb[NL80211_TXRATE_VHT]),
7727 mask.control[band].vht_mcs))
7728 return -EINVAL;
7729 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007730 if (tb[NL80211_TXRATE_GI]) {
7731 mask.control[band].gi =
7732 nla_get_u8(tb[NL80211_TXRATE_GI]);
7733 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7734 return -EINVAL;
7735 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007736
7737 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007738 /* don't allow empty legacy rates if HT or VHT
7739 * are not even supported.
7740 */
7741 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7742 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007743 return -EINVAL;
7744
7745 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007746 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007747 goto out;
7748
7749 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7750 if (mask.control[band].vht_mcs[i])
7751 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007752
7753 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007754 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007755 }
7756 }
7757
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007758out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007759 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007760}
7761
Johannes Berg2e161f72010-08-12 15:38:38 +02007762static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007763{
Johannes Berg4c476992010-10-04 21:36:35 +02007764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007765 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007766 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007767
7768 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7769 return -EINVAL;
7770
Johannes Berg2e161f72010-08-12 15:38:38 +02007771 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7772 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007773
Johannes Berg71bbc992012-06-15 15:30:18 +02007774 switch (wdev->iftype) {
7775 case NL80211_IFTYPE_STATION:
7776 case NL80211_IFTYPE_ADHOC:
7777 case NL80211_IFTYPE_P2P_CLIENT:
7778 case NL80211_IFTYPE_AP:
7779 case NL80211_IFTYPE_AP_VLAN:
7780 case NL80211_IFTYPE_MESH_POINT:
7781 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007782 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007783 break;
7784 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007785 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007786 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007787
7788 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007789 if (!rdev->ops->mgmt_tx)
7790 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007791
Eric W. Biederman15e47302012-09-07 20:12:54 +00007792 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007793 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7794 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007795}
7796
Johannes Berg2e161f72010-08-12 15:38:38 +02007797static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007798{
Johannes Berg4c476992010-10-04 21:36:35 +02007799 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007800 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007801 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007802 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007803 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007804 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007805 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007806 struct cfg80211_mgmt_tx_params params = {
7807 .dont_wait_for_ack =
7808 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7809 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007810
Johannes Berg683b6d32012-11-08 21:25:48 +01007811 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007812 return -EINVAL;
7813
Johannes Berg4c476992010-10-04 21:36:35 +02007814 if (!rdev->ops->mgmt_tx)
7815 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007816
Johannes Berg71bbc992012-06-15 15:30:18 +02007817 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007818 case NL80211_IFTYPE_P2P_DEVICE:
7819 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7820 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007821 case NL80211_IFTYPE_STATION:
7822 case NL80211_IFTYPE_ADHOC:
7823 case NL80211_IFTYPE_P2P_CLIENT:
7824 case NL80211_IFTYPE_AP:
7825 case NL80211_IFTYPE_AP_VLAN:
7826 case NL80211_IFTYPE_MESH_POINT:
7827 case NL80211_IFTYPE_P2P_GO:
7828 break;
7829 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007830 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007831 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007832
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007833 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007834 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007835 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007836 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007837
7838 /*
7839 * We should wait on the channel for at least a minimum amount
7840 * of time (10ms) but no longer than the driver supports.
7841 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007842 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7843 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007844 return -EINVAL;
7845
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007846 }
7847
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007848 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007849
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007850 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007851 return -EINVAL;
7852
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007853 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307854
Antonio Quartulliea141b752013-06-11 14:20:03 +02007855 /* get the channel if any has been specified, otherwise pass NULL to
7856 * the driver. The latter will use the current one
7857 */
7858 chandef.chan = NULL;
7859 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7860 err = nl80211_parse_chandef(rdev, info, &chandef);
7861 if (err)
7862 return err;
7863 }
7864
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007865 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007866 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007867
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03007868 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7869 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7870
7871 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
7872 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7873 int i;
7874
7875 if (len % sizeof(u16))
7876 return -EINVAL;
7877
7878 params.n_csa_offsets = len / sizeof(u16);
7879 params.csa_offsets =
7880 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7881
7882 /* check that all the offsets fit the frame */
7883 for (i = 0; i < params.n_csa_offsets; i++) {
7884 if (params.csa_offsets[i] >= params.len)
7885 return -EINVAL;
7886 }
7887 }
7888
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007889 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007890 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7891 if (!msg)
7892 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007893
Eric W. Biederman15e47302012-09-07 20:12:54 +00007894 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007895 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007896 if (!hdr) {
7897 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007898 goto free_msg;
7899 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007900 }
Johannes Berge247bd902011-11-04 11:18:21 +01007901
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007902 params.chan = chandef.chan;
7903 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007904 if (err)
7905 goto free_msg;
7906
Johannes Berge247bd902011-11-04 11:18:21 +01007907 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007908 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7909 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007910
Johannes Berge247bd902011-11-04 11:18:21 +01007911 genlmsg_end(msg, hdr);
7912 return genlmsg_reply(msg, info);
7913 }
7914
7915 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007916
7917 nla_put_failure:
7918 err = -ENOBUFS;
7919 free_msg:
7920 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007921 return err;
7922}
7923
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007924static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7925{
7926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007927 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007928 u64 cookie;
7929
7930 if (!info->attrs[NL80211_ATTR_COOKIE])
7931 return -EINVAL;
7932
7933 if (!rdev->ops->mgmt_tx_cancel_wait)
7934 return -EOPNOTSUPP;
7935
Johannes Berg71bbc992012-06-15 15:30:18 +02007936 switch (wdev->iftype) {
7937 case NL80211_IFTYPE_STATION:
7938 case NL80211_IFTYPE_ADHOC:
7939 case NL80211_IFTYPE_P2P_CLIENT:
7940 case NL80211_IFTYPE_AP:
7941 case NL80211_IFTYPE_AP_VLAN:
7942 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007943 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007944 break;
7945 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007946 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007947 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007948
7949 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7950
Hila Gonene35e4d22012-06-27 17:19:42 +03007951 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007952}
7953
Kalle Valoffb9eb32010-02-17 17:58:10 +02007954static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7955{
Johannes Berg4c476992010-10-04 21:36:35 +02007956 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007957 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007958 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007959 u8 ps_state;
7960 bool state;
7961 int err;
7962
Johannes Berg4c476992010-10-04 21:36:35 +02007963 if (!info->attrs[NL80211_ATTR_PS_STATE])
7964 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007965
7966 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7967
Johannes Berg4c476992010-10-04 21:36:35 +02007968 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7969 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007970
7971 wdev = dev->ieee80211_ptr;
7972
Johannes Berg4c476992010-10-04 21:36:35 +02007973 if (!rdev->ops->set_power_mgmt)
7974 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007975
7976 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7977
7978 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007979 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007980
Hila Gonene35e4d22012-06-27 17:19:42 +03007981 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007982 if (!err)
7983 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007984 return err;
7985}
7986
7987static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7988{
Johannes Berg4c476992010-10-04 21:36:35 +02007989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007990 enum nl80211_ps_state ps_state;
7991 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007992 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007993 struct sk_buff *msg;
7994 void *hdr;
7995 int err;
7996
Kalle Valoffb9eb32010-02-17 17:58:10 +02007997 wdev = dev->ieee80211_ptr;
7998
Johannes Berg4c476992010-10-04 21:36:35 +02007999 if (!rdev->ops->set_power_mgmt)
8000 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008001
8002 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008003 if (!msg)
8004 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008005
Eric W. Biederman15e47302012-09-07 20:12:54 +00008006 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008007 NL80211_CMD_GET_POWER_SAVE);
8008 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008009 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008010 goto free_msg;
8011 }
8012
8013 if (wdev->ps)
8014 ps_state = NL80211_PS_ENABLED;
8015 else
8016 ps_state = NL80211_PS_DISABLED;
8017
David S. Miller9360ffd2012-03-29 04:41:26 -04008018 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8019 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008020
8021 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008022 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008023
Johannes Berg4c476992010-10-04 21:36:35 +02008024 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008025 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008026 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008027 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008028 return err;
8029}
8030
Johannes Berg94e860f2014-01-20 23:58:15 +01008031static const struct nla_policy
8032nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008033 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8034 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8035 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008036 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8037 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8038 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008039};
8040
Thomas Pedersen84f10702012-07-12 16:17:33 -07008041static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008042 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008043{
8044 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008045 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008046 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008047
Johannes Bergd9d8b012012-11-26 12:51:52 +01008048 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008049 return -EINVAL;
8050
Thomas Pedersen84f10702012-07-12 16:17:33 -07008051 if (!rdev->ops->set_cqm_txe_config)
8052 return -EOPNOTSUPP;
8053
8054 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8055 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8056 return -EOPNOTSUPP;
8057
Hila Gonene35e4d22012-06-27 17:19:42 +03008058 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008059}
8060
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008061static int nl80211_set_cqm_rssi(struct genl_info *info,
8062 s32 threshold, u32 hysteresis)
8063{
Johannes Berg4c476992010-10-04 21:36:35 +02008064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008065 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008066 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008067
8068 if (threshold > 0)
8069 return -EINVAL;
8070
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008071 /* disabling - hysteresis should also be zero then */
8072 if (threshold == 0)
8073 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008074
Johannes Berg4c476992010-10-04 21:36:35 +02008075 if (!rdev->ops->set_cqm_rssi_config)
8076 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008077
Johannes Berg074ac8d2010-09-16 14:58:22 +02008078 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008079 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8080 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008081
Hila Gonene35e4d22012-06-27 17:19:42 +03008082 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008083}
8084
8085static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8086{
8087 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8088 struct nlattr *cqm;
8089 int err;
8090
8091 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008092 if (!cqm)
8093 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008094
8095 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8096 nl80211_attr_cqm_policy);
8097 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008098 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008099
8100 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8101 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008102 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8103 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008104
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008105 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8106 }
8107
8108 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8109 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8110 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8111 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8112 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8113 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8114
8115 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8116 }
8117
8118 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008119}
8120
Johannes Berg29cbe682010-12-03 09:20:44 +01008121static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8122{
8123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8124 struct net_device *dev = info->user_ptr[1];
8125 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008126 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008127 int err;
8128
8129 /* start with default */
8130 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008131 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008132
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008133 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008134 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008135 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008136 if (err)
8137 return err;
8138 }
8139
8140 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8141 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8142 return -EINVAL;
8143
Javier Cardonac80d5452010-12-16 17:37:49 -08008144 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8145 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8146
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008147 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8148 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8149 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8150 return -EINVAL;
8151
Marco Porsch9bdbf042013-01-07 16:04:51 +01008152 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8153 setup.beacon_interval =
8154 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8155 if (setup.beacon_interval < 10 ||
8156 setup.beacon_interval > 10000)
8157 return -EINVAL;
8158 }
8159
8160 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8161 setup.dtim_period =
8162 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8163 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8164 return -EINVAL;
8165 }
8166
Javier Cardonac80d5452010-12-16 17:37:49 -08008167 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8168 /* parse additional setup parameters if given */
8169 err = nl80211_parse_mesh_setup(info, &setup);
8170 if (err)
8171 return err;
8172 }
8173
Thomas Pedersend37bb182013-03-04 13:06:13 -08008174 if (setup.user_mpm)
8175 cfg.auto_open_plinks = false;
8176
Johannes Bergcc1d2802012-05-16 23:50:20 +02008177 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008178 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8179 if (err)
8180 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008181 } else {
8182 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008183 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008184 }
8185
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008186 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8187 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8188 int n_rates =
8189 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8190 struct ieee80211_supported_band *sband;
8191
8192 if (!setup.chandef.chan)
8193 return -EINVAL;
8194
8195 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8196
8197 err = ieee80211_get_ratemask(sband, rates, n_rates,
8198 &setup.basic_rates);
8199 if (err)
8200 return err;
8201 }
8202
Javier Cardonac80d5452010-12-16 17:37:49 -08008203 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008204}
8205
8206static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8207{
8208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8209 struct net_device *dev = info->user_ptr[1];
8210
8211 return cfg80211_leave_mesh(rdev, dev);
8212}
8213
Johannes Bergdfb89c52012-06-27 09:23:48 +02008214#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008215static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8216 struct cfg80211_registered_device *rdev)
8217{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008218 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008219 struct nlattr *nl_pats, *nl_pat;
8220 int i, pat_len;
8221
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008222 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008223 return 0;
8224
8225 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8226 if (!nl_pats)
8227 return -ENOBUFS;
8228
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008229 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008230 nl_pat = nla_nest_start(msg, i + 1);
8231 if (!nl_pat)
8232 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008233 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008234 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008235 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008236 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8237 wowlan->patterns[i].pattern) ||
8238 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008239 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008240 return -ENOBUFS;
8241 nla_nest_end(msg, nl_pat);
8242 }
8243 nla_nest_end(msg, nl_pats);
8244
8245 return 0;
8246}
8247
Johannes Berg2a0e0472013-01-23 22:57:40 +01008248static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8249 struct cfg80211_wowlan_tcp *tcp)
8250{
8251 struct nlattr *nl_tcp;
8252
8253 if (!tcp)
8254 return 0;
8255
8256 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8257 if (!nl_tcp)
8258 return -ENOBUFS;
8259
8260 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8261 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8262 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8263 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8264 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8265 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8266 tcp->payload_len, tcp->payload) ||
8267 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8268 tcp->data_interval) ||
8269 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8270 tcp->wake_len, tcp->wake_data) ||
8271 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8272 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8273 return -ENOBUFS;
8274
8275 if (tcp->payload_seq.len &&
8276 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8277 sizeof(tcp->payload_seq), &tcp->payload_seq))
8278 return -ENOBUFS;
8279
8280 if (tcp->payload_tok.len &&
8281 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8282 sizeof(tcp->payload_tok) + tcp->tokens_size,
8283 &tcp->payload_tok))
8284 return -ENOBUFS;
8285
Johannes Berge248ad32013-05-16 10:24:28 +02008286 nla_nest_end(msg, nl_tcp);
8287
Johannes Berg2a0e0472013-01-23 22:57:40 +01008288 return 0;
8289}
8290
Johannes Bergff1b6e62011-05-04 15:37:28 +02008291static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8292{
8293 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8294 struct sk_buff *msg;
8295 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008296 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008297
Johannes Berg964dc9e2013-06-03 17:25:34 +02008298 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008299 return -EOPNOTSUPP;
8300
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008301 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008302 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008303 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8304 rdev->wiphy.wowlan_config->tcp->payload_len +
8305 rdev->wiphy.wowlan_config->tcp->wake_len +
8306 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008307 }
8308
8309 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008310 if (!msg)
8311 return -ENOMEM;
8312
Eric W. Biederman15e47302012-09-07 20:12:54 +00008313 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008314 NL80211_CMD_GET_WOWLAN);
8315 if (!hdr)
8316 goto nla_put_failure;
8317
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008318 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008319 struct nlattr *nl_wowlan;
8320
8321 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8322 if (!nl_wowlan)
8323 goto nla_put_failure;
8324
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008325 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008326 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008327 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008328 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008329 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008330 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008331 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008332 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008333 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008334 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008335 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008336 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008337 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008338 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8339 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008340
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008341 if (nl80211_send_wowlan_patterns(msg, rdev))
8342 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008343
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008344 if (nl80211_send_wowlan_tcp(msg,
8345 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008346 goto nla_put_failure;
8347
Johannes Bergff1b6e62011-05-04 15:37:28 +02008348 nla_nest_end(msg, nl_wowlan);
8349 }
8350
8351 genlmsg_end(msg, hdr);
8352 return genlmsg_reply(msg, info);
8353
8354nla_put_failure:
8355 nlmsg_free(msg);
8356 return -ENOBUFS;
8357}
8358
Johannes Berg2a0e0472013-01-23 22:57:40 +01008359static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8360 struct nlattr *attr,
8361 struct cfg80211_wowlan *trig)
8362{
8363 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8364 struct cfg80211_wowlan_tcp *cfg;
8365 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8366 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8367 u32 size;
8368 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8369 int err, port;
8370
Johannes Berg964dc9e2013-06-03 17:25:34 +02008371 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008372 return -EINVAL;
8373
8374 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8375 nla_data(attr), nla_len(attr),
8376 nl80211_wowlan_tcp_policy);
8377 if (err)
8378 return err;
8379
8380 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8381 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8382 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8383 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8384 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8385 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8386 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8387 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8388 return -EINVAL;
8389
8390 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008391 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008392 return -EINVAL;
8393
8394 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008395 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008396 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008397 return -EINVAL;
8398
8399 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008400 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008401 return -EINVAL;
8402
8403 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8404 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8405 return -EINVAL;
8406
8407 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8408 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8409
8410 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8411 tokens_size = tokln - sizeof(*tok);
8412
8413 if (!tok->len || tokens_size % tok->len)
8414 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008415 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008416 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008417 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008418 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008419 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008420 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008421 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008422 return -EINVAL;
8423 if (tok->offset + tok->len > data_size)
8424 return -EINVAL;
8425 }
8426
8427 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8428 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008429 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008430 return -EINVAL;
8431 if (seq->len == 0 || seq->len > 4)
8432 return -EINVAL;
8433 if (seq->len + seq->offset > data_size)
8434 return -EINVAL;
8435 }
8436
8437 size = sizeof(*cfg);
8438 size += data_size;
8439 size += wake_size + wake_mask_size;
8440 size += tokens_size;
8441
8442 cfg = kzalloc(size, GFP_KERNEL);
8443 if (!cfg)
8444 return -ENOMEM;
8445 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8446 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8447 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8448 ETH_ALEN);
8449 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8450 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8451 else
8452 port = 0;
8453#ifdef CONFIG_INET
8454 /* allocate a socket and port for it and use it */
8455 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8456 IPPROTO_TCP, &cfg->sock, 1);
8457 if (err) {
8458 kfree(cfg);
8459 return err;
8460 }
8461 if (inet_csk_get_port(cfg->sock->sk, port)) {
8462 sock_release(cfg->sock);
8463 kfree(cfg);
8464 return -EADDRINUSE;
8465 }
8466 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8467#else
8468 if (!port) {
8469 kfree(cfg);
8470 return -EINVAL;
8471 }
8472 cfg->src_port = port;
8473#endif
8474
8475 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8476 cfg->payload_len = data_size;
8477 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8478 memcpy((void *)cfg->payload,
8479 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8480 data_size);
8481 if (seq)
8482 cfg->payload_seq = *seq;
8483 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8484 cfg->wake_len = wake_size;
8485 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8486 memcpy((void *)cfg->wake_data,
8487 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8488 wake_size);
8489 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8490 data_size + wake_size;
8491 memcpy((void *)cfg->wake_mask,
8492 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8493 wake_mask_size);
8494 if (tok) {
8495 cfg->tokens_size = tokens_size;
8496 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8497 }
8498
8499 trig->tcp = cfg;
8500
8501 return 0;
8502}
8503
Johannes Bergff1b6e62011-05-04 15:37:28 +02008504static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8505{
8506 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8507 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008508 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008509 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008510 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008511 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008512 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008513
Johannes Berg964dc9e2013-06-03 17:25:34 +02008514 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008515 return -EOPNOTSUPP;
8516
Johannes Bergae33bd82012-07-12 16:25:02 +02008517 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8518 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008519 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008520 goto set_wakeup;
8521 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008522
8523 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8524 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8525 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8526 nl80211_wowlan_policy);
8527 if (err)
8528 return err;
8529
8530 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8531 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8532 return -EINVAL;
8533 new_triggers.any = true;
8534 }
8535
8536 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8537 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8538 return -EINVAL;
8539 new_triggers.disconnect = true;
8540 }
8541
8542 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8543 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8544 return -EINVAL;
8545 new_triggers.magic_pkt = true;
8546 }
8547
Johannes Berg77dbbb12011-07-13 10:48:55 +02008548 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8549 return -EINVAL;
8550
8551 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8552 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8553 return -EINVAL;
8554 new_triggers.gtk_rekey_failure = true;
8555 }
8556
8557 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8558 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8559 return -EINVAL;
8560 new_triggers.eap_identity_req = true;
8561 }
8562
8563 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8564 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8565 return -EINVAL;
8566 new_triggers.four_way_handshake = true;
8567 }
8568
8569 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8570 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8571 return -EINVAL;
8572 new_triggers.rfkill_release = true;
8573 }
8574
Johannes Bergff1b6e62011-05-04 15:37:28 +02008575 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8576 struct nlattr *pat;
8577 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008578 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008579 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008580
8581 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8582 rem)
8583 n_patterns++;
8584 if (n_patterns > wowlan->n_patterns)
8585 return -EINVAL;
8586
8587 new_triggers.patterns = kcalloc(n_patterns,
8588 sizeof(new_triggers.patterns[0]),
8589 GFP_KERNEL);
8590 if (!new_triggers.patterns)
8591 return -ENOMEM;
8592
8593 new_triggers.n_patterns = n_patterns;
8594 i = 0;
8595
8596 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8597 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008598 u8 *mask_pat;
8599
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008600 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8601 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008602 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008603 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8604 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008605 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008606 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008607 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008608 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008609 goto error;
8610 if (pat_len > wowlan->pattern_max_len ||
8611 pat_len < wowlan->pattern_min_len)
8612 goto error;
8613
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008614 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008615 pkt_offset = 0;
8616 else
8617 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008618 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008619 if (pkt_offset > wowlan->max_pkt_offset)
8620 goto error;
8621 new_triggers.patterns[i].pkt_offset = pkt_offset;
8622
Johannes Berg922bd802014-05-19 17:59:50 +02008623 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8624 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008625 err = -ENOMEM;
8626 goto error;
8627 }
Johannes Berg922bd802014-05-19 17:59:50 +02008628 new_triggers.patterns[i].mask = mask_pat;
8629 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008630 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008631 mask_pat += mask_len;
8632 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008633 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008634 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008635 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008636 pat_len);
8637 i++;
8638 }
8639 }
8640
Johannes Berg2a0e0472013-01-23 22:57:40 +01008641 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8642 err = nl80211_parse_wowlan_tcp(
8643 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8644 &new_triggers);
8645 if (err)
8646 goto error;
8647 }
8648
Johannes Bergae33bd82012-07-12 16:25:02 +02008649 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8650 if (!ntrig) {
8651 err = -ENOMEM;
8652 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008653 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008654 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008655 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008656
Johannes Bergae33bd82012-07-12 16:25:02 +02008657 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008658 if (rdev->ops->set_wakeup &&
8659 prev_enabled != !!rdev->wiphy.wowlan_config)
8660 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008661
Johannes Bergff1b6e62011-05-04 15:37:28 +02008662 return 0;
8663 error:
8664 for (i = 0; i < new_triggers.n_patterns; i++)
8665 kfree(new_triggers.patterns[i].mask);
8666 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008667 if (new_triggers.tcp && new_triggers.tcp->sock)
8668 sock_release(new_triggers.tcp->sock);
8669 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008670 return err;
8671}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008672#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008673
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008674static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8675 struct cfg80211_registered_device *rdev)
8676{
8677 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8678 int i, j, pat_len;
8679 struct cfg80211_coalesce_rules *rule;
8680
8681 if (!rdev->coalesce->n_rules)
8682 return 0;
8683
8684 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8685 if (!nl_rules)
8686 return -ENOBUFS;
8687
8688 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8689 nl_rule = nla_nest_start(msg, i + 1);
8690 if (!nl_rule)
8691 return -ENOBUFS;
8692
8693 rule = &rdev->coalesce->rules[i];
8694 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8695 rule->delay))
8696 return -ENOBUFS;
8697
8698 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8699 rule->condition))
8700 return -ENOBUFS;
8701
8702 nl_pats = nla_nest_start(msg,
8703 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8704 if (!nl_pats)
8705 return -ENOBUFS;
8706
8707 for (j = 0; j < rule->n_patterns; j++) {
8708 nl_pat = nla_nest_start(msg, j + 1);
8709 if (!nl_pat)
8710 return -ENOBUFS;
8711 pat_len = rule->patterns[j].pattern_len;
8712 if (nla_put(msg, NL80211_PKTPAT_MASK,
8713 DIV_ROUND_UP(pat_len, 8),
8714 rule->patterns[j].mask) ||
8715 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8716 rule->patterns[j].pattern) ||
8717 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8718 rule->patterns[j].pkt_offset))
8719 return -ENOBUFS;
8720 nla_nest_end(msg, nl_pat);
8721 }
8722 nla_nest_end(msg, nl_pats);
8723 nla_nest_end(msg, nl_rule);
8724 }
8725 nla_nest_end(msg, nl_rules);
8726
8727 return 0;
8728}
8729
8730static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8731{
8732 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8733 struct sk_buff *msg;
8734 void *hdr;
8735
8736 if (!rdev->wiphy.coalesce)
8737 return -EOPNOTSUPP;
8738
8739 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8740 if (!msg)
8741 return -ENOMEM;
8742
8743 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8744 NL80211_CMD_GET_COALESCE);
8745 if (!hdr)
8746 goto nla_put_failure;
8747
8748 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8749 goto nla_put_failure;
8750
8751 genlmsg_end(msg, hdr);
8752 return genlmsg_reply(msg, info);
8753
8754nla_put_failure:
8755 nlmsg_free(msg);
8756 return -ENOBUFS;
8757}
8758
8759void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8760{
8761 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8762 int i, j;
8763 struct cfg80211_coalesce_rules *rule;
8764
8765 if (!coalesce)
8766 return;
8767
8768 for (i = 0; i < coalesce->n_rules; i++) {
8769 rule = &coalesce->rules[i];
8770 for (j = 0; j < rule->n_patterns; j++)
8771 kfree(rule->patterns[j].mask);
8772 kfree(rule->patterns);
8773 }
8774 kfree(coalesce->rules);
8775 kfree(coalesce);
8776 rdev->coalesce = NULL;
8777}
8778
8779static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8780 struct nlattr *rule,
8781 struct cfg80211_coalesce_rules *new_rule)
8782{
8783 int err, i;
8784 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8785 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8786 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8787 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8788
8789 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8790 nla_len(rule), nl80211_coalesce_policy);
8791 if (err)
8792 return err;
8793
8794 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8795 new_rule->delay =
8796 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8797 if (new_rule->delay > coalesce->max_delay)
8798 return -EINVAL;
8799
8800 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8801 new_rule->condition =
8802 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8803 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8804 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8805 return -EINVAL;
8806
8807 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8808 return -EINVAL;
8809
8810 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8811 rem)
8812 n_patterns++;
8813 if (n_patterns > coalesce->n_patterns)
8814 return -EINVAL;
8815
8816 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8817 GFP_KERNEL);
8818 if (!new_rule->patterns)
8819 return -ENOMEM;
8820
8821 new_rule->n_patterns = n_patterns;
8822 i = 0;
8823
8824 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8825 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008826 u8 *mask_pat;
8827
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008828 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8829 nla_len(pat), NULL);
8830 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8831 !pat_tb[NL80211_PKTPAT_PATTERN])
8832 return -EINVAL;
8833 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8834 mask_len = DIV_ROUND_UP(pat_len, 8);
8835 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8836 return -EINVAL;
8837 if (pat_len > coalesce->pattern_max_len ||
8838 pat_len < coalesce->pattern_min_len)
8839 return -EINVAL;
8840
8841 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8842 pkt_offset = 0;
8843 else
8844 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8845 if (pkt_offset > coalesce->max_pkt_offset)
8846 return -EINVAL;
8847 new_rule->patterns[i].pkt_offset = pkt_offset;
8848
Johannes Berg922bd802014-05-19 17:59:50 +02008849 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8850 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008851 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02008852
8853 new_rule->patterns[i].mask = mask_pat;
8854 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8855 mask_len);
8856
8857 mask_pat += mask_len;
8858 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008859 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008860 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8861 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008862 i++;
8863 }
8864
8865 return 0;
8866}
8867
8868static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8869{
8870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8871 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8872 struct cfg80211_coalesce new_coalesce = {};
8873 struct cfg80211_coalesce *n_coalesce;
8874 int err, rem_rule, n_rules = 0, i, j;
8875 struct nlattr *rule;
8876 struct cfg80211_coalesce_rules *tmp_rule;
8877
8878 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8879 return -EOPNOTSUPP;
8880
8881 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8882 cfg80211_rdev_free_coalesce(rdev);
8883 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8884 return 0;
8885 }
8886
8887 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8888 rem_rule)
8889 n_rules++;
8890 if (n_rules > coalesce->n_rules)
8891 return -EINVAL;
8892
8893 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8894 GFP_KERNEL);
8895 if (!new_coalesce.rules)
8896 return -ENOMEM;
8897
8898 new_coalesce.n_rules = n_rules;
8899 i = 0;
8900
8901 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8902 rem_rule) {
8903 err = nl80211_parse_coalesce_rule(rdev, rule,
8904 &new_coalesce.rules[i]);
8905 if (err)
8906 goto error;
8907
8908 i++;
8909 }
8910
8911 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8912 if (err)
8913 goto error;
8914
8915 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8916 if (!n_coalesce) {
8917 err = -ENOMEM;
8918 goto error;
8919 }
8920 cfg80211_rdev_free_coalesce(rdev);
8921 rdev->coalesce = n_coalesce;
8922
8923 return 0;
8924error:
8925 for (i = 0; i < new_coalesce.n_rules; i++) {
8926 tmp_rule = &new_coalesce.rules[i];
8927 for (j = 0; j < tmp_rule->n_patterns; j++)
8928 kfree(tmp_rule->patterns[j].mask);
8929 kfree(tmp_rule->patterns);
8930 }
8931 kfree(new_coalesce.rules);
8932
8933 return err;
8934}
8935
Johannes Berge5497d72011-07-05 16:35:40 +02008936static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8937{
8938 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8939 struct net_device *dev = info->user_ptr[1];
8940 struct wireless_dev *wdev = dev->ieee80211_ptr;
8941 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8942 struct cfg80211_gtk_rekey_data rekey_data;
8943 int err;
8944
8945 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8946 return -EINVAL;
8947
8948 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8949 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8950 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8951 nl80211_rekey_policy);
8952 if (err)
8953 return err;
8954
8955 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8956 return -ERANGE;
8957 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8958 return -ERANGE;
8959 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8960 return -ERANGE;
8961
8962 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8963 NL80211_KEK_LEN);
8964 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8965 NL80211_KCK_LEN);
8966 memcpy(rekey_data.replay_ctr,
8967 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8968 NL80211_REPLAY_CTR_LEN);
8969
8970 wdev_lock(wdev);
8971 if (!wdev->current_bss) {
8972 err = -ENOTCONN;
8973 goto out;
8974 }
8975
8976 if (!rdev->ops->set_rekey_data) {
8977 err = -EOPNOTSUPP;
8978 goto out;
8979 }
8980
Hila Gonene35e4d22012-06-27 17:19:42 +03008981 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008982 out:
8983 wdev_unlock(wdev);
8984 return err;
8985}
8986
Johannes Berg28946da2011-11-04 11:18:12 +01008987static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8988 struct genl_info *info)
8989{
8990 struct net_device *dev = info->user_ptr[1];
8991 struct wireless_dev *wdev = dev->ieee80211_ptr;
8992
8993 if (wdev->iftype != NL80211_IFTYPE_AP &&
8994 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8995 return -EINVAL;
8996
Eric W. Biederman15e47302012-09-07 20:12:54 +00008997 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008998 return -EBUSY;
8999
Eric W. Biederman15e47302012-09-07 20:12:54 +00009000 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009001 return 0;
9002}
9003
Johannes Berg7f6cf312011-11-04 11:18:15 +01009004static int nl80211_probe_client(struct sk_buff *skb,
9005 struct genl_info *info)
9006{
9007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9008 struct net_device *dev = info->user_ptr[1];
9009 struct wireless_dev *wdev = dev->ieee80211_ptr;
9010 struct sk_buff *msg;
9011 void *hdr;
9012 const u8 *addr;
9013 u64 cookie;
9014 int err;
9015
9016 if (wdev->iftype != NL80211_IFTYPE_AP &&
9017 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9018 return -EOPNOTSUPP;
9019
9020 if (!info->attrs[NL80211_ATTR_MAC])
9021 return -EINVAL;
9022
9023 if (!rdev->ops->probe_client)
9024 return -EOPNOTSUPP;
9025
9026 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9027 if (!msg)
9028 return -ENOMEM;
9029
Eric W. Biederman15e47302012-09-07 20:12:54 +00009030 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009031 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009032 if (!hdr) {
9033 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009034 goto free_msg;
9035 }
9036
9037 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9038
Hila Gonene35e4d22012-06-27 17:19:42 +03009039 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009040 if (err)
9041 goto free_msg;
9042
David S. Miller9360ffd2012-03-29 04:41:26 -04009043 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9044 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009045
9046 genlmsg_end(msg, hdr);
9047
9048 return genlmsg_reply(msg, info);
9049
9050 nla_put_failure:
9051 err = -ENOBUFS;
9052 free_msg:
9053 nlmsg_free(msg);
9054 return err;
9055}
9056
Johannes Berg5e7602302011-11-04 11:18:17 +01009057static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9058{
9059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009060 struct cfg80211_beacon_registration *reg, *nreg;
9061 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009062
9063 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9064 return -EOPNOTSUPP;
9065
Ben Greear37c73b52012-10-26 14:49:25 -07009066 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9067 if (!nreg)
9068 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01009069
Ben Greear37c73b52012-10-26 14:49:25 -07009070 /* First, check if already registered. */
9071 spin_lock_bh(&rdev->beacon_registrations_lock);
9072 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9073 if (reg->nlportid == info->snd_portid) {
9074 rv = -EALREADY;
9075 goto out_err;
9076 }
9077 }
9078 /* Add it to the list */
9079 nreg->nlportid = info->snd_portid;
9080 list_add(&nreg->list, &rdev->beacon_registrations);
9081
9082 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01009083
9084 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009085out_err:
9086 spin_unlock_bh(&rdev->beacon_registrations_lock);
9087 kfree(nreg);
9088 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009089}
9090
Johannes Berg98104fde2012-06-16 00:19:54 +02009091static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9092{
9093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9094 struct wireless_dev *wdev = info->user_ptr[1];
9095 int err;
9096
9097 if (!rdev->ops->start_p2p_device)
9098 return -EOPNOTSUPP;
9099
9100 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9101 return -EOPNOTSUPP;
9102
9103 if (wdev->p2p_started)
9104 return 0;
9105
Luciano Coelhob6a55012014-02-27 11:07:21 +02009106 if (rfkill_blocked(rdev->rfkill))
9107 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009108
Johannes Bergeeb126e2012-10-23 15:16:50 +02009109 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009110 if (err)
9111 return err;
9112
9113 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009114 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009115
9116 return 0;
9117}
9118
9119static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9120{
9121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9122 struct wireless_dev *wdev = info->user_ptr[1];
9123
9124 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9125 return -EOPNOTSUPP;
9126
9127 if (!rdev->ops->stop_p2p_device)
9128 return -EOPNOTSUPP;
9129
Johannes Bergf9f47522013-03-19 15:04:07 +01009130 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009131
9132 return 0;
9133}
9134
Johannes Berg3713b4e2013-02-14 16:19:38 +01009135static int nl80211_get_protocol_features(struct sk_buff *skb,
9136 struct genl_info *info)
9137{
9138 void *hdr;
9139 struct sk_buff *msg;
9140
9141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9142 if (!msg)
9143 return -ENOMEM;
9144
9145 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9146 NL80211_CMD_GET_PROTOCOL_FEATURES);
9147 if (!hdr)
9148 goto nla_put_failure;
9149
9150 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9151 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9152 goto nla_put_failure;
9153
9154 genlmsg_end(msg, hdr);
9155 return genlmsg_reply(msg, info);
9156
9157 nla_put_failure:
9158 kfree_skb(msg);
9159 return -ENOBUFS;
9160}
9161
Jouni Malinen355199e2013-02-27 17:14:27 +02009162static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9163{
9164 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9165 struct cfg80211_update_ft_ies_params ft_params;
9166 struct net_device *dev = info->user_ptr[1];
9167
9168 if (!rdev->ops->update_ft_ies)
9169 return -EOPNOTSUPP;
9170
9171 if (!info->attrs[NL80211_ATTR_MDID] ||
9172 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9173 return -EINVAL;
9174
9175 memset(&ft_params, 0, sizeof(ft_params));
9176 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9177 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9178 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9179
9180 return rdev_update_ft_ies(rdev, dev, &ft_params);
9181}
9182
Arend van Spriel5de17982013-04-18 15:49:00 +02009183static int nl80211_crit_protocol_start(struct sk_buff *skb,
9184 struct genl_info *info)
9185{
9186 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9187 struct wireless_dev *wdev = info->user_ptr[1];
9188 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9189 u16 duration;
9190 int ret;
9191
9192 if (!rdev->ops->crit_proto_start)
9193 return -EOPNOTSUPP;
9194
9195 if (WARN_ON(!rdev->ops->crit_proto_stop))
9196 return -EINVAL;
9197
9198 if (rdev->crit_proto_nlportid)
9199 return -EBUSY;
9200
9201 /* determine protocol if provided */
9202 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9203 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9204
9205 if (proto >= NUM_NL80211_CRIT_PROTO)
9206 return -EINVAL;
9207
9208 /* timeout must be provided */
9209 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9210 return -EINVAL;
9211
9212 duration =
9213 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9214
9215 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9216 return -ERANGE;
9217
9218 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9219 if (!ret)
9220 rdev->crit_proto_nlportid = info->snd_portid;
9221
9222 return ret;
9223}
9224
9225static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9226 struct genl_info *info)
9227{
9228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9229 struct wireless_dev *wdev = info->user_ptr[1];
9230
9231 if (!rdev->ops->crit_proto_stop)
9232 return -EOPNOTSUPP;
9233
9234 if (rdev->crit_proto_nlportid) {
9235 rdev->crit_proto_nlportid = 0;
9236 rdev_crit_proto_stop(rdev, wdev);
9237 }
9238 return 0;
9239}
9240
Johannes Bergad7e7182013-11-13 13:37:47 +01009241static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9242{
9243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9244 struct wireless_dev *wdev =
9245 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9246 int i, err;
9247 u32 vid, subcmd;
9248
9249 if (!rdev->wiphy.vendor_commands)
9250 return -EOPNOTSUPP;
9251
9252 if (IS_ERR(wdev)) {
9253 err = PTR_ERR(wdev);
9254 if (err != -EINVAL)
9255 return err;
9256 wdev = NULL;
9257 } else if (wdev->wiphy != &rdev->wiphy) {
9258 return -EINVAL;
9259 }
9260
9261 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9262 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9263 return -EINVAL;
9264
9265 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9266 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9267 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9268 const struct wiphy_vendor_command *vcmd;
9269 void *data = NULL;
9270 int len = 0;
9271
9272 vcmd = &rdev->wiphy.vendor_commands[i];
9273
9274 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9275 continue;
9276
9277 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9278 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9279 if (!wdev)
9280 return -EINVAL;
9281 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9282 !wdev->netdev)
9283 return -EINVAL;
9284
9285 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9286 if (wdev->netdev &&
9287 !netif_running(wdev->netdev))
9288 return -ENETDOWN;
9289 if (!wdev->netdev && !wdev->p2p_started)
9290 return -ENETDOWN;
9291 }
9292 } else {
9293 wdev = NULL;
9294 }
9295
9296 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9297 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9298 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9299 }
9300
9301 rdev->cur_cmd_info = info;
9302 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9303 data, len);
9304 rdev->cur_cmd_info = NULL;
9305 return err;
9306 }
9307
9308 return -EOPNOTSUPP;
9309}
9310
9311struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9312 enum nl80211_commands cmd,
9313 enum nl80211_attrs attr,
9314 int approxlen)
9315{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009316 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009317
9318 if (WARN_ON(!rdev->cur_cmd_info))
9319 return NULL;
9320
9321 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9322 rdev->cur_cmd_info->snd_portid,
9323 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009324 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009325}
9326EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9327
9328int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9329{
9330 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9331 void *hdr = ((void **)skb->cb)[1];
9332 struct nlattr *data = ((void **)skb->cb)[2];
9333
9334 if (WARN_ON(!rdev->cur_cmd_info)) {
9335 kfree_skb(skb);
9336 return -EINVAL;
9337 }
9338
9339 nla_nest_end(skb, data);
9340 genlmsg_end(skb, hdr);
9341 return genlmsg_reply(skb, rdev->cur_cmd_info);
9342}
9343EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9344
9345
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009346static int nl80211_set_qos_map(struct sk_buff *skb,
9347 struct genl_info *info)
9348{
9349 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9350 struct cfg80211_qos_map *qos_map = NULL;
9351 struct net_device *dev = info->user_ptr[1];
9352 u8 *pos, len, num_des, des_len, des;
9353 int ret;
9354
9355 if (!rdev->ops->set_qos_map)
9356 return -EOPNOTSUPP;
9357
9358 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9359 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9360 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9361
9362 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9363 len > IEEE80211_QOS_MAP_LEN_MAX)
9364 return -EINVAL;
9365
9366 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9367 if (!qos_map)
9368 return -ENOMEM;
9369
9370 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9371 if (num_des) {
9372 des_len = num_des *
9373 sizeof(struct cfg80211_dscp_exception);
9374 memcpy(qos_map->dscp_exception, pos, des_len);
9375 qos_map->num_des = num_des;
9376 for (des = 0; des < num_des; des++) {
9377 if (qos_map->dscp_exception[des].up > 7) {
9378 kfree(qos_map);
9379 return -EINVAL;
9380 }
9381 }
9382 pos += des_len;
9383 }
9384 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9385 }
9386
9387 wdev_lock(dev->ieee80211_ptr);
9388 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9389 if (!ret)
9390 ret = rdev_set_qos_map(rdev, dev, qos_map);
9391 wdev_unlock(dev->ieee80211_ptr);
9392
9393 kfree(qos_map);
9394 return ret;
9395}
9396
Johannes Berg4c476992010-10-04 21:36:35 +02009397#define NL80211_FLAG_NEED_WIPHY 0x01
9398#define NL80211_FLAG_NEED_NETDEV 0x02
9399#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009400#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9401#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9402 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009403#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009404/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009405#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9406 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009407
Johannes Bergf84f7712013-11-14 17:14:45 +01009408static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009409 struct genl_info *info)
9410{
9411 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009412 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009413 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009414 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9415
9416 if (rtnl)
9417 rtnl_lock();
9418
9419 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009420 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009421 if (IS_ERR(rdev)) {
9422 if (rtnl)
9423 rtnl_unlock();
9424 return PTR_ERR(rdev);
9425 }
9426 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009427 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9428 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009429 ASSERT_RTNL();
9430
Johannes Berg89a54e42012-06-15 14:33:17 +02009431 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9432 info->attrs);
9433 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009434 if (rtnl)
9435 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009436 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009437 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009438
Johannes Berg89a54e42012-06-15 14:33:17 +02009439 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009440 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009441
Johannes Berg1bf614e2012-06-15 15:23:36 +02009442 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9443 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009444 if (rtnl)
9445 rtnl_unlock();
9446 return -EINVAL;
9447 }
9448
9449 info->user_ptr[1] = dev;
9450 } else {
9451 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009452 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009453
Johannes Berg1bf614e2012-06-15 15:23:36 +02009454 if (dev) {
9455 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9456 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009457 if (rtnl)
9458 rtnl_unlock();
9459 return -ENETDOWN;
9460 }
9461
9462 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009463 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9464 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009465 if (rtnl)
9466 rtnl_unlock();
9467 return -ENETDOWN;
9468 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009469 }
9470
Johannes Berg4c476992010-10-04 21:36:35 +02009471 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009472 }
9473
9474 return 0;
9475}
9476
Johannes Bergf84f7712013-11-14 17:14:45 +01009477static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009478 struct genl_info *info)
9479{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009480 if (info->user_ptr[1]) {
9481 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9482 struct wireless_dev *wdev = info->user_ptr[1];
9483
9484 if (wdev->netdev)
9485 dev_put(wdev->netdev);
9486 } else {
9487 dev_put(info->user_ptr[1]);
9488 }
9489 }
Johannes Berg4c476992010-10-04 21:36:35 +02009490 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9491 rtnl_unlock();
9492}
9493
Johannes Berg4534de82013-11-14 17:14:46 +01009494static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009495 {
9496 .cmd = NL80211_CMD_GET_WIPHY,
9497 .doit = nl80211_get_wiphy,
9498 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009499 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009500 .policy = nl80211_policy,
9501 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009502 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9503 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009504 },
9505 {
9506 .cmd = NL80211_CMD_SET_WIPHY,
9507 .doit = nl80211_set_wiphy,
9508 .policy = nl80211_policy,
9509 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009510 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009511 },
9512 {
9513 .cmd = NL80211_CMD_GET_INTERFACE,
9514 .doit = nl80211_get_interface,
9515 .dumpit = nl80211_dump_interface,
9516 .policy = nl80211_policy,
9517 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009518 .internal_flags = NL80211_FLAG_NEED_WDEV |
9519 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009520 },
9521 {
9522 .cmd = NL80211_CMD_SET_INTERFACE,
9523 .doit = nl80211_set_interface,
9524 .policy = nl80211_policy,
9525 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009526 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9527 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009528 },
9529 {
9530 .cmd = NL80211_CMD_NEW_INTERFACE,
9531 .doit = nl80211_new_interface,
9532 .policy = nl80211_policy,
9533 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009534 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9535 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009536 },
9537 {
9538 .cmd = NL80211_CMD_DEL_INTERFACE,
9539 .doit = nl80211_del_interface,
9540 .policy = nl80211_policy,
9541 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009542 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009543 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009544 },
Johannes Berg41ade002007-12-19 02:03:29 +01009545 {
9546 .cmd = NL80211_CMD_GET_KEY,
9547 .doit = nl80211_get_key,
9548 .policy = nl80211_policy,
9549 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009550 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009551 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009552 },
9553 {
9554 .cmd = NL80211_CMD_SET_KEY,
9555 .doit = nl80211_set_key,
9556 .policy = nl80211_policy,
9557 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009558 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009559 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009560 },
9561 {
9562 .cmd = NL80211_CMD_NEW_KEY,
9563 .doit = nl80211_new_key,
9564 .policy = nl80211_policy,
9565 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009566 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009567 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009568 },
9569 {
9570 .cmd = NL80211_CMD_DEL_KEY,
9571 .doit = nl80211_del_key,
9572 .policy = nl80211_policy,
9573 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009574 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009575 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009576 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009577 {
9578 .cmd = NL80211_CMD_SET_BEACON,
9579 .policy = nl80211_policy,
9580 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009581 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009582 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009583 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009584 },
9585 {
Johannes Berg88600202012-02-13 15:17:18 +01009586 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009587 .policy = nl80211_policy,
9588 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009589 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009590 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009591 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009592 },
9593 {
Johannes Berg88600202012-02-13 15:17:18 +01009594 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009595 .policy = nl80211_policy,
9596 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009597 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009598 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009599 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009600 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009601 {
9602 .cmd = NL80211_CMD_GET_STATION,
9603 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009604 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009605 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009606 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9607 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009608 },
9609 {
9610 .cmd = NL80211_CMD_SET_STATION,
9611 .doit = nl80211_set_station,
9612 .policy = nl80211_policy,
9613 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009615 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009616 },
9617 {
9618 .cmd = NL80211_CMD_NEW_STATION,
9619 .doit = nl80211_new_station,
9620 .policy = nl80211_policy,
9621 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009623 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009624 },
9625 {
9626 .cmd = NL80211_CMD_DEL_STATION,
9627 .doit = nl80211_del_station,
9628 .policy = nl80211_policy,
9629 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009631 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009632 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009633 {
9634 .cmd = NL80211_CMD_GET_MPATH,
9635 .doit = nl80211_get_mpath,
9636 .dumpit = nl80211_dump_mpath,
9637 .policy = nl80211_policy,
9638 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009639 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009640 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009641 },
9642 {
9643 .cmd = NL80211_CMD_SET_MPATH,
9644 .doit = nl80211_set_mpath,
9645 .policy = nl80211_policy,
9646 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009648 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009649 },
9650 {
9651 .cmd = NL80211_CMD_NEW_MPATH,
9652 .doit = nl80211_new_mpath,
9653 .policy = nl80211_policy,
9654 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009656 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009657 },
9658 {
9659 .cmd = NL80211_CMD_DEL_MPATH,
9660 .doit = nl80211_del_mpath,
9661 .policy = nl80211_policy,
9662 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009663 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009664 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009665 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009666 {
9667 .cmd = NL80211_CMD_SET_BSS,
9668 .doit = nl80211_set_bss,
9669 .policy = nl80211_policy,
9670 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009672 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009673 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009674 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009675 .cmd = NL80211_CMD_GET_REG,
9676 .doit = nl80211_get_reg,
9677 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009678 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009679 /* can be retrieved by unprivileged users */
9680 },
9681 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009682 .cmd = NL80211_CMD_SET_REG,
9683 .doit = nl80211_set_reg,
9684 .policy = nl80211_policy,
9685 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009686 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009687 },
9688 {
9689 .cmd = NL80211_CMD_REQ_SET_REG,
9690 .doit = nl80211_req_set_reg,
9691 .policy = nl80211_policy,
9692 .flags = GENL_ADMIN_PERM,
9693 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009694 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009695 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9696 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009697 .policy = nl80211_policy,
9698 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009699 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009700 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009701 },
9702 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009703 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9704 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009705 .policy = nl80211_policy,
9706 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009707 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009708 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009709 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009710 {
Johannes Berg2a519312009-02-10 21:25:55 +01009711 .cmd = NL80211_CMD_TRIGGER_SCAN,
9712 .doit = nl80211_trigger_scan,
9713 .policy = nl80211_policy,
9714 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009715 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009716 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009717 },
9718 {
9719 .cmd = NL80211_CMD_GET_SCAN,
9720 .policy = nl80211_policy,
9721 .dumpit = nl80211_dump_scan,
9722 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009723 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009724 .cmd = NL80211_CMD_START_SCHED_SCAN,
9725 .doit = nl80211_start_sched_scan,
9726 .policy = nl80211_policy,
9727 .flags = GENL_ADMIN_PERM,
9728 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9729 NL80211_FLAG_NEED_RTNL,
9730 },
9731 {
9732 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9733 .doit = nl80211_stop_sched_scan,
9734 .policy = nl80211_policy,
9735 .flags = GENL_ADMIN_PERM,
9736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9737 NL80211_FLAG_NEED_RTNL,
9738 },
9739 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009740 .cmd = NL80211_CMD_AUTHENTICATE,
9741 .doit = nl80211_authenticate,
9742 .policy = nl80211_policy,
9743 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009745 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009746 },
9747 {
9748 .cmd = NL80211_CMD_ASSOCIATE,
9749 .doit = nl80211_associate,
9750 .policy = nl80211_policy,
9751 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009752 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009753 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009754 },
9755 {
9756 .cmd = NL80211_CMD_DEAUTHENTICATE,
9757 .doit = nl80211_deauthenticate,
9758 .policy = nl80211_policy,
9759 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009760 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009761 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009762 },
9763 {
9764 .cmd = NL80211_CMD_DISASSOCIATE,
9765 .doit = nl80211_disassociate,
9766 .policy = nl80211_policy,
9767 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009768 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009769 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009770 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009771 {
9772 .cmd = NL80211_CMD_JOIN_IBSS,
9773 .doit = nl80211_join_ibss,
9774 .policy = nl80211_policy,
9775 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009776 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009777 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009778 },
9779 {
9780 .cmd = NL80211_CMD_LEAVE_IBSS,
9781 .doit = nl80211_leave_ibss,
9782 .policy = nl80211_policy,
9783 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009785 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009786 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009787#ifdef CONFIG_NL80211_TESTMODE
9788 {
9789 .cmd = NL80211_CMD_TESTMODE,
9790 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009791 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009792 .policy = nl80211_policy,
9793 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009794 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9795 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009796 },
9797#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009798 {
9799 .cmd = NL80211_CMD_CONNECT,
9800 .doit = nl80211_connect,
9801 .policy = nl80211_policy,
9802 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009803 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009804 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009805 },
9806 {
9807 .cmd = NL80211_CMD_DISCONNECT,
9808 .doit = nl80211_disconnect,
9809 .policy = nl80211_policy,
9810 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009812 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009813 },
Johannes Berg463d0182009-07-14 00:33:35 +02009814 {
9815 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9816 .doit = nl80211_wiphy_netns,
9817 .policy = nl80211_policy,
9818 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009819 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9820 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009821 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009822 {
9823 .cmd = NL80211_CMD_GET_SURVEY,
9824 .policy = nl80211_policy,
9825 .dumpit = nl80211_dump_survey,
9826 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009827 {
9828 .cmd = NL80211_CMD_SET_PMKSA,
9829 .doit = nl80211_setdel_pmksa,
9830 .policy = nl80211_policy,
9831 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009832 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009833 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009834 },
9835 {
9836 .cmd = NL80211_CMD_DEL_PMKSA,
9837 .doit = nl80211_setdel_pmksa,
9838 .policy = nl80211_policy,
9839 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009840 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009841 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009842 },
9843 {
9844 .cmd = NL80211_CMD_FLUSH_PMKSA,
9845 .doit = nl80211_flush_pmksa,
9846 .policy = nl80211_policy,
9847 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009849 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009850 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009851 {
9852 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9853 .doit = nl80211_remain_on_channel,
9854 .policy = nl80211_policy,
9855 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009856 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009857 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009858 },
9859 {
9860 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9861 .doit = nl80211_cancel_remain_on_channel,
9862 .policy = nl80211_policy,
9863 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009864 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009865 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009866 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009867 {
9868 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9869 .doit = nl80211_set_tx_bitrate_mask,
9870 .policy = nl80211_policy,
9871 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009872 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9873 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009874 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009875 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009876 .cmd = NL80211_CMD_REGISTER_FRAME,
9877 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009878 .policy = nl80211_policy,
9879 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009880 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009881 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009882 },
9883 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009884 .cmd = NL80211_CMD_FRAME,
9885 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009886 .policy = nl80211_policy,
9887 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009888 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009889 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009890 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009891 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009892 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9893 .doit = nl80211_tx_mgmt_cancel_wait,
9894 .policy = nl80211_policy,
9895 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009896 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009897 NL80211_FLAG_NEED_RTNL,
9898 },
9899 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009900 .cmd = NL80211_CMD_SET_POWER_SAVE,
9901 .doit = nl80211_set_power_save,
9902 .policy = nl80211_policy,
9903 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009904 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9905 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009906 },
9907 {
9908 .cmd = NL80211_CMD_GET_POWER_SAVE,
9909 .doit = nl80211_get_power_save,
9910 .policy = nl80211_policy,
9911 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009912 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9913 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009914 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009915 {
9916 .cmd = NL80211_CMD_SET_CQM,
9917 .doit = nl80211_set_cqm,
9918 .policy = nl80211_policy,
9919 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009920 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9921 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009922 },
Johannes Bergf444de02010-05-05 15:25:02 +02009923 {
9924 .cmd = NL80211_CMD_SET_CHANNEL,
9925 .doit = nl80211_set_channel,
9926 .policy = nl80211_policy,
9927 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009928 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9929 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009930 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009931 {
9932 .cmd = NL80211_CMD_SET_WDS_PEER,
9933 .doit = nl80211_set_wds_peer,
9934 .policy = nl80211_policy,
9935 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009936 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9937 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009938 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009939 {
9940 .cmd = NL80211_CMD_JOIN_MESH,
9941 .doit = nl80211_join_mesh,
9942 .policy = nl80211_policy,
9943 .flags = GENL_ADMIN_PERM,
9944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9945 NL80211_FLAG_NEED_RTNL,
9946 },
9947 {
9948 .cmd = NL80211_CMD_LEAVE_MESH,
9949 .doit = nl80211_leave_mesh,
9950 .policy = nl80211_policy,
9951 .flags = GENL_ADMIN_PERM,
9952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9953 NL80211_FLAG_NEED_RTNL,
9954 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009955#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009956 {
9957 .cmd = NL80211_CMD_GET_WOWLAN,
9958 .doit = nl80211_get_wowlan,
9959 .policy = nl80211_policy,
9960 /* can be retrieved by unprivileged users */
9961 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9962 NL80211_FLAG_NEED_RTNL,
9963 },
9964 {
9965 .cmd = NL80211_CMD_SET_WOWLAN,
9966 .doit = nl80211_set_wowlan,
9967 .policy = nl80211_policy,
9968 .flags = GENL_ADMIN_PERM,
9969 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9970 NL80211_FLAG_NEED_RTNL,
9971 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009972#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009973 {
9974 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9975 .doit = nl80211_set_rekey_data,
9976 .policy = nl80211_policy,
9977 .flags = GENL_ADMIN_PERM,
9978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9979 NL80211_FLAG_NEED_RTNL,
9980 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009981 {
9982 .cmd = NL80211_CMD_TDLS_MGMT,
9983 .doit = nl80211_tdls_mgmt,
9984 .policy = nl80211_policy,
9985 .flags = GENL_ADMIN_PERM,
9986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9987 NL80211_FLAG_NEED_RTNL,
9988 },
9989 {
9990 .cmd = NL80211_CMD_TDLS_OPER,
9991 .doit = nl80211_tdls_oper,
9992 .policy = nl80211_policy,
9993 .flags = GENL_ADMIN_PERM,
9994 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9995 NL80211_FLAG_NEED_RTNL,
9996 },
Johannes Berg28946da2011-11-04 11:18:12 +01009997 {
9998 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9999 .doit = nl80211_register_unexpected_frame,
10000 .policy = nl80211_policy,
10001 .flags = GENL_ADMIN_PERM,
10002 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10003 NL80211_FLAG_NEED_RTNL,
10004 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010005 {
10006 .cmd = NL80211_CMD_PROBE_CLIENT,
10007 .doit = nl80211_probe_client,
10008 .policy = nl80211_policy,
10009 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010010 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010011 NL80211_FLAG_NEED_RTNL,
10012 },
Johannes Berg5e7602302011-11-04 11:18:17 +010010013 {
10014 .cmd = NL80211_CMD_REGISTER_BEACONS,
10015 .doit = nl80211_register_beacons,
10016 .policy = nl80211_policy,
10017 .flags = GENL_ADMIN_PERM,
10018 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10019 NL80211_FLAG_NEED_RTNL,
10020 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010021 {
10022 .cmd = NL80211_CMD_SET_NOACK_MAP,
10023 .doit = nl80211_set_noack_map,
10024 .policy = nl80211_policy,
10025 .flags = GENL_ADMIN_PERM,
10026 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10027 NL80211_FLAG_NEED_RTNL,
10028 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010029 {
10030 .cmd = NL80211_CMD_START_P2P_DEVICE,
10031 .doit = nl80211_start_p2p_device,
10032 .policy = nl80211_policy,
10033 .flags = GENL_ADMIN_PERM,
10034 .internal_flags = NL80211_FLAG_NEED_WDEV |
10035 NL80211_FLAG_NEED_RTNL,
10036 },
10037 {
10038 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10039 .doit = nl80211_stop_p2p_device,
10040 .policy = nl80211_policy,
10041 .flags = GENL_ADMIN_PERM,
10042 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10043 NL80211_FLAG_NEED_RTNL,
10044 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010045 {
10046 .cmd = NL80211_CMD_SET_MCAST_RATE,
10047 .doit = nl80211_set_mcast_rate,
10048 .policy = nl80211_policy,
10049 .flags = GENL_ADMIN_PERM,
10050 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10051 NL80211_FLAG_NEED_RTNL,
10052 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010053 {
10054 .cmd = NL80211_CMD_SET_MAC_ACL,
10055 .doit = nl80211_set_mac_acl,
10056 .policy = nl80211_policy,
10057 .flags = GENL_ADMIN_PERM,
10058 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10059 NL80211_FLAG_NEED_RTNL,
10060 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010061 {
10062 .cmd = NL80211_CMD_RADAR_DETECT,
10063 .doit = nl80211_start_radar_detection,
10064 .policy = nl80211_policy,
10065 .flags = GENL_ADMIN_PERM,
10066 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10067 NL80211_FLAG_NEED_RTNL,
10068 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010069 {
10070 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10071 .doit = nl80211_get_protocol_features,
10072 .policy = nl80211_policy,
10073 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010074 {
10075 .cmd = NL80211_CMD_UPDATE_FT_IES,
10076 .doit = nl80211_update_ft_ies,
10077 .policy = nl80211_policy,
10078 .flags = GENL_ADMIN_PERM,
10079 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10080 NL80211_FLAG_NEED_RTNL,
10081 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010082 {
10083 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10084 .doit = nl80211_crit_protocol_start,
10085 .policy = nl80211_policy,
10086 .flags = GENL_ADMIN_PERM,
10087 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10088 NL80211_FLAG_NEED_RTNL,
10089 },
10090 {
10091 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10092 .doit = nl80211_crit_protocol_stop,
10093 .policy = nl80211_policy,
10094 .flags = GENL_ADMIN_PERM,
10095 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10096 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010097 },
10098 {
10099 .cmd = NL80211_CMD_GET_COALESCE,
10100 .doit = nl80211_get_coalesce,
10101 .policy = nl80211_policy,
10102 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10103 NL80211_FLAG_NEED_RTNL,
10104 },
10105 {
10106 .cmd = NL80211_CMD_SET_COALESCE,
10107 .doit = nl80211_set_coalesce,
10108 .policy = nl80211_policy,
10109 .flags = GENL_ADMIN_PERM,
10110 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10111 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010112 },
10113 {
10114 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10115 .doit = nl80211_channel_switch,
10116 .policy = nl80211_policy,
10117 .flags = GENL_ADMIN_PERM,
10118 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10119 NL80211_FLAG_NEED_RTNL,
10120 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010121 {
10122 .cmd = NL80211_CMD_VENDOR,
10123 .doit = nl80211_vendor_cmd,
10124 .policy = nl80211_policy,
10125 .flags = GENL_ADMIN_PERM,
10126 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10127 NL80211_FLAG_NEED_RTNL,
10128 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010129 {
10130 .cmd = NL80211_CMD_SET_QOS_MAP,
10131 .doit = nl80211_set_qos_map,
10132 .policy = nl80211_policy,
10133 .flags = GENL_ADMIN_PERM,
10134 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10135 NL80211_FLAG_NEED_RTNL,
10136 },
Johannes Berg55682962007-09-20 13:09:35 -040010137};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010138
Johannes Berg55682962007-09-20 13:09:35 -040010139/* notification functions */
10140
Johannes Berg3bb20552014-05-26 13:52:25 +020010141void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10142 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010143{
10144 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010145 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010146
Johannes Berg3bb20552014-05-26 13:52:25 +020010147 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10148 cmd != NL80211_CMD_DEL_WIPHY);
10149
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010151 if (!msg)
10152 return;
10153
Johannes Berg3bb20552014-05-26 13:52:25 +020010154 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010155 nlmsg_free(msg);
10156 return;
10157 }
10158
Johannes Berg68eb5502013-11-19 15:19:38 +010010159 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010160 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010161}
10162
Johannes Berg362a4152009-05-24 16:43:15 +020010163static int nl80211_add_scan_req(struct sk_buff *msg,
10164 struct cfg80211_registered_device *rdev)
10165{
10166 struct cfg80211_scan_request *req = rdev->scan_req;
10167 struct nlattr *nest;
10168 int i;
10169
10170 if (WARN_ON(!req))
10171 return 0;
10172
10173 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10174 if (!nest)
10175 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010176 for (i = 0; i < req->n_ssids; i++) {
10177 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10178 goto nla_put_failure;
10179 }
Johannes Berg362a4152009-05-24 16:43:15 +020010180 nla_nest_end(msg, nest);
10181
10182 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10183 if (!nest)
10184 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010185 for (i = 0; i < req->n_channels; i++) {
10186 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10187 goto nla_put_failure;
10188 }
Johannes Berg362a4152009-05-24 16:43:15 +020010189 nla_nest_end(msg, nest);
10190
David S. Miller9360ffd2012-03-29 04:41:26 -040010191 if (req->ie &&
10192 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10193 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010194
Johannes Bergae917c92013-10-25 11:05:22 +020010195 if (req->flags &&
10196 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10197 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010198
Johannes Berg362a4152009-05-24 16:43:15 +020010199 return 0;
10200 nla_put_failure:
10201 return -ENOBUFS;
10202}
10203
Johannes Berga538e2d2009-06-16 19:56:42 +020010204static int nl80211_send_scan_msg(struct sk_buff *msg,
10205 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010206 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010207 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010208 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010209{
10210 void *hdr;
10211
Eric W. Biederman15e47302012-09-07 20:12:54 +000010212 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010213 if (!hdr)
10214 return -1;
10215
David S. Miller9360ffd2012-03-29 04:41:26 -040010216 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010217 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10218 wdev->netdev->ifindex)) ||
10219 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010220 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010221
Johannes Berg362a4152009-05-24 16:43:15 +020010222 /* ignore errors and send incomplete event anyway */
10223 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010224
10225 return genlmsg_end(msg, hdr);
10226
10227 nla_put_failure:
10228 genlmsg_cancel(msg, hdr);
10229 return -EMSGSIZE;
10230}
10231
Luciano Coelho807f8a82011-05-11 17:09:35 +030010232static int
10233nl80211_send_sched_scan_msg(struct sk_buff *msg,
10234 struct cfg80211_registered_device *rdev,
10235 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010236 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010237{
10238 void *hdr;
10239
Eric W. Biederman15e47302012-09-07 20:12:54 +000010240 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010241 if (!hdr)
10242 return -1;
10243
David S. Miller9360ffd2012-03-29 04:41:26 -040010244 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10245 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10246 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010247
10248 return genlmsg_end(msg, hdr);
10249
10250 nla_put_failure:
10251 genlmsg_cancel(msg, hdr);
10252 return -EMSGSIZE;
10253}
10254
Johannes Berga538e2d2009-06-16 19:56:42 +020010255void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010256 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010257{
10258 struct sk_buff *msg;
10259
Thomas Graf58050fc2012-06-28 03:57:45 +000010260 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010261 if (!msg)
10262 return;
10263
Johannes Bergfd014282012-06-18 19:17:03 +020010264 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010265 NL80211_CMD_TRIGGER_SCAN) < 0) {
10266 nlmsg_free(msg);
10267 return;
10268 }
10269
Johannes Berg68eb5502013-11-19 15:19:38 +010010270 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010271 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010272}
10273
Johannes Bergf9d15d12014-01-22 11:14:19 +020010274struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10275 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010276{
10277 struct sk_buff *msg;
10278
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010280 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010281 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010282
Johannes Bergfd014282012-06-18 19:17:03 +020010283 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010284 aborted ? NL80211_CMD_SCAN_ABORTED :
10285 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010286 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010287 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010288 }
10289
Johannes Bergf9d15d12014-01-22 11:14:19 +020010290 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010291}
10292
Johannes Bergf9d15d12014-01-22 11:14:19 +020010293void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10294 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010295{
Johannes Berg2a519312009-02-10 21:25:55 +010010296 if (!msg)
10297 return;
10298
Johannes Berg68eb5502013-11-19 15:19:38 +010010299 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010300 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010301}
10302
Luciano Coelho807f8a82011-05-11 17:09:35 +030010303void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10304 struct net_device *netdev)
10305{
10306 struct sk_buff *msg;
10307
10308 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10309 if (!msg)
10310 return;
10311
10312 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10313 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10314 nlmsg_free(msg);
10315 return;
10316 }
10317
Johannes Berg68eb5502013-11-19 15:19:38 +010010318 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010319 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010320}
10321
10322void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10323 struct net_device *netdev, u32 cmd)
10324{
10325 struct sk_buff *msg;
10326
Thomas Graf58050fc2012-06-28 03:57:45 +000010327 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010328 if (!msg)
10329 return;
10330
10331 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10332 nlmsg_free(msg);
10333 return;
10334 }
10335
Johannes Berg68eb5502013-11-19 15:19:38 +010010336 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010337 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010338}
10339
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010340/*
10341 * This can happen on global regulatory changes or device specific settings
10342 * based on custom world regulatory domains.
10343 */
10344void nl80211_send_reg_change_event(struct regulatory_request *request)
10345{
10346 struct sk_buff *msg;
10347 void *hdr;
10348
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010349 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010350 if (!msg)
10351 return;
10352
10353 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10354 if (!hdr) {
10355 nlmsg_free(msg);
10356 return;
10357 }
10358
10359 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010360 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10361 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010362
David S. Miller9360ffd2012-03-29 04:41:26 -040010363 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10364 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10365 NL80211_REGDOM_TYPE_WORLD))
10366 goto nla_put_failure;
10367 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10368 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10369 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10370 goto nla_put_failure;
10371 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10372 request->intersect) {
10373 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10374 NL80211_REGDOM_TYPE_INTERSECTION))
10375 goto nla_put_failure;
10376 } else {
10377 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10378 NL80211_REGDOM_TYPE_COUNTRY) ||
10379 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10380 request->alpha2))
10381 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010382 }
10383
Johannes Bergf4173762012-12-03 18:23:37 +010010384 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010385 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10386 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010387
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010388 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010389
Johannes Bergbc43b282009-07-25 10:54:13 +020010390 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010391 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010392 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010393 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010394
10395 return;
10396
10397nla_put_failure:
10398 genlmsg_cancel(msg, hdr);
10399 nlmsg_free(msg);
10400}
10401
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010402static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10403 struct net_device *netdev,
10404 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010405 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010406{
10407 struct sk_buff *msg;
10408 void *hdr;
10409
Johannes Berge6d6e342009-07-01 21:26:47 +020010410 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010411 if (!msg)
10412 return;
10413
10414 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10415 if (!hdr) {
10416 nlmsg_free(msg);
10417 return;
10418 }
10419
David S. Miller9360ffd2012-03-29 04:41:26 -040010420 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10421 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10422 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10423 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010424
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010425 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010426
Johannes Berg68eb5502013-11-19 15:19:38 +010010427 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010428 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010429 return;
10430
10431 nla_put_failure:
10432 genlmsg_cancel(msg, hdr);
10433 nlmsg_free(msg);
10434}
10435
10436void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010437 struct net_device *netdev, const u8 *buf,
10438 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010439{
10440 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010441 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010442}
10443
10444void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10445 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010446 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010447{
Johannes Berge6d6e342009-07-01 21:26:47 +020010448 nl80211_send_mlme_event(rdev, netdev, buf, len,
10449 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010450}
10451
Jouni Malinen53b46b82009-03-27 20:53:56 +020010452void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010453 struct net_device *netdev, const u8 *buf,
10454 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010455{
10456 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010457 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010458}
10459
Jouni Malinen53b46b82009-03-27 20:53:56 +020010460void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10461 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010462 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010463{
10464 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010465 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010466}
10467
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010468void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10469 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010470{
Johannes Berg947add32013-02-22 22:05:20 +010010471 struct wireless_dev *wdev = dev->ieee80211_ptr;
10472 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010473 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010474 const struct ieee80211_mgmt *mgmt = (void *)buf;
10475 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010476
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010477 if (WARN_ON(len < 2))
10478 return;
10479
10480 if (ieee80211_is_deauth(mgmt->frame_control))
10481 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10482 else
10483 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10484
10485 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10486 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010487}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010488EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010489
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010490static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10491 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010492 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010493{
10494 struct sk_buff *msg;
10495 void *hdr;
10496
Johannes Berge6d6e342009-07-01 21:26:47 +020010497 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010498 if (!msg)
10499 return;
10500
10501 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10502 if (!hdr) {
10503 nlmsg_free(msg);
10504 return;
10505 }
10506
David S. Miller9360ffd2012-03-29 04:41:26 -040010507 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10508 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10509 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10510 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10511 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010512
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010513 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010514
Johannes Berg68eb5502013-11-19 15:19:38 +010010515 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010516 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010517 return;
10518
10519 nla_put_failure:
10520 genlmsg_cancel(msg, hdr);
10521 nlmsg_free(msg);
10522}
10523
10524void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010525 struct net_device *netdev, const u8 *addr,
10526 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010527{
10528 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010529 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010530}
10531
10532void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010533 struct net_device *netdev, const u8 *addr,
10534 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010535{
Johannes Berge6d6e342009-07-01 21:26:47 +020010536 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10537 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010538}
10539
Samuel Ortizb23aa672009-07-01 21:26:54 +020010540void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10541 struct net_device *netdev, const u8 *bssid,
10542 const u8 *req_ie, size_t req_ie_len,
10543 const u8 *resp_ie, size_t resp_ie_len,
10544 u16 status, gfp_t gfp)
10545{
10546 struct sk_buff *msg;
10547 void *hdr;
10548
Thomas Graf58050fc2012-06-28 03:57:45 +000010549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010550 if (!msg)
10551 return;
10552
10553 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10554 if (!hdr) {
10555 nlmsg_free(msg);
10556 return;
10557 }
10558
David S. Miller9360ffd2012-03-29 04:41:26 -040010559 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10560 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10561 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10562 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10563 (req_ie &&
10564 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10565 (resp_ie &&
10566 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10567 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010568
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010569 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010570
Johannes Berg68eb5502013-11-19 15:19:38 +010010571 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010572 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010573 return;
10574
10575 nla_put_failure:
10576 genlmsg_cancel(msg, hdr);
10577 nlmsg_free(msg);
10578
10579}
10580
10581void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10582 struct net_device *netdev, const u8 *bssid,
10583 const u8 *req_ie, size_t req_ie_len,
10584 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10585{
10586 struct sk_buff *msg;
10587 void *hdr;
10588
Thomas Graf58050fc2012-06-28 03:57:45 +000010589 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010590 if (!msg)
10591 return;
10592
10593 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10594 if (!hdr) {
10595 nlmsg_free(msg);
10596 return;
10597 }
10598
David S. Miller9360ffd2012-03-29 04:41:26 -040010599 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10600 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10601 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10602 (req_ie &&
10603 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10604 (resp_ie &&
10605 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10606 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010607
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010608 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010609
Johannes Berg68eb5502013-11-19 15:19:38 +010010610 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010611 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010612 return;
10613
10614 nla_put_failure:
10615 genlmsg_cancel(msg, hdr);
10616 nlmsg_free(msg);
10617
10618}
10619
10620void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10621 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010622 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010623{
10624 struct sk_buff *msg;
10625 void *hdr;
10626
Thomas Graf58050fc2012-06-28 03:57:45 +000010627 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010628 if (!msg)
10629 return;
10630
10631 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10632 if (!hdr) {
10633 nlmsg_free(msg);
10634 return;
10635 }
10636
David S. Miller9360ffd2012-03-29 04:41:26 -040010637 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10638 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10639 (from_ap && reason &&
10640 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10641 (from_ap &&
10642 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10643 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10644 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010645
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010646 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010647
Johannes Berg68eb5502013-11-19 15:19:38 +010010648 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010649 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010650 return;
10651
10652 nla_put_failure:
10653 genlmsg_cancel(msg, hdr);
10654 nlmsg_free(msg);
10655
10656}
10657
Johannes Berg04a773a2009-04-19 21:24:32 +020010658void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10659 struct net_device *netdev, const u8 *bssid,
10660 gfp_t gfp)
10661{
10662 struct sk_buff *msg;
10663 void *hdr;
10664
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010666 if (!msg)
10667 return;
10668
10669 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10670 if (!hdr) {
10671 nlmsg_free(msg);
10672 return;
10673 }
10674
David S. Miller9360ffd2012-03-29 04:41:26 -040010675 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10676 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10677 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10678 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010679
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010680 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010681
Johannes Berg68eb5502013-11-19 15:19:38 +010010682 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010683 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010684 return;
10685
10686 nla_put_failure:
10687 genlmsg_cancel(msg, hdr);
10688 nlmsg_free(msg);
10689}
10690
Johannes Berg947add32013-02-22 22:05:20 +010010691void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10692 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010693{
Johannes Berg947add32013-02-22 22:05:20 +010010694 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010695 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010696 struct sk_buff *msg;
10697 void *hdr;
10698
Johannes Berg947add32013-02-22 22:05:20 +010010699 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10700 return;
10701
10702 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10703
Javier Cardonac93b5e72011-04-07 15:08:34 -070010704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10705 if (!msg)
10706 return;
10707
10708 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10709 if (!hdr) {
10710 nlmsg_free(msg);
10711 return;
10712 }
10713
David S. Miller9360ffd2012-03-29 04:41:26 -040010714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10716 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010717 (ie_len && ie &&
10718 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10719 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010720
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010721 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010722
Johannes Berg68eb5502013-11-19 15:19:38 +010010723 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010724 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010725 return;
10726
10727 nla_put_failure:
10728 genlmsg_cancel(msg, hdr);
10729 nlmsg_free(msg);
10730}
Johannes Berg947add32013-02-22 22:05:20 +010010731EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010732
Jouni Malinena3b8b052009-03-27 21:59:49 +020010733void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10734 struct net_device *netdev, const u8 *addr,
10735 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010736 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010737{
10738 struct sk_buff *msg;
10739 void *hdr;
10740
Johannes Berge6d6e342009-07-01 21:26:47 +020010741 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010742 if (!msg)
10743 return;
10744
10745 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10746 if (!hdr) {
10747 nlmsg_free(msg);
10748 return;
10749 }
10750
David S. Miller9360ffd2012-03-29 04:41:26 -040010751 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10752 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10753 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10754 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10755 (key_id != -1 &&
10756 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10757 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10758 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010759
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010760 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010761
Johannes Berg68eb5502013-11-19 15:19:38 +010010762 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010763 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010764 return;
10765
10766 nla_put_failure:
10767 genlmsg_cancel(msg, hdr);
10768 nlmsg_free(msg);
10769}
10770
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010771void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10772 struct ieee80211_channel *channel_before,
10773 struct ieee80211_channel *channel_after)
10774{
10775 struct sk_buff *msg;
10776 void *hdr;
10777 struct nlattr *nl_freq;
10778
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010779 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010780 if (!msg)
10781 return;
10782
10783 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10784 if (!hdr) {
10785 nlmsg_free(msg);
10786 return;
10787 }
10788
10789 /*
10790 * Since we are applying the beacon hint to a wiphy we know its
10791 * wiphy_idx is valid
10792 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010793 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10794 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010795
10796 /* Before */
10797 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10798 if (!nl_freq)
10799 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010800 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010801 goto nla_put_failure;
10802 nla_nest_end(msg, nl_freq);
10803
10804 /* After */
10805 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10806 if (!nl_freq)
10807 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010808 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010809 goto nla_put_failure;
10810 nla_nest_end(msg, nl_freq);
10811
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010812 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010813
Johannes Berg463d0182009-07-14 00:33:35 +020010814 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010815 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010816 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010817 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010818
10819 return;
10820
10821nla_put_failure:
10822 genlmsg_cancel(msg, hdr);
10823 nlmsg_free(msg);
10824}
10825
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010826static void nl80211_send_remain_on_chan_event(
10827 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010828 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010829 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010830 unsigned int duration, gfp_t gfp)
10831{
10832 struct sk_buff *msg;
10833 void *hdr;
10834
10835 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10836 if (!msg)
10837 return;
10838
10839 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10840 if (!hdr) {
10841 nlmsg_free(msg);
10842 return;
10843 }
10844
David S. Miller9360ffd2012-03-29 04:41:26 -040010845 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010846 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10847 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010848 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010849 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010850 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10851 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010852 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10853 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010854
David S. Miller9360ffd2012-03-29 04:41:26 -040010855 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10856 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10857 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010858
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010859 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010860
Johannes Berg68eb5502013-11-19 15:19:38 +010010861 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010862 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010863 return;
10864
10865 nla_put_failure:
10866 genlmsg_cancel(msg, hdr);
10867 nlmsg_free(msg);
10868}
10869
Johannes Berg947add32013-02-22 22:05:20 +010010870void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10871 struct ieee80211_channel *chan,
10872 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010873{
Johannes Berg947add32013-02-22 22:05:20 +010010874 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010875 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010876
10877 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010878 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010879 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010880 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010881}
Johannes Berg947add32013-02-22 22:05:20 +010010882EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010883
Johannes Berg947add32013-02-22 22:05:20 +010010884void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10885 struct ieee80211_channel *chan,
10886 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010887{
Johannes Berg947add32013-02-22 22:05:20 +010010888 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010889 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010890
10891 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010892 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010893 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010894}
Johannes Berg947add32013-02-22 22:05:20 +010010895EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010896
Johannes Berg947add32013-02-22 22:05:20 +010010897void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10898 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010899{
Johannes Berg947add32013-02-22 22:05:20 +010010900 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010901 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010902 struct sk_buff *msg;
10903
Johannes Berg947add32013-02-22 22:05:20 +010010904 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10905
Thomas Graf58050fc2012-06-28 03:57:45 +000010906 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010907 if (!msg)
10908 return;
10909
John W. Linville66266b32012-03-15 13:25:41 -040010910 if (nl80211_send_station(msg, 0, 0, 0,
10911 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010912 nlmsg_free(msg);
10913 return;
10914 }
10915
Johannes Berg68eb5502013-11-19 15:19:38 +010010916 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010917 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010918}
Johannes Berg947add32013-02-22 22:05:20 +010010919EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010920
Johannes Berg947add32013-02-22 22:05:20 +010010921void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010922{
Johannes Berg947add32013-02-22 22:05:20 +010010923 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010924 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010925 struct sk_buff *msg;
10926 void *hdr;
10927
Johannes Berg947add32013-02-22 22:05:20 +010010928 trace_cfg80211_del_sta(dev, mac_addr);
10929
Thomas Graf58050fc2012-06-28 03:57:45 +000010930 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010931 if (!msg)
10932 return;
10933
10934 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10935 if (!hdr) {
10936 nlmsg_free(msg);
10937 return;
10938 }
10939
David S. Miller9360ffd2012-03-29 04:41:26 -040010940 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10941 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10942 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010943
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010944 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +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);
Jouni Malinenec15e682011-03-23 15:29:52 +020010948 return;
10949
10950 nla_put_failure:
10951 genlmsg_cancel(msg, hdr);
10952 nlmsg_free(msg);
10953}
Johannes Berg947add32013-02-22 22:05:20 +010010954EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010955
Johannes Berg947add32013-02-22 22:05:20 +010010956void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10957 enum nl80211_connect_failed_reason reason,
10958 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010959{
Johannes Berg947add32013-02-22 22:05:20 +010010960 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010961 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010962 struct sk_buff *msg;
10963 void *hdr;
10964
10965 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10966 if (!msg)
10967 return;
10968
10969 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10970 if (!hdr) {
10971 nlmsg_free(msg);
10972 return;
10973 }
10974
10975 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10976 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10977 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10978 goto nla_put_failure;
10979
10980 genlmsg_end(msg, hdr);
10981
Johannes Berg68eb5502013-11-19 15:19:38 +010010982 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010983 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010984 return;
10985
10986 nla_put_failure:
10987 genlmsg_cancel(msg, hdr);
10988 nlmsg_free(msg);
10989}
Johannes Berg947add32013-02-22 22:05:20 +010010990EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010991
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010992static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10993 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010994{
10995 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010996 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010997 struct sk_buff *msg;
10998 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010999 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011000
Eric W. Biederman15e47302012-09-07 20:12:54 +000011001 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011002 return false;
11003
11004 msg = nlmsg_new(100, gfp);
11005 if (!msg)
11006 return true;
11007
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011008 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011009 if (!hdr) {
11010 nlmsg_free(msg);
11011 return true;
11012 }
11013
David S. Miller9360ffd2012-03-29 04:41:26 -040011014 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11015 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11016 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11017 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011018
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011019 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011020 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011021 return true;
11022
11023 nla_put_failure:
11024 genlmsg_cancel(msg, hdr);
11025 nlmsg_free(msg);
11026 return true;
11027}
11028
Johannes Berg947add32013-02-22 22:05:20 +010011029bool cfg80211_rx_spurious_frame(struct net_device *dev,
11030 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011031{
Johannes Berg947add32013-02-22 22:05:20 +010011032 struct wireless_dev *wdev = dev->ieee80211_ptr;
11033 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011034
Johannes Berg947add32013-02-22 22:05:20 +010011035 trace_cfg80211_rx_spurious_frame(dev, addr);
11036
11037 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11038 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11039 trace_cfg80211_return_bool(false);
11040 return false;
11041 }
11042 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11043 addr, gfp);
11044 trace_cfg80211_return_bool(ret);
11045 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011046}
Johannes Berg947add32013-02-22 22:05:20 +010011047EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11048
11049bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11050 const u8 *addr, gfp_t gfp)
11051{
11052 struct wireless_dev *wdev = dev->ieee80211_ptr;
11053 bool ret;
11054
11055 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11056
11057 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11058 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11059 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11060 trace_cfg80211_return_bool(false);
11061 return false;
11062 }
11063 ret = __nl80211_unexpected_frame(dev,
11064 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11065 addr, gfp);
11066 trace_cfg80211_return_bool(ret);
11067 return ret;
11068}
11069EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011070
Johannes Berg2e161f72010-08-12 15:38:38 +020011071int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011072 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011073 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011074 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011075{
Johannes Berg71bbc992012-06-15 15:30:18 +020011076 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011077 struct sk_buff *msg;
11078 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011079
11080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11081 if (!msg)
11082 return -ENOMEM;
11083
Johannes Berg2e161f72010-08-12 15:38:38 +020011084 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011085 if (!hdr) {
11086 nlmsg_free(msg);
11087 return -ENOMEM;
11088 }
11089
David S. Miller9360ffd2012-03-29 04:41:26 -040011090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011091 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11092 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011093 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011094 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11095 (sig_dbm &&
11096 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011097 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11098 (flags &&
11099 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011100 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011101
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011102 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011103
Eric W. Biederman15e47302012-09-07 20:12:54 +000011104 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011105
11106 nla_put_failure:
11107 genlmsg_cancel(msg, hdr);
11108 nlmsg_free(msg);
11109 return -ENOBUFS;
11110}
11111
Johannes Berg947add32013-02-22 22:05:20 +010011112void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11113 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011114{
Johannes Berg947add32013-02-22 22:05:20 +010011115 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011116 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011117 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011118 struct sk_buff *msg;
11119 void *hdr;
11120
Johannes Berg947add32013-02-22 22:05:20 +010011121 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11122
Jouni Malinen026331c2010-02-15 12:53:10 +020011123 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11124 if (!msg)
11125 return;
11126
Johannes Berg2e161f72010-08-12 15:38:38 +020011127 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011128 if (!hdr) {
11129 nlmsg_free(msg);
11130 return;
11131 }
11132
David S. Miller9360ffd2012-03-29 04:41:26 -040011133 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011134 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11135 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011136 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011137 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11138 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11139 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11140 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011141
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011142 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011143
Johannes Berg68eb5502013-11-19 15:19:38 +010011144 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011145 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011146 return;
11147
11148 nla_put_failure:
11149 genlmsg_cancel(msg, hdr);
11150 nlmsg_free(msg);
11151}
Johannes Berg947add32013-02-22 22:05:20 +010011152EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011153
Johannes Berg947add32013-02-22 22:05:20 +010011154void cfg80211_cqm_rssi_notify(struct net_device *dev,
11155 enum nl80211_cqm_rssi_threshold_event rssi_event,
11156 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011157{
Johannes Berg947add32013-02-22 22:05:20 +010011158 struct wireless_dev *wdev = dev->ieee80211_ptr;
11159 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011161 struct sk_buff *msg;
11162 struct nlattr *pinfoattr;
11163 void *hdr;
11164
Johannes Berg947add32013-02-22 22:05:20 +010011165 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11166
Thomas Graf58050fc2012-06-28 03:57:45 +000011167 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011168 if (!msg)
11169 return;
11170
11171 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11172 if (!hdr) {
11173 nlmsg_free(msg);
11174 return;
11175 }
11176
David S. Miller9360ffd2012-03-29 04:41:26 -040011177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011178 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011179 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011180
11181 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11182 if (!pinfoattr)
11183 goto nla_put_failure;
11184
David S. Miller9360ffd2012-03-29 04:41:26 -040011185 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11186 rssi_event))
11187 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011188
11189 nla_nest_end(msg, pinfoattr);
11190
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011191 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011192
Johannes Berg68eb5502013-11-19 15:19:38 +010011193 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011194 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011195 return;
11196
11197 nla_put_failure:
11198 genlmsg_cancel(msg, hdr);
11199 nlmsg_free(msg);
11200}
Johannes Berg947add32013-02-22 22:05:20 +010011201EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011202
Johannes Berg947add32013-02-22 22:05:20 +010011203static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11204 struct net_device *netdev, const u8 *bssid,
11205 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011206{
11207 struct sk_buff *msg;
11208 struct nlattr *rekey_attr;
11209 void *hdr;
11210
Thomas Graf58050fc2012-06-28 03:57:45 +000011211 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011212 if (!msg)
11213 return;
11214
11215 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11216 if (!hdr) {
11217 nlmsg_free(msg);
11218 return;
11219 }
11220
David S. Miller9360ffd2012-03-29 04:41:26 -040011221 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11222 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11223 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11224 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011225
11226 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11227 if (!rekey_attr)
11228 goto nla_put_failure;
11229
David S. Miller9360ffd2012-03-29 04:41:26 -040011230 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11231 NL80211_REPLAY_CTR_LEN, replay_ctr))
11232 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011233
11234 nla_nest_end(msg, rekey_attr);
11235
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011236 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011237
Johannes Berg68eb5502013-11-19 15:19:38 +010011238 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011239 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011240 return;
11241
11242 nla_put_failure:
11243 genlmsg_cancel(msg, hdr);
11244 nlmsg_free(msg);
11245}
11246
Johannes Berg947add32013-02-22 22:05:20 +010011247void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11248 const u8 *replay_ctr, gfp_t gfp)
11249{
11250 struct wireless_dev *wdev = dev->ieee80211_ptr;
11251 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011252 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011253
11254 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11255 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11256}
11257EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11258
11259static void
11260nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11261 struct net_device *netdev, int index,
11262 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011263{
11264 struct sk_buff *msg;
11265 struct nlattr *attr;
11266 void *hdr;
11267
Thomas Graf58050fc2012-06-28 03:57:45 +000011268 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011269 if (!msg)
11270 return;
11271
11272 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11273 if (!hdr) {
11274 nlmsg_free(msg);
11275 return;
11276 }
11277
David S. Miller9360ffd2012-03-29 04:41:26 -040011278 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11279 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11280 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011281
11282 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11283 if (!attr)
11284 goto nla_put_failure;
11285
David S. Miller9360ffd2012-03-29 04:41:26 -040011286 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11287 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11288 (preauth &&
11289 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11290 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011291
11292 nla_nest_end(msg, attr);
11293
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011294 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011295
Johannes Berg68eb5502013-11-19 15:19:38 +010011296 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011297 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011298 return;
11299
11300 nla_put_failure:
11301 genlmsg_cancel(msg, hdr);
11302 nlmsg_free(msg);
11303}
11304
Johannes Berg947add32013-02-22 22:05:20 +010011305void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11306 const u8 *bssid, bool preauth, gfp_t gfp)
11307{
11308 struct wireless_dev *wdev = dev->ieee80211_ptr;
11309 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011310 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011311
11312 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11313 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11314}
11315EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11316
11317static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11318 struct net_device *netdev,
11319 struct cfg80211_chan_def *chandef,
11320 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011321{
11322 struct sk_buff *msg;
11323 void *hdr;
11324
Thomas Graf58050fc2012-06-28 03:57:45 +000011325 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011326 if (!msg)
11327 return;
11328
11329 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11330 if (!hdr) {
11331 nlmsg_free(msg);
11332 return;
11333 }
11334
Johannes Berg683b6d32012-11-08 21:25:48 +010011335 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11336 goto nla_put_failure;
11337
11338 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011339 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011340
11341 genlmsg_end(msg, hdr);
11342
Johannes Berg68eb5502013-11-19 15:19:38 +010011343 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011344 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011345 return;
11346
11347 nla_put_failure:
11348 genlmsg_cancel(msg, hdr);
11349 nlmsg_free(msg);
11350}
11351
Johannes Berg947add32013-02-22 22:05:20 +010011352void cfg80211_ch_switch_notify(struct net_device *dev,
11353 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011354{
Johannes Berg947add32013-02-22 22:05:20 +010011355 struct wireless_dev *wdev = dev->ieee80211_ptr;
11356 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011357 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011358
Simon Wunderliche487eae2013-11-21 18:19:51 +010011359 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011360
Simon Wunderliche487eae2013-11-21 18:19:51 +010011361 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011362
11363 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011364 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011365 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11366 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011367 return;
Johannes Berg947add32013-02-22 22:05:20 +010011368
Michal Kazior9e0e2962014-01-29 14:22:27 +010011369 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011370 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011371 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011372}
11373EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11374
11375void cfg80211_cqm_txe_notify(struct net_device *dev,
11376 const u8 *peer, u32 num_packets,
11377 u32 rate, u32 intvl, gfp_t gfp)
11378{
11379 struct wireless_dev *wdev = dev->ieee80211_ptr;
11380 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011381 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011382 struct sk_buff *msg;
11383 struct nlattr *pinfoattr;
11384 void *hdr;
11385
11386 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11387 if (!msg)
11388 return;
11389
11390 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11391 if (!hdr) {
11392 nlmsg_free(msg);
11393 return;
11394 }
11395
11396 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011397 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011398 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11399 goto nla_put_failure;
11400
11401 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11402 if (!pinfoattr)
11403 goto nla_put_failure;
11404
11405 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11406 goto nla_put_failure;
11407
11408 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11409 goto nla_put_failure;
11410
11411 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11412 goto nla_put_failure;
11413
11414 nla_nest_end(msg, pinfoattr);
11415
11416 genlmsg_end(msg, hdr);
11417
Johannes Berg68eb5502013-11-19 15:19:38 +010011418 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011419 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011420 return;
11421
11422 nla_put_failure:
11423 genlmsg_cancel(msg, hdr);
11424 nlmsg_free(msg);
11425}
Johannes Berg947add32013-02-22 22:05:20 +010011426EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011427
11428void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011429nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011430 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011431 enum nl80211_radar_event event,
11432 struct net_device *netdev, gfp_t gfp)
11433{
11434 struct sk_buff *msg;
11435 void *hdr;
11436
11437 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11438 if (!msg)
11439 return;
11440
11441 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11442 if (!hdr) {
11443 nlmsg_free(msg);
11444 return;
11445 }
11446
11447 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11448 goto nla_put_failure;
11449
11450 /* NOP and radar events don't need a netdev parameter */
11451 if (netdev) {
11452 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11453
11454 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11455 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11456 goto nla_put_failure;
11457 }
11458
11459 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11460 goto nla_put_failure;
11461
11462 if (nl80211_send_chandef(msg, chandef))
11463 goto nla_put_failure;
11464
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011465 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011466
Johannes Berg68eb5502013-11-19 15:19:38 +010011467 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011468 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011469 return;
11470
11471 nla_put_failure:
11472 genlmsg_cancel(msg, hdr);
11473 nlmsg_free(msg);
11474}
11475
Johannes Berg947add32013-02-22 22:05:20 +010011476void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11477 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011478{
Johannes Berg947add32013-02-22 22:05:20 +010011479 struct wireless_dev *wdev = dev->ieee80211_ptr;
11480 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011481 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011482 struct sk_buff *msg;
11483 struct nlattr *pinfoattr;
11484 void *hdr;
11485
Johannes Berg947add32013-02-22 22:05:20 +010011486 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11487
Thomas Graf58050fc2012-06-28 03:57:45 +000011488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011489 if (!msg)
11490 return;
11491
11492 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11493 if (!hdr) {
11494 nlmsg_free(msg);
11495 return;
11496 }
11497
David S. Miller9360ffd2012-03-29 04:41:26 -040011498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011499 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011500 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11501 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011502
11503 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11504 if (!pinfoattr)
11505 goto nla_put_failure;
11506
David S. Miller9360ffd2012-03-29 04:41:26 -040011507 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11508 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011509
11510 nla_nest_end(msg, pinfoattr);
11511
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011512 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011513
Johannes Berg68eb5502013-11-19 15:19:38 +010011514 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011515 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011516 return;
11517
11518 nla_put_failure:
11519 genlmsg_cancel(msg, hdr);
11520 nlmsg_free(msg);
11521}
Johannes Berg947add32013-02-22 22:05:20 +010011522EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011523
Johannes Berg7f6cf312011-11-04 11:18:15 +010011524void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11525 u64 cookie, bool acked, gfp_t gfp)
11526{
11527 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011528 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011529 struct sk_buff *msg;
11530 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011531
Beni Lev4ee3e062012-08-27 12:49:39 +030011532 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11533
Thomas Graf58050fc2012-06-28 03:57:45 +000011534 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011535
Johannes Berg7f6cf312011-11-04 11:18:15 +010011536 if (!msg)
11537 return;
11538
11539 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11540 if (!hdr) {
11541 nlmsg_free(msg);
11542 return;
11543 }
11544
David S. Miller9360ffd2012-03-29 04:41:26 -040011545 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11546 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11547 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11548 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11549 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11550 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011551
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011552 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011553
Johannes Berg68eb5502013-11-19 15:19:38 +010011554 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011555 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011556 return;
11557
11558 nla_put_failure:
11559 genlmsg_cancel(msg, hdr);
11560 nlmsg_free(msg);
11561}
11562EXPORT_SYMBOL(cfg80211_probe_status);
11563
Johannes Berg5e7602302011-11-04 11:18:17 +010011564void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11565 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011566 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010011567{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011568 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010011569 struct sk_buff *msg;
11570 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011571 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010011572
Beni Lev4ee3e062012-08-27 12:49:39 +030011573 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11574
Ben Greear37c73b52012-10-26 14:49:25 -070011575 spin_lock_bh(&rdev->beacon_registrations_lock);
11576 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11577 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11578 if (!msg) {
11579 spin_unlock_bh(&rdev->beacon_registrations_lock);
11580 return;
11581 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011582
Ben Greear37c73b52012-10-26 14:49:25 -070011583 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11584 if (!hdr)
11585 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010011586
Ben Greear37c73b52012-10-26 14:49:25 -070011587 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11588 (freq &&
11589 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11590 (sig_dbm &&
11591 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11592 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11593 goto nla_put_failure;
11594
11595 genlmsg_end(msg, hdr);
11596
11597 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010011598 }
Ben Greear37c73b52012-10-26 14:49:25 -070011599 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010011600 return;
11601
11602 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011603 spin_unlock_bh(&rdev->beacon_registrations_lock);
11604 if (hdr)
11605 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010011606 nlmsg_free(msg);
11607}
11608EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11609
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011610#ifdef CONFIG_PM
11611void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11612 struct cfg80211_wowlan_wakeup *wakeup,
11613 gfp_t gfp)
11614{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011615 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011616 struct sk_buff *msg;
11617 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011618 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011619
11620 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11621
11622 if (wakeup)
11623 size += wakeup->packet_present_len;
11624
11625 msg = nlmsg_new(size, gfp);
11626 if (!msg)
11627 return;
11628
11629 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11630 if (!hdr)
11631 goto free_msg;
11632
11633 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11634 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11635 goto free_msg;
11636
11637 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11638 wdev->netdev->ifindex))
11639 goto free_msg;
11640
11641 if (wakeup) {
11642 struct nlattr *reasons;
11643
11644 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011645 if (!reasons)
11646 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011647
11648 if (wakeup->disconnect &&
11649 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11650 goto free_msg;
11651 if (wakeup->magic_pkt &&
11652 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11653 goto free_msg;
11654 if (wakeup->gtk_rekey_failure &&
11655 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11656 goto free_msg;
11657 if (wakeup->eap_identity_req &&
11658 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11659 goto free_msg;
11660 if (wakeup->four_way_handshake &&
11661 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11662 goto free_msg;
11663 if (wakeup->rfkill_release &&
11664 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11665 goto free_msg;
11666
11667 if (wakeup->pattern_idx >= 0 &&
11668 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11669 wakeup->pattern_idx))
11670 goto free_msg;
11671
Johannes Bergae917c92013-10-25 11:05:22 +020011672 if (wakeup->tcp_match &&
11673 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11674 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011675
Johannes Bergae917c92013-10-25 11:05:22 +020011676 if (wakeup->tcp_connlost &&
11677 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11678 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011679
Johannes Bergae917c92013-10-25 11:05:22 +020011680 if (wakeup->tcp_nomoretokens &&
11681 nla_put_flag(msg,
11682 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11683 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011684
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011685 if (wakeup->packet) {
11686 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11687 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11688
11689 if (!wakeup->packet_80211) {
11690 pkt_attr =
11691 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11692 len_attr =
11693 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11694 }
11695
11696 if (wakeup->packet_len &&
11697 nla_put_u32(msg, len_attr, wakeup->packet_len))
11698 goto free_msg;
11699
11700 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11701 wakeup->packet))
11702 goto free_msg;
11703 }
11704
11705 nla_nest_end(msg, reasons);
11706 }
11707
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011708 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011709
Johannes Berg68eb5502013-11-19 15:19:38 +010011710 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011711 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011712 return;
11713
11714 free_msg:
11715 nlmsg_free(msg);
11716}
11717EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11718#endif
11719
Jouni Malinen3475b092012-11-16 22:49:57 +020011720void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11721 enum nl80211_tdls_operation oper,
11722 u16 reason_code, gfp_t gfp)
11723{
11724 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011725 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011726 struct sk_buff *msg;
11727 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011728
11729 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11730 reason_code);
11731
11732 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11733 if (!msg)
11734 return;
11735
11736 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11737 if (!hdr) {
11738 nlmsg_free(msg);
11739 return;
11740 }
11741
11742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11743 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11744 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11745 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11746 (reason_code > 0 &&
11747 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11748 goto nla_put_failure;
11749
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011750 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011751
Johannes Berg68eb5502013-11-19 15:19:38 +010011752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011753 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011754 return;
11755
11756 nla_put_failure:
11757 genlmsg_cancel(msg, hdr);
11758 nlmsg_free(msg);
11759}
11760EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11761
Jouni Malinen026331c2010-02-15 12:53:10 +020011762static int nl80211_netlink_notify(struct notifier_block * nb,
11763 unsigned long state,
11764 void *_notify)
11765{
11766 struct netlink_notify *notify = _notify;
11767 struct cfg80211_registered_device *rdev;
11768 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011769 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011770
11771 if (state != NETLINK_URELEASE)
11772 return NOTIFY_DONE;
11773
11774 rcu_read_lock();
11775
Johannes Berg5e7602302011-11-04 11:18:17 +010011776 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011777 bool schedule_destroy_work = false;
11778
11779 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011780 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011781
Johannes Berg78f22b62014-03-24 17:57:27 +010011782 if (wdev->owner_nlportid == notify->portid)
11783 schedule_destroy_work = true;
11784 }
11785
Ben Greear37c73b52012-10-26 14:49:25 -070011786 spin_lock_bh(&rdev->beacon_registrations_lock);
11787 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11788 list) {
11789 if (reg->nlportid == notify->portid) {
11790 list_del(&reg->list);
11791 kfree(reg);
11792 break;
11793 }
11794 }
11795 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011796
11797 if (schedule_destroy_work) {
11798 struct cfg80211_iface_destroy *destroy;
11799
11800 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11801 if (destroy) {
11802 destroy->nlportid = notify->portid;
11803 spin_lock(&rdev->destroy_list_lock);
11804 list_add(&destroy->list, &rdev->destroy_list);
11805 spin_unlock(&rdev->destroy_list_lock);
11806 schedule_work(&rdev->destroy_work);
11807 }
11808 }
Johannes Berg5e7602302011-11-04 11:18:17 +010011809 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011810
11811 rcu_read_unlock();
11812
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011813 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011814}
11815
11816static struct notifier_block nl80211_netlink_notifier = {
11817 .notifier_call = nl80211_netlink_notify,
11818};
11819
Jouni Malinen355199e2013-02-27 17:14:27 +020011820void cfg80211_ft_event(struct net_device *netdev,
11821 struct cfg80211_ft_event_params *ft_event)
11822{
11823 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011824 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011825 struct sk_buff *msg;
11826 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011827
11828 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11829
11830 if (!ft_event->target_ap)
11831 return;
11832
11833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11834 if (!msg)
11835 return;
11836
11837 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011838 if (!hdr)
11839 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011840
Johannes Bergae917c92013-10-25 11:05:22 +020011841 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11842 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11843 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11844 goto out;
11845
11846 if (ft_event->ies &&
11847 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11848 goto out;
11849 if (ft_event->ric_ies &&
11850 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11851 ft_event->ric_ies))
11852 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011853
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011854 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011855
Johannes Berg68eb5502013-11-19 15:19:38 +010011856 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011857 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011858 return;
11859 out:
11860 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011861}
11862EXPORT_SYMBOL(cfg80211_ft_event);
11863
Arend van Spriel5de17982013-04-18 15:49:00 +020011864void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11865{
11866 struct cfg80211_registered_device *rdev;
11867 struct sk_buff *msg;
11868 void *hdr;
11869 u32 nlportid;
11870
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011871 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011872 if (!rdev->crit_proto_nlportid)
11873 return;
11874
11875 nlportid = rdev->crit_proto_nlportid;
11876 rdev->crit_proto_nlportid = 0;
11877
11878 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11879 if (!msg)
11880 return;
11881
11882 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11883 if (!hdr)
11884 goto nla_put_failure;
11885
11886 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11887 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11888 goto nla_put_failure;
11889
11890 genlmsg_end(msg, hdr);
11891
11892 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11893 return;
11894
11895 nla_put_failure:
11896 if (hdr)
11897 genlmsg_cancel(msg, hdr);
11898 nlmsg_free(msg);
11899
11900}
11901EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11902
Johannes Berg348baf02014-01-24 14:06:29 +010011903void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11904{
11905 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011906 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011907 struct sk_buff *msg;
11908 void *hdr;
11909
11910 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11911 if (!msg)
11912 return;
11913
11914 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11915 if (!hdr)
11916 goto out;
11917
11918 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11919 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11920 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11921 goto out;
11922
11923 genlmsg_end(msg, hdr);
11924
11925 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11926 NL80211_MCGRP_MLME, GFP_KERNEL);
11927 return;
11928 out:
11929 nlmsg_free(msg);
11930}
11931
Johannes Berg55682962007-09-20 13:09:35 -040011932/* initialisation/exit functions */
11933
11934int nl80211_init(void)
11935{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011936 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011937
Johannes Berg2a94fe42013-11-19 15:19:39 +010011938 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11939 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011940 if (err)
11941 return err;
11942
Jouni Malinen026331c2010-02-15 12:53:10 +020011943 err = netlink_register_notifier(&nl80211_netlink_notifier);
11944 if (err)
11945 goto err_out;
11946
Johannes Berg55682962007-09-20 13:09:35 -040011947 return 0;
11948 err_out:
11949 genl_unregister_family(&nl80211_fam);
11950 return err;
11951}
11952
11953void nl80211_exit(void)
11954{
Jouni Malinen026331c2010-02-15 12:53:10 +020011955 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011956 genl_unregister_family(&nl80211_fam);
11957}