blob: d98d4ea278199c260d8751d094e0dc894aa3f7b5 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
62 [NL80211_MCGRP_CONFIG] = { .name = "config", },
63 [NL80211_MCGRP_SCAN] = { .name = "scan", },
64 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
65 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010066 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
68 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
69#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee47782012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee47782012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000212static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100391 [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400398};
399
Johannes Berge31b8212010-10-05 19:39:30 +0200400/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000401static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200402 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200403 [NL80211_KEY_IDX] = { .type = NLA_U8 },
404 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200405 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200406 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
407 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200408 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100409 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
410};
411
412/* policy for the key default flags */
413static const struct nla_policy
414nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
415 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
416 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200417};
418
Johannes Bergff1b6e62011-05-04 15:37:28 +0200419/* policy for WoWLAN attributes */
420static const struct nla_policy
421nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
422 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
423 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
424 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200426 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
427 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100430 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
431};
432
433static const struct nla_policy
434nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
435 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
436 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
437 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
438 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
439 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
440 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
441 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
442 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
443 },
444 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
445 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
446 },
447 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
448 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
449 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200450};
451
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700452/* policy for coalesce rule attributes */
453static const struct nla_policy
454nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
455 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
456 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
457 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
458};
459
Johannes Berge5497d72011-07-05 16:35:40 +0200460/* policy for GTK rekey offload attributes */
461static const struct nla_policy
462nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
463 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
464 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
465 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
466};
467
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300468static const struct nla_policy
469nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200470 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300471 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700472 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300473};
474
Johannes Berg97990a02013-04-19 01:02:55 +0200475static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
476 struct netlink_callback *cb,
477 struct cfg80211_registered_device **rdev,
478 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100479{
Johannes Berg67748892010-10-04 21:14:06 +0200480 int err;
481
Johannes Berg67748892010-10-04 21:14:06 +0200482 rtnl_lock();
483
Johannes Berg97990a02013-04-19 01:02:55 +0200484 if (!cb->args[0]) {
485 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
486 nl80211_fam.attrbuf, nl80211_fam.maxattr,
487 nl80211_policy);
488 if (err)
489 goto out_unlock;
490
491 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
492 nl80211_fam.attrbuf);
493 if (IS_ERR(*wdev)) {
494 err = PTR_ERR(*wdev);
495 goto out_unlock;
496 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800497 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200498 /* 0 is the first index - add 1 to parse only once */
499 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200500 cb->args[1] = (*wdev)->identifier;
501 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200502 /* subtract the 1 again here */
503 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200504 struct wireless_dev *tmp;
505
506 if (!wiphy) {
507 err = -ENODEV;
508 goto out_unlock;
509 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800510 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200511 *wdev = NULL;
512
Johannes Berg97990a02013-04-19 01:02:55 +0200513 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
514 if (tmp->identifier == cb->args[1]) {
515 *wdev = tmp;
516 break;
517 }
518 }
Johannes Berg97990a02013-04-19 01:02:55 +0200519
520 if (!*wdev) {
521 err = -ENODEV;
522 goto out_unlock;
523 }
Johannes Berg67748892010-10-04 21:14:06 +0200524 }
525
Johannes Berg67748892010-10-04 21:14:06 +0200526 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200527 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200528 rtnl_unlock();
529 return err;
530}
531
Johannes Berg97990a02013-04-19 01:02:55 +0200532static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200533{
Johannes Berg67748892010-10-04 21:14:06 +0200534 rtnl_unlock();
535}
536
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100537/* IE validation */
538static bool is_valid_ie_attr(const struct nlattr *attr)
539{
540 const u8 *pos;
541 int len;
542
543 if (!attr)
544 return true;
545
546 pos = nla_data(attr);
547 len = nla_len(attr);
548
549 while (len) {
550 u8 elemlen;
551
552 if (len < 2)
553 return false;
554 len -= 2;
555
556 elemlen = pos[1];
557 if (elemlen > len)
558 return false;
559
560 len -= elemlen;
561 pos += 2 + elemlen;
562 }
563
564 return true;
565}
566
Johannes Berg55682962007-09-20 13:09:35 -0400567/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000568static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400569 int flags, u8 cmd)
570{
571 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000572 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400573}
574
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400575static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100576 struct ieee80211_channel *chan,
577 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400578{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200579 /* Some channels must be completely excluded from the
580 * list to protect old user-space tools from breaking
581 */
582 if (!large && chan->flags &
583 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
584 return 0;
585
David S. Miller9360ffd2012-03-29 04:41:26 -0400586 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
587 chan->center_freq))
588 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400589
David S. Miller9360ffd2012-03-29 04:41:26 -0400590 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
591 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
592 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200593 if (chan->flags & IEEE80211_CHAN_NO_IR) {
594 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
595 goto nla_put_failure;
596 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
597 goto nla_put_failure;
598 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100599 if (chan->flags & IEEE80211_CHAN_RADAR) {
600 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
601 goto nla_put_failure;
602 if (large) {
603 u32 time;
604
605 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
606
607 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
608 chan->dfs_state))
609 goto nla_put_failure;
610 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
611 time))
612 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100613 if (nla_put_u32(msg,
614 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
615 chan->dfs_cac_ms))
616 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100617 }
618 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400619
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100620 if (large) {
621 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
622 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
623 goto nla_put_failure;
624 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
625 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
626 goto nla_put_failure;
627 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
632 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200633 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
638 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200639 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
641 goto nla_put_failure;
642 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
644 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100645 }
646
David S. Miller9360ffd2012-03-29 04:41:26 -0400647 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
648 DBM_TO_MBM(chan->max_power)))
649 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400650
651 return 0;
652
653 nla_put_failure:
654 return -ENOBUFS;
655}
656
Johannes Berg55682962007-09-20 13:09:35 -0400657/* netlink command implementations */
658
Johannes Bergb9454e82009-07-08 13:29:08 +0200659struct key_parse {
660 struct key_params p;
661 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200662 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200663 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100664 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200665};
666
667static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
668{
669 struct nlattr *tb[NL80211_KEY_MAX + 1];
670 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
671 nl80211_key_policy);
672 if (err)
673 return err;
674
675 k->def = !!tb[NL80211_KEY_DEFAULT];
676 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
677
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100678 if (k->def) {
679 k->def_uni = true;
680 k->def_multi = true;
681 }
682 if (k->defmgmt)
683 k->def_multi = true;
684
Johannes Bergb9454e82009-07-08 13:29:08 +0200685 if (tb[NL80211_KEY_IDX])
686 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
687
688 if (tb[NL80211_KEY_DATA]) {
689 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
690 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
691 }
692
693 if (tb[NL80211_KEY_SEQ]) {
694 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
695 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
696 }
697
698 if (tb[NL80211_KEY_CIPHER])
699 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
700
Johannes Berge31b8212010-10-05 19:39:30 +0200701 if (tb[NL80211_KEY_TYPE]) {
702 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
703 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
704 return -EINVAL;
705 }
706
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100707 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
708 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100709 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
710 tb[NL80211_KEY_DEFAULT_TYPES],
711 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (err)
713 return err;
714
715 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
716 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
717 }
718
Johannes Bergb9454e82009-07-08 13:29:08 +0200719 return 0;
720}
721
722static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
723{
724 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
725 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
726 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
727 }
728
729 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
730 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
731 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
732 }
733
734 if (info->attrs[NL80211_ATTR_KEY_IDX])
735 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
736
737 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
738 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
739
740 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
741 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
742
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100743 if (k->def) {
744 k->def_uni = true;
745 k->def_multi = true;
746 }
747 if (k->defmgmt)
748 k->def_multi = true;
749
Johannes Berge31b8212010-10-05 19:39:30 +0200750 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
751 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
752 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
753 return -EINVAL;
754 }
755
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100756 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
757 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
758 int err = nla_parse_nested(
759 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
760 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
761 nl80211_key_default_policy);
762 if (err)
763 return err;
764
765 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
766 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
767 }
768
Johannes Bergb9454e82009-07-08 13:29:08 +0200769 return 0;
770}
771
772static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
773{
774 int err;
775
776 memset(k, 0, sizeof(*k));
777 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200778 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200779
780 if (info->attrs[NL80211_ATTR_KEY])
781 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
782 else
783 err = nl80211_parse_key_old(info, k);
784
785 if (err)
786 return err;
787
788 if (k->def && k->defmgmt)
789 return -EINVAL;
790
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100791 if (k->defmgmt) {
792 if (k->def_uni || !k->def_multi)
793 return -EINVAL;
794 }
795
Johannes Bergb9454e82009-07-08 13:29:08 +0200796 if (k->idx != -1) {
797 if (k->defmgmt) {
798 if (k->idx < 4 || k->idx > 5)
799 return -EINVAL;
800 } else if (k->def) {
801 if (k->idx < 0 || k->idx > 3)
802 return -EINVAL;
803 } else {
804 if (k->idx < 0 || k->idx > 5)
805 return -EINVAL;
806 }
807 }
808
809 return 0;
810}
811
Johannes Bergfffd0932009-07-08 14:22:54 +0200812static struct cfg80211_cached_keys *
813nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530814 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200815{
816 struct key_parse parse;
817 struct nlattr *key;
818 struct cfg80211_cached_keys *result;
819 int rem, err, def = 0;
820
821 result = kzalloc(sizeof(*result), GFP_KERNEL);
822 if (!result)
823 return ERR_PTR(-ENOMEM);
824
825 result->def = -1;
826 result->defmgmt = -1;
827
828 nla_for_each_nested(key, keys, rem) {
829 memset(&parse, 0, sizeof(parse));
830 parse.idx = -1;
831
832 err = nl80211_parse_key_new(key, &parse);
833 if (err)
834 goto error;
835 err = -EINVAL;
836 if (!parse.p.key)
837 goto error;
838 if (parse.idx < 0 || parse.idx > 4)
839 goto error;
840 if (parse.def) {
841 if (def)
842 goto error;
843 def = 1;
844 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100845 if (!parse.def_uni || !parse.def_multi)
846 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200847 } else if (parse.defmgmt)
848 goto error;
849 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200850 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200851 if (err)
852 goto error;
853 result->params[parse.idx].cipher = parse.p.cipher;
854 result->params[parse.idx].key_len = parse.p.key_len;
855 result->params[parse.idx].key = result->data[parse.idx];
856 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530857
858 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
859 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
860 if (no_ht)
861 *no_ht = true;
862 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200863 }
864
865 return result;
866 error:
867 kfree(result);
868 return ERR_PTR(err);
869}
870
871static int nl80211_key_allowed(struct wireless_dev *wdev)
872{
873 ASSERT_WDEV_LOCK(wdev);
874
Johannes Bergfffd0932009-07-08 14:22:54 +0200875 switch (wdev->iftype) {
876 case NL80211_IFTYPE_AP:
877 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200878 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700879 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200880 break;
881 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200883 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200884 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200885 return -ENOLINK;
886 break;
887 default:
888 return -EINVAL;
889 }
890
891 return 0;
892}
893
Jouni Malinen664834d2014-01-15 00:01:44 +0200894static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
895 struct nlattr *tb)
896{
897 struct ieee80211_channel *chan;
898
899 if (tb == NULL)
900 return NULL;
901 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
902 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
903 return NULL;
904 return chan;
905}
906
Johannes Berg7527a782011-05-13 10:58:57 +0200907static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
908{
909 struct nlattr *nl_modes = nla_nest_start(msg, attr);
910 int i;
911
912 if (!nl_modes)
913 goto nla_put_failure;
914
915 i = 0;
916 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400917 if ((ifmodes & 1) && nla_put_flag(msg, i))
918 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200919 ifmodes >>= 1;
920 i++;
921 }
922
923 nla_nest_end(msg, nl_modes);
924 return 0;
925
926nla_put_failure:
927 return -ENOBUFS;
928}
929
930static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100931 struct sk_buff *msg,
932 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200933{
934 struct nlattr *nl_combis;
935 int i, j;
936
937 nl_combis = nla_nest_start(msg,
938 NL80211_ATTR_INTERFACE_COMBINATIONS);
939 if (!nl_combis)
940 goto nla_put_failure;
941
942 for (i = 0; i < wiphy->n_iface_combinations; i++) {
943 const struct ieee80211_iface_combination *c;
944 struct nlattr *nl_combi, *nl_limits;
945
946 c = &wiphy->iface_combinations[i];
947
948 nl_combi = nla_nest_start(msg, i + 1);
949 if (!nl_combi)
950 goto nla_put_failure;
951
952 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
953 if (!nl_limits)
954 goto nla_put_failure;
955
956 for (j = 0; j < c->n_limits; j++) {
957 struct nlattr *nl_limit;
958
959 nl_limit = nla_nest_start(msg, j + 1);
960 if (!nl_limit)
961 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400962 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
963 c->limits[j].max))
964 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200965 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
966 c->limits[j].types))
967 goto nla_put_failure;
968 nla_nest_end(msg, nl_limit);
969 }
970
971 nla_nest_end(msg, nl_limits);
972
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (c->beacon_int_infra_match &&
974 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
975 goto nla_put_failure;
976 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
977 c->num_different_channels) ||
978 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
979 c->max_interfaces))
980 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100981 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200982 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
983 c->radar_detect_widths) ||
984 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
985 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100986 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200987
988 nla_nest_end(msg, nl_combi);
989 }
990
991 nla_nest_end(msg, nl_combis);
992
993 return 0;
994nla_put_failure:
995 return -ENOBUFS;
996}
997
Johannes Berg3713b4e2013-02-14 16:19:38 +0100998#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100999static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1000 struct sk_buff *msg)
1001{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001002 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001003 struct nlattr *nl_tcp;
1004
1005 if (!tcp)
1006 return 0;
1007
1008 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1009 if (!nl_tcp)
1010 return -ENOBUFS;
1011
1012 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1013 tcp->data_payload_max))
1014 return -ENOBUFS;
1015
1016 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1017 tcp->data_payload_max))
1018 return -ENOBUFS;
1019
1020 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1021 return -ENOBUFS;
1022
1023 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1024 sizeof(*tcp->tok), tcp->tok))
1025 return -ENOBUFS;
1026
1027 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1028 tcp->data_interval_max))
1029 return -ENOBUFS;
1030
1031 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1032 tcp->wake_payload_max))
1033 return -ENOBUFS;
1034
1035 nla_nest_end(msg, nl_tcp);
1036 return 0;
1037}
1038
Johannes Berg3713b4e2013-02-14 16:19:38 +01001039static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001040 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001041 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001042{
1043 struct nlattr *nl_wowlan;
1044
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001045 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046 return 0;
1047
1048 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1049 if (!nl_wowlan)
1050 return -ENOBUFS;
1051
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001054 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001055 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001058 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001060 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001067 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1068 return -ENOBUFS;
1069
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001071 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1073 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1074 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1075 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 };
1077
1078 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1079 sizeof(pat), &pat))
1080 return -ENOBUFS;
1081 }
1082
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001083 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001084 return -ENOBUFS;
1085
Johannes Berg3713b4e2013-02-14 16:19:38 +01001086 nla_nest_end(msg, nl_wowlan);
1087
1088 return 0;
1089}
1090#endif
1091
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001092static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001093 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001094{
1095 struct nl80211_coalesce_rule_support rule;
1096
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001097 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001098 return 0;
1099
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1101 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1102 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1103 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1104 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1105 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001106
1107 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1108 return -ENOBUFS;
1109
1110 return 0;
1111}
1112
Johannes Berg3713b4e2013-02-14 16:19:38 +01001113static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1114 struct ieee80211_supported_band *sband)
1115{
1116 struct nlattr *nl_rates, *nl_rate;
1117 struct ieee80211_rate *rate;
1118 int i;
1119
1120 /* add HT info */
1121 if (sband->ht_cap.ht_supported &&
1122 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1123 sizeof(sband->ht_cap.mcs),
1124 &sband->ht_cap.mcs) ||
1125 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1126 sband->ht_cap.cap) ||
1127 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1128 sband->ht_cap.ampdu_factor) ||
1129 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1130 sband->ht_cap.ampdu_density)))
1131 return -ENOBUFS;
1132
1133 /* add VHT info */
1134 if (sband->vht_cap.vht_supported &&
1135 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1136 sizeof(sband->vht_cap.vht_mcs),
1137 &sband->vht_cap.vht_mcs) ||
1138 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1139 sband->vht_cap.cap)))
1140 return -ENOBUFS;
1141
1142 /* add bitrates */
1143 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1144 if (!nl_rates)
1145 return -ENOBUFS;
1146
1147 for (i = 0; i < sband->n_bitrates; i++) {
1148 nl_rate = nla_nest_start(msg, i);
1149 if (!nl_rate)
1150 return -ENOBUFS;
1151
1152 rate = &sband->bitrates[i];
1153 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1154 rate->bitrate))
1155 return -ENOBUFS;
1156 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1157 nla_put_flag(msg,
1158 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1159 return -ENOBUFS;
1160
1161 nla_nest_end(msg, nl_rate);
1162 }
1163
1164 nla_nest_end(msg, nl_rates);
1165
1166 return 0;
1167}
1168
1169static int
1170nl80211_send_mgmt_stypes(struct sk_buff *msg,
1171 const struct ieee80211_txrx_stypes *mgmt_stypes)
1172{
1173 u16 stypes;
1174 struct nlattr *nl_ftypes, *nl_ifs;
1175 enum nl80211_iftype ift;
1176 int i;
1177
1178 if (!mgmt_stypes)
1179 return 0;
1180
1181 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1182 if (!nl_ifs)
1183 return -ENOBUFS;
1184
1185 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1186 nl_ftypes = nla_nest_start(msg, ift);
1187 if (!nl_ftypes)
1188 return -ENOBUFS;
1189 i = 0;
1190 stypes = mgmt_stypes[ift].tx;
1191 while (stypes) {
1192 if ((stypes & 1) &&
1193 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1194 (i << 4) | IEEE80211_FTYPE_MGMT))
1195 return -ENOBUFS;
1196 stypes >>= 1;
1197 i++;
1198 }
1199 nla_nest_end(msg, nl_ftypes);
1200 }
1201
1202 nla_nest_end(msg, nl_ifs);
1203
1204 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1205 if (!nl_ifs)
1206 return -ENOBUFS;
1207
1208 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1209 nl_ftypes = nla_nest_start(msg, ift);
1210 if (!nl_ftypes)
1211 return -ENOBUFS;
1212 i = 0;
1213 stypes = mgmt_stypes[ift].rx;
1214 while (stypes) {
1215 if ((stypes & 1) &&
1216 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1217 (i << 4) | IEEE80211_FTYPE_MGMT))
1218 return -ENOBUFS;
1219 stypes >>= 1;
1220 i++;
1221 }
1222 nla_nest_end(msg, nl_ftypes);
1223 }
1224 nla_nest_end(msg, nl_ifs);
1225
1226 return 0;
1227}
1228
Johannes Berg86e8cf92013-06-19 10:57:22 +02001229struct nl80211_dump_wiphy_state {
1230 s64 filter_wiphy;
1231 long start;
1232 long split_start, band_start, chan_start;
1233 bool split;
1234};
1235
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001236static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001237 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001238 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001239 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001240{
1241 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001242 struct nlattr *nl_bands, *nl_band;
1243 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001244 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001245 enum ieee80211_band band;
1246 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001247 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02001248 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001249 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001250 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001251
Johannes Berg3bb20552014-05-26 13:52:25 +02001252 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001253 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001254 return -ENOBUFS;
1255
Johannes Berg86e8cf92013-06-19 10:57:22 +02001256 if (WARN_ON(!state))
1257 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001258
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001259 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001260 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001261 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001262 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001264 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001265
Johannes Berg3bb20552014-05-26 13:52:25 +02001266 if (cmd != NL80211_CMD_NEW_WIPHY)
1267 goto finish;
1268
Johannes Berg86e8cf92013-06-19 10:57:22 +02001269 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 case 0:
1271 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001272 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001274 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001276 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001280 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001285 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001286 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001291 goto nla_put_failure;
1292
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1295 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1298 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1301 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1304 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001305 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1307 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001308 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001310 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001311 state->split_start++;
1312 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 break;
1314 case 1:
1315 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1317 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001318 goto nla_put_failure;
1319
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001322 goto nla_put_failure;
1323
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1326 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001327
Johannes Berg3713b4e2013-02-14 16:19:38 +01001328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001336 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001338
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 if ((rdev->wiphy.available_antennas_tx ||
1340 rdev->wiphy.available_antennas_rx) &&
1341 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 u32 tx_ant = 0, rx_ant = 0;
1343 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001344 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 if (!res) {
1346 if (nla_put_u32(msg,
1347 NL80211_ATTR_WIPHY_ANTENNA_TX,
1348 tx_ant) ||
1349 nla_put_u32(msg,
1350 NL80211_ATTR_WIPHY_ANTENNA_RX,
1351 rx_ant))
1352 goto nla_put_failure;
1353 }
Johannes Bergee688b002008-01-24 19:38:39 +01001354 }
1355
Johannes Berg86e8cf92013-06-19 10:57:22 +02001356 state->split_start++;
1357 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 break;
1359 case 2:
1360 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001361 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001363 state->split_start++;
1364 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001365 break;
1366 case 3:
1367 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1368 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001369 goto nla_put_failure;
1370
Johannes Berg86e8cf92013-06-19 10:57:22 +02001371 for (band = state->band_start;
1372 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001373 struct ieee80211_supported_band *sband;
1374
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001375 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376
1377 if (!sband)
1378 continue;
1379
1380 nl_band = nla_nest_start(msg, band);
1381 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001382 goto nla_put_failure;
1383
Johannes Berg86e8cf92013-06-19 10:57:22 +02001384 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385 case 0:
1386 if (nl80211_send_band_rateinfo(msg, sband))
1387 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001388 state->chan_start++;
1389 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001390 break;
1391 default:
1392 /* add frequencies */
1393 nl_freqs = nla_nest_start(
1394 msg, NL80211_BAND_ATTR_FREQS);
1395 if (!nl_freqs)
1396 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001397
Johannes Berg86e8cf92013-06-19 10:57:22 +02001398 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 i < sband->n_channels;
1400 i++) {
1401 nl_freq = nla_nest_start(msg, i);
1402 if (!nl_freq)
1403 goto nla_put_failure;
1404
1405 chan = &sband->channels[i];
1406
Johannes Berg86e8cf92013-06-19 10:57:22 +02001407 if (nl80211_msg_put_channel(
1408 msg, chan,
1409 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001410 goto nla_put_failure;
1411
1412 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001413 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 break;
1415 }
1416 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001418 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001419 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 nla_nest_end(msg, nl_freqs);
1421 }
1422
1423 nla_nest_end(msg, nl_band);
1424
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 band--;
1429 break;
1430 }
Johannes Bergee688b002008-01-24 19:38:39 +01001431 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001433
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001437 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001438
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001440 if (state->band_start == 0 && state->chan_start == 0)
1441 state->split_start++;
1442 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 break;
1444 case 4:
1445 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1446 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001447 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448
1449 i = 0;
1450#define CMD(op, n) \
1451 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001452 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 i++; \
1454 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1455 goto nla_put_failure; \
1456 } \
1457 } while (0)
1458
1459 CMD(add_virtual_intf, NEW_INTERFACE);
1460 CMD(change_virtual_intf, SET_INTERFACE);
1461 CMD(add_key, NEW_KEY);
1462 CMD(start_ap, START_AP);
1463 CMD(add_station, NEW_STATION);
1464 CMD(add_mpath, NEW_MPATH);
1465 CMD(update_mesh_config, SET_MESH_CONFIG);
1466 CMD(change_bss, SET_BSS);
1467 CMD(auth, AUTHENTICATE);
1468 CMD(assoc, ASSOCIATE);
1469 CMD(deauth, DEAUTHENTICATE);
1470 CMD(disassoc, DISASSOCIATE);
1471 CMD(join_ibss, JOIN_IBSS);
1472 CMD(join_mesh, JOIN_MESH);
1473 CMD(set_pmksa, SET_PMKSA);
1474 CMD(del_pmksa, DEL_PMKSA);
1475 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001476 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1478 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1479 CMD(mgmt_tx, FRAME);
1480 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001481 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 i++;
1483 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1484 goto nla_put_failure;
1485 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001486 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1487 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 i++;
1489 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1490 goto nla_put_failure;
1491 }
1492 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 CMD(tdls_mgmt, TDLS_MGMT);
1495 CMD(tdls_oper, TDLS_OPER);
1496 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 CMD(sched_scan_start, START_SCHED_SCAN);
1499 CMD(probe_client, PROBE_CLIENT);
1500 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001501 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001502 i++;
1503 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1504 goto nla_put_failure;
1505 }
1506 CMD(start_p2p_device, START_P2P_DEVICE);
1507 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001508#ifdef CONFIG_NL80211_TESTMODE
1509 CMD(testmode_cmd, TESTMODE);
1510#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001511 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001512 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1513 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001515 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001516 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001517 if (rdev->wiphy.features &
1518 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001519 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001520 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001521 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001522#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001523
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001524 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001525 i++;
1526 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f782010-08-12 15:38:38 +02001527 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001528 }
1529
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 i++;
1532 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1533 goto nla_put_failure;
1534 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001535
Johannes Berg3713b4e2013-02-14 16:19:38 +01001536 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001537 state->split_start++;
1538 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001539 break;
1540 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if (rdev->ops->remain_on_channel &&
1542 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 nla_put_u32(msg,
1544 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001545 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02001546 goto nla_put_failure;
1547
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001548 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1550 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02001551
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1553 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001554 state->split_start++;
1555 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 break;
1557 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001558#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001561 state->split_start++;
1562 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001563 break;
1564#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001565 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566#endif
1567 case 7:
1568 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001569 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001570 goto nla_put_failure;
1571
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001573 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001575
Johannes Berg86e8cf92013-06-19 10:57:22 +02001576 state->split_start++;
1577 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 break;
1579 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001580 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001581 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001582 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 goto nla_put_failure;
1584
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001586 /*
1587 * We can only add the per-channel limit information if the
1588 * dump is split, otherwise it makes it too big. Therefore
1589 * only advertise it in that case.
1590 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001591 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001592 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1593 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 goto nla_put_failure;
1595
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1599 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 goto nla_put_failure;
1601
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001602 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1603 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001605 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001606 goto nla_put_failure;
1607
1608 /*
1609 * Any information below this point is only available to
1610 * applications that can deal with it being split. This
1611 * helps ensure that newly added capabilities don't break
1612 * older tools by overrunning their buffers.
1613 *
1614 * We still increment split_start so that in the split
1615 * case we'll continue with more data in the next round,
1616 * but break unconditionally so unsplit data stops here.
1617 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001618 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001619 break;
1620 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001622 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 rdev->wiphy.extended_capabilities_len,
1624 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001625 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 rdev->wiphy.extended_capabilities_len,
1627 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001628 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001631 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1633 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001634 goto nla_put_failure;
1635
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001636 state->split_start++;
1637 break;
1638 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001640 goto nla_put_failure;
1641
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001643 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1644 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1645 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001646
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001648 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001650 goto nla_put_failure;
1651
Johannes Bergad7e7182013-11-13 13:37:47 +01001652 state->split_start++;
1653 break;
1654 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001656 const struct nl80211_vendor_cmd_info *info;
1657 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001658
Johannes Berg567ffc32013-12-18 14:43:31 +01001659 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1660 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001661 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1664 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001665 if (nla_put(msg, i + 1, sizeof(*info), info))
1666 goto nla_put_failure;
1667 }
1668 nla_nest_end(msg, nested);
1669 }
1670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 const struct nl80211_vendor_cmd_info *info;
1673 struct nlattr *nested;
1674
1675 nested = nla_nest_start(msg,
1676 NL80211_ATTR_VENDOR_EVENTS);
1677 if (!nested)
1678 goto nla_put_failure;
1679
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1681 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001682 if (nla_put(msg, i + 1, sizeof(*info), info))
1683 goto nla_put_failure;
1684 }
1685 nla_nest_end(msg, nested);
1686 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001687 state->split_start++;
1688 break;
1689 case 12:
1690 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1691 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1692 rdev->wiphy.max_num_csa_counters))
1693 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001694
Johannes Berg3713b4e2013-02-14 16:19:38 +01001695 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001696 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001697 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001698 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001699 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001700 return genlmsg_end(msg, hdr);
1701
1702 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001703 genlmsg_cancel(msg, hdr);
1704 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001705}
1706
Johannes Berg86e8cf92013-06-19 10:57:22 +02001707static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1708 struct netlink_callback *cb,
1709 struct nl80211_dump_wiphy_state *state)
1710{
1711 struct nlattr **tb = nl80211_fam.attrbuf;
1712 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1713 tb, nl80211_fam.maxattr, nl80211_policy);
1714 /* ignore parse errors for backward compatibility */
1715 if (ret)
1716 return 0;
1717
1718 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1719 if (tb[NL80211_ATTR_WIPHY])
1720 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1721 if (tb[NL80211_ATTR_WDEV])
1722 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1723 if (tb[NL80211_ATTR_IFINDEX]) {
1724 struct net_device *netdev;
1725 struct cfg80211_registered_device *rdev;
1726 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1727
Ying Xue7f2b8562014-01-15 10:23:45 +08001728 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001729 if (!netdev)
1730 return -ENODEV;
1731 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001732 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001733 netdev->ieee80211_ptr->wiphy);
1734 state->filter_wiphy = rdev->wiphy_idx;
1735 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001736 }
1737
1738 return 0;
1739}
1740
Johannes Berg55682962007-09-20 13:09:35 -04001741static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1742{
Johannes Berg645e77d2013-03-01 14:03:49 +01001743 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001745 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001746
Johannes Berg5fe231e2013-05-08 21:45:15 +02001747 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001748 if (!state) {
1749 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001750 if (!state) {
1751 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001754 state->filter_wiphy = -1;
1755 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1756 if (ret) {
1757 kfree(state);
1758 rtnl_unlock();
1759 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001760 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001761 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001762 }
1763
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001764 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1765 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001766 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001767 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001768 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001769 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001770 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001771 continue;
1772 /* attempt to fit multiple wiphy data chunks into the skb */
1773 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001774 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1775 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001776 NETLINK_CB(cb->skb).portid,
1777 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 if (ret < 0) {
1780 /*
1781 * If sending the wiphy data didn't fit (ENOBUFS
1782 * or EMSGSIZE returned), this SKB is still
1783 * empty (so it's not too big because another
1784 * wiphy dataset is already in the skb) and
1785 * we've not tried to adjust the dump allocation
1786 * yet ... then adjust the alloc size to be
1787 * bigger, and return 1 but with the empty skb.
1788 * This results in an empty message being RX'ed
1789 * in userspace, but that is ignored.
1790 *
1791 * We can then retry with the larger buffer.
1792 */
1793 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001794 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001795 cb->min_dump_alloc < 4096) {
1796 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001797 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001798 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001799 return 1;
1800 }
1801 idx--;
1802 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001803 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 break;
Johannes Berg55682962007-09-20 13:09:35 -04001806 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001807 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001808
Johannes Berg86e8cf92013-06-19 10:57:22 +02001809 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001810
1811 return skb->len;
1812}
1813
Johannes Berg86e8cf92013-06-19 10:57:22 +02001814static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1815{
1816 kfree((void *)cb->args[0]);
1817 return 0;
1818}
1819
Johannes Berg55682962007-09-20 13:09:35 -04001820static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1821{
1822 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001824 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001825
Johannes Berg645e77d2013-03-01 14:03:49 +01001826 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001827 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001828 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001829
Johannes Berg3bb20552014-05-26 13:52:25 +02001830 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1831 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001832 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001833 nlmsg_free(msg);
1834 return -ENOBUFS;
1835 }
Johannes Berg55682962007-09-20 13:09:35 -04001836
Johannes Berg134e6372009-07-10 09:51:34 +00001837 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001838}
1839
Jouni Malinen31888482008-10-30 16:59:24 +02001840static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1841 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1842 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1843 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1844 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1845 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1846};
1847
1848static int parse_txq_params(struct nlattr *tb[],
1849 struct ieee80211_txq_params *txq_params)
1850{
Johannes Berga3304b02012-03-28 11:04:24 +02001851 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001852 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1853 !tb[NL80211_TXQ_ATTR_AIFS])
1854 return -EINVAL;
1855
Johannes Berga3304b02012-03-28 11:04:24 +02001856 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001857 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1858 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1859 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1860 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1861
Johannes Berga3304b02012-03-28 11:04:24 +02001862 if (txq_params->ac >= NL80211_NUM_ACS)
1863 return -EINVAL;
1864
Jouni Malinen31888482008-10-30 16:59:24 +02001865 return 0;
1866}
1867
Johannes Bergf444de02010-05-05 15:25:02 +02001868static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1869{
1870 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001871 * You can only set the channel explicitly for WDS interfaces,
1872 * all others have their channel managed via their respective
1873 * "establish a connection" command (connect, join, ...)
1874 *
1875 * For AP/GO and mesh mode, the channel can be set with the
1876 * channel userspace API, but is only stored and passed to the
1877 * low-level driver when the AP starts or the mesh is joined.
1878 * This is for backward compatibility, userspace can also give
1879 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001880 *
1881 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001882 * whatever else is going on, so they have their own special
1883 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001884 */
1885 return !wdev ||
1886 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001887 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001888 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1889 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001890}
1891
Johannes Berg683b6d32012-11-08 21:25:48 +01001892static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1893 struct genl_info *info,
1894 struct cfg80211_chan_def *chandef)
1895{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301896 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001897
1898 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1899 return -EINVAL;
1900
1901 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1902
1903 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001904 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1905 chandef->center_freq1 = control_freq;
1906 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001907
1908 /* Primary channel not allowed */
1909 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1910 return -EINVAL;
1911
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001912 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1913 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001914
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001915 chantype = nla_get_u32(
1916 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1917
1918 switch (chantype) {
1919 case NL80211_CHAN_NO_HT:
1920 case NL80211_CHAN_HT20:
1921 case NL80211_CHAN_HT40PLUS:
1922 case NL80211_CHAN_HT40MINUS:
1923 cfg80211_chandef_create(chandef, chandef->chan,
1924 chantype);
1925 break;
1926 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001927 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001928 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001929 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1930 chandef->width =
1931 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1932 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1933 chandef->center_freq1 =
1934 nla_get_u32(
1935 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1936 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1937 chandef->center_freq2 =
1938 nla_get_u32(
1939 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1940 }
1941
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001942 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001943 return -EINVAL;
1944
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001945 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1946 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001947 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001948
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001949 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1950 chandef->width == NL80211_CHAN_WIDTH_10) &&
1951 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1952 return -EINVAL;
1953
Johannes Berg683b6d32012-11-08 21:25:48 +01001954 return 0;
1955}
1956
Johannes Bergf444de02010-05-05 15:25:02 +02001957static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001958 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001959 struct genl_info *info)
1960{
Johannes Berg683b6d32012-11-08 21:25:48 +01001961 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001962 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001963 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001964 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001965
Jouni Malinene16821b2014-04-28 11:22:08 +03001966 if (dev)
1967 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001968 if (!nl80211_can_set_dev_channel(wdev))
1969 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001970 if (wdev)
1971 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001972
Johannes Berg683b6d32012-11-08 21:25:48 +01001973 result = nl80211_parse_chandef(rdev, info, &chandef);
1974 if (result)
1975 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001976
Johannes Berge8c9bd52012-06-06 08:18:22 +02001977 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001978 case NL80211_IFTYPE_AP:
1979 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001980 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001981 result = -EINVAL;
1982 break;
1983 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001984 if (wdev->beacon_interval) {
1985 if (!dev || !rdev->ops->set_ap_chanwidth ||
1986 !(rdev->wiphy.features &
1987 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1988 result = -EBUSY;
1989 break;
1990 }
1991
1992 /* Only allow dynamic channel width changes */
1993 if (chandef.chan != wdev->preset_chandef.chan) {
1994 result = -EBUSY;
1995 break;
1996 }
1997 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1998 if (result)
1999 break;
2000 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002001 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002002 result = 0;
2003 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002004 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002005 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002006 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002007 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002008 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002009 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002010 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002011 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002012 }
Johannes Bergf444de02010-05-05 15:25:02 +02002013
2014 return result;
2015}
2016
2017static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2018{
Johannes Berg4c476992010-10-04 21:36:35 +02002019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2020 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002021
Jouni Malinene16821b2014-04-28 11:22:08 +03002022 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002023}
2024
Bill Jordane8347eb2010-10-01 13:54:28 -04002025static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2026{
Johannes Berg43b19952010-10-07 13:10:30 +02002027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2028 struct net_device *dev = info->user_ptr[1];
2029 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002030 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002031
2032 if (!info->attrs[NL80211_ATTR_MAC])
2033 return -EINVAL;
2034
Johannes Berg43b19952010-10-07 13:10:30 +02002035 if (netif_running(dev))
2036 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002037
Johannes Berg43b19952010-10-07 13:10:30 +02002038 if (!rdev->ops->set_wds_peer)
2039 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002040
Johannes Berg43b19952010-10-07 13:10:30 +02002041 if (wdev->iftype != NL80211_IFTYPE_WDS)
2042 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002043
2044 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002045 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002046}
2047
2048
Johannes Berg55682962007-09-20 13:09:35 -04002049static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2050{
2051 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002052 struct net_device *netdev = NULL;
2053 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002054 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002055 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056 u32 changed;
2057 u8 retry_short = 0, retry_long = 0;
2058 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002059 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002060
Johannes Berg5fe231e2013-05-08 21:45:15 +02002061 ASSERT_RTNL();
2062
Johannes Bergf444de02010-05-05 15:25:02 +02002063 /*
2064 * Try to find the wiphy and netdev. Normally this
2065 * function shouldn't need the netdev, but this is
2066 * done for backward compatibility -- previously
2067 * setting the channel was done per wiphy, but now
2068 * it is per netdev. Previous userland like hostapd
2069 * also passed a netdev to set_wiphy, so that it is
2070 * possible to let that go to the right netdev!
2071 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002072
Johannes Bergf444de02010-05-05 15:25:02 +02002073 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2074 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2075
Ying Xue7f2b8562014-01-15 10:23:45 +08002076 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002077 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002078 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002079 else
Johannes Bergf444de02010-05-05 15:25:02 +02002080 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002081 }
2082
Johannes Bergf444de02010-05-05 15:25:02 +02002083 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002084 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2085 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002086 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002087 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002088 wdev = NULL;
2089 netdev = NULL;
2090 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002091 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002092 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002093
2094 /*
2095 * end workaround code, by now the rdev is available
2096 * and locked, and wdev may or may not be NULL.
2097 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002098
2099 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002100 result = cfg80211_dev_rename(
2101 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002102
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002103 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002104 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002105
Jouni Malinen31888482008-10-30 16:59:24 +02002106 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2107 struct ieee80211_txq_params txq_params;
2108 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2109
Ying Xue7f2b8562014-01-15 10:23:45 +08002110 if (!rdev->ops->set_txq_params)
2111 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002112
Ying Xue7f2b8562014-01-15 10:23:45 +08002113 if (!netdev)
2114 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002115
Johannes Berg133a3ff2011-11-03 14:50:13 +01002116 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002117 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2118 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002119
Ying Xue7f2b8562014-01-15 10:23:45 +08002120 if (!netif_running(netdev))
2121 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002122
Jouni Malinen31888482008-10-30 16:59:24 +02002123 nla_for_each_nested(nl_txq_params,
2124 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2125 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002126 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2127 nla_data(nl_txq_params),
2128 nla_len(nl_txq_params),
2129 txq_params_policy);
2130 if (result)
2131 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002132 result = parse_txq_params(tb, &txq_params);
2133 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002134 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002135
Hila Gonene35e4d22012-06-27 17:19:42 +03002136 result = rdev_set_txq_params(rdev, netdev,
2137 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002138 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002140 }
2141 }
2142
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002143 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002144 result = __nl80211_set_channel(
2145 rdev,
2146 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2147 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002148 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002149 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002150 }
2151
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002152 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002153 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002154 enum nl80211_tx_power_setting type;
2155 int idx, mbm = 0;
2156
Johannes Bergc8442112012-10-24 10:17:18 +02002157 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2158 txp_wdev = NULL;
2159
Ying Xue7f2b8562014-01-15 10:23:45 +08002160 if (!rdev->ops->set_tx_power)
2161 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002162
2163 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2164 type = nla_get_u32(info->attrs[idx]);
2165
2166 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 (type != NL80211_TX_POWER_AUTOMATIC))
2168 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002169
2170 if (type != NL80211_TX_POWER_AUTOMATIC) {
2171 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2172 mbm = nla_get_u32(info->attrs[idx]);
2173 }
2174
Johannes Bergc8442112012-10-24 10:17:18 +02002175 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002176 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002177 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002178 }
2179
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002180 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2181 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2182 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002183 if ((!rdev->wiphy.available_antennas_tx &&
2184 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002185 !rdev->ops->set_antenna)
2186 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002187
2188 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2189 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2190
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002191 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002192 * available antenna masks, except for the "all" mask */
2193 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2195 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002196
Bruno Randolf7f531e02010-12-16 11:30:22 +09002197 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2198 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002199
Hila Gonene35e4d22012-06-27 17:19:42 +03002200 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002201 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002202 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002203 }
2204
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002205 changed = 0;
2206
2207 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2208 retry_short = nla_get_u8(
2209 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 if (retry_short == 0)
2211 return -EINVAL;
2212
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002213 changed |= WIPHY_PARAM_RETRY_SHORT;
2214 }
2215
2216 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2217 retry_long = nla_get_u8(
2218 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002219 if (retry_long == 0)
2220 return -EINVAL;
2221
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002222 changed |= WIPHY_PARAM_RETRY_LONG;
2223 }
2224
2225 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2226 frag_threshold = nla_get_u32(
2227 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 if (frag_threshold < 256)
2229 return -EINVAL;
2230
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002231 if (frag_threshold != (u32) -1) {
2232 /*
2233 * Fragments (apart from the last one) are required to
2234 * have even length. Make the fragmentation code
2235 * simpler by stripping LSB should someone try to use
2236 * odd threshold value.
2237 */
2238 frag_threshold &= ~0x1;
2239 }
2240 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2241 }
2242
2243 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2244 rts_threshold = nla_get_u32(
2245 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2246 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2247 }
2248
Lukáš Turek81077e82009-12-21 22:50:47 +01002249 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002250 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2251 return -EINVAL;
2252
Lukáš Turek81077e82009-12-21 22:50:47 +01002253 coverage_class = nla_get_u8(
2254 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2255 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2256 }
2257
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002258 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2259 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2260 return -EOPNOTSUPP;
2261
2262 changed |= WIPHY_PARAM_DYN_ACK;
2263 }
2264
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002265 if (changed) {
2266 u8 old_retry_short, old_retry_long;
2267 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002268 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002269
Ying Xue7f2b8562014-01-15 10:23:45 +08002270 if (!rdev->ops->set_wiphy_params)
2271 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002272
2273 old_retry_short = rdev->wiphy.retry_short;
2274 old_retry_long = rdev->wiphy.retry_long;
2275 old_frag_threshold = rdev->wiphy.frag_threshold;
2276 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002277 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002278
2279 if (changed & WIPHY_PARAM_RETRY_SHORT)
2280 rdev->wiphy.retry_short = retry_short;
2281 if (changed & WIPHY_PARAM_RETRY_LONG)
2282 rdev->wiphy.retry_long = retry_long;
2283 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2284 rdev->wiphy.frag_threshold = frag_threshold;
2285 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2286 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002287 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2288 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002289
Hila Gonene35e4d22012-06-27 17:19:42 +03002290 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002291 if (result) {
2292 rdev->wiphy.retry_short = old_retry_short;
2293 rdev->wiphy.retry_long = old_retry_long;
2294 rdev->wiphy.frag_threshold = old_frag_threshold;
2295 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002296 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002297 }
2298 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002299 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002300}
2301
Johannes Berg71bbc992012-06-15 15:30:18 +02002302static inline u64 wdev_id(struct wireless_dev *wdev)
2303{
2304 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002305 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002306}
Johannes Berg55682962007-09-20 13:09:35 -04002307
Johannes Berg683b6d32012-11-08 21:25:48 +01002308static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002309 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002310{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002311 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002312
Johannes Berg683b6d32012-11-08 21:25:48 +01002313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2314 chandef->chan->center_freq))
2315 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002316 switch (chandef->width) {
2317 case NL80211_CHAN_WIDTH_20_NOHT:
2318 case NL80211_CHAN_WIDTH_20:
2319 case NL80211_CHAN_WIDTH_40:
2320 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2321 cfg80211_get_chandef_type(chandef)))
2322 return -ENOBUFS;
2323 break;
2324 default:
2325 break;
2326 }
2327 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2328 return -ENOBUFS;
2329 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2330 return -ENOBUFS;
2331 if (chandef->center_freq2 &&
2332 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002333 return -ENOBUFS;
2334 return 0;
2335}
2336
Eric W. Biederman15e47302012-09-07 20:12:54 +00002337static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002338 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002339 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002340{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002341 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002342 void *hdr;
2343
Eric W. Biederman15e47302012-09-07 20:12:54 +00002344 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002345 if (!hdr)
2346 return -1;
2347
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002348 if (dev &&
2349 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002350 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002351 goto nla_put_failure;
2352
2353 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2354 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002355 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002356 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002357 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2358 rdev->devlist_generation ^
2359 (cfg80211_rdev_list_generation << 2)))
2360 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002361
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002362 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002363 int ret;
2364 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002365
Johannes Berg683b6d32012-11-08 21:25:48 +01002366 ret = rdev_get_channel(rdev, wdev, &chandef);
2367 if (ret == 0) {
2368 if (nl80211_send_chandef(msg, &chandef))
2369 goto nla_put_failure;
2370 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002371 }
2372
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002373 if (wdev->ssid_len) {
2374 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2375 goto nla_put_failure;
2376 }
2377
Johannes Berg55682962007-09-20 13:09:35 -04002378 return genlmsg_end(msg, hdr);
2379
2380 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002381 genlmsg_cancel(msg, hdr);
2382 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002383}
2384
2385static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2386{
2387 int wp_idx = 0;
2388 int if_idx = 0;
2389 int wp_start = cb->args[0];
2390 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002391 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002392 struct wireless_dev *wdev;
2393
Johannes Berg5fe231e2013-05-08 21:45:15 +02002394 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002395 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2396 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002397 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002398 if (wp_idx < wp_start) {
2399 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002400 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002401 }
Johannes Berg55682962007-09-20 13:09:35 -04002402 if_idx = 0;
2403
Johannes Berg89a54e42012-06-15 14:33:17 +02002404 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002405 if (if_idx < if_start) {
2406 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002407 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002408 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002409 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002410 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002411 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002412 goto out;
2413 }
2414 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002415 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002416
2417 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002418 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002419 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002420 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002421
2422 cb->args[0] = wp_idx;
2423 cb->args[1] = if_idx;
2424
2425 return skb->len;
2426}
2427
2428static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2429{
2430 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002432 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002433
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002434 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002435 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002436 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002437
Eric W. Biederman15e47302012-09-07 20:12:54 +00002438 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002439 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002440 nlmsg_free(msg);
2441 return -ENOBUFS;
2442 }
Johannes Berg55682962007-09-20 13:09:35 -04002443
Johannes Berg134e6372009-07-10 09:51:34 +00002444 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002445}
2446
Michael Wu66f7ac52008-01-31 19:48:22 +01002447static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2448 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2449 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2450 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2451 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2452 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002453 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002454};
2455
2456static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2457{
2458 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2459 int flag;
2460
2461 *mntrflags = 0;
2462
2463 if (!nla)
2464 return -EINVAL;
2465
2466 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2467 nla, mntr_flags_policy))
2468 return -EINVAL;
2469
2470 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2471 if (flags[flag])
2472 *mntrflags |= (1<<flag);
2473
2474 return 0;
2475}
2476
Johannes Berg9bc383d2009-11-19 11:55:19 +01002477static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002478 struct net_device *netdev, u8 use_4addr,
2479 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002480{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002481 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002482 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002483 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002484 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002485 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002486
2487 switch (iftype) {
2488 case NL80211_IFTYPE_AP_VLAN:
2489 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2490 return 0;
2491 break;
2492 case NL80211_IFTYPE_STATION:
2493 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2494 return 0;
2495 break;
2496 default:
2497 break;
2498 }
2499
2500 return -EOPNOTSUPP;
2501}
2502
Johannes Berg55682962007-09-20 13:09:35 -04002503static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2504{
Johannes Berg4c476992010-10-04 21:36:35 +02002505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002506 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002507 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002508 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002509 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002510 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002511 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002512
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002513 memset(&params, 0, sizeof(params));
2514
Johannes Berg04a773a2009-04-19 21:24:32 +02002515 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002516
Johannes Berg723b0382008-09-16 20:22:09 +02002517 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002518 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002519 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002520 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002521 if (ntype > NL80211_IFTYPE_MAX)
2522 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002523 }
2524
Johannes Berg92ffe052008-09-16 20:39:36 +02002525 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002526 struct wireless_dev *wdev = dev->ieee80211_ptr;
2527
Johannes Berg4c476992010-10-04 21:36:35 +02002528 if (ntype != NL80211_IFTYPE_MESH_POINT)
2529 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002530 if (netif_running(dev))
2531 return -EBUSY;
2532
2533 wdev_lock(wdev);
2534 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2535 IEEE80211_MAX_MESH_ID_LEN);
2536 wdev->mesh_id_up_len =
2537 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2538 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2539 wdev->mesh_id_up_len);
2540 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002541 }
2542
Felix Fietkau8b787642009-11-10 18:53:10 +01002543 if (info->attrs[NL80211_ATTR_4ADDR]) {
2544 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2545 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002546 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002547 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002548 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002549 } else {
2550 params.use_4addr = -1;
2551 }
2552
Johannes Berg92ffe052008-09-16 20:39:36 +02002553 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002554 if (ntype != NL80211_IFTYPE_MONITOR)
2555 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002556 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2557 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002558 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002559 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002560
2561 flags = &_flags;
2562 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002563 }
Johannes Berg3b858752009-03-12 09:55:09 +01002564
Luciano Coelho18003292013-08-29 13:26:57 +03002565 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002566 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2567 return -EOPNOTSUPP;
2568
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002569 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002570 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002571 else
2572 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002573
Johannes Berg9bc383d2009-11-19 11:55:19 +01002574 if (!err && params.use_4addr != -1)
2575 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2576
Johannes Berg55682962007-09-20 13:09:35 -04002577 return err;
2578}
2579
2580static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2581{
Johannes Berg4c476992010-10-04 21:36:35 +02002582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002583 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002584 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002585 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002586 int err;
2587 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002588 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002589
Johannes Berg78f22b62014-03-24 17:57:27 +01002590 /* to avoid failing a new interface creation due to pending removal */
2591 cfg80211_destroy_ifaces(rdev);
2592
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002593 memset(&params, 0, sizeof(params));
2594
Johannes Berg55682962007-09-20 13:09:35 -04002595 if (!info->attrs[NL80211_ATTR_IFNAME])
2596 return -EINVAL;
2597
2598 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2599 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2600 if (type > NL80211_IFTYPE_MAX)
2601 return -EINVAL;
2602 }
2603
Johannes Berg79c97e92009-07-07 03:56:12 +02002604 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002605 !(rdev->wiphy.interface_modes & (1 << type)))
2606 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002607
Arend van Spriel1c18f142013-01-08 10:17:27 +01002608 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2609 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2610 ETH_ALEN);
2611 if (!is_valid_ether_addr(params.macaddr))
2612 return -EADDRNOTAVAIL;
2613 }
2614
Johannes Berg9bc383d2009-11-19 11:55:19 +01002615 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002616 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002617 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002618 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002619 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002620 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002621
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2623 if (!msg)
2624 return -ENOMEM;
2625
Michael Wu66f7ac52008-01-31 19:48:22 +01002626 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2627 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2628 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002629
Luciano Coelho18003292013-08-29 13:26:57 +03002630 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002631 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2632 return -EOPNOTSUPP;
2633
Hila Gonene35e4d22012-06-27 17:19:42 +03002634 wdev = rdev_add_virtual_intf(rdev,
2635 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2636 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002637 if (IS_ERR(wdev)) {
2638 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002639 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002640 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002641
Johannes Berg78f22b62014-03-24 17:57:27 +01002642 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2643 wdev->owner_nlportid = info->snd_portid;
2644
Johannes Berg98104fde2012-06-16 00:19:54 +02002645 switch (type) {
2646 case NL80211_IFTYPE_MESH_POINT:
2647 if (!info->attrs[NL80211_ATTR_MESH_ID])
2648 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002649 wdev_lock(wdev);
2650 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2651 IEEE80211_MAX_MESH_ID_LEN);
2652 wdev->mesh_id_up_len =
2653 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2654 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2655 wdev->mesh_id_up_len);
2656 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002657 break;
2658 case NL80211_IFTYPE_P2P_DEVICE:
2659 /*
2660 * P2P Device doesn't have a netdev, so doesn't go
2661 * through the netdev notifier and must be added here
2662 */
2663 mutex_init(&wdev->mtx);
2664 INIT_LIST_HEAD(&wdev->event_list);
2665 spin_lock_init(&wdev->event_lock);
2666 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2667 spin_lock_init(&wdev->mgmt_registrations_lock);
2668
Johannes Berg98104fde2012-06-16 00:19:54 +02002669 wdev->identifier = ++rdev->wdev_id;
2670 list_add_rcu(&wdev->list, &rdev->wdev_list);
2671 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002672 break;
2673 default:
2674 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002675 }
2676
Eric W. Biederman15e47302012-09-07 20:12:54 +00002677 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002678 rdev, wdev) < 0) {
2679 nlmsg_free(msg);
2680 return -ENOBUFS;
2681 }
2682
2683 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002684}
2685
2686static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2687{
Johannes Berg4c476992010-10-04 21:36:35 +02002688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002689 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002690
Johannes Berg4c476992010-10-04 21:36:35 +02002691 if (!rdev->ops->del_virtual_intf)
2692 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002693
Johannes Berg84efbb82012-06-16 00:00:26 +02002694 /*
2695 * If we remove a wireless device without a netdev then clear
2696 * user_ptr[1] so that nl80211_post_doit won't dereference it
2697 * to check if it needs to do dev_put(). Otherwise it crashes
2698 * since the wdev has been freed, unlike with a netdev where
2699 * we need the dev_put() for the netdev to really be freed.
2700 */
2701 if (!wdev->netdev)
2702 info->user_ptr[1] = NULL;
2703
Hila Gonene35e4d22012-06-27 17:19:42 +03002704 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002705}
2706
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002707static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2708{
2709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2710 struct net_device *dev = info->user_ptr[1];
2711 u16 noack_map;
2712
2713 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2714 return -EINVAL;
2715
2716 if (!rdev->ops->set_noack_map)
2717 return -EOPNOTSUPP;
2718
2719 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2720
Hila Gonene35e4d22012-06-27 17:19:42 +03002721 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002722}
2723
Johannes Berg41ade002007-12-19 02:03:29 +01002724struct get_key_cookie {
2725 struct sk_buff *msg;
2726 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002727 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002728};
2729
2730static void get_key_callback(void *c, struct key_params *params)
2731{
Johannes Bergb9454e82009-07-08 13:29:08 +02002732 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002733 struct get_key_cookie *cookie = c;
2734
David S. Miller9360ffd2012-03-29 04:41:26 -04002735 if ((params->key &&
2736 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2737 params->key_len, params->key)) ||
2738 (params->seq &&
2739 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2740 params->seq_len, params->seq)) ||
2741 (params->cipher &&
2742 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2743 params->cipher)))
2744 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002745
Johannes Bergb9454e82009-07-08 13:29:08 +02002746 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2747 if (!key)
2748 goto nla_put_failure;
2749
David S. Miller9360ffd2012-03-29 04:41:26 -04002750 if ((params->key &&
2751 nla_put(cookie->msg, NL80211_KEY_DATA,
2752 params->key_len, params->key)) ||
2753 (params->seq &&
2754 nla_put(cookie->msg, NL80211_KEY_SEQ,
2755 params->seq_len, params->seq)) ||
2756 (params->cipher &&
2757 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2758 params->cipher)))
2759 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002760
David S. Miller9360ffd2012-03-29 04:41:26 -04002761 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2762 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002763
2764 nla_nest_end(cookie->msg, key);
2765
Johannes Berg41ade002007-12-19 02:03:29 +01002766 return;
2767 nla_put_failure:
2768 cookie->error = 1;
2769}
2770
2771static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2772{
Johannes Berg4c476992010-10-04 21:36:35 +02002773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002774 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002775 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002776 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002777 const u8 *mac_addr = NULL;
2778 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002779 struct get_key_cookie cookie = {
2780 .error = 0,
2781 };
2782 void *hdr;
2783 struct sk_buff *msg;
2784
2785 if (info->attrs[NL80211_ATTR_KEY_IDX])
2786 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2787
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002788 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002789 return -EINVAL;
2790
2791 if (info->attrs[NL80211_ATTR_MAC])
2792 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2793
Johannes Berge31b8212010-10-05 19:39:30 +02002794 pairwise = !!mac_addr;
2795 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2796 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2797 if (kt >= NUM_NL80211_KEYTYPES)
2798 return -EINVAL;
2799 if (kt != NL80211_KEYTYPE_GROUP &&
2800 kt != NL80211_KEYTYPE_PAIRWISE)
2801 return -EINVAL;
2802 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2803 }
2804
Johannes Berg4c476992010-10-04 21:36:35 +02002805 if (!rdev->ops->get_key)
2806 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002807
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002808 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002809 if (!msg)
2810 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002811
Eric W. Biederman15e47302012-09-07 20:12:54 +00002812 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002813 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002814 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002815 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002816
2817 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002819
David S. Miller9360ffd2012-03-29 04:41:26 -04002820 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2821 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2822 goto nla_put_failure;
2823 if (mac_addr &&
2824 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2825 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002826
Johannes Berge31b8212010-10-05 19:39:30 +02002827 if (pairwise && mac_addr &&
2828 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2829 return -ENOENT;
2830
Hila Gonene35e4d22012-06-27 17:19:42 +03002831 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2832 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002833
2834 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002835 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002836
2837 if (cookie.error)
2838 goto nla_put_failure;
2839
2840 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002841 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002842
2843 nla_put_failure:
2844 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002845 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002846 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002847 return err;
2848}
2849
2850static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2851{
Johannes Berg4c476992010-10-04 21:36:35 +02002852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002853 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002854 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002855 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002856
Johannes Bergb9454e82009-07-08 13:29:08 +02002857 err = nl80211_parse_key(info, &key);
2858 if (err)
2859 return err;
2860
2861 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002862 return -EINVAL;
2863
Johannes Bergb9454e82009-07-08 13:29:08 +02002864 /* only support setting default key */
2865 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002866 return -EINVAL;
2867
Johannes Bergfffd0932009-07-08 14:22:54 +02002868 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002869
2870 if (key.def) {
2871 if (!rdev->ops->set_default_key) {
2872 err = -EOPNOTSUPP;
2873 goto out;
2874 }
2875
2876 err = nl80211_key_allowed(dev->ieee80211_ptr);
2877 if (err)
2878 goto out;
2879
Hila Gonene35e4d22012-06-27 17:19:42 +03002880 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002881 key.def_uni, key.def_multi);
2882
2883 if (err)
2884 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002885
Johannes Berg3d23e342009-09-29 23:27:28 +02002886#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002887 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002888#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002889 } else {
2890 if (key.def_uni || !key.def_multi) {
2891 err = -EINVAL;
2892 goto out;
2893 }
2894
2895 if (!rdev->ops->set_default_mgmt_key) {
2896 err = -EOPNOTSUPP;
2897 goto out;
2898 }
2899
2900 err = nl80211_key_allowed(dev->ieee80211_ptr);
2901 if (err)
2902 goto out;
2903
Hila Gonene35e4d22012-06-27 17:19:42 +03002904 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002905 if (err)
2906 goto out;
2907
2908#ifdef CONFIG_CFG80211_WEXT
2909 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2910#endif
2911 }
2912
2913 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002914 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002915
Johannes Berg41ade002007-12-19 02:03:29 +01002916 return err;
2917}
2918
2919static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2920{
Johannes Berg4c476992010-10-04 21:36:35 +02002921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002922 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002923 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002924 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002925 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002926
Johannes Bergb9454e82009-07-08 13:29:08 +02002927 err = nl80211_parse_key(info, &key);
2928 if (err)
2929 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002930
Johannes Bergb9454e82009-07-08 13:29:08 +02002931 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002932 return -EINVAL;
2933
Johannes Berg41ade002007-12-19 02:03:29 +01002934 if (info->attrs[NL80211_ATTR_MAC])
2935 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2936
Johannes Berge31b8212010-10-05 19:39:30 +02002937 if (key.type == -1) {
2938 if (mac_addr)
2939 key.type = NL80211_KEYTYPE_PAIRWISE;
2940 else
2941 key.type = NL80211_KEYTYPE_GROUP;
2942 }
2943
2944 /* for now */
2945 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2946 key.type != NL80211_KEYTYPE_GROUP)
2947 return -EINVAL;
2948
Johannes Berg4c476992010-10-04 21:36:35 +02002949 if (!rdev->ops->add_key)
2950 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002951
Johannes Berge31b8212010-10-05 19:39:30 +02002952 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2953 key.type == NL80211_KEYTYPE_PAIRWISE,
2954 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002955 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002956
2957 wdev_lock(dev->ieee80211_ptr);
2958 err = nl80211_key_allowed(dev->ieee80211_ptr);
2959 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002960 err = rdev_add_key(rdev, dev, key.idx,
2961 key.type == NL80211_KEYTYPE_PAIRWISE,
2962 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002963 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002964
Johannes Berg41ade002007-12-19 02:03:29 +01002965 return err;
2966}
2967
2968static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2969{
Johannes Berg4c476992010-10-04 21:36:35 +02002970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002971 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002972 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002973 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002974 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002975
Johannes Bergb9454e82009-07-08 13:29:08 +02002976 err = nl80211_parse_key(info, &key);
2977 if (err)
2978 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002979
2980 if (info->attrs[NL80211_ATTR_MAC])
2981 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2982
Johannes Berge31b8212010-10-05 19:39:30 +02002983 if (key.type == -1) {
2984 if (mac_addr)
2985 key.type = NL80211_KEYTYPE_PAIRWISE;
2986 else
2987 key.type = NL80211_KEYTYPE_GROUP;
2988 }
2989
2990 /* for now */
2991 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2992 key.type != NL80211_KEYTYPE_GROUP)
2993 return -EINVAL;
2994
Johannes Berg4c476992010-10-04 21:36:35 +02002995 if (!rdev->ops->del_key)
2996 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002997
Johannes Bergfffd0932009-07-08 14:22:54 +02002998 wdev_lock(dev->ieee80211_ptr);
2999 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003000
3001 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3002 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3003 err = -ENOENT;
3004
Johannes Bergfffd0932009-07-08 14:22:54 +02003005 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003006 err = rdev_del_key(rdev, dev, key.idx,
3007 key.type == NL80211_KEYTYPE_PAIRWISE,
3008 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003009
Johannes Berg3d23e342009-09-29 23:27:28 +02003010#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003011 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003012 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003013 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003014 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003015 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3016 }
3017#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003018 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003019
Johannes Berg41ade002007-12-19 02:03:29 +01003020 return err;
3021}
3022
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303023/* This function returns an error or the number of nested attributes */
3024static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3025{
3026 struct nlattr *attr;
3027 int n_entries = 0, tmp;
3028
3029 nla_for_each_nested(attr, nl_attr, tmp) {
3030 if (nla_len(attr) != ETH_ALEN)
3031 return -EINVAL;
3032
3033 n_entries++;
3034 }
3035
3036 return n_entries;
3037}
3038
3039/*
3040 * This function parses ACL information and allocates memory for ACL data.
3041 * On successful return, the calling function is responsible to free the
3042 * ACL buffer returned by this function.
3043 */
3044static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3045 struct genl_info *info)
3046{
3047 enum nl80211_acl_policy acl_policy;
3048 struct nlattr *attr;
3049 struct cfg80211_acl_data *acl;
3050 int i = 0, n_entries, tmp;
3051
3052 if (!wiphy->max_acl_mac_addrs)
3053 return ERR_PTR(-EOPNOTSUPP);
3054
3055 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3056 return ERR_PTR(-EINVAL);
3057
3058 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3059 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3060 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3061 return ERR_PTR(-EINVAL);
3062
3063 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3064 return ERR_PTR(-EINVAL);
3065
3066 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3067 if (n_entries < 0)
3068 return ERR_PTR(n_entries);
3069
3070 if (n_entries > wiphy->max_acl_mac_addrs)
3071 return ERR_PTR(-ENOTSUPP);
3072
3073 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3074 GFP_KERNEL);
3075 if (!acl)
3076 return ERR_PTR(-ENOMEM);
3077
3078 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3079 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3080 i++;
3081 }
3082
3083 acl->n_acl_entries = n_entries;
3084 acl->acl_policy = acl_policy;
3085
3086 return acl;
3087}
3088
3089static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3090{
3091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3092 struct net_device *dev = info->user_ptr[1];
3093 struct cfg80211_acl_data *acl;
3094 int err;
3095
3096 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3097 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3098 return -EOPNOTSUPP;
3099
3100 if (!dev->ieee80211_ptr->beacon_interval)
3101 return -EINVAL;
3102
3103 acl = parse_acl_data(&rdev->wiphy, info);
3104 if (IS_ERR(acl))
3105 return PTR_ERR(acl);
3106
3107 err = rdev_set_mac_acl(rdev, dev, acl);
3108
3109 kfree(acl);
3110
3111 return err;
3112}
3113
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003114static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003115 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003116{
Johannes Berg88600202012-02-13 15:17:18 +01003117 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003118
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003119 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3120 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3121 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3122 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003123 return -EINVAL;
3124
Johannes Berg88600202012-02-13 15:17:18 +01003125 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003126
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003127 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3128 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3129 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003130 if (!bcn->head_len)
3131 return -EINVAL;
3132 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003133 }
3134
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003135 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3136 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3137 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003138 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003139 }
3140
Johannes Berg4c476992010-10-04 21:36:35 +02003141 if (!haveinfo)
3142 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003143
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003144 if (attrs[NL80211_ATTR_IE]) {
3145 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3146 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003147 }
3148
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003149 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003150 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003151 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003152 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003153 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003154 }
3155
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003156 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003157 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003158 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003159 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003160 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003161 }
3162
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003163 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3164 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3165 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003166 }
3167
Johannes Berg88600202012-02-13 15:17:18 +01003168 return 0;
3169}
3170
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003171static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3172 struct cfg80211_ap_settings *params)
3173{
3174 struct wireless_dev *wdev;
3175 bool ret = false;
3176
Johannes Berg89a54e42012-06-15 14:33:17 +02003177 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003178 if (wdev->iftype != NL80211_IFTYPE_AP &&
3179 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3180 continue;
3181
Johannes Berg683b6d32012-11-08 21:25:48 +01003182 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003183 continue;
3184
Johannes Berg683b6d32012-11-08 21:25:48 +01003185 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003186 ret = true;
3187 break;
3188 }
3189
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003190 return ret;
3191}
3192
Jouni Malinene39e5b52012-09-30 19:29:39 +03003193static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3194 enum nl80211_auth_type auth_type,
3195 enum nl80211_commands cmd)
3196{
3197 if (auth_type > NL80211_AUTHTYPE_MAX)
3198 return false;
3199
3200 switch (cmd) {
3201 case NL80211_CMD_AUTHENTICATE:
3202 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3203 auth_type == NL80211_AUTHTYPE_SAE)
3204 return false;
3205 return true;
3206 case NL80211_CMD_CONNECT:
3207 case NL80211_CMD_START_AP:
3208 /* SAE not supported yet */
3209 if (auth_type == NL80211_AUTHTYPE_SAE)
3210 return false;
3211 return true;
3212 default:
3213 return false;
3214 }
3215}
3216
Johannes Berg88600202012-02-13 15:17:18 +01003217static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3218{
3219 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3220 struct net_device *dev = info->user_ptr[1];
3221 struct wireless_dev *wdev = dev->ieee80211_ptr;
3222 struct cfg80211_ap_settings params;
3223 int err;
3224
3225 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3226 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3227 return -EOPNOTSUPP;
3228
3229 if (!rdev->ops->start_ap)
3230 return -EOPNOTSUPP;
3231
3232 if (wdev->beacon_interval)
3233 return -EALREADY;
3234
3235 memset(&params, 0, sizeof(params));
3236
3237 /* these are required for START_AP */
3238 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3239 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3240 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3241 return -EINVAL;
3242
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003243 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003244 if (err)
3245 return err;
3246
3247 params.beacon_interval =
3248 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3249 params.dtim_period =
3250 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3251
3252 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3253 if (err)
3254 return err;
3255
3256 /*
3257 * In theory, some of these attributes should be required here
3258 * but since they were not used when the command was originally
3259 * added, keep them optional for old user space programs to let
3260 * them continue to work with drivers that do not need the
3261 * additional information -- drivers must check!
3262 */
3263 if (info->attrs[NL80211_ATTR_SSID]) {
3264 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3265 params.ssid_len =
3266 nla_len(info->attrs[NL80211_ATTR_SSID]);
3267 if (params.ssid_len == 0 ||
3268 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3269 return -EINVAL;
3270 }
3271
3272 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3273 params.hidden_ssid = nla_get_u32(
3274 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3275 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3276 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3277 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3278 return -EINVAL;
3279 }
3280
3281 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3282
3283 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3284 params.auth_type = nla_get_u32(
3285 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003286 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3287 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003288 return -EINVAL;
3289 } else
3290 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3291
3292 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3293 NL80211_MAX_NR_CIPHER_SUITES);
3294 if (err)
3295 return err;
3296
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303297 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3298 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3299 return -EOPNOTSUPP;
3300 params.inactivity_timeout = nla_get_u16(
3301 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3302 }
3303
Johannes Berg53cabad2012-11-14 15:17:28 +01003304 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3305 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3306 return -EINVAL;
3307 params.p2p_ctwindow =
3308 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3309 if (params.p2p_ctwindow > 127)
3310 return -EINVAL;
3311 if (params.p2p_ctwindow != 0 &&
3312 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3313 return -EINVAL;
3314 }
3315
3316 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3317 u8 tmp;
3318
3319 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3320 return -EINVAL;
3321 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3322 if (tmp > 1)
3323 return -EINVAL;
3324 params.p2p_opp_ps = tmp;
3325 if (params.p2p_opp_ps != 0 &&
3326 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3327 return -EINVAL;
3328 }
3329
Johannes Bergaa430da2012-05-16 23:50:18 +02003330 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003331 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3332 if (err)
3333 return err;
3334 } else if (wdev->preset_chandef.chan) {
3335 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003336 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003337 return -EINVAL;
3338
Ilan Peer174e0cd2014-02-23 09:13:01 +02003339 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3340 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003341 return -EINVAL;
3342
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303343 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3344 params.acl = parse_acl_data(&rdev->wiphy, info);
3345 if (IS_ERR(params.acl))
3346 return PTR_ERR(params.acl);
3347 }
3348
Eliad Peller18998c32014-09-10 14:07:34 +03003349 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3350 params.smps_mode =
3351 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3352 switch (params.smps_mode) {
3353 case NL80211_SMPS_OFF:
3354 break;
3355 case NL80211_SMPS_STATIC:
3356 if (!(rdev->wiphy.features &
3357 NL80211_FEATURE_STATIC_SMPS))
3358 return -EINVAL;
3359 break;
3360 case NL80211_SMPS_DYNAMIC:
3361 if (!(rdev->wiphy.features &
3362 NL80211_FEATURE_DYNAMIC_SMPS))
3363 return -EINVAL;
3364 break;
3365 default:
3366 return -EINVAL;
3367 }
3368 } else {
3369 params.smps_mode = NL80211_SMPS_OFF;
3370 }
3371
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003372 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003373 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003374 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003375 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003376 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003377 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003378 wdev->ssid_len = params.ssid_len;
3379 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003380 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003381 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303382
3383 kfree(params.acl);
3384
Johannes Berg56d18932011-05-09 18:41:15 +02003385 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003386}
3387
Johannes Berg88600202012-02-13 15:17:18 +01003388static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3389{
3390 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3391 struct net_device *dev = info->user_ptr[1];
3392 struct wireless_dev *wdev = dev->ieee80211_ptr;
3393 struct cfg80211_beacon_data params;
3394 int err;
3395
3396 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3397 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3398 return -EOPNOTSUPP;
3399
3400 if (!rdev->ops->change_beacon)
3401 return -EOPNOTSUPP;
3402
3403 if (!wdev->beacon_interval)
3404 return -EINVAL;
3405
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003406 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003407 if (err)
3408 return err;
3409
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003410 wdev_lock(wdev);
3411 err = rdev_change_beacon(rdev, dev, &params);
3412 wdev_unlock(wdev);
3413
3414 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003415}
3416
3417static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003418{
Johannes Berg4c476992010-10-04 21:36:35 +02003419 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3420 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003421
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003422 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003423}
3424
Johannes Berg5727ef12007-12-19 02:03:34 +01003425static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3426 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3427 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3428 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003429 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003430 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003431 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003432};
3433
Johannes Bergeccb8e82009-05-11 21:57:56 +03003434static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003435 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003436 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003437{
3438 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003439 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003440 int flag;
3441
Johannes Bergeccb8e82009-05-11 21:57:56 +03003442 /*
3443 * Try parsing the new attribute first so userspace
3444 * can specify both for older kernels.
3445 */
3446 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3447 if (nla) {
3448 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003449
Johannes Bergeccb8e82009-05-11 21:57:56 +03003450 sta_flags = nla_data(nla);
3451 params->sta_flags_mask = sta_flags->mask;
3452 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003453 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003454 if ((params->sta_flags_mask |
3455 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3456 return -EINVAL;
3457 return 0;
3458 }
3459
3460 /* if present, parse the old attribute */
3461
3462 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003463 if (!nla)
3464 return 0;
3465
3466 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3467 nla, sta_flags_policy))
3468 return -EINVAL;
3469
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003470 /*
3471 * Only allow certain flags for interface types so that
3472 * other attributes are silently ignored. Remember that
3473 * this is backward compatibility code with old userspace
3474 * and shouldn't be hit in other cases anyway.
3475 */
3476 switch (iftype) {
3477 case NL80211_IFTYPE_AP:
3478 case NL80211_IFTYPE_AP_VLAN:
3479 case NL80211_IFTYPE_P2P_GO:
3480 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3481 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3482 BIT(NL80211_STA_FLAG_WME) |
3483 BIT(NL80211_STA_FLAG_MFP);
3484 break;
3485 case NL80211_IFTYPE_P2P_CLIENT:
3486 case NL80211_IFTYPE_STATION:
3487 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3488 BIT(NL80211_STA_FLAG_TDLS_PEER);
3489 break;
3490 case NL80211_IFTYPE_MESH_POINT:
3491 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3492 BIT(NL80211_STA_FLAG_MFP) |
3493 BIT(NL80211_STA_FLAG_AUTHORIZED);
3494 default:
3495 return -EINVAL;
3496 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003497
Johannes Berg3383b5a2012-05-10 20:14:43 +02003498 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3499 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003500 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003501
Johannes Berg3383b5a2012-05-10 20:14:43 +02003502 /* no longer support new API additions in old API */
3503 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3504 return -EINVAL;
3505 }
3506 }
3507
Johannes Berg5727ef12007-12-19 02:03:34 +01003508 return 0;
3509}
3510
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003511static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3512 int attr)
3513{
3514 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003515 u32 bitrate;
3516 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003517
3518 rate = nla_nest_start(msg, attr);
3519 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003520 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003521
3522 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3523 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003524 /* report 16-bit bitrate only if we can */
3525 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003526 if (bitrate > 0 &&
3527 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3528 return false;
3529 if (bitrate_compat > 0 &&
3530 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3531 return false;
3532
3533 if (info->flags & RATE_INFO_FLAGS_MCS) {
3534 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3535 return false;
3536 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3537 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3538 return false;
3539 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3540 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3541 return false;
3542 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3543 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3544 return false;
3545 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3546 return false;
3547 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3548 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3549 return false;
3550 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3551 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3552 return false;
3553 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3554 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3555 return false;
3556 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3557 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3558 return false;
3559 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3560 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3561 return false;
3562 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003563
3564 nla_nest_end(msg, rate);
3565 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003566}
3567
Felix Fietkau119363c2013-04-22 16:29:30 +02003568static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3569 int id)
3570{
3571 void *attr;
3572 int i = 0;
3573
3574 if (!mask)
3575 return true;
3576
3577 attr = nla_nest_start(msg, id);
3578 if (!attr)
3579 return false;
3580
3581 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3582 if (!(mask & BIT(i)))
3583 continue;
3584
3585 if (nla_put_u8(msg, i, signal[i]))
3586 return false;
3587 }
3588
3589 nla_nest_end(msg, attr);
3590
3591 return true;
3592}
3593
Eric W. Biederman15e47302012-09-07 20:12:54 +00003594static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003595 int flags,
3596 struct cfg80211_registered_device *rdev,
3597 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003598 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003599{
3600 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003601 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003602
Eric W. Biederman15e47302012-09-07 20:12:54 +00003603 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003604 if (!hdr)
3605 return -1;
3606
David S. Miller9360ffd2012-03-29 04:41:26 -04003607 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3608 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3609 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3610 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003611
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003612 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3613 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003614 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003615 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3616 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3617 sinfo->connected_time))
3618 goto nla_put_failure;
3619 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3620 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3621 sinfo->inactive_time))
3622 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003623 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3624 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003625 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003626 (u32)sinfo->rx_bytes))
3627 goto nla_put_failure;
3628 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003629 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003630 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3631 (u32)sinfo->tx_bytes))
3632 goto nla_put_failure;
3633 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3634 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003635 sinfo->rx_bytes))
3636 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003637 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3638 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003639 sinfo->tx_bytes))
3640 goto nla_put_failure;
3641 if ((sinfo->filled & STATION_INFO_LLID) &&
3642 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3643 goto nla_put_failure;
3644 if ((sinfo->filled & STATION_INFO_PLID) &&
3645 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3646 goto nla_put_failure;
3647 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3648 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3649 sinfo->plink_state))
3650 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003651 switch (rdev->wiphy.signal_type) {
3652 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003653 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3654 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3655 sinfo->signal))
3656 goto nla_put_failure;
3657 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3658 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3659 sinfo->signal_avg))
3660 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003661 break;
3662 default:
3663 break;
3664 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003665 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3666 if (!nl80211_put_signal(msg, sinfo->chains,
3667 sinfo->chain_signal,
3668 NL80211_STA_INFO_CHAIN_SIGNAL))
3669 goto nla_put_failure;
3670 }
3671 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3672 if (!nl80211_put_signal(msg, sinfo->chains,
3673 sinfo->chain_signal_avg,
3674 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3675 goto nla_put_failure;
3676 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003677 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003678 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3679 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003680 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003681 }
3682 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3683 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3684 NL80211_STA_INFO_RX_BITRATE))
3685 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003686 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003687 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3688 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3689 sinfo->rx_packets))
3690 goto nla_put_failure;
3691 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3692 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3693 sinfo->tx_packets))
3694 goto nla_put_failure;
3695 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3696 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3697 sinfo->tx_retries))
3698 goto nla_put_failure;
3699 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3700 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3701 sinfo->tx_failed))
3702 goto nla_put_failure;
Antonio Quartulli867d849f2014-05-19 21:53:19 +02003703 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3704 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3705 sinfo->expected_throughput))
3706 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003707 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3708 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3709 sinfo->beacon_loss_count))
3710 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003711 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3712 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3713 sinfo->local_pm))
3714 goto nla_put_failure;
3715 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3716 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3717 sinfo->peer_pm))
3718 goto nla_put_failure;
3719 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3720 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3721 sinfo->nonpeer_pm))
3722 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003723 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3724 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3725 if (!bss_param)
3726 goto nla_put_failure;
3727
David S. Miller9360ffd2012-03-29 04:41:26 -04003728 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3729 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3730 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3731 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3732 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3733 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3734 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3735 sinfo->bss_param.dtim_period) ||
3736 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3737 sinfo->bss_param.beacon_interval))
3738 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003739
3740 nla_nest_end(msg, bss_param);
3741 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003742 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3743 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3744 sizeof(struct nl80211_sta_flag_update),
3745 &sinfo->sta_flags))
3746 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003747 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3748 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3749 sinfo->t_offset))
3750 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003751 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003752
David S. Miller9360ffd2012-03-29 04:41:26 -04003753 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3754 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3755 sinfo->assoc_req_ies))
3756 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003757
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003758 return genlmsg_end(msg, hdr);
3759
3760 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003761 genlmsg_cancel(msg, hdr);
3762 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003763}
3764
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003765static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003766 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003767{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003768 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003769 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003770 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003771 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003772 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003773 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003774
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003775 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003776 if (err)
3777 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003778
Johannes Berg97990a02013-04-19 01:02:55 +02003779 if (!wdev->netdev) {
3780 err = -EINVAL;
3781 goto out_err;
3782 }
3783
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003784 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003785 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003786 goto out_err;
3787 }
3788
Johannes Bergbba95fe2008-07-29 13:22:51 +02003789 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003790 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003791 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003792 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003793 if (err == -ENOENT)
3794 break;
3795 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003796 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003797
3798 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003799 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003800 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003801 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003802 &sinfo) < 0)
3803 goto out;
3804
3805 sta_idx++;
3806 }
3807
3808
3809 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003810 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003811 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003812 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003813 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003814
3815 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003816}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003817
Johannes Berg5727ef12007-12-19 02:03:34 +01003818static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3819{
Johannes Berg4c476992010-10-04 21:36:35 +02003820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3821 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003822 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003823 struct sk_buff *msg;
3824 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003825 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003826
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003827 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003828
3829 if (!info->attrs[NL80211_ATTR_MAC])
3830 return -EINVAL;
3831
3832 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3833
Johannes Berg4c476992010-10-04 21:36:35 +02003834 if (!rdev->ops->get_station)
3835 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003836
Hila Gonene35e4d22012-06-27 17:19:42 +03003837 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003838 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003839 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003840
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003841 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003842 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003843 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003844
Eric W. Biederman15e47302012-09-07 20:12:54 +00003845 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003846 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003847 nlmsg_free(msg);
3848 return -ENOBUFS;
3849 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003850
Johannes Berg4c476992010-10-04 21:36:35 +02003851 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003852}
3853
Johannes Berg77ee7c82013-02-15 00:48:33 +01003854int cfg80211_check_station_change(struct wiphy *wiphy,
3855 struct station_parameters *params,
3856 enum cfg80211_station_type statype)
3857{
3858 if (params->listen_interval != -1)
3859 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003860 if (params->aid &&
3861 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003862 return -EINVAL;
3863
3864 /* When you run into this, adjust the code below for the new flag */
3865 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3866
3867 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003868 case CFG80211_STA_MESH_PEER_KERNEL:
3869 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003870 /*
3871 * No ignoring the TDLS flag here -- the userspace mesh
3872 * code doesn't have the bug of including TDLS in the
3873 * mask everywhere.
3874 */
3875 if (params->sta_flags_mask &
3876 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3877 BIT(NL80211_STA_FLAG_MFP) |
3878 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3879 return -EINVAL;
3880 break;
3881 case CFG80211_STA_TDLS_PEER_SETUP:
3882 case CFG80211_STA_TDLS_PEER_ACTIVE:
3883 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3884 return -EINVAL;
3885 /* ignore since it can't change */
3886 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3887 break;
3888 default:
3889 /* disallow mesh-specific things */
3890 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3891 return -EINVAL;
3892 if (params->local_pm)
3893 return -EINVAL;
3894 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3895 return -EINVAL;
3896 }
3897
3898 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3899 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3900 /* TDLS can't be set, ... */
3901 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3902 return -EINVAL;
3903 /*
3904 * ... but don't bother the driver with it. This works around
3905 * a hostapd/wpa_supplicant issue -- it always includes the
3906 * TLDS_PEER flag in the mask even for AP mode.
3907 */
3908 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3909 }
3910
3911 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3912 /* reject other things that can't change */
3913 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3914 return -EINVAL;
3915 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3916 return -EINVAL;
3917 if (params->supported_rates)
3918 return -EINVAL;
3919 if (params->ext_capab || params->ht_capa || params->vht_capa)
3920 return -EINVAL;
3921 }
3922
3923 if (statype != CFG80211_STA_AP_CLIENT) {
3924 if (params->vlan)
3925 return -EINVAL;
3926 }
3927
3928 switch (statype) {
3929 case CFG80211_STA_AP_MLME_CLIENT:
3930 /* Use this only for authorizing/unauthorizing a station */
3931 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3932 return -EOPNOTSUPP;
3933 break;
3934 case CFG80211_STA_AP_CLIENT:
3935 /* accept only the listed bits */
3936 if (params->sta_flags_mask &
3937 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3938 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3939 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3940 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3941 BIT(NL80211_STA_FLAG_WME) |
3942 BIT(NL80211_STA_FLAG_MFP)))
3943 return -EINVAL;
3944
3945 /* but authenticated/associated only if driver handles it */
3946 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3947 params->sta_flags_mask &
3948 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3949 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3950 return -EINVAL;
3951 break;
3952 case CFG80211_STA_IBSS:
3953 case CFG80211_STA_AP_STA:
3954 /* reject any changes other than AUTHORIZED */
3955 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3956 return -EINVAL;
3957 break;
3958 case CFG80211_STA_TDLS_PEER_SETUP:
3959 /* reject any changes other than AUTHORIZED or WME */
3960 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3961 BIT(NL80211_STA_FLAG_WME)))
3962 return -EINVAL;
3963 /* force (at least) rates when authorizing */
3964 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3965 !params->supported_rates)
3966 return -EINVAL;
3967 break;
3968 case CFG80211_STA_TDLS_PEER_ACTIVE:
3969 /* reject any changes */
3970 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003971 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003972 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3973 return -EINVAL;
3974 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003975 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003976 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3977 return -EINVAL;
3978 break;
3979 }
3980
3981 return 0;
3982}
3983EXPORT_SYMBOL(cfg80211_check_station_change);
3984
Johannes Berg5727ef12007-12-19 02:03:34 +01003985/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003986 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003987 */
Johannes Berg80b99892011-11-18 16:23:01 +01003988static struct net_device *get_vlan(struct genl_info *info,
3989 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003990{
Johannes Berg463d0182009-07-14 00:33:35 +02003991 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003992 struct net_device *v;
3993 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003994
Johannes Berg80b99892011-11-18 16:23:01 +01003995 if (!vlanattr)
3996 return NULL;
3997
3998 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3999 if (!v)
4000 return ERR_PTR(-ENODEV);
4001
4002 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4003 ret = -EINVAL;
4004 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004005 }
Johannes Berg80b99892011-11-18 16:23:01 +01004006
Johannes Berg77ee7c82013-02-15 00:48:33 +01004007 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4008 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4009 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4010 ret = -EINVAL;
4011 goto error;
4012 }
4013
Johannes Berg80b99892011-11-18 16:23:01 +01004014 if (!netif_running(v)) {
4015 ret = -ENETDOWN;
4016 goto error;
4017 }
4018
4019 return v;
4020 error:
4021 dev_put(v);
4022 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004023}
4024
Johannes Berg94e860f2014-01-20 23:58:15 +01004025static const struct nla_policy
4026nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004027 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4028 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4029};
4030
Johannes Bergff276692013-02-15 00:09:01 +01004031static int nl80211_parse_sta_wme(struct genl_info *info,
4032 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004033{
Jouni Malinendf881292013-02-14 21:10:54 +02004034 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4035 struct nlattr *nla;
4036 int err;
4037
Jouni Malinendf881292013-02-14 21:10:54 +02004038 /* parse WME attributes if present */
4039 if (!info->attrs[NL80211_ATTR_STA_WME])
4040 return 0;
4041
4042 nla = info->attrs[NL80211_ATTR_STA_WME];
4043 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4044 nl80211_sta_wme_policy);
4045 if (err)
4046 return err;
4047
4048 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4049 params->uapsd_queues = nla_get_u8(
4050 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4051 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4052 return -EINVAL;
4053
4054 if (tb[NL80211_STA_WME_MAX_SP])
4055 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4056
4057 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4058 return -EINVAL;
4059
4060 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4061
4062 return 0;
4063}
4064
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304065static int nl80211_parse_sta_channel_info(struct genl_info *info,
4066 struct station_parameters *params)
4067{
4068 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4069 params->supported_channels =
4070 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4071 params->supported_channels_len =
4072 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4073 /*
4074 * Need to include at least one (first channel, number of
4075 * channels) tuple for each subband, and must have proper
4076 * tuples for the rest of the data as well.
4077 */
4078 if (params->supported_channels_len < 2)
4079 return -EINVAL;
4080 if (params->supported_channels_len % 2)
4081 return -EINVAL;
4082 }
4083
4084 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4085 params->supported_oper_classes =
4086 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4087 params->supported_oper_classes_len =
4088 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4089 /*
4090 * The value of the Length field of the Supported Operating
4091 * Classes element is between 2 and 253.
4092 */
4093 if (params->supported_oper_classes_len < 2 ||
4094 params->supported_oper_classes_len > 253)
4095 return -EINVAL;
4096 }
4097 return 0;
4098}
4099
Johannes Bergff276692013-02-15 00:09:01 +01004100static int nl80211_set_station_tdls(struct genl_info *info,
4101 struct station_parameters *params)
4102{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304103 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004104 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004105 if (info->attrs[NL80211_ATTR_PEER_AID])
4106 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004107 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4108 params->ht_capa =
4109 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4110 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4111 params->vht_capa =
4112 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4113
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304114 err = nl80211_parse_sta_channel_info(info, params);
4115 if (err)
4116 return err;
4117
Johannes Bergff276692013-02-15 00:09:01 +01004118 return nl80211_parse_sta_wme(info, params);
4119}
4120
Johannes Berg5727ef12007-12-19 02:03:34 +01004121static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4122{
Johannes Berg4c476992010-10-04 21:36:35 +02004123 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004124 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004125 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004126 u8 *mac_addr;
4127 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004128
4129 memset(&params, 0, sizeof(params));
4130
4131 params.listen_interval = -1;
4132
Johannes Berg77ee7c82013-02-15 00:48:33 +01004133 if (!rdev->ops->change_station)
4134 return -EOPNOTSUPP;
4135
Johannes Berg5727ef12007-12-19 02:03:34 +01004136 if (info->attrs[NL80211_ATTR_STA_AID])
4137 return -EINVAL;
4138
4139 if (!info->attrs[NL80211_ATTR_MAC])
4140 return -EINVAL;
4141
4142 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4143
4144 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4145 params.supported_rates =
4146 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4147 params.supported_rates_len =
4148 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4149 }
4150
Jouni Malinen9d62a982013-02-14 21:10:13 +02004151 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4152 params.capability =
4153 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4154 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4155 }
4156
4157 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4158 params.ext_capab =
4159 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4160 params.ext_capab_len =
4161 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4162 }
4163
Jouni Malinendf881292013-02-14 21:10:54 +02004164 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004165 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004166
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004167 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004168 return -EINVAL;
4169
Johannes Bergf8bacc22013-02-14 23:27:01 +01004170 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004171 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004172 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4173 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4174 return -EINVAL;
4175 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004176
Johannes Bergf8bacc22013-02-14 23:27:01 +01004177 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004178 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004179 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4180 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4181 return -EINVAL;
4182 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4183 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004184
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004185 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4186 enum nl80211_mesh_power_mode pm = nla_get_u32(
4187 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4188
4189 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4190 pm > NL80211_MESH_POWER_MAX)
4191 return -EINVAL;
4192
4193 params.local_pm = pm;
4194 }
4195
Johannes Berg77ee7c82013-02-15 00:48:33 +01004196 /* Include parameters for TDLS peer (will check later) */
4197 err = nl80211_set_station_tdls(info, &params);
4198 if (err)
4199 return err;
4200
4201 params.vlan = get_vlan(info, rdev);
4202 if (IS_ERR(params.vlan))
4203 return PTR_ERR(params.vlan);
4204
Johannes Berga97f4422009-06-18 17:23:43 +02004205 switch (dev->ieee80211_ptr->iftype) {
4206 case NL80211_IFTYPE_AP:
4207 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004208 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004209 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004210 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004211 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004212 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004213 break;
4214 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004215 err = -EOPNOTSUPP;
4216 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004217 }
4218
Johannes Berg77ee7c82013-02-15 00:48:33 +01004219 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004220 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004221
Johannes Berg77ee7c82013-02-15 00:48:33 +01004222 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004223 if (params.vlan)
4224 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004225
Johannes Berg5727ef12007-12-19 02:03:34 +01004226 return err;
4227}
4228
4229static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4230{
Johannes Berg4c476992010-10-04 21:36:35 +02004231 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004232 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004233 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004234 struct station_parameters params;
4235 u8 *mac_addr = NULL;
4236
4237 memset(&params, 0, sizeof(params));
4238
Johannes Berg984c3112013-02-14 23:43:25 +01004239 if (!rdev->ops->add_station)
4240 return -EOPNOTSUPP;
4241
Johannes Berg5727ef12007-12-19 02:03:34 +01004242 if (!info->attrs[NL80211_ATTR_MAC])
4243 return -EINVAL;
4244
Johannes Berg5727ef12007-12-19 02:03:34 +01004245 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4246 return -EINVAL;
4247
4248 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4249 return -EINVAL;
4250
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004251 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4252 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004253 return -EINVAL;
4254
Johannes Berg5727ef12007-12-19 02:03:34 +01004255 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4256 params.supported_rates =
4257 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4258 params.supported_rates_len =
4259 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4260 params.listen_interval =
4261 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004262
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004263 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004264 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004265 else
4266 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004267 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4268 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004269
Jouni Malinen9d62a982013-02-14 21:10:13 +02004270 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4271 params.capability =
4272 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4273 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4274 }
4275
4276 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4277 params.ext_capab =
4278 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4279 params.ext_capab_len =
4280 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4281 }
4282
Jouni Malinen36aedc92008-08-25 11:58:58 +03004283 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4284 params.ht_capa =
4285 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004286
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004287 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4288 params.vht_capa =
4289 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4290
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004291 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4292 params.opmode_notif_used = true;
4293 params.opmode_notif =
4294 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4295 }
4296
Johannes Bergf8bacc22013-02-14 23:27:01 +01004297 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004298 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004299 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4300 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4301 return -EINVAL;
4302 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004303
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304304 err = nl80211_parse_sta_channel_info(info, &params);
4305 if (err)
4306 return err;
4307
Johannes Bergff276692013-02-15 00:09:01 +01004308 err = nl80211_parse_sta_wme(info, &params);
4309 if (err)
4310 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004311
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004312 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004313 return -EINVAL;
4314
Johannes Berg77ee7c82013-02-15 00:48:33 +01004315 /* When you run into this, adjust the code below for the new flag */
4316 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4317
Johannes Bergbdd90d52011-12-14 12:20:27 +01004318 switch (dev->ieee80211_ptr->iftype) {
4319 case NL80211_IFTYPE_AP:
4320 case NL80211_IFTYPE_AP_VLAN:
4321 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004322 /* ignore WME attributes if iface/sta is not capable */
4323 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4324 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4325 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004326
Johannes Bergbdd90d52011-12-14 12:20:27 +01004327 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004328 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4329 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004330 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004331 /* but don't bother the driver with it */
4332 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004333
Johannes Bergd582cff2012-10-26 17:53:44 +02004334 /* allow authenticated/associated only if driver handles it */
4335 if (!(rdev->wiphy.features &
4336 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4337 params.sta_flags_mask &
4338 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4339 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4340 return -EINVAL;
4341
Johannes Bergbdd90d52011-12-14 12:20:27 +01004342 /* must be last in here for error handling */
4343 params.vlan = get_vlan(info, rdev);
4344 if (IS_ERR(params.vlan))
4345 return PTR_ERR(params.vlan);
4346 break;
4347 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004348 /* ignore uAPSD data */
4349 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4350
Johannes Bergd582cff2012-10-26 17:53:44 +02004351 /* associated is disallowed */
4352 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4353 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004354 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004355 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4356 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004357 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004358 break;
4359 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004360 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004361 /* ignore uAPSD data */
4362 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4363
Johannes Berg77ee7c82013-02-15 00:48:33 +01004364 /* these are disallowed */
4365 if (params.sta_flags_mask &
4366 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4367 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004368 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004369 /* Only TDLS peers can be added */
4370 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4371 return -EINVAL;
4372 /* Can only add if TDLS ... */
4373 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4374 return -EOPNOTSUPP;
4375 /* ... with external setup is supported */
4376 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4377 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004378 /*
4379 * Older wpa_supplicant versions always mark the TDLS peer
4380 * as authorized, but it shouldn't yet be.
4381 */
4382 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004383 break;
4384 default:
4385 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004386 }
4387
Johannes Bergbdd90d52011-12-14 12:20:27 +01004388 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004389
Hila Gonene35e4d22012-06-27 17:19:42 +03004390 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004391
Johannes Berg5727ef12007-12-19 02:03:34 +01004392 if (params.vlan)
4393 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004394 return err;
4395}
4396
4397static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4398{
Johannes Berg4c476992010-10-04 21:36:35 +02004399 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4400 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004401 struct station_del_parameters params;
4402
4403 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004404
4405 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004406 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004407
Johannes Berge80cf852009-05-11 14:43:13 +02004408 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004409 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004410 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004411 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4412 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004413
Johannes Berg4c476992010-10-04 21:36:35 +02004414 if (!rdev->ops->del_station)
4415 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004416
Jouni Malinen98856862014-10-20 13:20:45 +03004417 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4418 params.subtype =
4419 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4420 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4421 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4422 return -EINVAL;
4423 } else {
4424 /* Default to Deauthentication frame */
4425 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4426 }
4427
4428 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4429 params.reason_code =
4430 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4431 if (params.reason_code == 0)
4432 return -EINVAL; /* 0 is reserved */
4433 } else {
4434 /* Default to reason code 2 */
4435 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4436 }
4437
Jouni Malinen89c771e2014-10-10 20:52:40 +03004438 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004439}
4440
Eric W. Biederman15e47302012-09-07 20:12:54 +00004441static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004442 int flags, struct net_device *dev,
4443 u8 *dst, u8 *next_hop,
4444 struct mpath_info *pinfo)
4445{
4446 void *hdr;
4447 struct nlattr *pinfoattr;
4448
Eric W. Biederman15e47302012-09-07 20:12:54 +00004449 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004450 if (!hdr)
4451 return -1;
4452
David S. Miller9360ffd2012-03-29 04:41:26 -04004453 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4454 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4455 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4456 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4457 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004458
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004459 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4460 if (!pinfoattr)
4461 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004462 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4463 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4464 pinfo->frame_qlen))
4465 goto nla_put_failure;
4466 if (((pinfo->filled & MPATH_INFO_SN) &&
4467 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4468 ((pinfo->filled & MPATH_INFO_METRIC) &&
4469 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4470 pinfo->metric)) ||
4471 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4472 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4473 pinfo->exptime)) ||
4474 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4475 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4476 pinfo->flags)) ||
4477 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4478 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4479 pinfo->discovery_timeout)) ||
4480 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4481 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4482 pinfo->discovery_retries)))
4483 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004484
4485 nla_nest_end(msg, pinfoattr);
4486
4487 return genlmsg_end(msg, hdr);
4488
4489 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004490 genlmsg_cancel(msg, hdr);
4491 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004492}
4493
4494static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004495 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004496{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004497 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004498 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004499 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004500 u8 dst[ETH_ALEN];
4501 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004502 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004503 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004505 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004506 if (err)
4507 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004508
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004509 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004510 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004511 goto out_err;
4512 }
4513
Johannes Berg97990a02013-04-19 01:02:55 +02004514 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004515 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004516 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004517 }
4518
Johannes Bergbba95fe2008-07-29 13:22:51 +02004519 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004520 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004521 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004522 if (err == -ENOENT)
4523 break;
4524 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004525 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004526
Eric W. Biederman15e47302012-09-07 20:12:54 +00004527 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004528 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004529 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004530 &pinfo) < 0)
4531 goto out;
4532
4533 path_idx++;
4534 }
4535
4536
4537 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004538 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004539 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004540 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004541 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004542 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543}
4544
4545static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4546{
Johannes Berg4c476992010-10-04 21:36:35 +02004547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004548 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004549 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004550 struct mpath_info pinfo;
4551 struct sk_buff *msg;
4552 u8 *dst = NULL;
4553 u8 next_hop[ETH_ALEN];
4554
4555 memset(&pinfo, 0, sizeof(pinfo));
4556
4557 if (!info->attrs[NL80211_ATTR_MAC])
4558 return -EINVAL;
4559
4560 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4561
Johannes Berg4c476992010-10-04 21:36:35 +02004562 if (!rdev->ops->get_mpath)
4563 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004564
Johannes Berg4c476992010-10-04 21:36:35 +02004565 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4566 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004567
Hila Gonene35e4d22012-06-27 17:19:42 +03004568 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004569 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004570 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004571
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004573 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004574 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004575
Eric W. Biederman15e47302012-09-07 20:12:54 +00004576 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004577 dev, dst, next_hop, &pinfo) < 0) {
4578 nlmsg_free(msg);
4579 return -ENOBUFS;
4580 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004581
Johannes Berg4c476992010-10-04 21:36:35 +02004582 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004583}
4584
4585static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4586{
Johannes Berg4c476992010-10-04 21:36:35 +02004587 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4588 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004589 u8 *dst = NULL;
4590 u8 *next_hop = NULL;
4591
4592 if (!info->attrs[NL80211_ATTR_MAC])
4593 return -EINVAL;
4594
4595 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4596 return -EINVAL;
4597
4598 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4599 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4600
Johannes Berg4c476992010-10-04 21:36:35 +02004601 if (!rdev->ops->change_mpath)
4602 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004603
Johannes Berg4c476992010-10-04 21:36:35 +02004604 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4605 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004606
Hila Gonene35e4d22012-06-27 17:19:42 +03004607 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004608}
Johannes Berg4c476992010-10-04 21:36:35 +02004609
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004610static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4611{
Johannes Berg4c476992010-10-04 21:36:35 +02004612 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4613 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004614 u8 *dst = NULL;
4615 u8 *next_hop = NULL;
4616
4617 if (!info->attrs[NL80211_ATTR_MAC])
4618 return -EINVAL;
4619
4620 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4621 return -EINVAL;
4622
4623 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4624 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4625
Johannes Berg4c476992010-10-04 21:36:35 +02004626 if (!rdev->ops->add_mpath)
4627 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004628
Johannes Berg4c476992010-10-04 21:36:35 +02004629 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4630 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004631
Hila Gonene35e4d22012-06-27 17:19:42 +03004632 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004633}
4634
4635static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4636{
Johannes Berg4c476992010-10-04 21:36:35 +02004637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4638 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004639 u8 *dst = NULL;
4640
4641 if (info->attrs[NL80211_ATTR_MAC])
4642 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4643
Johannes Berg4c476992010-10-04 21:36:35 +02004644 if (!rdev->ops->del_mpath)
4645 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004646
Hila Gonene35e4d22012-06-27 17:19:42 +03004647 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004648}
4649
Henning Rogge66be7d22014-09-12 08:58:49 +02004650static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4651{
4652 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4653 int err;
4654 struct net_device *dev = info->user_ptr[1];
4655 struct mpath_info pinfo;
4656 struct sk_buff *msg;
4657 u8 *dst = NULL;
4658 u8 mpp[ETH_ALEN];
4659
4660 memset(&pinfo, 0, sizeof(pinfo));
4661
4662 if (!info->attrs[NL80211_ATTR_MAC])
4663 return -EINVAL;
4664
4665 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4666
4667 if (!rdev->ops->get_mpp)
4668 return -EOPNOTSUPP;
4669
4670 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4671 return -EOPNOTSUPP;
4672
4673 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4674 if (err)
4675 return err;
4676
4677 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4678 if (!msg)
4679 return -ENOMEM;
4680
4681 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4682 dev, dst, mpp, &pinfo) < 0) {
4683 nlmsg_free(msg);
4684 return -ENOBUFS;
4685 }
4686
4687 return genlmsg_reply(msg, info);
4688}
4689
4690static int nl80211_dump_mpp(struct sk_buff *skb,
4691 struct netlink_callback *cb)
4692{
4693 struct mpath_info pinfo;
4694 struct cfg80211_registered_device *rdev;
4695 struct wireless_dev *wdev;
4696 u8 dst[ETH_ALEN];
4697 u8 mpp[ETH_ALEN];
4698 int path_idx = cb->args[2];
4699 int err;
4700
4701 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4702 if (err)
4703 return err;
4704
4705 if (!rdev->ops->dump_mpp) {
4706 err = -EOPNOTSUPP;
4707 goto out_err;
4708 }
4709
4710 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4711 err = -EOPNOTSUPP;
4712 goto out_err;
4713 }
4714
4715 while (1) {
4716 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4717 mpp, &pinfo);
4718 if (err == -ENOENT)
4719 break;
4720 if (err)
4721 goto out_err;
4722
4723 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4724 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4725 wdev->netdev, dst, mpp,
4726 &pinfo) < 0)
4727 goto out;
4728
4729 path_idx++;
4730 }
4731
4732 out:
4733 cb->args[2] = path_idx;
4734 err = skb->len;
4735 out_err:
4736 nl80211_finish_wdev_dump(rdev);
4737 return err;
4738}
4739
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004740static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4741{
Johannes Berg4c476992010-10-04 21:36:35 +02004742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4743 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004744 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004745 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004746 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004747
4748 memset(&params, 0, sizeof(params));
4749 /* default to not changing parameters */
4750 params.use_cts_prot = -1;
4751 params.use_short_preamble = -1;
4752 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004753 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004754 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004755 params.p2p_ctwindow = -1;
4756 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004757
4758 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4759 params.use_cts_prot =
4760 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4761 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4762 params.use_short_preamble =
4763 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4764 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4765 params.use_short_slot_time =
4766 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004767 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4768 params.basic_rates =
4769 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4770 params.basic_rates_len =
4771 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4772 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004773 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4774 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004775 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4776 params.ht_opmode =
4777 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004778
Johannes Berg53cabad2012-11-14 15:17:28 +01004779 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4780 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4781 return -EINVAL;
4782 params.p2p_ctwindow =
4783 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4784 if (params.p2p_ctwindow < 0)
4785 return -EINVAL;
4786 if (params.p2p_ctwindow != 0 &&
4787 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4788 return -EINVAL;
4789 }
4790
4791 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4792 u8 tmp;
4793
4794 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4795 return -EINVAL;
4796 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4797 if (tmp > 1)
4798 return -EINVAL;
4799 params.p2p_opp_ps = tmp;
4800 if (params.p2p_opp_ps &&
4801 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4802 return -EINVAL;
4803 }
4804
Johannes Berg4c476992010-10-04 21:36:35 +02004805 if (!rdev->ops->change_bss)
4806 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004807
Johannes Berg074ac8d2010-09-16 14:58:22 +02004808 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004809 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4810 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004811
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004812 wdev_lock(wdev);
4813 err = rdev_change_bss(rdev, dev, &params);
4814 wdev_unlock(wdev);
4815
4816 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004817}
4818
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004819static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004820 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4821 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4822 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4823 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4824 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4825 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004826 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004827};
4828
4829static int parse_reg_rule(struct nlattr *tb[],
4830 struct ieee80211_reg_rule *reg_rule)
4831{
4832 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4833 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4834
4835 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4836 return -EINVAL;
4837 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4838 return -EINVAL;
4839 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4840 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004841 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4842 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004843 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4844 return -EINVAL;
4845
4846 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4847
4848 freq_range->start_freq_khz =
4849 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4850 freq_range->end_freq_khz =
4851 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004852 freq_range->max_bandwidth_khz =
4853 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004854
4855 power_rule->max_eirp =
4856 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4857
4858 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4859 power_rule->max_antenna_gain =
4860 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4861
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004862 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4863 reg_rule->dfs_cac_ms =
4864 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4865
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004866 return 0;
4867}
4868
4869static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4870{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004871 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004872 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004873
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004874 /*
4875 * You should only get this when cfg80211 hasn't yet initialized
4876 * completely when built-in to the kernel right between the time
4877 * window between nl80211_init() and regulatory_init(), if that is
4878 * even possible.
4879 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004880 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004881 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004882
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004883 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4884 user_reg_hint_type =
4885 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4886 else
4887 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4888
4889 switch (user_reg_hint_type) {
4890 case NL80211_USER_REG_HINT_USER:
4891 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004892 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4893 return -EINVAL;
4894
4895 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4896 return regulatory_hint_user(data, user_reg_hint_type);
4897 case NL80211_USER_REG_HINT_INDOOR:
4898 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004899 default:
4900 return -EINVAL;
4901 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004902}
4903
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004904static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004905 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004906{
Johannes Berg4c476992010-10-04 21:36:35 +02004907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004908 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004909 struct wireless_dev *wdev = dev->ieee80211_ptr;
4910 struct mesh_config cur_params;
4911 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004912 void *hdr;
4913 struct nlattr *pinfoattr;
4914 struct sk_buff *msg;
4915
Johannes Berg29cbe682010-12-03 09:20:44 +01004916 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4917 return -EOPNOTSUPP;
4918
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004919 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004920 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004921
Johannes Berg29cbe682010-12-03 09:20:44 +01004922 wdev_lock(wdev);
4923 /* If not connected, get default parameters */
4924 if (!wdev->mesh_id_len)
4925 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4926 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004927 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004928 wdev_unlock(wdev);
4929
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004930 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004931 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004932
4933 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004934 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004935 if (!msg)
4936 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004937 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004938 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004939 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004940 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004941 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004942 if (!pinfoattr)
4943 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004944 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4945 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4946 cur_params.dot11MeshRetryTimeout) ||
4947 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4948 cur_params.dot11MeshConfirmTimeout) ||
4949 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4950 cur_params.dot11MeshHoldingTimeout) ||
4951 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4952 cur_params.dot11MeshMaxPeerLinks) ||
4953 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4954 cur_params.dot11MeshMaxRetries) ||
4955 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4956 cur_params.dot11MeshTTL) ||
4957 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4958 cur_params.element_ttl) ||
4959 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4960 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004961 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4962 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004963 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4964 cur_params.dot11MeshHWMPmaxPREQretries) ||
4965 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4966 cur_params.path_refresh_time) ||
4967 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4968 cur_params.min_discovery_timeout) ||
4969 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4970 cur_params.dot11MeshHWMPactivePathTimeout) ||
4971 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4972 cur_params.dot11MeshHWMPpreqMinInterval) ||
4973 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4974 cur_params.dot11MeshHWMPperrMinInterval) ||
4975 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4976 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4977 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4978 cur_params.dot11MeshHWMPRootMode) ||
4979 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4980 cur_params.dot11MeshHWMPRannInterval) ||
4981 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4982 cur_params.dot11MeshGateAnnouncementProtocol) ||
4983 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4984 cur_params.dot11MeshForwarding) ||
4985 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004986 cur_params.rssi_threshold) ||
4987 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004988 cur_params.ht_opmode) ||
4989 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4990 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4991 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004992 cur_params.dot11MeshHWMProotInterval) ||
4993 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004994 cur_params.dot11MeshHWMPconfirmationInterval) ||
4995 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4996 cur_params.power_mode) ||
4997 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004998 cur_params.dot11MeshAwakeWindowDuration) ||
4999 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5000 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005001 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005002 nla_nest_end(msg, pinfoattr);
5003 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005004 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005005
Johannes Berg3b858752009-03-12 09:55:09 +01005006 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005007 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005008 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005009 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005010 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005011}
5012
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005013static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005014 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5015 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5016 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5017 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5018 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5019 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005020 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005021 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005022 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005023 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5024 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5025 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5026 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5027 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005028 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005029 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005030 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005031 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005032 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005033 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005034 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5035 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005036 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5037 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005038 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005039 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5040 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005041 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005042};
5043
Javier Cardonac80d5452010-12-16 17:37:49 -08005044static const struct nla_policy
5045 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005046 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005047 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5048 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005049 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005050 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005051 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005052 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005053 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005054 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005055};
5056
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005057static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005058 struct mesh_config *cfg,
5059 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005060{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005061 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005062 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005063
Marco Porschea54fba2013-01-07 16:04:48 +01005064#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5065do { \
5066 if (tb[attr]) { \
5067 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5068 return -EINVAL; \
5069 cfg->param = fn(tb[attr]); \
5070 mask |= (1 << (attr - 1)); \
5071 } \
5072} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005073
5074
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005075 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005076 return -EINVAL;
5077 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005078 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005079 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005080 return -EINVAL;
5081
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005082 /* This makes sure that there aren't more than 32 mesh config
5083 * parameters (otherwise our bitfield scheme would not work.) */
5084 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5085
5086 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005087 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005088 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5089 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005090 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005091 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5092 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005093 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005094 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5095 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005096 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005097 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5098 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005099 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005100 mask, NL80211_MESHCONF_MAX_RETRIES,
5101 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005102 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005103 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005104 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005105 mask, NL80211_MESHCONF_ELEMENT_TTL,
5106 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005107 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005108 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5109 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005110 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5111 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005112 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5113 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005114 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005115 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5116 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005117 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005118 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5119 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005120 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005121 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5122 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005123 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5124 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005125 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5126 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005127 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005128 1, 65535, mask,
5129 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005130 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005131 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005132 1, 65535, mask,
5133 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005134 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005135 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005136 dot11MeshHWMPnetDiameterTraversalTime,
5137 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005138 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5139 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005140 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5141 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5142 nla_get_u8);
5143 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5144 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005145 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005146 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005147 dot11MeshGateAnnouncementProtocol, 0, 1,
5148 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005149 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005150 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005151 mask, NL80211_MESHCONF_FORWARDING,
5152 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005153 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005154 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005155 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005156 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005157 mask, NL80211_MESHCONF_HT_OPMODE,
5158 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005159 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005160 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005161 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5162 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005163 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005164 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5165 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005166 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005167 dot11MeshHWMPconfirmationInterval,
5168 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005169 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5170 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005171 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5172 NL80211_MESH_POWER_ACTIVE,
5173 NL80211_MESH_POWER_MAX,
5174 mask, NL80211_MESHCONF_POWER_MODE,
5175 nla_get_u32);
5176 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5177 0, 65535, mask,
5178 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005179 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5180 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5181 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005182 if (mask_out)
5183 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005184
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005185 return 0;
5186
5187#undef FILL_IN_MESH_PARAM_IF_SET
5188}
5189
Javier Cardonac80d5452010-12-16 17:37:49 -08005190static int nl80211_parse_mesh_setup(struct genl_info *info,
5191 struct mesh_setup *setup)
5192{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005193 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005194 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5195
5196 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5197 return -EINVAL;
5198 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5199 info->attrs[NL80211_ATTR_MESH_SETUP],
5200 nl80211_mesh_setup_params_policy))
5201 return -EINVAL;
5202
Javier Cardonad299a1f2012-03-31 11:31:33 -07005203 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5204 setup->sync_method =
5205 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5206 IEEE80211_SYNC_METHOD_VENDOR :
5207 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5208
Javier Cardonac80d5452010-12-16 17:37:49 -08005209 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5210 setup->path_sel_proto =
5211 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5212 IEEE80211_PATH_PROTOCOL_VENDOR :
5213 IEEE80211_PATH_PROTOCOL_HWMP;
5214
5215 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5216 setup->path_metric =
5217 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5218 IEEE80211_PATH_METRIC_VENDOR :
5219 IEEE80211_PATH_METRIC_AIRTIME;
5220
Javier Cardona581a8b02011-04-07 15:08:27 -07005221
5222 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005223 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005224 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005225 if (!is_valid_ie_attr(ieattr))
5226 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005227 setup->ie = nla_data(ieattr);
5228 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005229 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005230 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5231 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5232 return -EINVAL;
5233 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005234 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5235 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005236 if (setup->is_secure)
5237 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005238
Colleen Twitty6e16d902013-05-08 11:45:59 -07005239 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5240 if (!setup->user_mpm)
5241 return -EINVAL;
5242 setup->auth_id =
5243 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5244 }
5245
Javier Cardonac80d5452010-12-16 17:37:49 -08005246 return 0;
5247}
5248
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005249static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005250 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005251{
5252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5253 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005254 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005255 struct mesh_config cfg;
5256 u32 mask;
5257 int err;
5258
Johannes Berg29cbe682010-12-03 09:20:44 +01005259 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5260 return -EOPNOTSUPP;
5261
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005262 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005263 return -EOPNOTSUPP;
5264
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005265 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005266 if (err)
5267 return err;
5268
Johannes Berg29cbe682010-12-03 09:20:44 +01005269 wdev_lock(wdev);
5270 if (!wdev->mesh_id_len)
5271 err = -ENOLINK;
5272
5273 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005274 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005275
5276 wdev_unlock(wdev);
5277
5278 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005279}
5280
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005281static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5282{
Johannes Berg458f4f92012-12-06 15:47:38 +01005283 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005284 struct sk_buff *msg;
5285 void *hdr = NULL;
5286 struct nlattr *nl_reg_rules;
5287 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005288
5289 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005290 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005291
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005292 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005293 if (!msg)
5294 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005295
Eric W. Biederman15e47302012-09-07 20:12:54 +00005296 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005297 NL80211_CMD_GET_REG);
5298 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005299 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005300
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005301 if (reg_last_request_cell_base() &&
5302 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5303 NL80211_USER_REG_HINT_CELL_BASE))
5304 goto nla_put_failure;
5305
Johannes Berg458f4f92012-12-06 15:47:38 +01005306 rcu_read_lock();
5307 regdom = rcu_dereference(cfg80211_regdomain);
5308
5309 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5310 (regdom->dfs_region &&
5311 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5312 goto nla_put_failure_rcu;
5313
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005314 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5315 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005316 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005317
Johannes Berg458f4f92012-12-06 15:47:38 +01005318 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005319 struct nlattr *nl_reg_rule;
5320 const struct ieee80211_reg_rule *reg_rule;
5321 const struct ieee80211_freq_range *freq_range;
5322 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005323 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005324
Johannes Berg458f4f92012-12-06 15:47:38 +01005325 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005326 freq_range = &reg_rule->freq_range;
5327 power_rule = &reg_rule->power_rule;
5328
5329 nl_reg_rule = nla_nest_start(msg, i);
5330 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005331 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005332
Janusz Dziedzic97524822014-01-30 09:52:20 +01005333 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5334 if (!max_bandwidth_khz)
5335 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5336 reg_rule);
5337
David S. Miller9360ffd2012-03-29 04:41:26 -04005338 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5339 reg_rule->flags) ||
5340 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5341 freq_range->start_freq_khz) ||
5342 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5343 freq_range->end_freq_khz) ||
5344 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005345 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005346 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5347 power_rule->max_antenna_gain) ||
5348 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005349 power_rule->max_eirp) ||
5350 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5351 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005352 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005353
5354 nla_nest_end(msg, nl_reg_rule);
5355 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005356 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005357
5358 nla_nest_end(msg, nl_reg_rules);
5359
5360 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005361 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005362
Johannes Berg458f4f92012-12-06 15:47:38 +01005363nla_put_failure_rcu:
5364 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005365nla_put_failure:
5366 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005367put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005368 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005369 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005370}
5371
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005372static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5373{
5374 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5375 struct nlattr *nl_reg_rule;
5376 char *alpha2 = NULL;
5377 int rem_reg_rules = 0, r = 0;
5378 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005379 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005380 struct ieee80211_regdomain *rd = NULL;
5381
5382 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5383 return -EINVAL;
5384
5385 if (!info->attrs[NL80211_ATTR_REG_RULES])
5386 return -EINVAL;
5387
5388 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5389
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005390 if (info->attrs[NL80211_ATTR_DFS_REGION])
5391 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5392
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005393 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005394 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005395 num_rules++;
5396 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005397 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005398 }
5399
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005400 if (!reg_is_valid_request(alpha2))
5401 return -EINVAL;
5402
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005403 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005404 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005405
5406 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005407 if (!rd)
5408 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005409
5410 rd->n_reg_rules = num_rules;
5411 rd->alpha2[0] = alpha2[0];
5412 rd->alpha2[1] = alpha2[1];
5413
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005414 /*
5415 * Disable DFS master mode if the DFS region was
5416 * not supported or known on this kernel.
5417 */
5418 if (reg_supported_dfs_region(dfs_region))
5419 rd->dfs_region = dfs_region;
5420
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005421 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005422 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005423 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5424 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5425 reg_rule_policy);
5426 if (r)
5427 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005428 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5429 if (r)
5430 goto bad_reg;
5431
5432 rule_idx++;
5433
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005434 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5435 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005436 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005437 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005438 }
5439
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005440 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005441 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005442 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005443
Johannes Bergd2372b32008-10-24 20:32:20 +02005444 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005445 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005446 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005447}
5448
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005449static int validate_scan_freqs(struct nlattr *freqs)
5450{
5451 struct nlattr *attr1, *attr2;
5452 int n_channels = 0, tmp1, tmp2;
5453
5454 nla_for_each_nested(attr1, freqs, tmp1) {
5455 n_channels++;
5456 /*
5457 * Some hardware has a limited channel list for
5458 * scanning, and it is pretty much nonsensical
5459 * to scan for a channel twice, so disallow that
5460 * and don't require drivers to check that the
5461 * channel list they get isn't longer than what
5462 * they can scan, as long as they can scan all
5463 * the channels they registered at once.
5464 */
5465 nla_for_each_nested(attr2, freqs, tmp2)
5466 if (attr1 != attr2 &&
5467 nla_get_u32(attr1) == nla_get_u32(attr2))
5468 return 0;
5469 }
5470
5471 return n_channels;
5472}
5473
Johannes Berg2a519312009-02-10 21:25:55 +01005474static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5475{
Johannes Berg4c476992010-10-04 21:36:35 +02005476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005477 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005478 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005479 struct nlattr *attr;
5480 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005481 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005482 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005483
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005484 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5485 return -EINVAL;
5486
Johannes Berg79c97e92009-07-07 03:56:12 +02005487 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005488
Johannes Berg4c476992010-10-04 21:36:35 +02005489 if (!rdev->ops->scan)
5490 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005491
Johannes Bergf9d15d12014-01-22 11:14:19 +02005492 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005493 err = -EBUSY;
5494 goto unlock;
5495 }
Johannes Berg2a519312009-02-10 21:25:55 +01005496
5497 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005498 n_channels = validate_scan_freqs(
5499 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005500 if (!n_channels) {
5501 err = -EINVAL;
5502 goto unlock;
5503 }
Johannes Berg2a519312009-02-10 21:25:55 +01005504 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005505 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005506 }
5507
5508 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5509 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5510 n_ssids++;
5511
Johannes Bergf9f47522013-03-19 15:04:07 +01005512 if (n_ssids > wiphy->max_scan_ssids) {
5513 err = -EINVAL;
5514 goto unlock;
5515 }
Johannes Berg2a519312009-02-10 21:25:55 +01005516
Jouni Malinen70692ad2009-02-16 19:39:13 +02005517 if (info->attrs[NL80211_ATTR_IE])
5518 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5519 else
5520 ie_len = 0;
5521
Johannes Bergf9f47522013-03-19 15:04:07 +01005522 if (ie_len > wiphy->max_scan_ie_len) {
5523 err = -EINVAL;
5524 goto unlock;
5525 }
Johannes Berg18a83652009-03-31 12:12:05 +02005526
Johannes Berg2a519312009-02-10 21:25:55 +01005527 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005528 + sizeof(*request->ssids) * n_ssids
5529 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005530 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005531 if (!request) {
5532 err = -ENOMEM;
5533 goto unlock;
5534 }
Johannes Berg2a519312009-02-10 21:25:55 +01005535
Johannes Berg2a519312009-02-10 21:25:55 +01005536 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005537 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005538 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005539 if (ie_len) {
5540 if (request->ssids)
5541 request->ie = (void *)(request->ssids + n_ssids);
5542 else
5543 request->ie = (void *)(request->channels + n_channels);
5544 }
Johannes Berg2a519312009-02-10 21:25:55 +01005545
Johannes Berg584991d2009-11-02 13:32:03 +01005546 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005547 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5548 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005549 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005550 struct ieee80211_channel *chan;
5551
5552 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5553
5554 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005555 err = -EINVAL;
5556 goto out_free;
5557 }
Johannes Berg584991d2009-11-02 13:32:03 +01005558
5559 /* ignore disabled channels */
5560 if (chan->flags & IEEE80211_CHAN_DISABLED)
5561 continue;
5562
5563 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005564 i++;
5565 }
5566 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005567 enum ieee80211_band band;
5568
Johannes Berg2a519312009-02-10 21:25:55 +01005569 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005570 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5571 int j;
5572 if (!wiphy->bands[band])
5573 continue;
5574 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005575 struct ieee80211_channel *chan;
5576
5577 chan = &wiphy->bands[band]->channels[j];
5578
5579 if (chan->flags & IEEE80211_CHAN_DISABLED)
5580 continue;
5581
5582 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005583 i++;
5584 }
5585 }
5586 }
5587
Johannes Berg584991d2009-11-02 13:32:03 +01005588 if (!i) {
5589 err = -EINVAL;
5590 goto out_free;
5591 }
5592
5593 request->n_channels = i;
5594
Johannes Berg2a519312009-02-10 21:25:55 +01005595 i = 0;
5596 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5597 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005598 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005599 err = -EINVAL;
5600 goto out_free;
5601 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005602 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005603 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005604 i++;
5605 }
5606 }
5607
Jouni Malinen70692ad2009-02-16 19:39:13 +02005608 if (info->attrs[NL80211_ATTR_IE]) {
5609 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02005610 memcpy((void *)request->ie,
5611 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005612 request->ie_len);
5613 }
5614
Johannes Berg34850ab2011-07-18 18:08:35 +02005615 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005616 if (wiphy->bands[i])
5617 request->rates[i] =
5618 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005619
5620 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5621 nla_for_each_nested(attr,
5622 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5623 tmp) {
5624 enum ieee80211_band band = nla_type(attr);
5625
Dan Carpenter84404622011-07-29 11:52:18 +03005626 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005627 err = -EINVAL;
5628 goto out_free;
5629 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005630
5631 if (!wiphy->bands[band])
5632 continue;
5633
Johannes Berg34850ab2011-07-18 18:08:35 +02005634 err = ieee80211_get_ratemask(wiphy->bands[band],
5635 nla_data(attr),
5636 nla_len(attr),
5637 &request->rates[band]);
5638 if (err)
5639 goto out_free;
5640 }
5641 }
5642
Sam Leffler46856bb2012-10-11 21:03:32 -07005643 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005644 request->flags = nla_get_u32(
5645 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005646 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5647 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005648 err = -EOPNOTSUPP;
5649 goto out_free;
5650 }
5651 }
Sam Lefflered4737712012-10-11 21:03:31 -07005652
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305653 request->no_cck =
5654 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5655
Johannes Bergfd014282012-06-18 19:17:03 +02005656 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005657 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005658 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005659
Johannes Berg79c97e92009-07-07 03:56:12 +02005660 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005661 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005662
Johannes Berg463d0182009-07-14 00:33:35 +02005663 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005664 nl80211_send_scan_start(rdev, wdev);
5665 if (wdev->netdev)
5666 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005667 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005668 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005669 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005670 kfree(request);
5671 }
Johannes Berg3b858752009-03-12 09:55:09 +01005672
Johannes Bergf9f47522013-03-19 15:04:07 +01005673 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005674 return err;
5675}
5676
Luciano Coelho807f8a82011-05-11 17:09:35 +03005677static int nl80211_start_sched_scan(struct sk_buff *skb,
5678 struct genl_info *info)
5679{
5680 struct cfg80211_sched_scan_request *request;
5681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5682 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005683 struct nlattr *attr;
5684 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005685 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005686 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005687 enum ieee80211_band band;
5688 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005689 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005690 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005691
5692 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5693 !rdev->ops->sched_scan_start)
5694 return -EOPNOTSUPP;
5695
5696 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5697 return -EINVAL;
5698
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005699 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5700 return -EINVAL;
5701
5702 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5703 if (interval == 0)
5704 return -EINVAL;
5705
Luciano Coelho807f8a82011-05-11 17:09:35 +03005706 wiphy = &rdev->wiphy;
5707
5708 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5709 n_channels = validate_scan_freqs(
5710 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5711 if (!n_channels)
5712 return -EINVAL;
5713 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005714 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005715 }
5716
5717 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5718 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5719 tmp)
5720 n_ssids++;
5721
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005722 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005723 return -EINVAL;
5724
Johannes Bergea73cbc2014-01-24 10:53:53 +01005725 /*
5726 * First, count the number of 'real' matchsets. Due to an issue with
5727 * the old implementation, matchsets containing only the RSSI attribute
5728 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5729 * RSSI for all matchsets, rather than their own matchset for reporting
5730 * all APs with a strong RSSI. This is needed to be compatible with
5731 * older userspace that treated a matchset with only the RSSI as the
5732 * global RSSI for all other matchsets - if there are other matchsets.
5733 */
5734 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005735 nla_for_each_nested(attr,
5736 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005737 tmp) {
5738 struct nlattr *rssi;
5739
5740 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5741 nla_data(attr), nla_len(attr),
5742 nl80211_match_policy);
5743 if (err)
5744 return err;
5745 /* add other standalone attributes here */
5746 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5747 n_match_sets++;
5748 continue;
5749 }
5750 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5751 if (rssi)
5752 default_match_rssi = nla_get_s32(rssi);
5753 }
5754 }
5755
5756 /* However, if there's no other matchset, add the RSSI one */
5757 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5758 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005759
5760 if (n_match_sets > wiphy->max_match_sets)
5761 return -EINVAL;
5762
Luciano Coelho807f8a82011-05-11 17:09:35 +03005763 if (info->attrs[NL80211_ATTR_IE])
5764 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5765 else
5766 ie_len = 0;
5767
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005768 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005769 return -EINVAL;
5770
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005771 if (rdev->sched_scan_req) {
5772 err = -EINPROGRESS;
5773 goto out;
5774 }
5775
Luciano Coelho807f8a82011-05-11 17:09:35 +03005776 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005777 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005778 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005779 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005780 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005781 if (!request) {
5782 err = -ENOMEM;
5783 goto out;
5784 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005785
5786 if (n_ssids)
5787 request->ssids = (void *)&request->channels[n_channels];
5788 request->n_ssids = n_ssids;
5789 if (ie_len) {
5790 if (request->ssids)
5791 request->ie = (void *)(request->ssids + n_ssids);
5792 else
5793 request->ie = (void *)(request->channels + n_channels);
5794 }
5795
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005796 if (n_match_sets) {
5797 if (request->ie)
5798 request->match_sets = (void *)(request->ie + ie_len);
5799 else if (request->ssids)
5800 request->match_sets =
5801 (void *)(request->ssids + n_ssids);
5802 else
5803 request->match_sets =
5804 (void *)(request->channels + n_channels);
5805 }
5806 request->n_match_sets = n_match_sets;
5807
Luciano Coelho807f8a82011-05-11 17:09:35 +03005808 i = 0;
5809 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5810 /* user specified, bail out if channel not found */
5811 nla_for_each_nested(attr,
5812 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5813 tmp) {
5814 struct ieee80211_channel *chan;
5815
5816 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5817
5818 if (!chan) {
5819 err = -EINVAL;
5820 goto out_free;
5821 }
5822
5823 /* ignore disabled channels */
5824 if (chan->flags & IEEE80211_CHAN_DISABLED)
5825 continue;
5826
5827 request->channels[i] = chan;
5828 i++;
5829 }
5830 } else {
5831 /* all channels */
5832 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5833 int j;
5834 if (!wiphy->bands[band])
5835 continue;
5836 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5837 struct ieee80211_channel *chan;
5838
5839 chan = &wiphy->bands[band]->channels[j];
5840
5841 if (chan->flags & IEEE80211_CHAN_DISABLED)
5842 continue;
5843
5844 request->channels[i] = chan;
5845 i++;
5846 }
5847 }
5848 }
5849
5850 if (!i) {
5851 err = -EINVAL;
5852 goto out_free;
5853 }
5854
5855 request->n_channels = i;
5856
5857 i = 0;
5858 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5859 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5860 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005861 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005862 err = -EINVAL;
5863 goto out_free;
5864 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005865 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005866 memcpy(request->ssids[i].ssid, nla_data(attr),
5867 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005868 i++;
5869 }
5870 }
5871
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005872 i = 0;
5873 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5874 nla_for_each_nested(attr,
5875 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5876 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005877 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005878
Johannes Bergae811e22014-01-24 10:17:47 +01005879 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5880 nla_data(attr), nla_len(attr),
5881 nl80211_match_policy);
5882 if (err)
5883 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005884 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005885 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005886 if (WARN_ON(i >= n_match_sets)) {
5887 /* this indicates a programming error,
5888 * the loop above should have verified
5889 * things properly
5890 */
5891 err = -EINVAL;
5892 goto out_free;
5893 }
5894
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005895 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5896 err = -EINVAL;
5897 goto out_free;
5898 }
5899 memcpy(request->match_sets[i].ssid.ssid,
5900 nla_data(ssid), nla_len(ssid));
5901 request->match_sets[i].ssid.ssid_len =
5902 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005903 /* special attribute - old implemenation w/a */
5904 request->match_sets[i].rssi_thold =
5905 default_match_rssi;
5906 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5907 if (rssi)
5908 request->match_sets[i].rssi_thold =
5909 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005910 }
5911 i++;
5912 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005913
5914 /* there was no other matchset, so the RSSI one is alone */
5915 if (i == 0)
5916 request->match_sets[0].rssi_thold = default_match_rssi;
5917
5918 request->min_rssi_thold = INT_MAX;
5919 for (i = 0; i < n_match_sets; i++)
5920 request->min_rssi_thold =
5921 min(request->match_sets[i].rssi_thold,
5922 request->min_rssi_thold);
5923 } else {
5924 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005925 }
5926
Johannes Berg9900e482014-02-04 21:01:25 +01005927 if (ie_len) {
5928 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005929 memcpy((void *)request->ie,
5930 nla_data(info->attrs[NL80211_ATTR_IE]),
5931 request->ie_len);
5932 }
5933
Sam Leffler46856bb2012-10-11 21:03:32 -07005934 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005935 request->flags = nla_get_u32(
5936 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005937 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5938 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005939 err = -EOPNOTSUPP;
5940 goto out_free;
5941 }
5942 }
Sam Lefflered4737712012-10-11 21:03:31 -07005943
Luciano Coelho807f8a82011-05-11 17:09:35 +03005944 request->dev = dev;
5945 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005946 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005947 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005948
Hila Gonene35e4d22012-06-27 17:19:42 +03005949 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005950 if (!err) {
5951 rdev->sched_scan_req = request;
5952 nl80211_send_sched_scan(rdev, dev,
5953 NL80211_CMD_START_SCHED_SCAN);
5954 goto out;
5955 }
5956
5957out_free:
5958 kfree(request);
5959out:
5960 return err;
5961}
5962
5963static int nl80211_stop_sched_scan(struct sk_buff *skb,
5964 struct genl_info *info)
5965{
5966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5967
5968 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5969 !rdev->ops->sched_scan_stop)
5970 return -EOPNOTSUPP;
5971
Johannes Berg5fe231e2013-05-08 21:45:15 +02005972 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005973}
5974
Simon Wunderlich04f39042013-02-08 18:16:19 +01005975static int nl80211_start_radar_detection(struct sk_buff *skb,
5976 struct genl_info *info)
5977{
5978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5979 struct net_device *dev = info->user_ptr[1];
5980 struct wireless_dev *wdev = dev->ieee80211_ptr;
5981 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005982 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005983 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005984 int err;
5985
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005986 dfs_region = reg_get_dfs_region(wdev->wiphy);
5987 if (dfs_region == NL80211_DFS_UNSET)
5988 return -EINVAL;
5989
Simon Wunderlich04f39042013-02-08 18:16:19 +01005990 err = nl80211_parse_chandef(rdev, info, &chandef);
5991 if (err)
5992 return err;
5993
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005994 if (netif_carrier_ok(dev))
5995 return -EBUSY;
5996
Simon Wunderlich04f39042013-02-08 18:16:19 +01005997 if (wdev->cac_started)
5998 return -EBUSY;
5999
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006000 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006001 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006002 if (err < 0)
6003 return err;
6004
6005 if (err == 0)
6006 return -EINVAL;
6007
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006008 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006009 return -EINVAL;
6010
6011 if (!rdev->ops->start_radar_detection)
6012 return -EOPNOTSUPP;
6013
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006014 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6015 if (WARN_ON(!cac_time_ms))
6016 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6017
6018 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6019 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006020 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006021 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006022 wdev->cac_started = true;
6023 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006024 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006025 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006026 return err;
6027}
6028
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006029static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6030{
6031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6032 struct net_device *dev = info->user_ptr[1];
6033 struct wireless_dev *wdev = dev->ieee80211_ptr;
6034 struct cfg80211_csa_settings params;
6035 /* csa_attrs is defined static to avoid waste of stack size - this
6036 * function is called under RTNL lock, so this should not be a problem.
6037 */
6038 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
6039 u8 radar_detect_width = 0;
6040 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006041 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006042 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006043 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006044
6045 if (!rdev->ops->channel_switch ||
6046 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6047 return -EOPNOTSUPP;
6048
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006049 switch (dev->ieee80211_ptr->iftype) {
6050 case NL80211_IFTYPE_AP:
6051 case NL80211_IFTYPE_P2P_GO:
6052 need_new_beacon = true;
6053
6054 /* useless if AP is not running */
6055 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006056 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006057 break;
6058 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006059 if (!wdev->ssid_len)
6060 return -ENOTCONN;
6061 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006062 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006063 if (!wdev->mesh_id_len)
6064 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006065 break;
6066 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006067 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006068 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006069
6070 memset(&params, 0, sizeof(params));
6071
6072 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6073 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6074 return -EINVAL;
6075
6076 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006077 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006078 return -EINVAL;
6079
Luciano Coelho252e07c2014-10-08 09:48:34 +03006080 /* Even though the attribute is u32, the specification says
6081 * u8, so let's make sure we don't overflow.
6082 */
6083 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6084 if (cs_count > 255)
6085 return -EINVAL;
6086
6087 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006088
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006089 if (!need_new_beacon)
6090 goto skip_beacons;
6091
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006092 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6093 if (err)
6094 return err;
6095
6096 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6097 info->attrs[NL80211_ATTR_CSA_IES],
6098 nl80211_policy);
6099 if (err)
6100 return err;
6101
6102 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6103 if (err)
6104 return err;
6105
6106 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6107 return -EINVAL;
6108
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006109 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6110 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006111 return -EINVAL;
6112
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006113 params.n_counter_offsets_beacon = len / sizeof(u16);
6114 if (rdev->wiphy.max_num_csa_counters &&
6115 (params.n_counter_offsets_beacon >
6116 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006117 return -EINVAL;
6118
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006119 params.counter_offsets_beacon =
6120 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6121
6122 /* sanity checks - counters should fit and be the same */
6123 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6124 u16 offset = params.counter_offsets_beacon[i];
6125
6126 if (offset >= params.beacon_csa.tail_len)
6127 return -EINVAL;
6128
6129 if (params.beacon_csa.tail[offset] != params.count)
6130 return -EINVAL;
6131 }
6132
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006133 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006134 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6135 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006136 return -EINVAL;
6137
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006138 params.n_counter_offsets_presp = len / sizeof(u16);
6139 if (rdev->wiphy.max_num_csa_counters &&
6140 (params.n_counter_offsets_beacon >
6141 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006142 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006143
6144 params.counter_offsets_presp =
6145 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6146
6147 /* sanity checks - counters should fit and be the same */
6148 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6149 u16 offset = params.counter_offsets_presp[i];
6150
6151 if (offset >= params.beacon_csa.probe_resp_len)
6152 return -EINVAL;
6153
6154 if (params.beacon_csa.probe_resp[offset] !=
6155 params.count)
6156 return -EINVAL;
6157 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006158 }
6159
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006160skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006161 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6162 if (err)
6163 return err;
6164
Ilan Peer174e0cd2014-02-23 09:13:01 +02006165 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6166 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006167 return -EINVAL;
6168
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006169 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6170 &params.chandef,
6171 wdev->iftype);
6172 if (err < 0)
6173 return err;
6174
6175 if (err > 0) {
6176 radar_detect_width = BIT(params.chandef.width);
6177 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006178 }
6179
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006180 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6181 params.block_tx = true;
6182
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006183 wdev_lock(wdev);
6184 err = rdev_channel_switch(rdev, dev, &params);
6185 wdev_unlock(wdev);
6186
6187 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006188}
6189
Johannes Berg9720bb32011-06-21 09:45:33 +02006190static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6191 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006192 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006193 struct wireless_dev *wdev,
6194 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006195{
Johannes Berg48ab9052009-07-10 18:42:31 +02006196 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006197 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006198 void *hdr;
6199 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006200
6201 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006202
Eric W. Biederman15e47302012-09-07 20:12:54 +00006203 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006204 NL80211_CMD_NEW_SCAN_RESULTS);
6205 if (!hdr)
6206 return -1;
6207
Johannes Berg9720bb32011-06-21 09:45:33 +02006208 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6209
Johannes Berg97990a02013-04-19 01:02:55 +02006210 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6211 goto nla_put_failure;
6212 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006213 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6214 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006215 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6216 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006217
6218 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6219 if (!bss)
6220 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006221 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006222 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006223 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006224
6225 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006226 /* indicate whether we have probe response data or not */
6227 if (rcu_access_pointer(res->proberesp_ies) &&
6228 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6229 goto fail_unlock_rcu;
6230
6231 /* this pointer prefers to be pointed to probe response data
6232 * but is always valid
6233 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006234 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006235 if (ies) {
6236 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6237 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006238 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6239 ies->len, ies->data))
6240 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006241 }
Johannes Berg0e227082014-08-12 20:34:30 +02006242
6243 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006244 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006245 if (ies && ies->from_beacon) {
6246 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006247 goto fail_unlock_rcu;
6248 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6249 ies->len, ies->data))
6250 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006251 }
6252 rcu_read_unlock();
6253
David S. Miller9360ffd2012-03-29 04:41:26 -04006254 if (res->beacon_interval &&
6255 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6256 goto nla_put_failure;
6257 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6258 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006259 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006260 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6261 jiffies_to_msecs(jiffies - intbss->ts)))
6262 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006263
Johannes Berg77965c972009-02-18 18:45:06 +01006264 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006265 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006266 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6267 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006268 break;
6269 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006270 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6271 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006272 break;
6273 default:
6274 break;
6275 }
6276
Johannes Berg48ab9052009-07-10 18:42:31 +02006277 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006278 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006279 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006280 if (intbss == wdev->current_bss &&
6281 nla_put_u32(msg, NL80211_BSS_STATUS,
6282 NL80211_BSS_STATUS_ASSOCIATED))
6283 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006284 break;
6285 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006286 if (intbss == wdev->current_bss &&
6287 nla_put_u32(msg, NL80211_BSS_STATUS,
6288 NL80211_BSS_STATUS_IBSS_JOINED))
6289 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006290 break;
6291 default:
6292 break;
6293 }
6294
Johannes Berg2a519312009-02-10 21:25:55 +01006295 nla_nest_end(msg, bss);
6296
6297 return genlmsg_end(msg, hdr);
6298
Johannes Berg8cef2c92013-02-05 16:54:31 +01006299 fail_unlock_rcu:
6300 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006301 nla_put_failure:
6302 genlmsg_cancel(msg, hdr);
6303 return -EMSGSIZE;
6304}
6305
Johannes Berg97990a02013-04-19 01:02:55 +02006306static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006307{
Johannes Berg48ab9052009-07-10 18:42:31 +02006308 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006309 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006310 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006311 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006312 int err;
6313
Johannes Berg97990a02013-04-19 01:02:55 +02006314 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006315 if (err)
6316 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006317
Johannes Berg48ab9052009-07-10 18:42:31 +02006318 wdev_lock(wdev);
6319 spin_lock_bh(&rdev->bss_lock);
6320 cfg80211_bss_expire(rdev);
6321
Johannes Berg9720bb32011-06-21 09:45:33 +02006322 cb->seq = rdev->bss_generation;
6323
Johannes Berg48ab9052009-07-10 18:42:31 +02006324 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006325 if (++idx <= start)
6326 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006327 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006328 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006329 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006330 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006331 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006332 }
6333 }
6334
Johannes Berg48ab9052009-07-10 18:42:31 +02006335 spin_unlock_bh(&rdev->bss_lock);
6336 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006337
Johannes Berg97990a02013-04-19 01:02:55 +02006338 cb->args[2] = idx;
6339 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006340
Johannes Berg67748892010-10-04 21:14:06 +02006341 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006342}
6343
Eric W. Biederman15e47302012-09-07 20:12:54 +00006344static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006345 int flags, struct net_device *dev,
6346 struct survey_info *survey)
6347{
6348 void *hdr;
6349 struct nlattr *infoattr;
6350
Eric W. Biederman15e47302012-09-07 20:12:54 +00006351 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006352 NL80211_CMD_NEW_SURVEY_RESULTS);
6353 if (!hdr)
6354 return -ENOMEM;
6355
David S. Miller9360ffd2012-03-29 04:41:26 -04006356 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6357 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006358
6359 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6360 if (!infoattr)
6361 goto nla_put_failure;
6362
David S. Miller9360ffd2012-03-29 04:41:26 -04006363 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6364 survey->channel->center_freq))
6365 goto nla_put_failure;
6366
6367 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6368 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6369 goto nla_put_failure;
6370 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6371 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6372 goto nla_put_failure;
6373 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6374 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6375 survey->channel_time))
6376 goto nla_put_failure;
6377 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6378 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6379 survey->channel_time_busy))
6380 goto nla_put_failure;
6381 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6382 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6383 survey->channel_time_ext_busy))
6384 goto nla_put_failure;
6385 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6386 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6387 survey->channel_time_rx))
6388 goto nla_put_failure;
6389 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6390 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6391 survey->channel_time_tx))
6392 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006393
6394 nla_nest_end(msg, infoattr);
6395
6396 return genlmsg_end(msg, hdr);
6397
6398 nla_put_failure:
6399 genlmsg_cancel(msg, hdr);
6400 return -EMSGSIZE;
6401}
6402
6403static int nl80211_dump_survey(struct sk_buff *skb,
6404 struct netlink_callback *cb)
6405{
6406 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006407 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006408 struct wireless_dev *wdev;
6409 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006410 int res;
6411
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006412 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006413 if (res)
6414 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006415
Johannes Berg97990a02013-04-19 01:02:55 +02006416 if (!wdev->netdev) {
6417 res = -EINVAL;
6418 goto out_err;
6419 }
6420
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006421 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006422 res = -EOPNOTSUPP;
6423 goto out_err;
6424 }
6425
6426 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006427 struct ieee80211_channel *chan;
6428
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006429 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006430 if (res == -ENOENT)
6431 break;
6432 if (res)
6433 goto out_err;
6434
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006435 /* Survey without a channel doesn't make sense */
6436 if (!survey.channel) {
6437 res = -EINVAL;
6438 goto out;
6439 }
6440
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006441 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006442 survey.channel->center_freq);
6443 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6444 survey_idx++;
6445 continue;
6446 }
6447
Holger Schurig61fa7132009-11-11 12:25:40 +01006448 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006449 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006450 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006451 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006452 goto out;
6453 survey_idx++;
6454 }
6455
6456 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006457 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006458 res = skb->len;
6459 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006460 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006461 return res;
6462}
6463
Samuel Ortizb23aa672009-07-01 21:26:54 +02006464static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6465{
6466 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6467 NL80211_WPA_VERSION_2));
6468}
6469
Jouni Malinen636a5d32009-03-19 13:39:22 +02006470static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6471{
Johannes Berg4c476992010-10-04 21:36:35 +02006472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6473 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006474 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006475 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6476 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006477 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006478 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006479 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006480
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006481 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6482 return -EINVAL;
6483
6484 if (!info->attrs[NL80211_ATTR_MAC])
6485 return -EINVAL;
6486
Jouni Malinen17780922009-03-27 20:52:47 +02006487 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6488 return -EINVAL;
6489
Johannes Berg19957bb2009-07-02 17:20:43 +02006490 if (!info->attrs[NL80211_ATTR_SSID])
6491 return -EINVAL;
6492
6493 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6494 return -EINVAL;
6495
Johannes Bergfffd0932009-07-08 14:22:54 +02006496 err = nl80211_parse_key(info, &key);
6497 if (err)
6498 return err;
6499
6500 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006501 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6502 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006503 if (!key.p.key || !key.p.key_len)
6504 return -EINVAL;
6505 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6506 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6507 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6508 key.p.key_len != WLAN_KEY_LEN_WEP104))
6509 return -EINVAL;
6510 if (key.idx > 4)
6511 return -EINVAL;
6512 } else {
6513 key.p.key_len = 0;
6514 key.p.key = NULL;
6515 }
6516
Johannes Bergafea0b72010-08-10 09:46:42 +02006517 if (key.idx >= 0) {
6518 int i;
6519 bool ok = false;
6520 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6521 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6522 ok = true;
6523 break;
6524 }
6525 }
Johannes Berg4c476992010-10-04 21:36:35 +02006526 if (!ok)
6527 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006528 }
6529
Johannes Berg4c476992010-10-04 21:36:35 +02006530 if (!rdev->ops->auth)
6531 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006532
Johannes Berg074ac8d2010-09-16 14:58:22 +02006533 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006534 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6535 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006536
Johannes Berg19957bb2009-07-02 17:20:43 +02006537 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006538 chan = nl80211_get_valid_chan(&rdev->wiphy,
6539 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6540 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006541 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006542
Johannes Berg19957bb2009-07-02 17:20:43 +02006543 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6544 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6545
6546 if (info->attrs[NL80211_ATTR_IE]) {
6547 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6548 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6549 }
6550
6551 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006552 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006553 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006554
Jouni Malinene39e5b52012-09-30 19:29:39 +03006555 if (auth_type == NL80211_AUTHTYPE_SAE &&
6556 !info->attrs[NL80211_ATTR_SAE_DATA])
6557 return -EINVAL;
6558
6559 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6560 if (auth_type != NL80211_AUTHTYPE_SAE)
6561 return -EINVAL;
6562 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6563 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6564 /* need to include at least Auth Transaction and Status Code */
6565 if (sae_data_len < 4)
6566 return -EINVAL;
6567 }
6568
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006569 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6570
Johannes Berg95de8172012-01-20 13:55:25 +01006571 /*
6572 * Since we no longer track auth state, ignore
6573 * requests to only change local state.
6574 */
6575 if (local_state_change)
6576 return 0;
6577
Johannes Berg91bf9b22013-05-15 17:44:01 +02006578 wdev_lock(dev->ieee80211_ptr);
6579 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6580 ssid, ssid_len, ie, ie_len,
6581 key.p.key, key.p.key_len, key.idx,
6582 sae_data, sae_data_len);
6583 wdev_unlock(dev->ieee80211_ptr);
6584 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006585}
6586
Johannes Bergc0692b82010-08-27 14:26:53 +03006587static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6588 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006589 struct cfg80211_crypto_settings *settings,
6590 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006591{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006592 memset(settings, 0, sizeof(*settings));
6593
Samuel Ortizb23aa672009-07-01 21:26:54 +02006594 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6595
Johannes Bergc0692b82010-08-27 14:26:53 +03006596 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6597 u16 proto;
6598 proto = nla_get_u16(
6599 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6600 settings->control_port_ethertype = cpu_to_be16(proto);
6601 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6602 proto != ETH_P_PAE)
6603 return -EINVAL;
6604 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6605 settings->control_port_no_encrypt = true;
6606 } else
6607 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6608
Samuel Ortizb23aa672009-07-01 21:26:54 +02006609 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6610 void *data;
6611 int len, i;
6612
6613 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6614 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6615 settings->n_ciphers_pairwise = len / sizeof(u32);
6616
6617 if (len % sizeof(u32))
6618 return -EINVAL;
6619
Johannes Berg3dc27d22009-07-02 21:36:37 +02006620 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006621 return -EINVAL;
6622
6623 memcpy(settings->ciphers_pairwise, data, len);
6624
6625 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006626 if (!cfg80211_supported_cipher_suite(
6627 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006628 settings->ciphers_pairwise[i]))
6629 return -EINVAL;
6630 }
6631
6632 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6633 settings->cipher_group =
6634 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006635 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6636 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006637 return -EINVAL;
6638 }
6639
6640 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6641 settings->wpa_versions =
6642 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6643 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6644 return -EINVAL;
6645 }
6646
6647 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6648 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006649 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006650
6651 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6652 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6653 settings->n_akm_suites = len / sizeof(u32);
6654
6655 if (len % sizeof(u32))
6656 return -EINVAL;
6657
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006658 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6659 return -EINVAL;
6660
Samuel Ortizb23aa672009-07-01 21:26:54 +02006661 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006662 }
6663
6664 return 0;
6665}
6666
Jouni Malinen636a5d32009-03-19 13:39:22 +02006667static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6668{
Johannes Berg4c476992010-10-04 21:36:35 +02006669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6670 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006671 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006672 struct cfg80211_assoc_request req = {};
6673 const u8 *bssid, *ssid;
6674 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006675
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006676 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6677 return -EINVAL;
6678
6679 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006680 !info->attrs[NL80211_ATTR_SSID] ||
6681 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006682 return -EINVAL;
6683
Johannes Berg4c476992010-10-04 21:36:35 +02006684 if (!rdev->ops->assoc)
6685 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006686
Johannes Berg074ac8d2010-09-16 14:58:22 +02006687 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006688 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6689 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006690
Johannes Berg19957bb2009-07-02 17:20:43 +02006691 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006692
Jouni Malinen664834d2014-01-15 00:01:44 +02006693 chan = nl80211_get_valid_chan(&rdev->wiphy,
6694 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6695 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006696 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006697
Johannes Berg19957bb2009-07-02 17:20:43 +02006698 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6699 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006700
6701 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006702 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6703 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006704 }
6705
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006706 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006707 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006708 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006709 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006710 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006711 else if (mfp != NL80211_MFP_NO)
6712 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006713 }
6714
Johannes Berg3e5d7642009-07-07 14:37:26 +02006715 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006716 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006717
Ben Greear7e7c8922011-11-18 11:31:59 -08006718 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006719 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006720
6721 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006722 memcpy(&req.ht_capa_mask,
6723 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6724 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006725
6726 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006727 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006728 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006729 memcpy(&req.ht_capa,
6730 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6731 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006732 }
6733
Johannes Bergee2aca32013-02-21 17:36:01 +01006734 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006735 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006736
6737 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006738 memcpy(&req.vht_capa_mask,
6739 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6740 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006741
6742 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006743 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006744 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006745 memcpy(&req.vht_capa,
6746 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6747 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006748 }
6749
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006750 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6751 if (!(rdev->wiphy.features &
6752 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6753 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6754 return -EINVAL;
6755 req.flags |= ASSOC_REQ_USE_RRM;
6756 }
6757
Johannes Bergf62fab72013-02-21 20:09:09 +01006758 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006759 if (!err) {
6760 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006761 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6762 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006763 wdev_unlock(dev->ieee80211_ptr);
6764 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006765
Jouni Malinen636a5d32009-03-19 13:39:22 +02006766 return err;
6767}
6768
6769static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6770{
Johannes Berg4c476992010-10-04 21:36:35 +02006771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6772 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006773 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006774 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006775 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006776 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006777
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006778 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6779 return -EINVAL;
6780
6781 if (!info->attrs[NL80211_ATTR_MAC])
6782 return -EINVAL;
6783
6784 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6785 return -EINVAL;
6786
Johannes Berg4c476992010-10-04 21:36:35 +02006787 if (!rdev->ops->deauth)
6788 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006789
Johannes Berg074ac8d2010-09-16 14:58:22 +02006790 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006791 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6792 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006793
Johannes Berg19957bb2009-07-02 17:20:43 +02006794 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006795
Johannes Berg19957bb2009-07-02 17:20:43 +02006796 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6797 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006798 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006799 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006800 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006801
6802 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006803 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6804 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006805 }
6806
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006807 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6808
Johannes Berg91bf9b22013-05-15 17:44:01 +02006809 wdev_lock(dev->ieee80211_ptr);
6810 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6811 local_state_change);
6812 wdev_unlock(dev->ieee80211_ptr);
6813 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006814}
6815
6816static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6817{
Johannes Berg4c476992010-10-04 21:36:35 +02006818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6819 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006820 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006821 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006822 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006823 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006824
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006825 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6826 return -EINVAL;
6827
6828 if (!info->attrs[NL80211_ATTR_MAC])
6829 return -EINVAL;
6830
6831 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6832 return -EINVAL;
6833
Johannes Berg4c476992010-10-04 21:36:35 +02006834 if (!rdev->ops->disassoc)
6835 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006836
Johannes Berg074ac8d2010-09-16 14:58:22 +02006837 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006838 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6839 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006840
Johannes Berg19957bb2009-07-02 17:20:43 +02006841 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006842
Johannes Berg19957bb2009-07-02 17:20:43 +02006843 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6844 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006845 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006846 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006847 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006848
6849 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006850 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6851 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006852 }
6853
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006854 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6855
Johannes Berg91bf9b22013-05-15 17:44:01 +02006856 wdev_lock(dev->ieee80211_ptr);
6857 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6858 local_state_change);
6859 wdev_unlock(dev->ieee80211_ptr);
6860 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006861}
6862
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006863static bool
6864nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6865 int mcast_rate[IEEE80211_NUM_BANDS],
6866 int rateval)
6867{
6868 struct wiphy *wiphy = &rdev->wiphy;
6869 bool found = false;
6870 int band, i;
6871
6872 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6873 struct ieee80211_supported_band *sband;
6874
6875 sband = wiphy->bands[band];
6876 if (!sband)
6877 continue;
6878
6879 for (i = 0; i < sband->n_bitrates; i++) {
6880 if (sband->bitrates[i].bitrate == rateval) {
6881 mcast_rate[band] = i + 1;
6882 found = true;
6883 break;
6884 }
6885 }
6886 }
6887
6888 return found;
6889}
6890
Johannes Berg04a773a2009-04-19 21:24:32 +02006891static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6892{
Johannes Berg4c476992010-10-04 21:36:35 +02006893 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6894 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006895 struct cfg80211_ibss_params ibss;
6896 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006897 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006898 int err;
6899
Johannes Berg8e30bc52009-04-22 17:45:38 +02006900 memset(&ibss, 0, sizeof(ibss));
6901
Johannes Berg04a773a2009-04-19 21:24:32 +02006902 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6903 return -EINVAL;
6904
Johannes Berg683b6d32012-11-08 21:25:48 +01006905 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006906 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6907 return -EINVAL;
6908
Johannes Berg8e30bc52009-04-22 17:45:38 +02006909 ibss.beacon_interval = 100;
6910
6911 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6912 ibss.beacon_interval =
6913 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6914 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6915 return -EINVAL;
6916 }
6917
Johannes Berg4c476992010-10-04 21:36:35 +02006918 if (!rdev->ops->join_ibss)
6919 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006920
Johannes Berg4c476992010-10-04 21:36:35 +02006921 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6922 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006923
Johannes Berg79c97e92009-07-07 03:56:12 +02006924 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006925
Johannes Berg39193492011-09-16 13:45:25 +02006926 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006927 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006928
6929 if (!is_valid_ether_addr(ibss.bssid))
6930 return -EINVAL;
6931 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006932 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6933 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6934
6935 if (info->attrs[NL80211_ATTR_IE]) {
6936 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6937 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6938 }
6939
Johannes Berg683b6d32012-11-08 21:25:48 +01006940 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6941 if (err)
6942 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006943
Ilan Peer174e0cd2014-02-23 09:13:01 +02006944 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6945 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006946 return -EINVAL;
6947
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006948 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006949 case NL80211_CHAN_WIDTH_5:
6950 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006951 case NL80211_CHAN_WIDTH_20_NOHT:
6952 break;
6953 case NL80211_CHAN_WIDTH_20:
6954 case NL80211_CHAN_WIDTH_40:
6955 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6956 break;
6957 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006958 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006959 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006960
Johannes Berg04a773a2009-04-19 21:24:32 +02006961 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006962 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006963
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006964 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6965 u8 *rates =
6966 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6967 int n_rates =
6968 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6969 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006970 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006971
Johannes Berg34850ab2011-07-18 18:08:35 +02006972 err = ieee80211_get_ratemask(sband, rates, n_rates,
6973 &ibss.basic_rates);
6974 if (err)
6975 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006976 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006977
Simon Wunderlich803768f2013-06-28 10:39:58 +02006978 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6979 memcpy(&ibss.ht_capa_mask,
6980 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6981 sizeof(ibss.ht_capa_mask));
6982
6983 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6984 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6985 return -EINVAL;
6986 memcpy(&ibss.ht_capa,
6987 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6988 sizeof(ibss.ht_capa));
6989 }
6990
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006991 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6992 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6993 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6994 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006995
Johannes Berg4c476992010-10-04 21:36:35 +02006996 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306997 bool no_ht = false;
6998
Johannes Berg4c476992010-10-04 21:36:35 +02006999 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307000 info->attrs[NL80211_ATTR_KEYS],
7001 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007002 if (IS_ERR(connkeys))
7003 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307004
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007005 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7006 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307007 kfree(connkeys);
7008 return -EINVAL;
7009 }
Johannes Berg4c476992010-10-04 21:36:35 +02007010 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007011
Antonio Quartulli267335d2012-01-31 20:25:47 +01007012 ibss.control_port =
7013 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7014
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007015 ibss.userspace_handles_dfs =
7016 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7017
Johannes Berg4c476992010-10-04 21:36:35 +02007018 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007019 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007020 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007021 return err;
7022}
7023
7024static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7025{
Johannes Berg4c476992010-10-04 21:36:35 +02007026 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7027 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007028
Johannes Berg4c476992010-10-04 21:36:35 +02007029 if (!rdev->ops->leave_ibss)
7030 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007031
Johannes Berg4c476992010-10-04 21:36:35 +02007032 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7033 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007034
Johannes Berg4c476992010-10-04 21:36:35 +02007035 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007036}
7037
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007038static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7039{
7040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7041 struct net_device *dev = info->user_ptr[1];
7042 int mcast_rate[IEEE80211_NUM_BANDS];
7043 u32 nla_rate;
7044 int err;
7045
7046 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7047 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7048 return -EOPNOTSUPP;
7049
7050 if (!rdev->ops->set_mcast_rate)
7051 return -EOPNOTSUPP;
7052
7053 memset(mcast_rate, 0, sizeof(mcast_rate));
7054
7055 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7056 return -EINVAL;
7057
7058 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7059 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7060 return -EINVAL;
7061
7062 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7063
7064 return err;
7065}
7066
Johannes Bergad7e7182013-11-13 13:37:47 +01007067static struct sk_buff *
7068__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7069 int approxlen, u32 portid, u32 seq,
7070 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007071 enum nl80211_attrs attr,
7072 const struct nl80211_vendor_cmd_info *info,
7073 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007074{
7075 struct sk_buff *skb;
7076 void *hdr;
7077 struct nlattr *data;
7078
7079 skb = nlmsg_new(approxlen + 100, gfp);
7080 if (!skb)
7081 return NULL;
7082
7083 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7084 if (!hdr) {
7085 kfree_skb(skb);
7086 return NULL;
7087 }
7088
7089 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7090 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007091
7092 if (info) {
7093 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7094 info->vendor_id))
7095 goto nla_put_failure;
7096 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7097 info->subcmd))
7098 goto nla_put_failure;
7099 }
7100
Johannes Bergad7e7182013-11-13 13:37:47 +01007101 data = nla_nest_start(skb, attr);
7102
7103 ((void **)skb->cb)[0] = rdev;
7104 ((void **)skb->cb)[1] = hdr;
7105 ((void **)skb->cb)[2] = data;
7106
7107 return skb;
7108
7109 nla_put_failure:
7110 kfree_skb(skb);
7111 return NULL;
7112}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007113
Johannes Berge03ad6e2014-01-01 17:22:30 +01007114struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7115 enum nl80211_commands cmd,
7116 enum nl80211_attrs attr,
7117 int vendor_event_idx,
7118 int approxlen, gfp_t gfp)
7119{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007120 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007121 const struct nl80211_vendor_cmd_info *info;
7122
7123 switch (cmd) {
7124 case NL80211_CMD_TESTMODE:
7125 if (WARN_ON(vendor_event_idx != -1))
7126 return NULL;
7127 info = NULL;
7128 break;
7129 case NL80211_CMD_VENDOR:
7130 if (WARN_ON(vendor_event_idx < 0 ||
7131 vendor_event_idx >= wiphy->n_vendor_events))
7132 return NULL;
7133 info = &wiphy->vendor_events[vendor_event_idx];
7134 break;
7135 default:
7136 WARN_ON(1);
7137 return NULL;
7138 }
7139
7140 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7141 cmd, attr, info, gfp);
7142}
7143EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7144
7145void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7146{
7147 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7148 void *hdr = ((void **)skb->cb)[1];
7149 struct nlattr *data = ((void **)skb->cb)[2];
7150 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7151
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007152 /* clear CB data for netlink core to own from now on */
7153 memset(skb->cb, 0, sizeof(skb->cb));
7154
Johannes Berge03ad6e2014-01-01 17:22:30 +01007155 nla_nest_end(skb, data);
7156 genlmsg_end(skb, hdr);
7157
7158 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7159 mcgrp = NL80211_MCGRP_VENDOR;
7160
7161 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7162 mcgrp, gfp);
7163}
7164EXPORT_SYMBOL(__cfg80211_send_event_skb);
7165
Johannes Bergaff89a92009-07-01 21:26:51 +02007166#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007167static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7168{
Johannes Berg4c476992010-10-04 21:36:35 +02007169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007170 struct wireless_dev *wdev =
7171 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007172 int err;
7173
David Spinadelfc73f112013-07-31 18:04:15 +03007174 if (!rdev->ops->testmode_cmd)
7175 return -EOPNOTSUPP;
7176
7177 if (IS_ERR(wdev)) {
7178 err = PTR_ERR(wdev);
7179 if (err != -EINVAL)
7180 return err;
7181 wdev = NULL;
7182 } else if (wdev->wiphy != &rdev->wiphy) {
7183 return -EINVAL;
7184 }
7185
Johannes Bergaff89a92009-07-01 21:26:51 +02007186 if (!info->attrs[NL80211_ATTR_TESTDATA])
7187 return -EINVAL;
7188
Johannes Bergad7e7182013-11-13 13:37:47 +01007189 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007190 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007191 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7192 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007193 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007194
Johannes Bergaff89a92009-07-01 21:26:51 +02007195 return err;
7196}
7197
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007198static int nl80211_testmode_dump(struct sk_buff *skb,
7199 struct netlink_callback *cb)
7200{
Johannes Berg00918d32011-12-13 17:22:05 +01007201 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007202 int err;
7203 long phy_idx;
7204 void *data = NULL;
7205 int data_len = 0;
7206
Johannes Berg5fe231e2013-05-08 21:45:15 +02007207 rtnl_lock();
7208
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007209 if (cb->args[0]) {
7210 /*
7211 * 0 is a valid index, but not valid for args[0],
7212 * so we need to offset by 1.
7213 */
7214 phy_idx = cb->args[0] - 1;
7215 } else {
7216 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7217 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7218 nl80211_policy);
7219 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007220 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007221
Johannes Berg2bd7e352012-06-15 14:23:16 +02007222 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7223 nl80211_fam.attrbuf);
7224 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007225 err = PTR_ERR(rdev);
7226 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007227 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007228 phy_idx = rdev->wiphy_idx;
7229 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007230
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007231 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7232 cb->args[1] =
7233 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7234 }
7235
7236 if (cb->args[1]) {
7237 data = nla_data((void *)cb->args[1]);
7238 data_len = nla_len((void *)cb->args[1]);
7239 }
7240
Johannes Berg00918d32011-12-13 17:22:05 +01007241 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7242 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007243 err = -ENOENT;
7244 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007245 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007246
Johannes Berg00918d32011-12-13 17:22:05 +01007247 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007248 err = -EOPNOTSUPP;
7249 goto out_err;
7250 }
7251
7252 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007253 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007254 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7255 NL80211_CMD_TESTMODE);
7256 struct nlattr *tmdata;
7257
Dan Carpentercb35fba2013-08-14 14:50:01 +03007258 if (!hdr)
7259 break;
7260
David S. Miller9360ffd2012-03-29 04:41:26 -04007261 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007262 genlmsg_cancel(skb, hdr);
7263 break;
7264 }
7265
7266 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7267 if (!tmdata) {
7268 genlmsg_cancel(skb, hdr);
7269 break;
7270 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007271 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007272 nla_nest_end(skb, tmdata);
7273
7274 if (err == -ENOBUFS || err == -ENOENT) {
7275 genlmsg_cancel(skb, hdr);
7276 break;
7277 } else if (err) {
7278 genlmsg_cancel(skb, hdr);
7279 goto out_err;
7280 }
7281
7282 genlmsg_end(skb, hdr);
7283 }
7284
7285 err = skb->len;
7286 /* see above */
7287 cb->args[0] = phy_idx + 1;
7288 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007289 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007290 return err;
7291}
Johannes Bergaff89a92009-07-01 21:26:51 +02007292#endif
7293
Samuel Ortizb23aa672009-07-01 21:26:54 +02007294static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7295{
Johannes Berg4c476992010-10-04 21:36:35 +02007296 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7297 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007298 struct cfg80211_connect_params connect;
7299 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007300 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007301 int err;
7302
7303 memset(&connect, 0, sizeof(connect));
7304
7305 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7306 return -EINVAL;
7307
7308 if (!info->attrs[NL80211_ATTR_SSID] ||
7309 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7310 return -EINVAL;
7311
7312 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7313 connect.auth_type =
7314 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007315 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7316 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007317 return -EINVAL;
7318 } else
7319 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7320
7321 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7322
Johannes Bergc0692b82010-08-27 14:26:53 +03007323 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007324 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007325 if (err)
7326 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007327
Johannes Berg074ac8d2010-09-16 14:58:22 +02007328 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007329 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7330 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007331
Johannes Berg79c97e92009-07-07 03:56:12 +02007332 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007333
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307334 connect.bg_scan_period = -1;
7335 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7336 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7337 connect.bg_scan_period =
7338 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7339 }
7340
Samuel Ortizb23aa672009-07-01 21:26:54 +02007341 if (info->attrs[NL80211_ATTR_MAC])
7342 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007343 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7344 connect.bssid_hint =
7345 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007346 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7347 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7348
7349 if (info->attrs[NL80211_ATTR_IE]) {
7350 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7351 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7352 }
7353
Jouni Malinencee00a92013-01-15 17:15:57 +02007354 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7355 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7356 if (connect.mfp != NL80211_MFP_REQUIRED &&
7357 connect.mfp != NL80211_MFP_NO)
7358 return -EINVAL;
7359 } else {
7360 connect.mfp = NL80211_MFP_NO;
7361 }
7362
Samuel Ortizb23aa672009-07-01 21:26:54 +02007363 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007364 connect.channel = nl80211_get_valid_chan(
7365 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7366 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007367 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007368 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007369 connect.channel_hint = nl80211_get_valid_chan(
7370 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7371 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007372 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007373 }
7374
Johannes Bergfffd0932009-07-08 14:22:54 +02007375 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7376 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307377 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007378 if (IS_ERR(connkeys))
7379 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007380 }
7381
Ben Greear7e7c8922011-11-18 11:31:59 -08007382 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7383 connect.flags |= ASSOC_REQ_DISABLE_HT;
7384
7385 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7386 memcpy(&connect.ht_capa_mask,
7387 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7388 sizeof(connect.ht_capa_mask));
7389
7390 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007391 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007392 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007393 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007394 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007395 memcpy(&connect.ht_capa,
7396 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7397 sizeof(connect.ht_capa));
7398 }
7399
Johannes Bergee2aca32013-02-21 17:36:01 +01007400 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7401 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7402
7403 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7404 memcpy(&connect.vht_capa_mask,
7405 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7406 sizeof(connect.vht_capa_mask));
7407
7408 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7409 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007410 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007411 return -EINVAL;
7412 }
7413 memcpy(&connect.vht_capa,
7414 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7415 sizeof(connect.vht_capa));
7416 }
7417
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007418 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7419 if (!(rdev->wiphy.features &
7420 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7421 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7422 return -EINVAL;
7423 connect.flags |= ASSOC_REQ_USE_RRM;
7424 }
7425
Johannes Berg83739b02013-05-15 17:44:01 +02007426 wdev_lock(dev->ieee80211_ptr);
7427 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7428 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007429 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007430 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007431 return err;
7432}
7433
7434static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7435{
Johannes Berg4c476992010-10-04 21:36:35 +02007436 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7437 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007438 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007439 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007440
7441 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7442 reason = WLAN_REASON_DEAUTH_LEAVING;
7443 else
7444 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7445
7446 if (reason == 0)
7447 return -EINVAL;
7448
Johannes Berg074ac8d2010-09-16 14:58:22 +02007449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007450 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7451 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007452
Johannes Berg83739b02013-05-15 17:44:01 +02007453 wdev_lock(dev->ieee80211_ptr);
7454 ret = cfg80211_disconnect(rdev, dev, reason, true);
7455 wdev_unlock(dev->ieee80211_ptr);
7456 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007457}
7458
Johannes Berg463d0182009-07-14 00:33:35 +02007459static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7460{
Johannes Berg4c476992010-10-04 21:36:35 +02007461 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007462 struct net *net;
7463 int err;
7464 u32 pid;
7465
7466 if (!info->attrs[NL80211_ATTR_PID])
7467 return -EINVAL;
7468
7469 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7470
Johannes Berg463d0182009-07-14 00:33:35 +02007471 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007472 if (IS_ERR(net))
7473 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007474
7475 err = 0;
7476
7477 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007478 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7479 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007480
Johannes Berg463d0182009-07-14 00:33:35 +02007481 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007482 return err;
7483}
7484
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007485static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7486{
Johannes Berg4c476992010-10-04 21:36:35 +02007487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007488 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7489 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007490 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007491 struct cfg80211_pmksa pmksa;
7492
7493 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7494
7495 if (!info->attrs[NL80211_ATTR_MAC])
7496 return -EINVAL;
7497
7498 if (!info->attrs[NL80211_ATTR_PMKID])
7499 return -EINVAL;
7500
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007501 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7502 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7503
Johannes Berg074ac8d2010-09-16 14:58:22 +02007504 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007505 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7506 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007507
7508 switch (info->genlhdr->cmd) {
7509 case NL80211_CMD_SET_PMKSA:
7510 rdev_ops = rdev->ops->set_pmksa;
7511 break;
7512 case NL80211_CMD_DEL_PMKSA:
7513 rdev_ops = rdev->ops->del_pmksa;
7514 break;
7515 default:
7516 WARN_ON(1);
7517 break;
7518 }
7519
Johannes Berg4c476992010-10-04 21:36:35 +02007520 if (!rdev_ops)
7521 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007522
Johannes Berg4c476992010-10-04 21:36:35 +02007523 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007524}
7525
7526static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7527{
Johannes Berg4c476992010-10-04 21:36:35 +02007528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7529 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007530
Johannes Berg074ac8d2010-09-16 14:58:22 +02007531 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007532 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7533 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007534
Johannes Berg4c476992010-10-04 21:36:35 +02007535 if (!rdev->ops->flush_pmksa)
7536 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007537
Hila Gonene35e4d22012-06-27 17:19:42 +03007538 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007539}
7540
Arik Nemtsov109086c2011-09-28 14:12:50 +03007541static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7542{
7543 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7544 struct net_device *dev = info->user_ptr[1];
7545 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307546 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007547 u16 status_code;
7548 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007549 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007550
7551 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7552 !rdev->ops->tdls_mgmt)
7553 return -EOPNOTSUPP;
7554
7555 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7556 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7557 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7558 !info->attrs[NL80211_ATTR_IE] ||
7559 !info->attrs[NL80211_ATTR_MAC])
7560 return -EINVAL;
7561
7562 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7563 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7564 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7565 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007566 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307567 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7568 peer_capability =
7569 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007570
Hila Gonene35e4d22012-06-27 17:19:42 +03007571 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307572 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007573 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007574 nla_data(info->attrs[NL80211_ATTR_IE]),
7575 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007576}
7577
7578static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7579{
7580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7581 struct net_device *dev = info->user_ptr[1];
7582 enum nl80211_tdls_operation operation;
7583 u8 *peer;
7584
7585 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7586 !rdev->ops->tdls_oper)
7587 return -EOPNOTSUPP;
7588
7589 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7590 !info->attrs[NL80211_ATTR_MAC])
7591 return -EINVAL;
7592
7593 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7594 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7595
Hila Gonene35e4d22012-06-27 17:19:42 +03007596 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007597}
7598
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007599static int nl80211_remain_on_channel(struct sk_buff *skb,
7600 struct genl_info *info)
7601{
Johannes Berg4c476992010-10-04 21:36:35 +02007602 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007603 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007604 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007605 struct sk_buff *msg;
7606 void *hdr;
7607 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007608 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007609 int err;
7610
7611 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7612 !info->attrs[NL80211_ATTR_DURATION])
7613 return -EINVAL;
7614
7615 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7616
Johannes Berg7c4ef712011-11-18 15:33:48 +01007617 if (!rdev->ops->remain_on_channel ||
7618 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007619 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007620
Johannes Bergebf348f2012-06-01 12:50:54 +02007621 /*
7622 * We should be on that channel for at least a minimum amount of
7623 * time (10ms) but no longer than the driver supports.
7624 */
7625 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7626 duration > rdev->wiphy.max_remain_on_channel_duration)
7627 return -EINVAL;
7628
Johannes Berg683b6d32012-11-08 21:25:48 +01007629 err = nl80211_parse_chandef(rdev, info, &chandef);
7630 if (err)
7631 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007632
7633 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007634 if (!msg)
7635 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007636
Eric W. Biederman15e47302012-09-07 20:12:54 +00007637 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007638 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007639 if (!hdr) {
7640 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007641 goto free_msg;
7642 }
7643
Johannes Berg683b6d32012-11-08 21:25:48 +01007644 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7645 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007646
7647 if (err)
7648 goto free_msg;
7649
David S. Miller9360ffd2012-03-29 04:41:26 -04007650 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7651 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007652
7653 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007654
7655 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007656
7657 nla_put_failure:
7658 err = -ENOBUFS;
7659 free_msg:
7660 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007661 return err;
7662}
7663
7664static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7665 struct genl_info *info)
7666{
Johannes Berg4c476992010-10-04 21:36:35 +02007667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007668 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007669 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007670
7671 if (!info->attrs[NL80211_ATTR_COOKIE])
7672 return -EINVAL;
7673
Johannes Berg4c476992010-10-04 21:36:35 +02007674 if (!rdev->ops->cancel_remain_on_channel)
7675 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007676
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007677 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7678
Hila Gonene35e4d22012-06-27 17:19:42 +03007679 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007680}
7681
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007682static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7683 u8 *rates, u8 rates_len)
7684{
7685 u8 i;
7686 u32 mask = 0;
7687
7688 for (i = 0; i < rates_len; i++) {
7689 int rate = (rates[i] & 0x7f) * 5;
7690 int ridx;
7691 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7692 struct ieee80211_rate *srate =
7693 &sband->bitrates[ridx];
7694 if (rate == srate->bitrate) {
7695 mask |= 1 << ridx;
7696 break;
7697 }
7698 }
7699 if (ridx == sband->n_bitrates)
7700 return 0; /* rate not found */
7701 }
7702
7703 return mask;
7704}
7705
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007706static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7707 u8 *rates, u8 rates_len,
7708 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7709{
7710 u8 i;
7711
7712 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7713
7714 for (i = 0; i < rates_len; i++) {
7715 int ridx, rbit;
7716
7717 ridx = rates[i] / 8;
7718 rbit = BIT(rates[i] % 8);
7719
7720 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007721 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007722 return false;
7723
7724 /* check availability */
7725 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7726 mcs[ridx] |= rbit;
7727 else
7728 return false;
7729 }
7730
7731 return true;
7732}
7733
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007734static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7735{
7736 u16 mcs_mask = 0;
7737
7738 switch (vht_mcs_map) {
7739 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7740 break;
7741 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7742 mcs_mask = 0x00FF;
7743 break;
7744 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7745 mcs_mask = 0x01FF;
7746 break;
7747 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7748 mcs_mask = 0x03FF;
7749 break;
7750 default:
7751 break;
7752 }
7753
7754 return mcs_mask;
7755}
7756
7757static void vht_build_mcs_mask(u16 vht_mcs_map,
7758 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7759{
7760 u8 nss;
7761
7762 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7763 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7764 vht_mcs_map >>= 2;
7765 }
7766}
7767
7768static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7769 struct nl80211_txrate_vht *txrate,
7770 u16 mcs[NL80211_VHT_NSS_MAX])
7771{
7772 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7773 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7774 u8 i;
7775
7776 if (!sband->vht_cap.vht_supported)
7777 return false;
7778
7779 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7780
7781 /* Build vht_mcs_mask from VHT capabilities */
7782 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7783
7784 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7785 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7786 mcs[i] = txrate->mcs[i];
7787 else
7788 return false;
7789 }
7790
7791 return true;
7792}
7793
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007794static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007795 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7796 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007797 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7798 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007799 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007800 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007801};
7802
7803static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7804 struct genl_info *info)
7805{
7806 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007808 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007809 int rem, i;
7810 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007811 struct nlattr *tx_rates;
7812 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007813 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007814
Johannes Berg4c476992010-10-04 21:36:35 +02007815 if (!rdev->ops->set_bitrate_mask)
7816 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007817
7818 memset(&mask, 0, sizeof(mask));
7819 /* Default to all rates enabled */
7820 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7821 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007822
7823 if (!sband)
7824 continue;
7825
7826 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007827 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007828 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007829 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007830
7831 if (!sband->vht_cap.vht_supported)
7832 continue;
7833
7834 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7835 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007836 }
7837
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007838 /* if no rates are given set it back to the defaults */
7839 if (!info->attrs[NL80211_ATTR_TX_RATES])
7840 goto out;
7841
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007842 /*
7843 * The nested attribute uses enum nl80211_band as the index. This maps
7844 * directly to the enum ieee80211_band values used in cfg80211.
7845 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007846 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007847 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007848 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007849 int err;
7850
Johannes Berg4c476992010-10-04 21:36:35 +02007851 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7852 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007853 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007854 if (sband == NULL)
7855 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007856 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7857 nla_len(tx_rates), nl80211_txattr_policy);
7858 if (err)
7859 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007860 if (tb[NL80211_TXRATE_LEGACY]) {
7861 mask.control[band].legacy = rateset_to_mask(
7862 sband,
7863 nla_data(tb[NL80211_TXRATE_LEGACY]),
7864 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307865 if ((mask.control[band].legacy == 0) &&
7866 nla_len(tb[NL80211_TXRATE_LEGACY]))
7867 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007868 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007869 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007870 if (!ht_rateset_to_mask(
7871 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007872 nla_data(tb[NL80211_TXRATE_HT]),
7873 nla_len(tb[NL80211_TXRATE_HT]),
7874 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007875 return -EINVAL;
7876 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007877 if (tb[NL80211_TXRATE_VHT]) {
7878 if (!vht_set_mcs_mask(
7879 sband,
7880 nla_data(tb[NL80211_TXRATE_VHT]),
7881 mask.control[band].vht_mcs))
7882 return -EINVAL;
7883 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007884 if (tb[NL80211_TXRATE_GI]) {
7885 mask.control[band].gi =
7886 nla_get_u8(tb[NL80211_TXRATE_GI]);
7887 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7888 return -EINVAL;
7889 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007890
7891 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007892 /* don't allow empty legacy rates if HT or VHT
7893 * are not even supported.
7894 */
7895 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7896 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007897 return -EINVAL;
7898
7899 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007900 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007901 goto out;
7902
7903 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7904 if (mask.control[band].vht_mcs[i])
7905 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007906
7907 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007908 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007909 }
7910 }
7911
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007912out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007913 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007914}
7915
Johannes Berg2e161f782010-08-12 15:38:38 +02007916static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007917{
Johannes Berg4c476992010-10-04 21:36:35 +02007918 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007919 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02007920 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007921
7922 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7923 return -EINVAL;
7924
Johannes Berg2e161f782010-08-12 15:38:38 +02007925 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7926 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007927
Johannes Berg71bbc992012-06-15 15:30:18 +02007928 switch (wdev->iftype) {
7929 case NL80211_IFTYPE_STATION:
7930 case NL80211_IFTYPE_ADHOC:
7931 case NL80211_IFTYPE_P2P_CLIENT:
7932 case NL80211_IFTYPE_AP:
7933 case NL80211_IFTYPE_AP_VLAN:
7934 case NL80211_IFTYPE_MESH_POINT:
7935 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007936 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007937 break;
7938 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007939 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007940 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007941
7942 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007943 if (!rdev->ops->mgmt_tx)
7944 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007945
Eric W. Biederman15e47302012-09-07 20:12:54 +00007946 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007947 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7948 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007949}
7950
Johannes Berg2e161f782010-08-12 15:38:38 +02007951static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007952{
Johannes Berg4c476992010-10-04 21:36:35 +02007953 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007954 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007955 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007956 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007957 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007958 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007959 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007960 struct cfg80211_mgmt_tx_params params = {
7961 .dont_wait_for_ack =
7962 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7963 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007964
Johannes Berg683b6d32012-11-08 21:25:48 +01007965 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007966 return -EINVAL;
7967
Johannes Berg4c476992010-10-04 21:36:35 +02007968 if (!rdev->ops->mgmt_tx)
7969 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007970
Johannes Berg71bbc992012-06-15 15:30:18 +02007971 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007972 case NL80211_IFTYPE_P2P_DEVICE:
7973 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7974 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007975 case NL80211_IFTYPE_STATION:
7976 case NL80211_IFTYPE_ADHOC:
7977 case NL80211_IFTYPE_P2P_CLIENT:
7978 case NL80211_IFTYPE_AP:
7979 case NL80211_IFTYPE_AP_VLAN:
7980 case NL80211_IFTYPE_MESH_POINT:
7981 case NL80211_IFTYPE_P2P_GO:
7982 break;
7983 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007984 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007985 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007986
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007987 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007988 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007989 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007990 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007991
7992 /*
7993 * We should wait on the channel for at least a minimum amount
7994 * of time (10ms) but no longer than the driver supports.
7995 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007996 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7997 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007998 return -EINVAL;
7999
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008000 }
8001
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008002 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008003
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008004 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008005 return -EINVAL;
8006
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008007 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308008
Antonio Quartulliea141b752013-06-11 14:20:03 +02008009 /* get the channel if any has been specified, otherwise pass NULL to
8010 * the driver. The latter will use the current one
8011 */
8012 chandef.chan = NULL;
8013 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8014 err = nl80211_parse_chandef(rdev, info, &chandef);
8015 if (err)
8016 return err;
8017 }
8018
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008019 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008020 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008021
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008022 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8023 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8024
8025 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8026 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8027 int i;
8028
8029 if (len % sizeof(u16))
8030 return -EINVAL;
8031
8032 params.n_csa_offsets = len / sizeof(u16);
8033 params.csa_offsets =
8034 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8035
8036 /* check that all the offsets fit the frame */
8037 for (i = 0; i < params.n_csa_offsets; i++) {
8038 if (params.csa_offsets[i] >= params.len)
8039 return -EINVAL;
8040 }
8041 }
8042
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008043 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008044 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8045 if (!msg)
8046 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008047
Eric W. Biederman15e47302012-09-07 20:12:54 +00008048 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008049 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008050 if (!hdr) {
8051 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008052 goto free_msg;
8053 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008054 }
Johannes Berge247bd902011-11-04 11:18:21 +01008055
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008056 params.chan = chandef.chan;
8057 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008058 if (err)
8059 goto free_msg;
8060
Johannes Berge247bd902011-11-04 11:18:21 +01008061 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008062 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8063 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008064
Johannes Berge247bd902011-11-04 11:18:21 +01008065 genlmsg_end(msg, hdr);
8066 return genlmsg_reply(msg, info);
8067 }
8068
8069 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008070
8071 nla_put_failure:
8072 err = -ENOBUFS;
8073 free_msg:
8074 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008075 return err;
8076}
8077
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008078static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8079{
8080 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008081 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008082 u64 cookie;
8083
8084 if (!info->attrs[NL80211_ATTR_COOKIE])
8085 return -EINVAL;
8086
8087 if (!rdev->ops->mgmt_tx_cancel_wait)
8088 return -EOPNOTSUPP;
8089
Johannes Berg71bbc992012-06-15 15:30:18 +02008090 switch (wdev->iftype) {
8091 case NL80211_IFTYPE_STATION:
8092 case NL80211_IFTYPE_ADHOC:
8093 case NL80211_IFTYPE_P2P_CLIENT:
8094 case NL80211_IFTYPE_AP:
8095 case NL80211_IFTYPE_AP_VLAN:
8096 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008097 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008098 break;
8099 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008100 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008101 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008102
8103 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8104
Hila Gonene35e4d22012-06-27 17:19:42 +03008105 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008106}
8107
Kalle Valoffb9eb32010-02-17 17:58:10 +02008108static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8109{
Johannes Berg4c476992010-10-04 21:36:35 +02008110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008111 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008112 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008113 u8 ps_state;
8114 bool state;
8115 int err;
8116
Johannes Berg4c476992010-10-04 21:36:35 +02008117 if (!info->attrs[NL80211_ATTR_PS_STATE])
8118 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008119
8120 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8121
Johannes Berg4c476992010-10-04 21:36:35 +02008122 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8123 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008124
8125 wdev = dev->ieee80211_ptr;
8126
Johannes Berg4c476992010-10-04 21:36:35 +02008127 if (!rdev->ops->set_power_mgmt)
8128 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008129
8130 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8131
8132 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008133 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008134
Hila Gonene35e4d22012-06-27 17:19:42 +03008135 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008136 if (!err)
8137 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008138 return err;
8139}
8140
8141static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8142{
Johannes Berg4c476992010-10-04 21:36:35 +02008143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008144 enum nl80211_ps_state ps_state;
8145 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008146 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008147 struct sk_buff *msg;
8148 void *hdr;
8149 int err;
8150
Kalle Valoffb9eb32010-02-17 17:58:10 +02008151 wdev = dev->ieee80211_ptr;
8152
Johannes Berg4c476992010-10-04 21:36:35 +02008153 if (!rdev->ops->set_power_mgmt)
8154 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008155
8156 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008157 if (!msg)
8158 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008159
Eric W. Biederman15e47302012-09-07 20:12:54 +00008160 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008161 NL80211_CMD_GET_POWER_SAVE);
8162 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008163 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008164 goto free_msg;
8165 }
8166
8167 if (wdev->ps)
8168 ps_state = NL80211_PS_ENABLED;
8169 else
8170 ps_state = NL80211_PS_DISABLED;
8171
David S. Miller9360ffd2012-03-29 04:41:26 -04008172 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8173 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008174
8175 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008176 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008177
Johannes Berg4c476992010-10-04 21:36:35 +02008178 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008179 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008180 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008181 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008182 return err;
8183}
8184
Johannes Berg94e860f2014-01-20 23:58:15 +01008185static const struct nla_policy
8186nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008187 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8188 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8189 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008190 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8191 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8192 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008193};
8194
Thomas Pedersen84f10702012-07-12 16:17:33 -07008195static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008196 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008197{
8198 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008199 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008200 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008201
Johannes Bergd9d8b012012-11-26 12:51:52 +01008202 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008203 return -EINVAL;
8204
Thomas Pedersen84f10702012-07-12 16:17:33 -07008205 if (!rdev->ops->set_cqm_txe_config)
8206 return -EOPNOTSUPP;
8207
8208 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8209 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8210 return -EOPNOTSUPP;
8211
Hila Gonene35e4d22012-06-27 17:19:42 +03008212 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008213}
8214
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008215static int nl80211_set_cqm_rssi(struct genl_info *info,
8216 s32 threshold, u32 hysteresis)
8217{
Johannes Berg4c476992010-10-04 21:36:35 +02008218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008219 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008220 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008221
8222 if (threshold > 0)
8223 return -EINVAL;
8224
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008225 /* disabling - hysteresis should also be zero then */
8226 if (threshold == 0)
8227 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008228
Johannes Berg4c476992010-10-04 21:36:35 +02008229 if (!rdev->ops->set_cqm_rssi_config)
8230 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008231
Johannes Berg074ac8d2010-09-16 14:58:22 +02008232 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008233 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8234 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008235
Hila Gonene35e4d22012-06-27 17:19:42 +03008236 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008237}
8238
8239static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8240{
8241 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8242 struct nlattr *cqm;
8243 int err;
8244
8245 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008246 if (!cqm)
8247 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008248
8249 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8250 nl80211_attr_cqm_policy);
8251 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008252 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008253
8254 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8255 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008256 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8257 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008258
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008259 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8260 }
8261
8262 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8263 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8264 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8265 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8266 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8267 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8268
8269 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8270 }
8271
8272 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008273}
8274
Johannes Berg29cbe682010-12-03 09:20:44 +01008275static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8276{
8277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8278 struct net_device *dev = info->user_ptr[1];
8279 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008280 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008281 int err;
8282
8283 /* start with default */
8284 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008285 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008286
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008287 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008288 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008289 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008290 if (err)
8291 return err;
8292 }
8293
8294 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8295 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8296 return -EINVAL;
8297
Javier Cardonac80d5452010-12-16 17:37:49 -08008298 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8299 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8300
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008301 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8302 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8303 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8304 return -EINVAL;
8305
Marco Porsch9bdbf042013-01-07 16:04:51 +01008306 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8307 setup.beacon_interval =
8308 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8309 if (setup.beacon_interval < 10 ||
8310 setup.beacon_interval > 10000)
8311 return -EINVAL;
8312 }
8313
8314 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8315 setup.dtim_period =
8316 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8317 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8318 return -EINVAL;
8319 }
8320
Javier Cardonac80d5452010-12-16 17:37:49 -08008321 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8322 /* parse additional setup parameters if given */
8323 err = nl80211_parse_mesh_setup(info, &setup);
8324 if (err)
8325 return err;
8326 }
8327
Thomas Pedersend37bb182013-03-04 13:06:13 -08008328 if (setup.user_mpm)
8329 cfg.auto_open_plinks = false;
8330
Johannes Bergcc1d2802012-05-16 23:50:20 +02008331 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008332 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8333 if (err)
8334 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008335 } else {
8336 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008337 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008338 }
8339
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008340 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8341 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8342 int n_rates =
8343 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8344 struct ieee80211_supported_band *sband;
8345
8346 if (!setup.chandef.chan)
8347 return -EINVAL;
8348
8349 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8350
8351 err = ieee80211_get_ratemask(sband, rates, n_rates,
8352 &setup.basic_rates);
8353 if (err)
8354 return err;
8355 }
8356
Javier Cardonac80d5452010-12-16 17:37:49 -08008357 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008358}
8359
8360static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8361{
8362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8363 struct net_device *dev = info->user_ptr[1];
8364
8365 return cfg80211_leave_mesh(rdev, dev);
8366}
8367
Johannes Bergdfb89c52012-06-27 09:23:48 +02008368#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008369static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8370 struct cfg80211_registered_device *rdev)
8371{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008372 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008373 struct nlattr *nl_pats, *nl_pat;
8374 int i, pat_len;
8375
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008376 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008377 return 0;
8378
8379 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8380 if (!nl_pats)
8381 return -ENOBUFS;
8382
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008383 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008384 nl_pat = nla_nest_start(msg, i + 1);
8385 if (!nl_pat)
8386 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008387 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008388 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008389 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008390 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8391 wowlan->patterns[i].pattern) ||
8392 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008393 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008394 return -ENOBUFS;
8395 nla_nest_end(msg, nl_pat);
8396 }
8397 nla_nest_end(msg, nl_pats);
8398
8399 return 0;
8400}
8401
Johannes Berg2a0e0472013-01-23 22:57:40 +01008402static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8403 struct cfg80211_wowlan_tcp *tcp)
8404{
8405 struct nlattr *nl_tcp;
8406
8407 if (!tcp)
8408 return 0;
8409
8410 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8411 if (!nl_tcp)
8412 return -ENOBUFS;
8413
8414 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8415 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8416 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8417 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8418 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8419 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8420 tcp->payload_len, tcp->payload) ||
8421 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8422 tcp->data_interval) ||
8423 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8424 tcp->wake_len, tcp->wake_data) ||
8425 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8426 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8427 return -ENOBUFS;
8428
8429 if (tcp->payload_seq.len &&
8430 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8431 sizeof(tcp->payload_seq), &tcp->payload_seq))
8432 return -ENOBUFS;
8433
8434 if (tcp->payload_tok.len &&
8435 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8436 sizeof(tcp->payload_tok) + tcp->tokens_size,
8437 &tcp->payload_tok))
8438 return -ENOBUFS;
8439
Johannes Berge248ad32013-05-16 10:24:28 +02008440 nla_nest_end(msg, nl_tcp);
8441
Johannes Berg2a0e0472013-01-23 22:57:40 +01008442 return 0;
8443}
8444
Johannes Bergff1b6e62011-05-04 15:37:28 +02008445static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8446{
8447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8448 struct sk_buff *msg;
8449 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008450 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008451
Johannes Berg964dc9e2013-06-03 17:25:34 +02008452 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008453 return -EOPNOTSUPP;
8454
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008455 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008456 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008457 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8458 rdev->wiphy.wowlan_config->tcp->payload_len +
8459 rdev->wiphy.wowlan_config->tcp->wake_len +
8460 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008461 }
8462
8463 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008464 if (!msg)
8465 return -ENOMEM;
8466
Eric W. Biederman15e47302012-09-07 20:12:54 +00008467 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008468 NL80211_CMD_GET_WOWLAN);
8469 if (!hdr)
8470 goto nla_put_failure;
8471
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008472 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008473 struct nlattr *nl_wowlan;
8474
8475 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8476 if (!nl_wowlan)
8477 goto nla_put_failure;
8478
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008479 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008480 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008481 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008482 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008483 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008484 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008485 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008486 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008487 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008488 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008489 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008490 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008491 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008492 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8493 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008494
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008495 if (nl80211_send_wowlan_patterns(msg, rdev))
8496 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008497
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008498 if (nl80211_send_wowlan_tcp(msg,
8499 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008500 goto nla_put_failure;
8501
Johannes Bergff1b6e62011-05-04 15:37:28 +02008502 nla_nest_end(msg, nl_wowlan);
8503 }
8504
8505 genlmsg_end(msg, hdr);
8506 return genlmsg_reply(msg, info);
8507
8508nla_put_failure:
8509 nlmsg_free(msg);
8510 return -ENOBUFS;
8511}
8512
Johannes Berg2a0e0472013-01-23 22:57:40 +01008513static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8514 struct nlattr *attr,
8515 struct cfg80211_wowlan *trig)
8516{
8517 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8518 struct cfg80211_wowlan_tcp *cfg;
8519 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8520 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8521 u32 size;
8522 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8523 int err, port;
8524
Johannes Berg964dc9e2013-06-03 17:25:34 +02008525 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008526 return -EINVAL;
8527
8528 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8529 nla_data(attr), nla_len(attr),
8530 nl80211_wowlan_tcp_policy);
8531 if (err)
8532 return err;
8533
8534 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8535 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8536 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8537 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8538 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8539 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8540 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8541 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8542 return -EINVAL;
8543
8544 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008545 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008546 return -EINVAL;
8547
8548 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008549 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008550 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008551 return -EINVAL;
8552
8553 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008554 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008555 return -EINVAL;
8556
8557 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8558 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8559 return -EINVAL;
8560
8561 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8562 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8563
8564 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8565 tokens_size = tokln - sizeof(*tok);
8566
8567 if (!tok->len || tokens_size % tok->len)
8568 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008569 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008570 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008571 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008572 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008573 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008574 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008575 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008576 return -EINVAL;
8577 if (tok->offset + tok->len > data_size)
8578 return -EINVAL;
8579 }
8580
8581 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8582 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008583 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008584 return -EINVAL;
8585 if (seq->len == 0 || seq->len > 4)
8586 return -EINVAL;
8587 if (seq->len + seq->offset > data_size)
8588 return -EINVAL;
8589 }
8590
8591 size = sizeof(*cfg);
8592 size += data_size;
8593 size += wake_size + wake_mask_size;
8594 size += tokens_size;
8595
8596 cfg = kzalloc(size, GFP_KERNEL);
8597 if (!cfg)
8598 return -ENOMEM;
8599 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8600 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8601 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8602 ETH_ALEN);
8603 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8604 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8605 else
8606 port = 0;
8607#ifdef CONFIG_INET
8608 /* allocate a socket and port for it and use it */
8609 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8610 IPPROTO_TCP, &cfg->sock, 1);
8611 if (err) {
8612 kfree(cfg);
8613 return err;
8614 }
8615 if (inet_csk_get_port(cfg->sock->sk, port)) {
8616 sock_release(cfg->sock);
8617 kfree(cfg);
8618 return -EADDRINUSE;
8619 }
8620 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8621#else
8622 if (!port) {
8623 kfree(cfg);
8624 return -EINVAL;
8625 }
8626 cfg->src_port = port;
8627#endif
8628
8629 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8630 cfg->payload_len = data_size;
8631 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8632 memcpy((void *)cfg->payload,
8633 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8634 data_size);
8635 if (seq)
8636 cfg->payload_seq = *seq;
8637 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8638 cfg->wake_len = wake_size;
8639 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8640 memcpy((void *)cfg->wake_data,
8641 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8642 wake_size);
8643 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8644 data_size + wake_size;
8645 memcpy((void *)cfg->wake_mask,
8646 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8647 wake_mask_size);
8648 if (tok) {
8649 cfg->tokens_size = tokens_size;
8650 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8651 }
8652
8653 trig->tcp = cfg;
8654
8655 return 0;
8656}
8657
Johannes Bergff1b6e62011-05-04 15:37:28 +02008658static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8659{
8660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8661 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008662 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008663 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008664 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008665 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008666 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008667
Johannes Berg964dc9e2013-06-03 17:25:34 +02008668 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008669 return -EOPNOTSUPP;
8670
Johannes Bergae33bd82012-07-12 16:25:02 +02008671 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8672 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008673 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008674 goto set_wakeup;
8675 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008676
8677 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8678 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8679 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8680 nl80211_wowlan_policy);
8681 if (err)
8682 return err;
8683
8684 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8685 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8686 return -EINVAL;
8687 new_triggers.any = true;
8688 }
8689
8690 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8691 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8692 return -EINVAL;
8693 new_triggers.disconnect = true;
8694 }
8695
8696 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8697 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8698 return -EINVAL;
8699 new_triggers.magic_pkt = true;
8700 }
8701
Johannes Berg77dbbb12011-07-13 10:48:55 +02008702 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8703 return -EINVAL;
8704
8705 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8706 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8707 return -EINVAL;
8708 new_triggers.gtk_rekey_failure = true;
8709 }
8710
8711 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8712 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8713 return -EINVAL;
8714 new_triggers.eap_identity_req = true;
8715 }
8716
8717 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8718 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8719 return -EINVAL;
8720 new_triggers.four_way_handshake = true;
8721 }
8722
8723 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8724 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8725 return -EINVAL;
8726 new_triggers.rfkill_release = true;
8727 }
8728
Johannes Bergff1b6e62011-05-04 15:37:28 +02008729 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8730 struct nlattr *pat;
8731 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008732 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008733 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008734
8735 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8736 rem)
8737 n_patterns++;
8738 if (n_patterns > wowlan->n_patterns)
8739 return -EINVAL;
8740
8741 new_triggers.patterns = kcalloc(n_patterns,
8742 sizeof(new_triggers.patterns[0]),
8743 GFP_KERNEL);
8744 if (!new_triggers.patterns)
8745 return -ENOMEM;
8746
8747 new_triggers.n_patterns = n_patterns;
8748 i = 0;
8749
8750 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8751 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008752 u8 *mask_pat;
8753
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008754 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8755 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008756 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008757 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8758 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008759 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008760 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008761 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008762 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008763 goto error;
8764 if (pat_len > wowlan->pattern_max_len ||
8765 pat_len < wowlan->pattern_min_len)
8766 goto error;
8767
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008768 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008769 pkt_offset = 0;
8770 else
8771 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008772 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008773 if (pkt_offset > wowlan->max_pkt_offset)
8774 goto error;
8775 new_triggers.patterns[i].pkt_offset = pkt_offset;
8776
Johannes Berg922bd802014-05-19 17:59:50 +02008777 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8778 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008779 err = -ENOMEM;
8780 goto error;
8781 }
Johannes Berg922bd802014-05-19 17:59:50 +02008782 new_triggers.patterns[i].mask = mask_pat;
8783 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008784 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008785 mask_pat += mask_len;
8786 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008787 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008788 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008789 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008790 pat_len);
8791 i++;
8792 }
8793 }
8794
Johannes Berg2a0e0472013-01-23 22:57:40 +01008795 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8796 err = nl80211_parse_wowlan_tcp(
8797 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8798 &new_triggers);
8799 if (err)
8800 goto error;
8801 }
8802
Johannes Bergae33bd82012-07-12 16:25:02 +02008803 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8804 if (!ntrig) {
8805 err = -ENOMEM;
8806 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008807 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008808 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008809 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008810
Johannes Bergae33bd82012-07-12 16:25:02 +02008811 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008812 if (rdev->ops->set_wakeup &&
8813 prev_enabled != !!rdev->wiphy.wowlan_config)
8814 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008815
Johannes Bergff1b6e62011-05-04 15:37:28 +02008816 return 0;
8817 error:
8818 for (i = 0; i < new_triggers.n_patterns; i++)
8819 kfree(new_triggers.patterns[i].mask);
8820 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008821 if (new_triggers.tcp && new_triggers.tcp->sock)
8822 sock_release(new_triggers.tcp->sock);
8823 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008824 return err;
8825}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008826#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008827
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07008828static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8829 struct cfg80211_registered_device *rdev)
8830{
8831 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8832 int i, j, pat_len;
8833 struct cfg80211_coalesce_rules *rule;
8834
8835 if (!rdev->coalesce->n_rules)
8836 return 0;
8837
8838 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8839 if (!nl_rules)
8840 return -ENOBUFS;
8841
8842 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8843 nl_rule = nla_nest_start(msg, i + 1);
8844 if (!nl_rule)
8845 return -ENOBUFS;
8846
8847 rule = &rdev->coalesce->rules[i];
8848 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8849 rule->delay))
8850 return -ENOBUFS;
8851
8852 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8853 rule->condition))
8854 return -ENOBUFS;
8855
8856 nl_pats = nla_nest_start(msg,
8857 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8858 if (!nl_pats)
8859 return -ENOBUFS;
8860
8861 for (j = 0; j < rule->n_patterns; j++) {
8862 nl_pat = nla_nest_start(msg, j + 1);
8863 if (!nl_pat)
8864 return -ENOBUFS;
8865 pat_len = rule->patterns[j].pattern_len;
8866 if (nla_put(msg, NL80211_PKTPAT_MASK,
8867 DIV_ROUND_UP(pat_len, 8),
8868 rule->patterns[j].mask) ||
8869 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8870 rule->patterns[j].pattern) ||
8871 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8872 rule->patterns[j].pkt_offset))
8873 return -ENOBUFS;
8874 nla_nest_end(msg, nl_pat);
8875 }
8876 nla_nest_end(msg, nl_pats);
8877 nla_nest_end(msg, nl_rule);
8878 }
8879 nla_nest_end(msg, nl_rules);
8880
8881 return 0;
8882}
8883
8884static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8885{
8886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8887 struct sk_buff *msg;
8888 void *hdr;
8889
8890 if (!rdev->wiphy.coalesce)
8891 return -EOPNOTSUPP;
8892
8893 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8894 if (!msg)
8895 return -ENOMEM;
8896
8897 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8898 NL80211_CMD_GET_COALESCE);
8899 if (!hdr)
8900 goto nla_put_failure;
8901
8902 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8903 goto nla_put_failure;
8904
8905 genlmsg_end(msg, hdr);
8906 return genlmsg_reply(msg, info);
8907
8908nla_put_failure:
8909 nlmsg_free(msg);
8910 return -ENOBUFS;
8911}
8912
8913void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8914{
8915 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8916 int i, j;
8917 struct cfg80211_coalesce_rules *rule;
8918
8919 if (!coalesce)
8920 return;
8921
8922 for (i = 0; i < coalesce->n_rules; i++) {
8923 rule = &coalesce->rules[i];
8924 for (j = 0; j < rule->n_patterns; j++)
8925 kfree(rule->patterns[j].mask);
8926 kfree(rule->patterns);
8927 }
8928 kfree(coalesce->rules);
8929 kfree(coalesce);
8930 rdev->coalesce = NULL;
8931}
8932
8933static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8934 struct nlattr *rule,
8935 struct cfg80211_coalesce_rules *new_rule)
8936{
8937 int err, i;
8938 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8939 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8940 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8941 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8942
8943 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8944 nla_len(rule), nl80211_coalesce_policy);
8945 if (err)
8946 return err;
8947
8948 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8949 new_rule->delay =
8950 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8951 if (new_rule->delay > coalesce->max_delay)
8952 return -EINVAL;
8953
8954 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8955 new_rule->condition =
8956 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8957 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8958 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8959 return -EINVAL;
8960
8961 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8962 return -EINVAL;
8963
8964 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8965 rem)
8966 n_patterns++;
8967 if (n_patterns > coalesce->n_patterns)
8968 return -EINVAL;
8969
8970 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8971 GFP_KERNEL);
8972 if (!new_rule->patterns)
8973 return -ENOMEM;
8974
8975 new_rule->n_patterns = n_patterns;
8976 i = 0;
8977
8978 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8979 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008980 u8 *mask_pat;
8981
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07008982 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8983 nla_len(pat), NULL);
8984 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8985 !pat_tb[NL80211_PKTPAT_PATTERN])
8986 return -EINVAL;
8987 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8988 mask_len = DIV_ROUND_UP(pat_len, 8);
8989 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8990 return -EINVAL;
8991 if (pat_len > coalesce->pattern_max_len ||
8992 pat_len < coalesce->pattern_min_len)
8993 return -EINVAL;
8994
8995 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8996 pkt_offset = 0;
8997 else
8998 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8999 if (pkt_offset > coalesce->max_pkt_offset)
9000 return -EINVAL;
9001 new_rule->patterns[i].pkt_offset = pkt_offset;
9002
Johannes Berg922bd802014-05-19 17:59:50 +02009003 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9004 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009005 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009006
9007 new_rule->patterns[i].mask = mask_pat;
9008 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9009 mask_len);
9010
9011 mask_pat += mask_len;
9012 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009013 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009014 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9015 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009016 i++;
9017 }
9018
9019 return 0;
9020}
9021
9022static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9023{
9024 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9025 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9026 struct cfg80211_coalesce new_coalesce = {};
9027 struct cfg80211_coalesce *n_coalesce;
9028 int err, rem_rule, n_rules = 0, i, j;
9029 struct nlattr *rule;
9030 struct cfg80211_coalesce_rules *tmp_rule;
9031
9032 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9033 return -EOPNOTSUPP;
9034
9035 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9036 cfg80211_rdev_free_coalesce(rdev);
9037 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9038 return 0;
9039 }
9040
9041 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9042 rem_rule)
9043 n_rules++;
9044 if (n_rules > coalesce->n_rules)
9045 return -EINVAL;
9046
9047 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9048 GFP_KERNEL);
9049 if (!new_coalesce.rules)
9050 return -ENOMEM;
9051
9052 new_coalesce.n_rules = n_rules;
9053 i = 0;
9054
9055 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9056 rem_rule) {
9057 err = nl80211_parse_coalesce_rule(rdev, rule,
9058 &new_coalesce.rules[i]);
9059 if (err)
9060 goto error;
9061
9062 i++;
9063 }
9064
9065 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9066 if (err)
9067 goto error;
9068
9069 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9070 if (!n_coalesce) {
9071 err = -ENOMEM;
9072 goto error;
9073 }
9074 cfg80211_rdev_free_coalesce(rdev);
9075 rdev->coalesce = n_coalesce;
9076
9077 return 0;
9078error:
9079 for (i = 0; i < new_coalesce.n_rules; i++) {
9080 tmp_rule = &new_coalesce.rules[i];
9081 for (j = 0; j < tmp_rule->n_patterns; j++)
9082 kfree(tmp_rule->patterns[j].mask);
9083 kfree(tmp_rule->patterns);
9084 }
9085 kfree(new_coalesce.rules);
9086
9087 return err;
9088}
9089
Johannes Berge5497d72011-07-05 16:35:40 +02009090static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9091{
9092 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9093 struct net_device *dev = info->user_ptr[1];
9094 struct wireless_dev *wdev = dev->ieee80211_ptr;
9095 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9096 struct cfg80211_gtk_rekey_data rekey_data;
9097 int err;
9098
9099 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9100 return -EINVAL;
9101
9102 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9103 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9104 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9105 nl80211_rekey_policy);
9106 if (err)
9107 return err;
9108
9109 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9110 return -ERANGE;
9111 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9112 return -ERANGE;
9113 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9114 return -ERANGE;
9115
Johannes Berg78f686c2014-09-10 22:28:06 +03009116 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9117 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9118 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009119
9120 wdev_lock(wdev);
9121 if (!wdev->current_bss) {
9122 err = -ENOTCONN;
9123 goto out;
9124 }
9125
9126 if (!rdev->ops->set_rekey_data) {
9127 err = -EOPNOTSUPP;
9128 goto out;
9129 }
9130
Hila Gonene35e4d22012-06-27 17:19:42 +03009131 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009132 out:
9133 wdev_unlock(wdev);
9134 return err;
9135}
9136
Johannes Berg28946da2011-11-04 11:18:12 +01009137static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9138 struct genl_info *info)
9139{
9140 struct net_device *dev = info->user_ptr[1];
9141 struct wireless_dev *wdev = dev->ieee80211_ptr;
9142
9143 if (wdev->iftype != NL80211_IFTYPE_AP &&
9144 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9145 return -EINVAL;
9146
Eric W. Biederman15e47302012-09-07 20:12:54 +00009147 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009148 return -EBUSY;
9149
Eric W. Biederman15e47302012-09-07 20:12:54 +00009150 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009151 return 0;
9152}
9153
Johannes Berg7f6cf312011-11-04 11:18:15 +01009154static int nl80211_probe_client(struct sk_buff *skb,
9155 struct genl_info *info)
9156{
9157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9158 struct net_device *dev = info->user_ptr[1];
9159 struct wireless_dev *wdev = dev->ieee80211_ptr;
9160 struct sk_buff *msg;
9161 void *hdr;
9162 const u8 *addr;
9163 u64 cookie;
9164 int err;
9165
9166 if (wdev->iftype != NL80211_IFTYPE_AP &&
9167 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9168 return -EOPNOTSUPP;
9169
9170 if (!info->attrs[NL80211_ATTR_MAC])
9171 return -EINVAL;
9172
9173 if (!rdev->ops->probe_client)
9174 return -EOPNOTSUPP;
9175
9176 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9177 if (!msg)
9178 return -ENOMEM;
9179
Eric W. Biederman15e47302012-09-07 20:12:54 +00009180 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009181 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009182 if (!hdr) {
9183 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009184 goto free_msg;
9185 }
9186
9187 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9188
Hila Gonene35e4d22012-06-27 17:19:42 +03009189 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009190 if (err)
9191 goto free_msg;
9192
David S. Miller9360ffd2012-03-29 04:41:26 -04009193 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9194 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009195
9196 genlmsg_end(msg, hdr);
9197
9198 return genlmsg_reply(msg, info);
9199
9200 nla_put_failure:
9201 err = -ENOBUFS;
9202 free_msg:
9203 nlmsg_free(msg);
9204 return err;
9205}
9206
Johannes Berg5e760232011-11-04 11:18:17 +01009207static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9208{
9209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009210 struct cfg80211_beacon_registration *reg, *nreg;
9211 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009212
9213 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9214 return -EOPNOTSUPP;
9215
Ben Greear37c73b52012-10-26 14:49:25 -07009216 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9217 if (!nreg)
9218 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009219
Ben Greear37c73b52012-10-26 14:49:25 -07009220 /* First, check if already registered. */
9221 spin_lock_bh(&rdev->beacon_registrations_lock);
9222 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9223 if (reg->nlportid == info->snd_portid) {
9224 rv = -EALREADY;
9225 goto out_err;
9226 }
9227 }
9228 /* Add it to the list */
9229 nreg->nlportid = info->snd_portid;
9230 list_add(&nreg->list, &rdev->beacon_registrations);
9231
9232 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009233
9234 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009235out_err:
9236 spin_unlock_bh(&rdev->beacon_registrations_lock);
9237 kfree(nreg);
9238 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009239}
9240
Johannes Berg98104fde2012-06-16 00:19:54 +02009241static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9242{
9243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9244 struct wireless_dev *wdev = info->user_ptr[1];
9245 int err;
9246
9247 if (!rdev->ops->start_p2p_device)
9248 return -EOPNOTSUPP;
9249
9250 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9251 return -EOPNOTSUPP;
9252
9253 if (wdev->p2p_started)
9254 return 0;
9255
Luciano Coelhob6a55012014-02-27 11:07:21 +02009256 if (rfkill_blocked(rdev->rfkill))
9257 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009258
Johannes Bergeeb126e2012-10-23 15:16:50 +02009259 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009260 if (err)
9261 return err;
9262
9263 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009264 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009265
9266 return 0;
9267}
9268
9269static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9270{
9271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9272 struct wireless_dev *wdev = info->user_ptr[1];
9273
9274 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9275 return -EOPNOTSUPP;
9276
9277 if (!rdev->ops->stop_p2p_device)
9278 return -EOPNOTSUPP;
9279
Johannes Bergf9f47522013-03-19 15:04:07 +01009280 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009281
9282 return 0;
9283}
9284
Johannes Berg3713b4e2013-02-14 16:19:38 +01009285static int nl80211_get_protocol_features(struct sk_buff *skb,
9286 struct genl_info *info)
9287{
9288 void *hdr;
9289 struct sk_buff *msg;
9290
9291 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9292 if (!msg)
9293 return -ENOMEM;
9294
9295 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9296 NL80211_CMD_GET_PROTOCOL_FEATURES);
9297 if (!hdr)
9298 goto nla_put_failure;
9299
9300 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9301 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9302 goto nla_put_failure;
9303
9304 genlmsg_end(msg, hdr);
9305 return genlmsg_reply(msg, info);
9306
9307 nla_put_failure:
9308 kfree_skb(msg);
9309 return -ENOBUFS;
9310}
9311
Jouni Malinen355199e2013-02-27 17:14:27 +02009312static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9313{
9314 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9315 struct cfg80211_update_ft_ies_params ft_params;
9316 struct net_device *dev = info->user_ptr[1];
9317
9318 if (!rdev->ops->update_ft_ies)
9319 return -EOPNOTSUPP;
9320
9321 if (!info->attrs[NL80211_ATTR_MDID] ||
9322 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9323 return -EINVAL;
9324
9325 memset(&ft_params, 0, sizeof(ft_params));
9326 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9327 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9328 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9329
9330 return rdev_update_ft_ies(rdev, dev, &ft_params);
9331}
9332
Arend van Spriel5de17982013-04-18 15:49:00 +02009333static int nl80211_crit_protocol_start(struct sk_buff *skb,
9334 struct genl_info *info)
9335{
9336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9337 struct wireless_dev *wdev = info->user_ptr[1];
9338 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9339 u16 duration;
9340 int ret;
9341
9342 if (!rdev->ops->crit_proto_start)
9343 return -EOPNOTSUPP;
9344
9345 if (WARN_ON(!rdev->ops->crit_proto_stop))
9346 return -EINVAL;
9347
9348 if (rdev->crit_proto_nlportid)
9349 return -EBUSY;
9350
9351 /* determine protocol if provided */
9352 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9353 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9354
9355 if (proto >= NUM_NL80211_CRIT_PROTO)
9356 return -EINVAL;
9357
9358 /* timeout must be provided */
9359 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9360 return -EINVAL;
9361
9362 duration =
9363 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9364
9365 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9366 return -ERANGE;
9367
9368 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9369 if (!ret)
9370 rdev->crit_proto_nlportid = info->snd_portid;
9371
9372 return ret;
9373}
9374
9375static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9376 struct genl_info *info)
9377{
9378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9379 struct wireless_dev *wdev = info->user_ptr[1];
9380
9381 if (!rdev->ops->crit_proto_stop)
9382 return -EOPNOTSUPP;
9383
9384 if (rdev->crit_proto_nlportid) {
9385 rdev->crit_proto_nlportid = 0;
9386 rdev_crit_proto_stop(rdev, wdev);
9387 }
9388 return 0;
9389}
9390
Johannes Bergad7e7182013-11-13 13:37:47 +01009391static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9392{
9393 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9394 struct wireless_dev *wdev =
9395 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9396 int i, err;
9397 u32 vid, subcmd;
9398
9399 if (!rdev->wiphy.vendor_commands)
9400 return -EOPNOTSUPP;
9401
9402 if (IS_ERR(wdev)) {
9403 err = PTR_ERR(wdev);
9404 if (err != -EINVAL)
9405 return err;
9406 wdev = NULL;
9407 } else if (wdev->wiphy != &rdev->wiphy) {
9408 return -EINVAL;
9409 }
9410
9411 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9412 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9413 return -EINVAL;
9414
9415 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9416 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9417 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9418 const struct wiphy_vendor_command *vcmd;
9419 void *data = NULL;
9420 int len = 0;
9421
9422 vcmd = &rdev->wiphy.vendor_commands[i];
9423
9424 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9425 continue;
9426
9427 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9428 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9429 if (!wdev)
9430 return -EINVAL;
9431 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9432 !wdev->netdev)
9433 return -EINVAL;
9434
9435 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9436 if (wdev->netdev &&
9437 !netif_running(wdev->netdev))
9438 return -ENETDOWN;
9439 if (!wdev->netdev && !wdev->p2p_started)
9440 return -ENETDOWN;
9441 }
9442 } else {
9443 wdev = NULL;
9444 }
9445
9446 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9447 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9448 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9449 }
9450
9451 rdev->cur_cmd_info = info;
9452 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9453 data, len);
9454 rdev->cur_cmd_info = NULL;
9455 return err;
9456 }
9457
9458 return -EOPNOTSUPP;
9459}
9460
9461struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9462 enum nl80211_commands cmd,
9463 enum nl80211_attrs attr,
9464 int approxlen)
9465{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009466 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009467
9468 if (WARN_ON(!rdev->cur_cmd_info))
9469 return NULL;
9470
9471 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9472 rdev->cur_cmd_info->snd_portid,
9473 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009474 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009475}
9476EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9477
9478int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9479{
9480 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9481 void *hdr = ((void **)skb->cb)[1];
9482 struct nlattr *data = ((void **)skb->cb)[2];
9483
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009484 /* clear CB data for netlink core to own from now on */
9485 memset(skb->cb, 0, sizeof(skb->cb));
9486
Johannes Bergad7e7182013-11-13 13:37:47 +01009487 if (WARN_ON(!rdev->cur_cmd_info)) {
9488 kfree_skb(skb);
9489 return -EINVAL;
9490 }
9491
9492 nla_nest_end(skb, data);
9493 genlmsg_end(skb, hdr);
9494 return genlmsg_reply(skb, rdev->cur_cmd_info);
9495}
9496EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9497
9498
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009499static int nl80211_set_qos_map(struct sk_buff *skb,
9500 struct genl_info *info)
9501{
9502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9503 struct cfg80211_qos_map *qos_map = NULL;
9504 struct net_device *dev = info->user_ptr[1];
9505 u8 *pos, len, num_des, des_len, des;
9506 int ret;
9507
9508 if (!rdev->ops->set_qos_map)
9509 return -EOPNOTSUPP;
9510
9511 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9512 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9513 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9514
9515 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9516 len > IEEE80211_QOS_MAP_LEN_MAX)
9517 return -EINVAL;
9518
9519 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9520 if (!qos_map)
9521 return -ENOMEM;
9522
9523 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9524 if (num_des) {
9525 des_len = num_des *
9526 sizeof(struct cfg80211_dscp_exception);
9527 memcpy(qos_map->dscp_exception, pos, des_len);
9528 qos_map->num_des = num_des;
9529 for (des = 0; des < num_des; des++) {
9530 if (qos_map->dscp_exception[des].up > 7) {
9531 kfree(qos_map);
9532 return -EINVAL;
9533 }
9534 }
9535 pos += des_len;
9536 }
9537 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9538 }
9539
9540 wdev_lock(dev->ieee80211_ptr);
9541 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9542 if (!ret)
9543 ret = rdev_set_qos_map(rdev, dev, qos_map);
9544 wdev_unlock(dev->ieee80211_ptr);
9545
9546 kfree(qos_map);
9547 return ret;
9548}
9549
Johannes Berg960d01a2014-09-09 22:55:35 +03009550static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9551{
9552 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9553 struct net_device *dev = info->user_ptr[1];
9554 struct wireless_dev *wdev = dev->ieee80211_ptr;
9555 const u8 *peer;
9556 u8 tsid, up;
9557 u16 admitted_time = 0;
9558 int err;
9559
Johannes Berg723e73a2014-10-22 09:25:06 +02009560 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009561 return -EOPNOTSUPP;
9562
9563 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9564 !info->attrs[NL80211_ATTR_USER_PRIO])
9565 return -EINVAL;
9566
9567 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9568 if (tsid >= IEEE80211_NUM_TIDS)
9569 return -EINVAL;
9570
9571 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9572 if (up >= IEEE80211_NUM_UPS)
9573 return -EINVAL;
9574
9575 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009576 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009577 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009578 * need more attributes for that (e.g. BA session requirement);
9579 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009580 */
9581 return -EINVAL;
9582 }
9583
9584 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9585
9586 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9587 admitted_time =
9588 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9589 if (!admitted_time)
9590 return -EINVAL;
9591 }
9592
9593 wdev_lock(wdev);
9594 switch (wdev->iftype) {
9595 case NL80211_IFTYPE_STATION:
9596 case NL80211_IFTYPE_P2P_CLIENT:
9597 if (wdev->current_bss)
9598 break;
9599 err = -ENOTCONN;
9600 goto out;
9601 default:
9602 err = -EOPNOTSUPP;
9603 goto out;
9604 }
9605
9606 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9607
9608 out:
9609 wdev_unlock(wdev);
9610 return err;
9611}
9612
9613static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9614{
9615 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9616 struct net_device *dev = info->user_ptr[1];
9617 struct wireless_dev *wdev = dev->ieee80211_ptr;
9618 const u8 *peer;
9619 u8 tsid;
9620 int err;
9621
9622 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9623 return -EINVAL;
9624
9625 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9626 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9627
9628 wdev_lock(wdev);
9629 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9630 wdev_unlock(wdev);
9631
9632 return err;
9633}
9634
Johannes Berg4c476992010-10-04 21:36:35 +02009635#define NL80211_FLAG_NEED_WIPHY 0x01
9636#define NL80211_FLAG_NEED_NETDEV 0x02
9637#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009638#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9639#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9640 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009641#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009642/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009643#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9644 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +03009645#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +02009646
Johannes Bergf84f7712013-11-14 17:14:45 +01009647static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009648 struct genl_info *info)
9649{
9650 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009651 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009652 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009653 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9654
9655 if (rtnl)
9656 rtnl_lock();
9657
9658 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009659 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009660 if (IS_ERR(rdev)) {
9661 if (rtnl)
9662 rtnl_unlock();
9663 return PTR_ERR(rdev);
9664 }
9665 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009666 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9667 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009668 ASSERT_RTNL();
9669
Johannes Berg89a54e42012-06-15 14:33:17 +02009670 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9671 info->attrs);
9672 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009673 if (rtnl)
9674 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009675 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009676 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009677
Johannes Berg89a54e42012-06-15 14:33:17 +02009678 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009679 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009680
Johannes Berg1bf614e2012-06-15 15:23:36 +02009681 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9682 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009683 if (rtnl)
9684 rtnl_unlock();
9685 return -EINVAL;
9686 }
9687
9688 info->user_ptr[1] = dev;
9689 } else {
9690 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009691 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009692
Johannes Berg1bf614e2012-06-15 15:23:36 +02009693 if (dev) {
9694 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9695 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009696 if (rtnl)
9697 rtnl_unlock();
9698 return -ENETDOWN;
9699 }
9700
9701 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009702 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9703 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009704 if (rtnl)
9705 rtnl_unlock();
9706 return -ENETDOWN;
9707 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009708 }
9709
Johannes Berg4c476992010-10-04 21:36:35 +02009710 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009711 }
9712
9713 return 0;
9714}
9715
Johannes Bergf84f7712013-11-14 17:14:45 +01009716static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009717 struct genl_info *info)
9718{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009719 if (info->user_ptr[1]) {
9720 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9721 struct wireless_dev *wdev = info->user_ptr[1];
9722
9723 if (wdev->netdev)
9724 dev_put(wdev->netdev);
9725 } else {
9726 dev_put(info->user_ptr[1]);
9727 }
9728 }
Johannes Berg5393b912014-09-10 15:00:16 +03009729
Johannes Berg4c476992010-10-04 21:36:35 +02009730 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9731 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +03009732
9733 /* If needed, clear the netlink message payload from the SKB
9734 * as it might contain key data that shouldn't stick around on
9735 * the heap after the SKB is freed. The netlink message header
9736 * is still needed for further processing, so leave it intact.
9737 */
9738 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
9739 struct nlmsghdr *nlh = nlmsg_hdr(skb);
9740
9741 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
9742 }
Johannes Berg4c476992010-10-04 21:36:35 +02009743}
9744
Johannes Berg4534de82013-11-14 17:14:46 +01009745static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009746 {
9747 .cmd = NL80211_CMD_GET_WIPHY,
9748 .doit = nl80211_get_wiphy,
9749 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009750 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009751 .policy = nl80211_policy,
9752 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009753 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9754 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009755 },
9756 {
9757 .cmd = NL80211_CMD_SET_WIPHY,
9758 .doit = nl80211_set_wiphy,
9759 .policy = nl80211_policy,
9760 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009761 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009762 },
9763 {
9764 .cmd = NL80211_CMD_GET_INTERFACE,
9765 .doit = nl80211_get_interface,
9766 .dumpit = nl80211_dump_interface,
9767 .policy = nl80211_policy,
9768 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009769 .internal_flags = NL80211_FLAG_NEED_WDEV |
9770 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009771 },
9772 {
9773 .cmd = NL80211_CMD_SET_INTERFACE,
9774 .doit = nl80211_set_interface,
9775 .policy = nl80211_policy,
9776 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009777 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9778 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009779 },
9780 {
9781 .cmd = NL80211_CMD_NEW_INTERFACE,
9782 .doit = nl80211_new_interface,
9783 .policy = nl80211_policy,
9784 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009785 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9786 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009787 },
9788 {
9789 .cmd = NL80211_CMD_DEL_INTERFACE,
9790 .doit = nl80211_del_interface,
9791 .policy = nl80211_policy,
9792 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009793 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009794 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009795 },
Johannes Berg41ade002007-12-19 02:03:29 +01009796 {
9797 .cmd = NL80211_CMD_GET_KEY,
9798 .doit = nl80211_get_key,
9799 .policy = nl80211_policy,
9800 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009802 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009803 },
9804 {
9805 .cmd = NL80211_CMD_SET_KEY,
9806 .doit = nl80211_set_key,
9807 .policy = nl80211_policy,
9808 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009809 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009810 NL80211_FLAG_NEED_RTNL |
9811 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009812 },
9813 {
9814 .cmd = NL80211_CMD_NEW_KEY,
9815 .doit = nl80211_new_key,
9816 .policy = nl80211_policy,
9817 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009818 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +03009819 NL80211_FLAG_NEED_RTNL |
9820 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +01009821 },
9822 {
9823 .cmd = NL80211_CMD_DEL_KEY,
9824 .doit = nl80211_del_key,
9825 .policy = nl80211_policy,
9826 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009827 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009828 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009829 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009830 {
9831 .cmd = NL80211_CMD_SET_BEACON,
9832 .policy = nl80211_policy,
9833 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009834 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009836 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009837 },
9838 {
Johannes Berg88600202012-02-13 15:17:18 +01009839 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009840 .policy = nl80211_policy,
9841 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009842 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009844 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009845 },
9846 {
Johannes Berg88600202012-02-13 15:17:18 +01009847 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009848 .policy = nl80211_policy,
9849 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009850 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009852 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009853 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009854 {
9855 .cmd = NL80211_CMD_GET_STATION,
9856 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009857 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009858 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009859 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9860 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009861 },
9862 {
9863 .cmd = NL80211_CMD_SET_STATION,
9864 .doit = nl80211_set_station,
9865 .policy = nl80211_policy,
9866 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009868 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009869 },
9870 {
9871 .cmd = NL80211_CMD_NEW_STATION,
9872 .doit = nl80211_new_station,
9873 .policy = nl80211_policy,
9874 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009875 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009876 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009877 },
9878 {
9879 .cmd = NL80211_CMD_DEL_STATION,
9880 .doit = nl80211_del_station,
9881 .policy = nl80211_policy,
9882 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009883 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009884 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009885 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009886 {
9887 .cmd = NL80211_CMD_GET_MPATH,
9888 .doit = nl80211_get_mpath,
9889 .dumpit = nl80211_dump_mpath,
9890 .policy = nl80211_policy,
9891 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009892 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009893 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009894 },
9895 {
Henning Rogge66be7d22014-09-12 08:58:49 +02009896 .cmd = NL80211_CMD_GET_MPP,
9897 .doit = nl80211_get_mpp,
9898 .dumpit = nl80211_dump_mpp,
9899 .policy = nl80211_policy,
9900 .flags = GENL_ADMIN_PERM,
9901 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9902 NL80211_FLAG_NEED_RTNL,
9903 },
9904 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009905 .cmd = NL80211_CMD_SET_MPATH,
9906 .doit = nl80211_set_mpath,
9907 .policy = nl80211_policy,
9908 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009909 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009910 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009911 },
9912 {
9913 .cmd = NL80211_CMD_NEW_MPATH,
9914 .doit = nl80211_new_mpath,
9915 .policy = nl80211_policy,
9916 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009917 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009918 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009919 },
9920 {
9921 .cmd = NL80211_CMD_DEL_MPATH,
9922 .doit = nl80211_del_mpath,
9923 .policy = nl80211_policy,
9924 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009925 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009926 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009927 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009928 {
9929 .cmd = NL80211_CMD_SET_BSS,
9930 .doit = nl80211_set_bss,
9931 .policy = nl80211_policy,
9932 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009934 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009935 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009936 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009937 .cmd = NL80211_CMD_GET_REG,
9938 .doit = nl80211_get_reg,
9939 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009940 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009941 /* can be retrieved by unprivileged users */
9942 },
9943 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009944 .cmd = NL80211_CMD_SET_REG,
9945 .doit = nl80211_set_reg,
9946 .policy = nl80211_policy,
9947 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009948 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009949 },
9950 {
9951 .cmd = NL80211_CMD_REQ_SET_REG,
9952 .doit = nl80211_req_set_reg,
9953 .policy = nl80211_policy,
9954 .flags = GENL_ADMIN_PERM,
9955 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009956 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009957 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9958 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009959 .policy = nl80211_policy,
9960 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009961 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009962 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009963 },
9964 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009965 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9966 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009967 .policy = nl80211_policy,
9968 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009969 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009970 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009971 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009972 {
Johannes Berg2a519312009-02-10 21:25:55 +01009973 .cmd = NL80211_CMD_TRIGGER_SCAN,
9974 .doit = nl80211_trigger_scan,
9975 .policy = nl80211_policy,
9976 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009977 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009978 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009979 },
9980 {
9981 .cmd = NL80211_CMD_GET_SCAN,
9982 .policy = nl80211_policy,
9983 .dumpit = nl80211_dump_scan,
9984 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009985 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009986 .cmd = NL80211_CMD_START_SCHED_SCAN,
9987 .doit = nl80211_start_sched_scan,
9988 .policy = nl80211_policy,
9989 .flags = GENL_ADMIN_PERM,
9990 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9991 NL80211_FLAG_NEED_RTNL,
9992 },
9993 {
9994 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9995 .doit = nl80211_stop_sched_scan,
9996 .policy = nl80211_policy,
9997 .flags = GENL_ADMIN_PERM,
9998 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9999 NL80211_FLAG_NEED_RTNL,
10000 },
10001 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010002 .cmd = NL80211_CMD_AUTHENTICATE,
10003 .doit = nl80211_authenticate,
10004 .policy = nl80211_policy,
10005 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010006 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010007 NL80211_FLAG_NEED_RTNL |
10008 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010009 },
10010 {
10011 .cmd = NL80211_CMD_ASSOCIATE,
10012 .doit = nl80211_associate,
10013 .policy = nl80211_policy,
10014 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010016 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010017 },
10018 {
10019 .cmd = NL80211_CMD_DEAUTHENTICATE,
10020 .doit = nl80211_deauthenticate,
10021 .policy = nl80211_policy,
10022 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010024 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010025 },
10026 {
10027 .cmd = NL80211_CMD_DISASSOCIATE,
10028 .doit = nl80211_disassociate,
10029 .policy = nl80211_policy,
10030 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010032 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010033 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010034 {
10035 .cmd = NL80211_CMD_JOIN_IBSS,
10036 .doit = nl80211_join_ibss,
10037 .policy = nl80211_policy,
10038 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010040 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010041 },
10042 {
10043 .cmd = NL80211_CMD_LEAVE_IBSS,
10044 .doit = nl80211_leave_ibss,
10045 .policy = nl80211_policy,
10046 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010047 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010048 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010049 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010050#ifdef CONFIG_NL80211_TESTMODE
10051 {
10052 .cmd = NL80211_CMD_TESTMODE,
10053 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010054 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010055 .policy = nl80211_policy,
10056 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010057 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10058 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010059 },
10060#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010061 {
10062 .cmd = NL80211_CMD_CONNECT,
10063 .doit = nl80211_connect,
10064 .policy = nl80211_policy,
10065 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010066 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010067 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010068 },
10069 {
10070 .cmd = NL80211_CMD_DISCONNECT,
10071 .doit = nl80211_disconnect,
10072 .policy = nl80211_policy,
10073 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010074 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010075 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010076 },
Johannes Berg463d0182009-07-14 00:33:35 +020010077 {
10078 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10079 .doit = nl80211_wiphy_netns,
10080 .policy = nl80211_policy,
10081 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010082 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10083 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010084 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010085 {
10086 .cmd = NL80211_CMD_GET_SURVEY,
10087 .policy = nl80211_policy,
10088 .dumpit = nl80211_dump_survey,
10089 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010090 {
10091 .cmd = NL80211_CMD_SET_PMKSA,
10092 .doit = nl80211_setdel_pmksa,
10093 .policy = nl80211_policy,
10094 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010095 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010096 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010097 },
10098 {
10099 .cmd = NL80211_CMD_DEL_PMKSA,
10100 .doit = nl80211_setdel_pmksa,
10101 .policy = nl80211_policy,
10102 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010103 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010104 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010105 },
10106 {
10107 .cmd = NL80211_CMD_FLUSH_PMKSA,
10108 .doit = nl80211_flush_pmksa,
10109 .policy = nl80211_policy,
10110 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010111 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010112 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010113 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010114 {
10115 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10116 .doit = nl80211_remain_on_channel,
10117 .policy = nl80211_policy,
10118 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010119 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010120 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010121 },
10122 {
10123 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10124 .doit = nl80211_cancel_remain_on_channel,
10125 .policy = nl80211_policy,
10126 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010127 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010128 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010129 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010130 {
10131 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10132 .doit = nl80211_set_tx_bitrate_mask,
10133 .policy = nl80211_policy,
10134 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010135 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10136 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010137 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010138 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010139 .cmd = NL80211_CMD_REGISTER_FRAME,
10140 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010141 .policy = nl80211_policy,
10142 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010143 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010144 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010145 },
10146 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010147 .cmd = NL80211_CMD_FRAME,
10148 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010149 .policy = nl80211_policy,
10150 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010151 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010152 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010153 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010154 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010155 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10156 .doit = nl80211_tx_mgmt_cancel_wait,
10157 .policy = nl80211_policy,
10158 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010159 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010160 NL80211_FLAG_NEED_RTNL,
10161 },
10162 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010163 .cmd = NL80211_CMD_SET_POWER_SAVE,
10164 .doit = nl80211_set_power_save,
10165 .policy = nl80211_policy,
10166 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010167 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10168 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010169 },
10170 {
10171 .cmd = NL80211_CMD_GET_POWER_SAVE,
10172 .doit = nl80211_get_power_save,
10173 .policy = nl80211_policy,
10174 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010175 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10176 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010177 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010178 {
10179 .cmd = NL80211_CMD_SET_CQM,
10180 .doit = nl80211_set_cqm,
10181 .policy = nl80211_policy,
10182 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010183 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10184 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010185 },
Johannes Bergf444de02010-05-05 15:25:02 +020010186 {
10187 .cmd = NL80211_CMD_SET_CHANNEL,
10188 .doit = nl80211_set_channel,
10189 .policy = nl80211_policy,
10190 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010191 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10192 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010193 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010194 {
10195 .cmd = NL80211_CMD_SET_WDS_PEER,
10196 .doit = nl80211_set_wds_peer,
10197 .policy = nl80211_policy,
10198 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010199 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10200 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010201 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010202 {
10203 .cmd = NL80211_CMD_JOIN_MESH,
10204 .doit = nl80211_join_mesh,
10205 .policy = nl80211_policy,
10206 .flags = GENL_ADMIN_PERM,
10207 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10208 NL80211_FLAG_NEED_RTNL,
10209 },
10210 {
10211 .cmd = NL80211_CMD_LEAVE_MESH,
10212 .doit = nl80211_leave_mesh,
10213 .policy = nl80211_policy,
10214 .flags = GENL_ADMIN_PERM,
10215 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10216 NL80211_FLAG_NEED_RTNL,
10217 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010218#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010219 {
10220 .cmd = NL80211_CMD_GET_WOWLAN,
10221 .doit = nl80211_get_wowlan,
10222 .policy = nl80211_policy,
10223 /* can be retrieved by unprivileged users */
10224 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10225 NL80211_FLAG_NEED_RTNL,
10226 },
10227 {
10228 .cmd = NL80211_CMD_SET_WOWLAN,
10229 .doit = nl80211_set_wowlan,
10230 .policy = nl80211_policy,
10231 .flags = GENL_ADMIN_PERM,
10232 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10233 NL80211_FLAG_NEED_RTNL,
10234 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010235#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010236 {
10237 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10238 .doit = nl80211_set_rekey_data,
10239 .policy = nl80211_policy,
10240 .flags = GENL_ADMIN_PERM,
10241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010242 NL80211_FLAG_NEED_RTNL |
10243 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010244 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010245 {
10246 .cmd = NL80211_CMD_TDLS_MGMT,
10247 .doit = nl80211_tdls_mgmt,
10248 .policy = nl80211_policy,
10249 .flags = GENL_ADMIN_PERM,
10250 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10251 NL80211_FLAG_NEED_RTNL,
10252 },
10253 {
10254 .cmd = NL80211_CMD_TDLS_OPER,
10255 .doit = nl80211_tdls_oper,
10256 .policy = nl80211_policy,
10257 .flags = GENL_ADMIN_PERM,
10258 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10259 NL80211_FLAG_NEED_RTNL,
10260 },
Johannes Berg28946da2011-11-04 11:18:12 +010010261 {
10262 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10263 .doit = nl80211_register_unexpected_frame,
10264 .policy = nl80211_policy,
10265 .flags = GENL_ADMIN_PERM,
10266 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10267 NL80211_FLAG_NEED_RTNL,
10268 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010269 {
10270 .cmd = NL80211_CMD_PROBE_CLIENT,
10271 .doit = nl80211_probe_client,
10272 .policy = nl80211_policy,
10273 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010274 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010275 NL80211_FLAG_NEED_RTNL,
10276 },
Johannes Berg5e760232011-11-04 11:18:17 +010010277 {
10278 .cmd = NL80211_CMD_REGISTER_BEACONS,
10279 .doit = nl80211_register_beacons,
10280 .policy = nl80211_policy,
10281 .flags = GENL_ADMIN_PERM,
10282 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10283 NL80211_FLAG_NEED_RTNL,
10284 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010285 {
10286 .cmd = NL80211_CMD_SET_NOACK_MAP,
10287 .doit = nl80211_set_noack_map,
10288 .policy = nl80211_policy,
10289 .flags = GENL_ADMIN_PERM,
10290 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10291 NL80211_FLAG_NEED_RTNL,
10292 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010293 {
10294 .cmd = NL80211_CMD_START_P2P_DEVICE,
10295 .doit = nl80211_start_p2p_device,
10296 .policy = nl80211_policy,
10297 .flags = GENL_ADMIN_PERM,
10298 .internal_flags = NL80211_FLAG_NEED_WDEV |
10299 NL80211_FLAG_NEED_RTNL,
10300 },
10301 {
10302 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10303 .doit = nl80211_stop_p2p_device,
10304 .policy = nl80211_policy,
10305 .flags = GENL_ADMIN_PERM,
10306 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10307 NL80211_FLAG_NEED_RTNL,
10308 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010309 {
10310 .cmd = NL80211_CMD_SET_MCAST_RATE,
10311 .doit = nl80211_set_mcast_rate,
10312 .policy = nl80211_policy,
10313 .flags = GENL_ADMIN_PERM,
10314 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10315 NL80211_FLAG_NEED_RTNL,
10316 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010317 {
10318 .cmd = NL80211_CMD_SET_MAC_ACL,
10319 .doit = nl80211_set_mac_acl,
10320 .policy = nl80211_policy,
10321 .flags = GENL_ADMIN_PERM,
10322 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10323 NL80211_FLAG_NEED_RTNL,
10324 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010325 {
10326 .cmd = NL80211_CMD_RADAR_DETECT,
10327 .doit = nl80211_start_radar_detection,
10328 .policy = nl80211_policy,
10329 .flags = GENL_ADMIN_PERM,
10330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10331 NL80211_FLAG_NEED_RTNL,
10332 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010333 {
10334 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10335 .doit = nl80211_get_protocol_features,
10336 .policy = nl80211_policy,
10337 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010338 {
10339 .cmd = NL80211_CMD_UPDATE_FT_IES,
10340 .doit = nl80211_update_ft_ies,
10341 .policy = nl80211_policy,
10342 .flags = GENL_ADMIN_PERM,
10343 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10344 NL80211_FLAG_NEED_RTNL,
10345 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010346 {
10347 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10348 .doit = nl80211_crit_protocol_start,
10349 .policy = nl80211_policy,
10350 .flags = GENL_ADMIN_PERM,
10351 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10352 NL80211_FLAG_NEED_RTNL,
10353 },
10354 {
10355 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10356 .doit = nl80211_crit_protocol_stop,
10357 .policy = nl80211_policy,
10358 .flags = GENL_ADMIN_PERM,
10359 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10360 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010361 },
10362 {
10363 .cmd = NL80211_CMD_GET_COALESCE,
10364 .doit = nl80211_get_coalesce,
10365 .policy = nl80211_policy,
10366 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10367 NL80211_FLAG_NEED_RTNL,
10368 },
10369 {
10370 .cmd = NL80211_CMD_SET_COALESCE,
10371 .doit = nl80211_set_coalesce,
10372 .policy = nl80211_policy,
10373 .flags = GENL_ADMIN_PERM,
10374 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10375 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010376 },
10377 {
10378 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10379 .doit = nl80211_channel_switch,
10380 .policy = nl80211_policy,
10381 .flags = GENL_ADMIN_PERM,
10382 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10383 NL80211_FLAG_NEED_RTNL,
10384 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010385 {
10386 .cmd = NL80211_CMD_VENDOR,
10387 .doit = nl80211_vendor_cmd,
10388 .policy = nl80211_policy,
10389 .flags = GENL_ADMIN_PERM,
10390 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10391 NL80211_FLAG_NEED_RTNL,
10392 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010393 {
10394 .cmd = NL80211_CMD_SET_QOS_MAP,
10395 .doit = nl80211_set_qos_map,
10396 .policy = nl80211_policy,
10397 .flags = GENL_ADMIN_PERM,
10398 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10399 NL80211_FLAG_NEED_RTNL,
10400 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010401 {
10402 .cmd = NL80211_CMD_ADD_TX_TS,
10403 .doit = nl80211_add_tx_ts,
10404 .policy = nl80211_policy,
10405 .flags = GENL_ADMIN_PERM,
10406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10407 NL80211_FLAG_NEED_RTNL,
10408 },
10409 {
10410 .cmd = NL80211_CMD_DEL_TX_TS,
10411 .doit = nl80211_del_tx_ts,
10412 .policy = nl80211_policy,
10413 .flags = GENL_ADMIN_PERM,
10414 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10415 NL80211_FLAG_NEED_RTNL,
10416 },
Johannes Berg55682962007-09-20 13:09:35 -040010417};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010418
Johannes Berg55682962007-09-20 13:09:35 -040010419/* notification functions */
10420
Johannes Berg3bb20552014-05-26 13:52:25 +020010421void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10422 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010423{
10424 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010425 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010426
Johannes Berg3bb20552014-05-26 13:52:25 +020010427 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10428 cmd != NL80211_CMD_DEL_WIPHY);
10429
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010431 if (!msg)
10432 return;
10433
Johannes Berg3bb20552014-05-26 13:52:25 +020010434 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010435 nlmsg_free(msg);
10436 return;
10437 }
10438
Johannes Berg68eb5502013-11-19 15:19:38 +010010439 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010440 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010441}
10442
Johannes Berg362a4152009-05-24 16:43:15 +020010443static int nl80211_add_scan_req(struct sk_buff *msg,
10444 struct cfg80211_registered_device *rdev)
10445{
10446 struct cfg80211_scan_request *req = rdev->scan_req;
10447 struct nlattr *nest;
10448 int i;
10449
10450 if (WARN_ON(!req))
10451 return 0;
10452
10453 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10454 if (!nest)
10455 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010456 for (i = 0; i < req->n_ssids; i++) {
10457 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10458 goto nla_put_failure;
10459 }
Johannes Berg362a4152009-05-24 16:43:15 +020010460 nla_nest_end(msg, nest);
10461
10462 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10463 if (!nest)
10464 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010465 for (i = 0; i < req->n_channels; i++) {
10466 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10467 goto nla_put_failure;
10468 }
Johannes Berg362a4152009-05-24 16:43:15 +020010469 nla_nest_end(msg, nest);
10470
David S. Miller9360ffd2012-03-29 04:41:26 -040010471 if (req->ie &&
10472 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10473 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010474
Johannes Bergae917c92013-10-25 11:05:22 +020010475 if (req->flags &&
10476 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10477 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010478
Johannes Berg362a4152009-05-24 16:43:15 +020010479 return 0;
10480 nla_put_failure:
10481 return -ENOBUFS;
10482}
10483
Johannes Berga538e2d2009-06-16 19:56:42 +020010484static int nl80211_send_scan_msg(struct sk_buff *msg,
10485 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010486 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010487 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010488 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010489{
10490 void *hdr;
10491
Eric W. Biederman15e47302012-09-07 20:12:54 +000010492 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010493 if (!hdr)
10494 return -1;
10495
David S. Miller9360ffd2012-03-29 04:41:26 -040010496 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010497 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10498 wdev->netdev->ifindex)) ||
10499 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010500 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010501
Johannes Berg362a4152009-05-24 16:43:15 +020010502 /* ignore errors and send incomplete event anyway */
10503 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010504
10505 return genlmsg_end(msg, hdr);
10506
10507 nla_put_failure:
10508 genlmsg_cancel(msg, hdr);
10509 return -EMSGSIZE;
10510}
10511
Luciano Coelho807f8a82011-05-11 17:09:35 +030010512static int
10513nl80211_send_sched_scan_msg(struct sk_buff *msg,
10514 struct cfg80211_registered_device *rdev,
10515 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010516 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010517{
10518 void *hdr;
10519
Eric W. Biederman15e47302012-09-07 20:12:54 +000010520 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010521 if (!hdr)
10522 return -1;
10523
David S. Miller9360ffd2012-03-29 04:41:26 -040010524 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10525 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10526 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010527
10528 return genlmsg_end(msg, hdr);
10529
10530 nla_put_failure:
10531 genlmsg_cancel(msg, hdr);
10532 return -EMSGSIZE;
10533}
10534
Johannes Berga538e2d2009-06-16 19:56:42 +020010535void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010536 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010537{
10538 struct sk_buff *msg;
10539
Thomas Graf58050fc2012-06-28 03:57:45 +000010540 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010541 if (!msg)
10542 return;
10543
Johannes Bergfd014282012-06-18 19:17:03 +020010544 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010545 NL80211_CMD_TRIGGER_SCAN) < 0) {
10546 nlmsg_free(msg);
10547 return;
10548 }
10549
Johannes Berg68eb5502013-11-19 15:19:38 +010010550 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010551 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010552}
10553
Johannes Bergf9d15d12014-01-22 11:14:19 +020010554struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10555 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010556{
10557 struct sk_buff *msg;
10558
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010559 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010560 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010561 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010562
Johannes Bergfd014282012-06-18 19:17:03 +020010563 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010564 aborted ? NL80211_CMD_SCAN_ABORTED :
10565 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010566 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010567 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010568 }
10569
Johannes Bergf9d15d12014-01-22 11:14:19 +020010570 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010571}
10572
Johannes Bergf9d15d12014-01-22 11:14:19 +020010573void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10574 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010575{
Johannes Berg2a519312009-02-10 21:25:55 +010010576 if (!msg)
10577 return;
10578
Johannes Berg68eb5502013-11-19 15:19:38 +010010579 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010580 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010581}
10582
Luciano Coelho807f8a82011-05-11 17:09:35 +030010583void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10584 struct net_device *netdev)
10585{
10586 struct sk_buff *msg;
10587
10588 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10589 if (!msg)
10590 return;
10591
10592 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10593 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10594 nlmsg_free(msg);
10595 return;
10596 }
10597
Johannes Berg68eb5502013-11-19 15:19:38 +010010598 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010599 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010600}
10601
10602void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10603 struct net_device *netdev, u32 cmd)
10604{
10605 struct sk_buff *msg;
10606
Thomas Graf58050fc2012-06-28 03:57:45 +000010607 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010608 if (!msg)
10609 return;
10610
10611 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10612 nlmsg_free(msg);
10613 return;
10614 }
10615
Johannes Berg68eb5502013-11-19 15:19:38 +010010616 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010617 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010618}
10619
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010620/*
10621 * This can happen on global regulatory changes or device specific settings
10622 * based on custom world regulatory domains.
10623 */
10624void nl80211_send_reg_change_event(struct regulatory_request *request)
10625{
10626 struct sk_buff *msg;
10627 void *hdr;
10628
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010629 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010630 if (!msg)
10631 return;
10632
10633 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10634 if (!hdr) {
10635 nlmsg_free(msg);
10636 return;
10637 }
10638
10639 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010640 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10641 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010642
David S. Miller9360ffd2012-03-29 04:41:26 -040010643 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10644 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10645 NL80211_REGDOM_TYPE_WORLD))
10646 goto nla_put_failure;
10647 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10648 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10649 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10650 goto nla_put_failure;
10651 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10652 request->intersect) {
10653 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10654 NL80211_REGDOM_TYPE_INTERSECTION))
10655 goto nla_put_failure;
10656 } else {
10657 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10658 NL80211_REGDOM_TYPE_COUNTRY) ||
10659 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10660 request->alpha2))
10661 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010662 }
10663
Johannes Bergf4173762012-12-03 18:23:37 +010010664 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010665 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10666 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010667
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010668 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010669
Johannes Bergbc43b282009-07-25 10:54:13 +020010670 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010671 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010672 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010673 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010674
10675 return;
10676
10677nla_put_failure:
10678 genlmsg_cancel(msg, hdr);
10679 nlmsg_free(msg);
10680}
10681
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010682static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10683 struct net_device *netdev,
10684 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010685 enum nl80211_commands cmd, gfp_t gfp,
10686 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010687{
10688 struct sk_buff *msg;
10689 void *hdr;
10690
Johannes Berge6d6e342009-07-01 21:26:47 +020010691 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010692 if (!msg)
10693 return;
10694
10695 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10696 if (!hdr) {
10697 nlmsg_free(msg);
10698 return;
10699 }
10700
David S. Miller9360ffd2012-03-29 04:41:26 -040010701 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10702 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10703 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10704 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010705
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010706 if (uapsd_queues >= 0) {
10707 struct nlattr *nla_wmm =
10708 nla_nest_start(msg, NL80211_ATTR_STA_WME);
10709 if (!nla_wmm)
10710 goto nla_put_failure;
10711
10712 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
10713 uapsd_queues))
10714 goto nla_put_failure;
10715
10716 nla_nest_end(msg, nla_wmm);
10717 }
10718
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010719 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010720
Johannes Berg68eb5502013-11-19 15:19:38 +010010721 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010722 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010723 return;
10724
10725 nla_put_failure:
10726 genlmsg_cancel(msg, hdr);
10727 nlmsg_free(msg);
10728}
10729
10730void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010731 struct net_device *netdev, const u8 *buf,
10732 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010733{
10734 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010735 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010736}
10737
10738void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10739 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010740 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010741{
Johannes Berge6d6e342009-07-01 21:26:47 +020010742 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010743 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010744}
10745
Jouni Malinen53b46b82009-03-27 20:53:56 +020010746void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010747 struct net_device *netdev, const u8 *buf,
10748 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010749{
10750 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010751 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010752}
10753
Jouni Malinen53b46b82009-03-27 20:53:56 +020010754void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10755 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010756 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010757{
10758 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010759 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010760}
10761
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010762void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10763 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010764{
Johannes Berg947add32013-02-22 22:05:20 +010010765 struct wireless_dev *wdev = dev->ieee80211_ptr;
10766 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010767 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010768 const struct ieee80211_mgmt *mgmt = (void *)buf;
10769 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010770
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010771 if (WARN_ON(len < 2))
10772 return;
10773
10774 if (ieee80211_is_deauth(mgmt->frame_control))
10775 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10776 else
10777 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10778
10779 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030010780 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010781}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010782EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010783
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010784static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10785 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010786 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010787{
10788 struct sk_buff *msg;
10789 void *hdr;
10790
Johannes Berge6d6e342009-07-01 21:26:47 +020010791 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010792 if (!msg)
10793 return;
10794
10795 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10796 if (!hdr) {
10797 nlmsg_free(msg);
10798 return;
10799 }
10800
David S. Miller9360ffd2012-03-29 04:41:26 -040010801 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10802 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10803 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10804 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10805 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010806
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010807 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010808
Johannes Berg68eb5502013-11-19 15:19:38 +010010809 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010810 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010811 return;
10812
10813 nla_put_failure:
10814 genlmsg_cancel(msg, hdr);
10815 nlmsg_free(msg);
10816}
10817
10818void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010819 struct net_device *netdev, const u8 *addr,
10820 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010821{
10822 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010823 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010824}
10825
10826void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010827 struct net_device *netdev, const u8 *addr,
10828 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010829{
Johannes Berge6d6e342009-07-01 21:26:47 +020010830 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10831 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010832}
10833
Samuel Ortizb23aa672009-07-01 21:26:54 +020010834void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10835 struct net_device *netdev, const u8 *bssid,
10836 const u8 *req_ie, size_t req_ie_len,
10837 const u8 *resp_ie, size_t resp_ie_len,
10838 u16 status, gfp_t gfp)
10839{
10840 struct sk_buff *msg;
10841 void *hdr;
10842
Thomas Graf58050fc2012-06-28 03:57:45 +000010843 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010844 if (!msg)
10845 return;
10846
10847 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10848 if (!hdr) {
10849 nlmsg_free(msg);
10850 return;
10851 }
10852
David S. Miller9360ffd2012-03-29 04:41:26 -040010853 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10854 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10855 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10856 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10857 (req_ie &&
10858 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10859 (resp_ie &&
10860 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10861 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010862
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010863 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010864
Johannes Berg68eb5502013-11-19 15:19:38 +010010865 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010866 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010867 return;
10868
10869 nla_put_failure:
10870 genlmsg_cancel(msg, hdr);
10871 nlmsg_free(msg);
10872
10873}
10874
10875void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10876 struct net_device *netdev, const u8 *bssid,
10877 const u8 *req_ie, size_t req_ie_len,
10878 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10879{
10880 struct sk_buff *msg;
10881 void *hdr;
10882
Thomas Graf58050fc2012-06-28 03:57:45 +000010883 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010884 if (!msg)
10885 return;
10886
10887 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10888 if (!hdr) {
10889 nlmsg_free(msg);
10890 return;
10891 }
10892
David S. Miller9360ffd2012-03-29 04:41:26 -040010893 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10894 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10895 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10896 (req_ie &&
10897 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10898 (resp_ie &&
10899 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10900 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010901
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010902 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010903
Johannes Berg68eb5502013-11-19 15:19:38 +010010904 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010905 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010906 return;
10907
10908 nla_put_failure:
10909 genlmsg_cancel(msg, hdr);
10910 nlmsg_free(msg);
10911
10912}
10913
10914void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10915 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010916 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010917{
10918 struct sk_buff *msg;
10919 void *hdr;
10920
Thomas Graf58050fc2012-06-28 03:57:45 +000010921 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010922 if (!msg)
10923 return;
10924
10925 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10926 if (!hdr) {
10927 nlmsg_free(msg);
10928 return;
10929 }
10930
David S. Miller9360ffd2012-03-29 04:41:26 -040010931 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10932 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10933 (from_ap && reason &&
10934 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10935 (from_ap &&
10936 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10937 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10938 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010939
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010940 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010941
Johannes Berg68eb5502013-11-19 15:19:38 +010010942 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010943 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010944 return;
10945
10946 nla_put_failure:
10947 genlmsg_cancel(msg, hdr);
10948 nlmsg_free(msg);
10949
10950}
10951
Johannes Berg04a773a2009-04-19 21:24:32 +020010952void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10953 struct net_device *netdev, const u8 *bssid,
10954 gfp_t gfp)
10955{
10956 struct sk_buff *msg;
10957 void *hdr;
10958
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010959 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010960 if (!msg)
10961 return;
10962
10963 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10964 if (!hdr) {
10965 nlmsg_free(msg);
10966 return;
10967 }
10968
David S. Miller9360ffd2012-03-29 04:41:26 -040010969 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10970 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10971 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10972 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010973
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010974 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010975
Johannes Berg68eb5502013-11-19 15:19:38 +010010976 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010977 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010978 return;
10979
10980 nla_put_failure:
10981 genlmsg_cancel(msg, hdr);
10982 nlmsg_free(msg);
10983}
10984
Johannes Berg947add32013-02-22 22:05:20 +010010985void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10986 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010987{
Johannes Berg947add32013-02-22 22:05:20 +010010988 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010989 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010990 struct sk_buff *msg;
10991 void *hdr;
10992
Johannes Berg947add32013-02-22 22:05:20 +010010993 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10994 return;
10995
10996 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10997
Javier Cardonac93b5e72011-04-07 15:08:34 -070010998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10999 if (!msg)
11000 return;
11001
11002 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11003 if (!hdr) {
11004 nlmsg_free(msg);
11005 return;
11006 }
11007
David S. Miller9360ffd2012-03-29 04:41:26 -040011008 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011009 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11010 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011011 (ie_len && ie &&
11012 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11013 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011014
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011015 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011016
Johannes Berg68eb5502013-11-19 15:19:38 +010011017 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011018 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011019 return;
11020
11021 nla_put_failure:
11022 genlmsg_cancel(msg, hdr);
11023 nlmsg_free(msg);
11024}
Johannes Berg947add32013-02-22 22:05:20 +010011025EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011026
Jouni Malinena3b8b052009-03-27 21:59:49 +020011027void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11028 struct net_device *netdev, const u8 *addr,
11029 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011030 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011031{
11032 struct sk_buff *msg;
11033 void *hdr;
11034
Johannes Berge6d6e342009-07-01 21:26:47 +020011035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011036 if (!msg)
11037 return;
11038
11039 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11040 if (!hdr) {
11041 nlmsg_free(msg);
11042 return;
11043 }
11044
David S. Miller9360ffd2012-03-29 04:41:26 -040011045 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11046 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11047 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11048 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11049 (key_id != -1 &&
11050 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11051 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11052 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011053
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011054 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011055
Johannes Berg68eb5502013-11-19 15:19:38 +010011056 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011057 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011058 return;
11059
11060 nla_put_failure:
11061 genlmsg_cancel(msg, hdr);
11062 nlmsg_free(msg);
11063}
11064
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011065void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11066 struct ieee80211_channel *channel_before,
11067 struct ieee80211_channel *channel_after)
11068{
11069 struct sk_buff *msg;
11070 void *hdr;
11071 struct nlattr *nl_freq;
11072
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011073 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011074 if (!msg)
11075 return;
11076
11077 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11078 if (!hdr) {
11079 nlmsg_free(msg);
11080 return;
11081 }
11082
11083 /*
11084 * Since we are applying the beacon hint to a wiphy we know its
11085 * wiphy_idx is valid
11086 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11088 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011089
11090 /* Before */
11091 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11092 if (!nl_freq)
11093 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011094 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011095 goto nla_put_failure;
11096 nla_nest_end(msg, nl_freq);
11097
11098 /* After */
11099 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11100 if (!nl_freq)
11101 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011102 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011103 goto nla_put_failure;
11104 nla_nest_end(msg, nl_freq);
11105
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011106 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011107
Johannes Berg463d0182009-07-14 00:33:35 +020011108 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011109 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011110 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011111 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011112
11113 return;
11114
11115nla_put_failure:
11116 genlmsg_cancel(msg, hdr);
11117 nlmsg_free(msg);
11118}
11119
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011120static void nl80211_send_remain_on_chan_event(
11121 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011122 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011123 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011124 unsigned int duration, gfp_t gfp)
11125{
11126 struct sk_buff *msg;
11127 void *hdr;
11128
11129 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11130 if (!msg)
11131 return;
11132
11133 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11134 if (!hdr) {
11135 nlmsg_free(msg);
11136 return;
11137 }
11138
David S. Miller9360ffd2012-03-29 04:41:26 -040011139 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011140 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11141 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011142 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011143 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011144 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11145 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011146 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11147 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011148
David S. Miller9360ffd2012-03-29 04:41:26 -040011149 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11150 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11151 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011152
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011153 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011154
Johannes Berg68eb5502013-11-19 15:19:38 +010011155 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011156 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011157 return;
11158
11159 nla_put_failure:
11160 genlmsg_cancel(msg, hdr);
11161 nlmsg_free(msg);
11162}
11163
Johannes Berg947add32013-02-22 22:05:20 +010011164void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11165 struct ieee80211_channel *chan,
11166 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011167{
Johannes Berg947add32013-02-22 22:05:20 +010011168 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011169 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011170
11171 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011172 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011173 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011174 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011175}
Johannes Berg947add32013-02-22 22:05:20 +010011176EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011177
Johannes Berg947add32013-02-22 22:05:20 +010011178void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11179 struct ieee80211_channel *chan,
11180 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011181{
Johannes Berg947add32013-02-22 22:05:20 +010011182 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011183 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011184
11185 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011186 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011187 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011188}
Johannes Berg947add32013-02-22 22:05:20 +010011189EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011190
Johannes Berg947add32013-02-22 22:05:20 +010011191void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11192 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011193{
Johannes Berg947add32013-02-22 22:05:20 +010011194 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011195 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011196 struct sk_buff *msg;
11197
Johannes Berg947add32013-02-22 22:05:20 +010011198 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11199
Thomas Graf58050fc2012-06-28 03:57:45 +000011200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011201 if (!msg)
11202 return;
11203
John W. Linville66266b32012-03-15 13:25:41 -040011204 if (nl80211_send_station(msg, 0, 0, 0,
11205 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011206 nlmsg_free(msg);
11207 return;
11208 }
11209
Johannes Berg68eb5502013-11-19 15:19:38 +010011210 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011211 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011212}
Johannes Berg947add32013-02-22 22:05:20 +010011213EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011214
Johannes Berg947add32013-02-22 22:05:20 +010011215void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011216{
Johannes Berg947add32013-02-22 22:05:20 +010011217 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011218 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011219 struct sk_buff *msg;
11220 void *hdr;
11221
Johannes Berg947add32013-02-22 22:05:20 +010011222 trace_cfg80211_del_sta(dev, mac_addr);
11223
Thomas Graf58050fc2012-06-28 03:57:45 +000011224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011225 if (!msg)
11226 return;
11227
11228 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11229 if (!hdr) {
11230 nlmsg_free(msg);
11231 return;
11232 }
11233
David S. Miller9360ffd2012-03-29 04:41:26 -040011234 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11235 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11236 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011237
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011238 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011239
Johannes Berg68eb5502013-11-19 15:19:38 +010011240 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011241 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011242 return;
11243
11244 nla_put_failure:
11245 genlmsg_cancel(msg, hdr);
11246 nlmsg_free(msg);
11247}
Johannes Berg947add32013-02-22 22:05:20 +010011248EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011249
Johannes Berg947add32013-02-22 22:05:20 +010011250void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11251 enum nl80211_connect_failed_reason reason,
11252 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011253{
Johannes Berg947add32013-02-22 22:05:20 +010011254 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011255 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011256 struct sk_buff *msg;
11257 void *hdr;
11258
11259 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11260 if (!msg)
11261 return;
11262
11263 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11264 if (!hdr) {
11265 nlmsg_free(msg);
11266 return;
11267 }
11268
11269 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11270 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11271 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11272 goto nla_put_failure;
11273
11274 genlmsg_end(msg, hdr);
11275
Johannes Berg68eb5502013-11-19 15:19:38 +010011276 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011277 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011278 return;
11279
11280 nla_put_failure:
11281 genlmsg_cancel(msg, hdr);
11282 nlmsg_free(msg);
11283}
Johannes Berg947add32013-02-22 22:05:20 +010011284EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011285
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011286static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11287 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011288{
11289 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011290 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011291 struct sk_buff *msg;
11292 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011293 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011294
Eric W. Biederman15e47302012-09-07 20:12:54 +000011295 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011296 return false;
11297
11298 msg = nlmsg_new(100, gfp);
11299 if (!msg)
11300 return true;
11301
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011302 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011303 if (!hdr) {
11304 nlmsg_free(msg);
11305 return true;
11306 }
11307
David S. Miller9360ffd2012-03-29 04:41:26 -040011308 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11309 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11310 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11311 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011312
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011313 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011314 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011315 return true;
11316
11317 nla_put_failure:
11318 genlmsg_cancel(msg, hdr);
11319 nlmsg_free(msg);
11320 return true;
11321}
11322
Johannes Berg947add32013-02-22 22:05:20 +010011323bool cfg80211_rx_spurious_frame(struct net_device *dev,
11324 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011325{
Johannes Berg947add32013-02-22 22:05:20 +010011326 struct wireless_dev *wdev = dev->ieee80211_ptr;
11327 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011328
Johannes Berg947add32013-02-22 22:05:20 +010011329 trace_cfg80211_rx_spurious_frame(dev, addr);
11330
11331 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11332 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11333 trace_cfg80211_return_bool(false);
11334 return false;
11335 }
11336 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11337 addr, gfp);
11338 trace_cfg80211_return_bool(ret);
11339 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011340}
Johannes Berg947add32013-02-22 22:05:20 +010011341EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11342
11343bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11344 const u8 *addr, gfp_t gfp)
11345{
11346 struct wireless_dev *wdev = dev->ieee80211_ptr;
11347 bool ret;
11348
11349 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11350
11351 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11352 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11353 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11354 trace_cfg80211_return_bool(false);
11355 return false;
11356 }
11357 ret = __nl80211_unexpected_frame(dev,
11358 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11359 addr, gfp);
11360 trace_cfg80211_return_bool(ret);
11361 return ret;
11362}
11363EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011364
Johannes Berg2e161f782010-08-12 15:38:38 +020011365int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011366 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011367 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011368 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011369{
Johannes Berg71bbc992012-06-15 15:30:18 +020011370 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011371 struct sk_buff *msg;
11372 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011373
11374 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11375 if (!msg)
11376 return -ENOMEM;
11377
Johannes Berg2e161f782010-08-12 15:38:38 +020011378 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011379 if (!hdr) {
11380 nlmsg_free(msg);
11381 return -ENOMEM;
11382 }
11383
David S. Miller9360ffd2012-03-29 04:41:26 -040011384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011385 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11386 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011387 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011388 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11389 (sig_dbm &&
11390 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011391 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11392 (flags &&
11393 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011394 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011395
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011396 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011397
Eric W. Biederman15e47302012-09-07 20:12:54 +000011398 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011399
11400 nla_put_failure:
11401 genlmsg_cancel(msg, hdr);
11402 nlmsg_free(msg);
11403 return -ENOBUFS;
11404}
11405
Johannes Berg947add32013-02-22 22:05:20 +010011406void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11407 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011408{
Johannes Berg947add32013-02-22 22:05:20 +010011409 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011410 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011411 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011412 struct sk_buff *msg;
11413 void *hdr;
11414
Johannes Berg947add32013-02-22 22:05:20 +010011415 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11416
Jouni Malinen026331c2010-02-15 12:53:10 +020011417 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11418 if (!msg)
11419 return;
11420
Johannes Berg2e161f782010-08-12 15:38:38 +020011421 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011422 if (!hdr) {
11423 nlmsg_free(msg);
11424 return;
11425 }
11426
David S. Miller9360ffd2012-03-29 04:41:26 -040011427 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011428 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11429 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011430 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011431 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11432 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11433 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11434 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011435
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011436 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011437
Johannes Berg68eb5502013-11-19 15:19:38 +010011438 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011439 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011440 return;
11441
11442 nla_put_failure:
11443 genlmsg_cancel(msg, hdr);
11444 nlmsg_free(msg);
11445}
Johannes Berg947add32013-02-22 22:05:20 +010011446EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011447
Johannes Berg947add32013-02-22 22:05:20 +010011448void cfg80211_cqm_rssi_notify(struct net_device *dev,
11449 enum nl80211_cqm_rssi_threshold_event rssi_event,
11450 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011451{
Johannes Berg947add32013-02-22 22:05:20 +010011452 struct wireless_dev *wdev = dev->ieee80211_ptr;
11453 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011454 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011455 struct sk_buff *msg;
11456 struct nlattr *pinfoattr;
11457 void *hdr;
11458
Johannes Berg947add32013-02-22 22:05:20 +010011459 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11460
Thomas Graf58050fc2012-06-28 03:57:45 +000011461 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011462 if (!msg)
11463 return;
11464
11465 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11466 if (!hdr) {
11467 nlmsg_free(msg);
11468 return;
11469 }
11470
David S. Miller9360ffd2012-03-29 04:41:26 -040011471 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011472 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011473 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011474
11475 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11476 if (!pinfoattr)
11477 goto nla_put_failure;
11478
David S. Miller9360ffd2012-03-29 04:41:26 -040011479 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11480 rssi_event))
11481 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011482
11483 nla_nest_end(msg, pinfoattr);
11484
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011485 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011486
Johannes Berg68eb5502013-11-19 15:19:38 +010011487 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011488 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011489 return;
11490
11491 nla_put_failure:
11492 genlmsg_cancel(msg, hdr);
11493 nlmsg_free(msg);
11494}
Johannes Berg947add32013-02-22 22:05:20 +010011495EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011496
Johannes Berg947add32013-02-22 22:05:20 +010011497static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11498 struct net_device *netdev, const u8 *bssid,
11499 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011500{
11501 struct sk_buff *msg;
11502 struct nlattr *rekey_attr;
11503 void *hdr;
11504
Thomas Graf58050fc2012-06-28 03:57:45 +000011505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011506 if (!msg)
11507 return;
11508
11509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11510 if (!hdr) {
11511 nlmsg_free(msg);
11512 return;
11513 }
11514
David S. Miller9360ffd2012-03-29 04:41:26 -040011515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11517 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11518 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011519
11520 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11521 if (!rekey_attr)
11522 goto nla_put_failure;
11523
David S. Miller9360ffd2012-03-29 04:41:26 -040011524 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11525 NL80211_REPLAY_CTR_LEN, replay_ctr))
11526 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011527
11528 nla_nest_end(msg, rekey_attr);
11529
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011530 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011531
Johannes Berg68eb5502013-11-19 15:19:38 +010011532 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011533 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011534 return;
11535
11536 nla_put_failure:
11537 genlmsg_cancel(msg, hdr);
11538 nlmsg_free(msg);
11539}
11540
Johannes Berg947add32013-02-22 22:05:20 +010011541void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11542 const u8 *replay_ctr, gfp_t gfp)
11543{
11544 struct wireless_dev *wdev = dev->ieee80211_ptr;
11545 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011546 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011547
11548 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11549 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11550}
11551EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11552
11553static void
11554nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11555 struct net_device *netdev, int index,
11556 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011557{
11558 struct sk_buff *msg;
11559 struct nlattr *attr;
11560 void *hdr;
11561
Thomas Graf58050fc2012-06-28 03:57:45 +000011562 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011563 if (!msg)
11564 return;
11565
11566 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11567 if (!hdr) {
11568 nlmsg_free(msg);
11569 return;
11570 }
11571
David S. Miller9360ffd2012-03-29 04:41:26 -040011572 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11573 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11574 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011575
11576 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11577 if (!attr)
11578 goto nla_put_failure;
11579
David S. Miller9360ffd2012-03-29 04:41:26 -040011580 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11581 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11582 (preauth &&
11583 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11584 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011585
11586 nla_nest_end(msg, attr);
11587
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011588 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011589
Johannes Berg68eb5502013-11-19 15:19:38 +010011590 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011591 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011592 return;
11593
11594 nla_put_failure:
11595 genlmsg_cancel(msg, hdr);
11596 nlmsg_free(msg);
11597}
11598
Johannes Berg947add32013-02-22 22:05:20 +010011599void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11600 const u8 *bssid, bool preauth, gfp_t gfp)
11601{
11602 struct wireless_dev *wdev = dev->ieee80211_ptr;
11603 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011604 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011605
11606 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11607 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11608}
11609EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11610
11611static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11612 struct net_device *netdev,
11613 struct cfg80211_chan_def *chandef,
11614 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011615{
11616 struct sk_buff *msg;
11617 void *hdr;
11618
Thomas Graf58050fc2012-06-28 03:57:45 +000011619 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011620 if (!msg)
11621 return;
11622
11623 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11624 if (!hdr) {
11625 nlmsg_free(msg);
11626 return;
11627 }
11628
Johannes Berg683b6d32012-11-08 21:25:48 +010011629 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11630 goto nla_put_failure;
11631
11632 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011633 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011634
11635 genlmsg_end(msg, hdr);
11636
Johannes Berg68eb5502013-11-19 15:19:38 +010011637 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011638 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011639 return;
11640
11641 nla_put_failure:
11642 genlmsg_cancel(msg, hdr);
11643 nlmsg_free(msg);
11644}
11645
Johannes Berg947add32013-02-22 22:05:20 +010011646void cfg80211_ch_switch_notify(struct net_device *dev,
11647 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011648{
Johannes Berg947add32013-02-22 22:05:20 +010011649 struct wireless_dev *wdev = dev->ieee80211_ptr;
11650 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011651 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011652
Simon Wunderliche487eae2013-11-21 18:19:51 +010011653 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011654
Simon Wunderliche487eae2013-11-21 18:19:51 +010011655 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011656
11657 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011658 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011659 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11660 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011661 return;
Johannes Berg947add32013-02-22 22:05:20 +010011662
Michal Kazior9e0e2962014-01-29 14:22:27 +010011663 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011664 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011665 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011666}
11667EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11668
11669void cfg80211_cqm_txe_notify(struct net_device *dev,
11670 const u8 *peer, u32 num_packets,
11671 u32 rate, u32 intvl, gfp_t gfp)
11672{
11673 struct wireless_dev *wdev = dev->ieee80211_ptr;
11674 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011675 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011676 struct sk_buff *msg;
11677 struct nlattr *pinfoattr;
11678 void *hdr;
11679
11680 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11681 if (!msg)
11682 return;
11683
11684 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11685 if (!hdr) {
11686 nlmsg_free(msg);
11687 return;
11688 }
11689
11690 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011692 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11693 goto nla_put_failure;
11694
11695 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11696 if (!pinfoattr)
11697 goto nla_put_failure;
11698
11699 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11700 goto nla_put_failure;
11701
11702 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11703 goto nla_put_failure;
11704
11705 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11706 goto nla_put_failure;
11707
11708 nla_nest_end(msg, pinfoattr);
11709
11710 genlmsg_end(msg, hdr);
11711
Johannes Berg68eb5502013-11-19 15:19:38 +010011712 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011713 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011714 return;
11715
11716 nla_put_failure:
11717 genlmsg_cancel(msg, hdr);
11718 nlmsg_free(msg);
11719}
Johannes Berg947add32013-02-22 22:05:20 +010011720EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011721
11722void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011723nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011724 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011725 enum nl80211_radar_event event,
11726 struct net_device *netdev, gfp_t gfp)
11727{
11728 struct sk_buff *msg;
11729 void *hdr;
11730
11731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11732 if (!msg)
11733 return;
11734
11735 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11736 if (!hdr) {
11737 nlmsg_free(msg);
11738 return;
11739 }
11740
11741 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11742 goto nla_put_failure;
11743
11744 /* NOP and radar events don't need a netdev parameter */
11745 if (netdev) {
11746 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11747
11748 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11749 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11750 goto nla_put_failure;
11751 }
11752
11753 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11754 goto nla_put_failure;
11755
11756 if (nl80211_send_chandef(msg, chandef))
11757 goto nla_put_failure;
11758
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011759 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011760
Johannes Berg68eb5502013-11-19 15:19:38 +010011761 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011762 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011763 return;
11764
11765 nla_put_failure:
11766 genlmsg_cancel(msg, hdr);
11767 nlmsg_free(msg);
11768}
11769
Johannes Berg947add32013-02-22 22:05:20 +010011770void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11771 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011772{
Johannes Berg947add32013-02-22 22:05:20 +010011773 struct wireless_dev *wdev = dev->ieee80211_ptr;
11774 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011775 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011776 struct sk_buff *msg;
11777 struct nlattr *pinfoattr;
11778 void *hdr;
11779
Johannes Berg947add32013-02-22 22:05:20 +010011780 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11781
Thomas Graf58050fc2012-06-28 03:57:45 +000011782 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011783 if (!msg)
11784 return;
11785
11786 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11787 if (!hdr) {
11788 nlmsg_free(msg);
11789 return;
11790 }
11791
David S. Miller9360ffd2012-03-29 04:41:26 -040011792 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011793 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011794 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11795 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011796
11797 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11798 if (!pinfoattr)
11799 goto nla_put_failure;
11800
David S. Miller9360ffd2012-03-29 04:41:26 -040011801 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11802 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011803
11804 nla_nest_end(msg, pinfoattr);
11805
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011806 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011807
Johannes Berg68eb5502013-11-19 15:19:38 +010011808 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011809 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011810 return;
11811
11812 nla_put_failure:
11813 genlmsg_cancel(msg, hdr);
11814 nlmsg_free(msg);
11815}
Johannes Berg947add32013-02-22 22:05:20 +010011816EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011817
Johannes Berg7f6cf312011-11-04 11:18:15 +010011818void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11819 u64 cookie, bool acked, gfp_t gfp)
11820{
11821 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011822 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011823 struct sk_buff *msg;
11824 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011825
Beni Lev4ee3e062012-08-27 12:49:39 +030011826 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11827
Thomas Graf58050fc2012-06-28 03:57:45 +000011828 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011829
Johannes Berg7f6cf312011-11-04 11:18:15 +010011830 if (!msg)
11831 return;
11832
11833 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11834 if (!hdr) {
11835 nlmsg_free(msg);
11836 return;
11837 }
11838
David S. Miller9360ffd2012-03-29 04:41:26 -040011839 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11840 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11841 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11842 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11843 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11844 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011845
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011846 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011847
Johannes Berg68eb5502013-11-19 15:19:38 +010011848 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011849 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011850 return;
11851
11852 nla_put_failure:
11853 genlmsg_cancel(msg, hdr);
11854 nlmsg_free(msg);
11855}
11856EXPORT_SYMBOL(cfg80211_probe_status);
11857
Johannes Berg5e760232011-11-04 11:18:17 +010011858void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11859 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011860 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011861{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011862 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011863 struct sk_buff *msg;
11864 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011865 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011866
Beni Lev4ee3e062012-08-27 12:49:39 +030011867 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11868
Ben Greear37c73b52012-10-26 14:49:25 -070011869 spin_lock_bh(&rdev->beacon_registrations_lock);
11870 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11871 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11872 if (!msg) {
11873 spin_unlock_bh(&rdev->beacon_registrations_lock);
11874 return;
11875 }
Johannes Berg5e760232011-11-04 11:18:17 +010011876
Ben Greear37c73b52012-10-26 14:49:25 -070011877 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11878 if (!hdr)
11879 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011880
Ben Greear37c73b52012-10-26 14:49:25 -070011881 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11882 (freq &&
11883 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11884 (sig_dbm &&
11885 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11886 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11887 goto nla_put_failure;
11888
11889 genlmsg_end(msg, hdr);
11890
11891 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011892 }
Ben Greear37c73b52012-10-26 14:49:25 -070011893 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011894 return;
11895
11896 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011897 spin_unlock_bh(&rdev->beacon_registrations_lock);
11898 if (hdr)
11899 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011900 nlmsg_free(msg);
11901}
11902EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11903
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011904#ifdef CONFIG_PM
11905void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11906 struct cfg80211_wowlan_wakeup *wakeup,
11907 gfp_t gfp)
11908{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011909 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011910 struct sk_buff *msg;
11911 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011912 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011913
11914 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11915
11916 if (wakeup)
11917 size += wakeup->packet_present_len;
11918
11919 msg = nlmsg_new(size, gfp);
11920 if (!msg)
11921 return;
11922
11923 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11924 if (!hdr)
11925 goto free_msg;
11926
11927 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11928 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11929 goto free_msg;
11930
11931 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11932 wdev->netdev->ifindex))
11933 goto free_msg;
11934
11935 if (wakeup) {
11936 struct nlattr *reasons;
11937
11938 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011939 if (!reasons)
11940 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011941
11942 if (wakeup->disconnect &&
11943 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11944 goto free_msg;
11945 if (wakeup->magic_pkt &&
11946 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11947 goto free_msg;
11948 if (wakeup->gtk_rekey_failure &&
11949 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11950 goto free_msg;
11951 if (wakeup->eap_identity_req &&
11952 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11953 goto free_msg;
11954 if (wakeup->four_way_handshake &&
11955 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11956 goto free_msg;
11957 if (wakeup->rfkill_release &&
11958 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11959 goto free_msg;
11960
11961 if (wakeup->pattern_idx >= 0 &&
11962 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11963 wakeup->pattern_idx))
11964 goto free_msg;
11965
Johannes Bergae917c92013-10-25 11:05:22 +020011966 if (wakeup->tcp_match &&
11967 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11968 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011969
Johannes Bergae917c92013-10-25 11:05:22 +020011970 if (wakeup->tcp_connlost &&
11971 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11972 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011973
Johannes Bergae917c92013-10-25 11:05:22 +020011974 if (wakeup->tcp_nomoretokens &&
11975 nla_put_flag(msg,
11976 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11977 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011978
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011979 if (wakeup->packet) {
11980 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11981 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11982
11983 if (!wakeup->packet_80211) {
11984 pkt_attr =
11985 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11986 len_attr =
11987 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11988 }
11989
11990 if (wakeup->packet_len &&
11991 nla_put_u32(msg, len_attr, wakeup->packet_len))
11992 goto free_msg;
11993
11994 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11995 wakeup->packet))
11996 goto free_msg;
11997 }
11998
11999 nla_nest_end(msg, reasons);
12000 }
12001
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012002 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012003
Johannes Berg68eb5502013-11-19 15:19:38 +010012004 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012005 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012006 return;
12007
12008 free_msg:
12009 nlmsg_free(msg);
12010}
12011EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12012#endif
12013
Jouni Malinen3475b092012-11-16 22:49:57 +020012014void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12015 enum nl80211_tdls_operation oper,
12016 u16 reason_code, gfp_t gfp)
12017{
12018 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012019 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012020 struct sk_buff *msg;
12021 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012022
12023 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12024 reason_code);
12025
12026 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12027 if (!msg)
12028 return;
12029
12030 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12031 if (!hdr) {
12032 nlmsg_free(msg);
12033 return;
12034 }
12035
12036 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12037 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12038 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12039 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12040 (reason_code > 0 &&
12041 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12042 goto nla_put_failure;
12043
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012044 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012045
Johannes Berg68eb5502013-11-19 15:19:38 +010012046 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012047 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012048 return;
12049
12050 nla_put_failure:
12051 genlmsg_cancel(msg, hdr);
12052 nlmsg_free(msg);
12053}
12054EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12055
Jouni Malinen026331c2010-02-15 12:53:10 +020012056static int nl80211_netlink_notify(struct notifier_block * nb,
12057 unsigned long state,
12058 void *_notify)
12059{
12060 struct netlink_notify *notify = _notify;
12061 struct cfg80211_registered_device *rdev;
12062 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012063 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012064
12065 if (state != NETLINK_URELEASE)
12066 return NOTIFY_DONE;
12067
12068 rcu_read_lock();
12069
Johannes Berg5e760232011-11-04 11:18:17 +010012070 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012071 bool schedule_destroy_work = false;
12072
12073 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012074 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012075
Johannes Berg78f22b62014-03-24 17:57:27 +010012076 if (wdev->owner_nlportid == notify->portid)
12077 schedule_destroy_work = true;
12078 }
12079
Ben Greear37c73b52012-10-26 14:49:25 -070012080 spin_lock_bh(&rdev->beacon_registrations_lock);
12081 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12082 list) {
12083 if (reg->nlportid == notify->portid) {
12084 list_del(&reg->list);
12085 kfree(reg);
12086 break;
12087 }
12088 }
12089 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012090
12091 if (schedule_destroy_work) {
12092 struct cfg80211_iface_destroy *destroy;
12093
12094 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12095 if (destroy) {
12096 destroy->nlportid = notify->portid;
12097 spin_lock(&rdev->destroy_list_lock);
12098 list_add(&destroy->list, &rdev->destroy_list);
12099 spin_unlock(&rdev->destroy_list_lock);
12100 schedule_work(&rdev->destroy_work);
12101 }
12102 }
Johannes Berg5e760232011-11-04 11:18:17 +010012103 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012104
12105 rcu_read_unlock();
12106
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012107 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012108}
12109
12110static struct notifier_block nl80211_netlink_notifier = {
12111 .notifier_call = nl80211_netlink_notify,
12112};
12113
Jouni Malinen355199e2013-02-27 17:14:27 +020012114void cfg80211_ft_event(struct net_device *netdev,
12115 struct cfg80211_ft_event_params *ft_event)
12116{
12117 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012118 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012119 struct sk_buff *msg;
12120 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012121
12122 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12123
12124 if (!ft_event->target_ap)
12125 return;
12126
12127 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12128 if (!msg)
12129 return;
12130
12131 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012132 if (!hdr)
12133 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012134
Johannes Bergae917c92013-10-25 11:05:22 +020012135 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12136 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12137 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12138 goto out;
12139
12140 if (ft_event->ies &&
12141 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12142 goto out;
12143 if (ft_event->ric_ies &&
12144 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12145 ft_event->ric_ies))
12146 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012147
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012148 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012149
Johannes Berg68eb5502013-11-19 15:19:38 +010012150 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012151 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012152 return;
12153 out:
12154 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012155}
12156EXPORT_SYMBOL(cfg80211_ft_event);
12157
Arend van Spriel5de17982013-04-18 15:49:00 +020012158void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12159{
12160 struct cfg80211_registered_device *rdev;
12161 struct sk_buff *msg;
12162 void *hdr;
12163 u32 nlportid;
12164
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012165 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012166 if (!rdev->crit_proto_nlportid)
12167 return;
12168
12169 nlportid = rdev->crit_proto_nlportid;
12170 rdev->crit_proto_nlportid = 0;
12171
12172 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12173 if (!msg)
12174 return;
12175
12176 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12177 if (!hdr)
12178 goto nla_put_failure;
12179
12180 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12181 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12182 goto nla_put_failure;
12183
12184 genlmsg_end(msg, hdr);
12185
12186 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12187 return;
12188
12189 nla_put_failure:
12190 if (hdr)
12191 genlmsg_cancel(msg, hdr);
12192 nlmsg_free(msg);
12193
12194}
12195EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12196
Johannes Berg348baf02014-01-24 14:06:29 +010012197void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12198{
12199 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012200 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012201 struct sk_buff *msg;
12202 void *hdr;
12203
12204 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12205 if (!msg)
12206 return;
12207
12208 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12209 if (!hdr)
12210 goto out;
12211
12212 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12213 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12214 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12215 goto out;
12216
12217 genlmsg_end(msg, hdr);
12218
12219 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12220 NL80211_MCGRP_MLME, GFP_KERNEL);
12221 return;
12222 out:
12223 nlmsg_free(msg);
12224}
12225
Johannes Berg55682962007-09-20 13:09:35 -040012226/* initialisation/exit functions */
12227
12228int nl80211_init(void)
12229{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012230 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012231
Johannes Berg2a94fe42013-11-19 15:19:39 +010012232 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12233 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012234 if (err)
12235 return err;
12236
Jouni Malinen026331c2010-02-15 12:53:10 +020012237 err = netlink_register_notifier(&nl80211_netlink_notifier);
12238 if (err)
12239 goto err_out;
12240
Johannes Berg55682962007-09-20 13:09:35 -040012241 return 0;
12242 err_out:
12243 genl_unregister_family(&nl80211_fam);
12244 return err;
12245}
12246
12247void nl80211_exit(void)
12248{
Jouni Malinen026331c2010-02-15 12:53:10 +020012249 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012250 genl_unregister_family(&nl80211_fam);
12251}