blob: 459dc2769d0ead4a5cdb836fc19a128b376e8ea6 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
62 [NL80211_MCGRP_CONFIG] = { .name = "config", },
63 [NL80211_MCGRP_SCAN] = { .name = "scan", },
64 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
65 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010066 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
68 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
69#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000212static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400229
230 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100233
Eliad Pellere007b852011-11-24 18:13:56 +0200234 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
235 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100236
Johannes Bergb9454e82009-07-08 13:29:08 +0200237 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100238 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
239 .len = WLAN_MAX_KEY_LEN },
240 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
241 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
242 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200243 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200244 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100245
246 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
247 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
248 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
249 .len = IEEE80211_MAX_DATA_LEN },
250 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100252 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
253 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
254 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
255 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
256 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100257 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100258 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200259 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100260 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800261 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300263
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700264 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
265 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
266
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300267 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200270 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
271 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100272 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300273
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800274 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700275 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700276
Johannes Berg6c739412011-11-03 09:27:01 +0100277 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200278
279 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
280 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
281 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100282 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
283 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200284
285 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
286 .len = IEEE80211_MAX_SSID_LEN },
287 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
288 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200289 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300290 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300291 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300292 [NL80211_ATTR_STA_FLAGS2] = {
293 .len = sizeof(struct nl80211_sta_flag_update),
294 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300295 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300296 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
297 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200298 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
299 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
300 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200301 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100302 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100303 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
304 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100305 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
306 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200307 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200308 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
309 .len = IEEE80211_MAX_DATA_LEN },
310 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200311 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200312 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300313 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200314 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300315 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
316 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200317 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900318 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
319 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100320 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100321 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100322 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200323 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700324 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300325 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200326 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200327 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300328 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300329 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
330 .len = IEEE80211_MAX_DATA_LEN },
331 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
332 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530333 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300334 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530335 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300336 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
340 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300341 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100342 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200343 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
344 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700345 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800346 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
347 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
348 .len = NL80211_HT_CAPABILITY_LEN
349 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100350 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530351 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530352 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200353 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700354 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300355 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000356 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700357 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100358 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
359 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530360 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
361 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200362 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
363 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100364 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100365 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
366 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
367 .len = NL80211_VHT_CAPABILITY_LEN,
368 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200369 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
370 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
371 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300372 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200373 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
374 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
375 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300376 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
377 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530378 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
379 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200380 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100381 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100382 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
383 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800385 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
386 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200387 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
388 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530389 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Johannes Berg78f22b62014-03-24 17:57:27 +0100390 [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300391 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300392 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400393};
394
Johannes Berge31b8212010-10-05 19:39:30 +0200395/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000396static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200397 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200398 [NL80211_KEY_IDX] = { .type = NLA_U8 },
399 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200400 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200401 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
402 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200403 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100404 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
405};
406
407/* policy for the key default flags */
408static const struct nla_policy
409nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
410 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
411 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200412};
413
Johannes Bergff1b6e62011-05-04 15:37:28 +0200414/* policy for WoWLAN attributes */
415static const struct nla_policy
416nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
417 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
419 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
420 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200421 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
422 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
423 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
424 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100425 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
426};
427
428static const struct nla_policy
429nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
430 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
431 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
432 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
433 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
434 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
435 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
436 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
437 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
438 },
439 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
440 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
441 },
442 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
443 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
444 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200445};
446
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700447/* policy for coalesce rule attributes */
448static const struct nla_policy
449nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
450 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
451 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
452 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
453};
454
Johannes Berge5497d72011-07-05 16:35:40 +0200455/* policy for GTK rekey offload attributes */
456static const struct nla_policy
457nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
458 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
459 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
460 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
461};
462
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300463static const struct nla_policy
464nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200465 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300466 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700467 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300468};
469
Johannes Berg97990a02013-04-19 01:02:55 +0200470static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
471 struct netlink_callback *cb,
472 struct cfg80211_registered_device **rdev,
473 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100474{
Johannes Berg67748892010-10-04 21:14:06 +0200475 int err;
476
Johannes Berg67748892010-10-04 21:14:06 +0200477 rtnl_lock();
478
Johannes Berg97990a02013-04-19 01:02:55 +0200479 if (!cb->args[0]) {
480 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
481 nl80211_fam.attrbuf, nl80211_fam.maxattr,
482 nl80211_policy);
483 if (err)
484 goto out_unlock;
485
486 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
487 nl80211_fam.attrbuf);
488 if (IS_ERR(*wdev)) {
489 err = PTR_ERR(*wdev);
490 goto out_unlock;
491 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800492 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200493 /* 0 is the first index - add 1 to parse only once */
494 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200495 cb->args[1] = (*wdev)->identifier;
496 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200497 /* subtract the 1 again here */
498 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200499 struct wireless_dev *tmp;
500
501 if (!wiphy) {
502 err = -ENODEV;
503 goto out_unlock;
504 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800505 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200506 *wdev = NULL;
507
Johannes Berg97990a02013-04-19 01:02:55 +0200508 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
509 if (tmp->identifier == cb->args[1]) {
510 *wdev = tmp;
511 break;
512 }
513 }
Johannes Berg97990a02013-04-19 01:02:55 +0200514
515 if (!*wdev) {
516 err = -ENODEV;
517 goto out_unlock;
518 }
Johannes Berg67748892010-10-04 21:14:06 +0200519 }
520
Johannes Berg67748892010-10-04 21:14:06 +0200521 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200522 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200523 rtnl_unlock();
524 return err;
525}
526
Johannes Berg97990a02013-04-19 01:02:55 +0200527static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200528{
Johannes Berg67748892010-10-04 21:14:06 +0200529 rtnl_unlock();
530}
531
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100532/* IE validation */
533static bool is_valid_ie_attr(const struct nlattr *attr)
534{
535 const u8 *pos;
536 int len;
537
538 if (!attr)
539 return true;
540
541 pos = nla_data(attr);
542 len = nla_len(attr);
543
544 while (len) {
545 u8 elemlen;
546
547 if (len < 2)
548 return false;
549 len -= 2;
550
551 elemlen = pos[1];
552 if (elemlen > len)
553 return false;
554
555 len -= elemlen;
556 pos += 2 + elemlen;
557 }
558
559 return true;
560}
561
Johannes Berg55682962007-09-20 13:09:35 -0400562/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000563static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400564 int flags, u8 cmd)
565{
566 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000567 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400568}
569
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400570static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100571 struct ieee80211_channel *chan,
572 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400573{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200574 /* Some channels must be completely excluded from the
575 * list to protect old user-space tools from breaking
576 */
577 if (!large && chan->flags &
578 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
579 return 0;
580
David S. Miller9360ffd2012-03-29 04:41:26 -0400581 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
582 chan->center_freq))
583 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400584
David S. Miller9360ffd2012-03-29 04:41:26 -0400585 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
586 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
587 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200588 if (chan->flags & IEEE80211_CHAN_NO_IR) {
589 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
590 goto nla_put_failure;
591 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
592 goto nla_put_failure;
593 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100594 if (chan->flags & IEEE80211_CHAN_RADAR) {
595 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
596 goto nla_put_failure;
597 if (large) {
598 u32 time;
599
600 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
601
602 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
603 chan->dfs_state))
604 goto nla_put_failure;
605 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
606 time))
607 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100608 if (nla_put_u32(msg,
609 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
610 chan->dfs_cac_ms))
611 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100612 }
613 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400614
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100615 if (large) {
616 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
617 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
618 goto nla_put_failure;
619 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
620 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
621 goto nla_put_failure;
622 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
623 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
624 goto nla_put_failure;
625 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
626 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
627 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200628 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
629 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
630 goto nla_put_failure;
631 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
632 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
633 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200634 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
635 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
636 goto nla_put_failure;
637 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
638 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
639 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100640 }
641
David S. Miller9360ffd2012-03-29 04:41:26 -0400642 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
643 DBM_TO_MBM(chan->max_power)))
644 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400645
646 return 0;
647
648 nla_put_failure:
649 return -ENOBUFS;
650}
651
Johannes Berg55682962007-09-20 13:09:35 -0400652/* netlink command implementations */
653
Johannes Bergb9454e82009-07-08 13:29:08 +0200654struct key_parse {
655 struct key_params p;
656 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200657 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200658 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100659 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200660};
661
662static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
663{
664 struct nlattr *tb[NL80211_KEY_MAX + 1];
665 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
666 nl80211_key_policy);
667 if (err)
668 return err;
669
670 k->def = !!tb[NL80211_KEY_DEFAULT];
671 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
672
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100673 if (k->def) {
674 k->def_uni = true;
675 k->def_multi = true;
676 }
677 if (k->defmgmt)
678 k->def_multi = true;
679
Johannes Bergb9454e82009-07-08 13:29:08 +0200680 if (tb[NL80211_KEY_IDX])
681 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
682
683 if (tb[NL80211_KEY_DATA]) {
684 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
685 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
686 }
687
688 if (tb[NL80211_KEY_SEQ]) {
689 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
690 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
691 }
692
693 if (tb[NL80211_KEY_CIPHER])
694 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
695
Johannes Berge31b8212010-10-05 19:39:30 +0200696 if (tb[NL80211_KEY_TYPE]) {
697 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
698 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
699 return -EINVAL;
700 }
701
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100702 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
703 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100704 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
705 tb[NL80211_KEY_DEFAULT_TYPES],
706 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100707 if (err)
708 return err;
709
710 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
711 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
712 }
713
Johannes Bergb9454e82009-07-08 13:29:08 +0200714 return 0;
715}
716
717static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
718{
719 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
720 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
721 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
722 }
723
724 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
725 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
726 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
727 }
728
729 if (info->attrs[NL80211_ATTR_KEY_IDX])
730 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
731
732 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
733 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
734
735 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
736 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
737
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100738 if (k->def) {
739 k->def_uni = true;
740 k->def_multi = true;
741 }
742 if (k->defmgmt)
743 k->def_multi = true;
744
Johannes Berge31b8212010-10-05 19:39:30 +0200745 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
746 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
747 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
748 return -EINVAL;
749 }
750
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100751 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
752 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
753 int err = nla_parse_nested(
754 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
755 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
756 nl80211_key_default_policy);
757 if (err)
758 return err;
759
760 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
761 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
762 }
763
Johannes Bergb9454e82009-07-08 13:29:08 +0200764 return 0;
765}
766
767static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
768{
769 int err;
770
771 memset(k, 0, sizeof(*k));
772 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200773 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200774
775 if (info->attrs[NL80211_ATTR_KEY])
776 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
777 else
778 err = nl80211_parse_key_old(info, k);
779
780 if (err)
781 return err;
782
783 if (k->def && k->defmgmt)
784 return -EINVAL;
785
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100786 if (k->defmgmt) {
787 if (k->def_uni || !k->def_multi)
788 return -EINVAL;
789 }
790
Johannes Bergb9454e82009-07-08 13:29:08 +0200791 if (k->idx != -1) {
792 if (k->defmgmt) {
793 if (k->idx < 4 || k->idx > 5)
794 return -EINVAL;
795 } else if (k->def) {
796 if (k->idx < 0 || k->idx > 3)
797 return -EINVAL;
798 } else {
799 if (k->idx < 0 || k->idx > 5)
800 return -EINVAL;
801 }
802 }
803
804 return 0;
805}
806
Johannes Bergfffd0932009-07-08 14:22:54 +0200807static struct cfg80211_cached_keys *
808nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530809 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200810{
811 struct key_parse parse;
812 struct nlattr *key;
813 struct cfg80211_cached_keys *result;
814 int rem, err, def = 0;
815
816 result = kzalloc(sizeof(*result), GFP_KERNEL);
817 if (!result)
818 return ERR_PTR(-ENOMEM);
819
820 result->def = -1;
821 result->defmgmt = -1;
822
823 nla_for_each_nested(key, keys, rem) {
824 memset(&parse, 0, sizeof(parse));
825 parse.idx = -1;
826
827 err = nl80211_parse_key_new(key, &parse);
828 if (err)
829 goto error;
830 err = -EINVAL;
831 if (!parse.p.key)
832 goto error;
833 if (parse.idx < 0 || parse.idx > 4)
834 goto error;
835 if (parse.def) {
836 if (def)
837 goto error;
838 def = 1;
839 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100840 if (!parse.def_uni || !parse.def_multi)
841 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200842 } else if (parse.defmgmt)
843 goto error;
844 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200845 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200846 if (err)
847 goto error;
848 result->params[parse.idx].cipher = parse.p.cipher;
849 result->params[parse.idx].key_len = parse.p.key_len;
850 result->params[parse.idx].key = result->data[parse.idx];
851 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530852
853 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
854 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
855 if (no_ht)
856 *no_ht = true;
857 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200858 }
859
860 return result;
861 error:
862 kfree(result);
863 return ERR_PTR(err);
864}
865
866static int nl80211_key_allowed(struct wireless_dev *wdev)
867{
868 ASSERT_WDEV_LOCK(wdev);
869
Johannes Bergfffd0932009-07-08 14:22:54 +0200870 switch (wdev->iftype) {
871 case NL80211_IFTYPE_AP:
872 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200873 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700874 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200875 break;
876 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200877 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200878 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200879 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200880 return -ENOLINK;
881 break;
882 default:
883 return -EINVAL;
884 }
885
886 return 0;
887}
888
Jouni Malinen664834d2014-01-15 00:01:44 +0200889static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
890 struct nlattr *tb)
891{
892 struct ieee80211_channel *chan;
893
894 if (tb == NULL)
895 return NULL;
896 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
897 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
898 return NULL;
899 return chan;
900}
901
Johannes Berg7527a782011-05-13 10:58:57 +0200902static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
903{
904 struct nlattr *nl_modes = nla_nest_start(msg, attr);
905 int i;
906
907 if (!nl_modes)
908 goto nla_put_failure;
909
910 i = 0;
911 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400912 if ((ifmodes & 1) && nla_put_flag(msg, i))
913 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200914 ifmodes >>= 1;
915 i++;
916 }
917
918 nla_nest_end(msg, nl_modes);
919 return 0;
920
921nla_put_failure:
922 return -ENOBUFS;
923}
924
925static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100926 struct sk_buff *msg,
927 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200928{
929 struct nlattr *nl_combis;
930 int i, j;
931
932 nl_combis = nla_nest_start(msg,
933 NL80211_ATTR_INTERFACE_COMBINATIONS);
934 if (!nl_combis)
935 goto nla_put_failure;
936
937 for (i = 0; i < wiphy->n_iface_combinations; i++) {
938 const struct ieee80211_iface_combination *c;
939 struct nlattr *nl_combi, *nl_limits;
940
941 c = &wiphy->iface_combinations[i];
942
943 nl_combi = nla_nest_start(msg, i + 1);
944 if (!nl_combi)
945 goto nla_put_failure;
946
947 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
948 if (!nl_limits)
949 goto nla_put_failure;
950
951 for (j = 0; j < c->n_limits; j++) {
952 struct nlattr *nl_limit;
953
954 nl_limit = nla_nest_start(msg, j + 1);
955 if (!nl_limit)
956 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400957 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
958 c->limits[j].max))
959 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200960 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
961 c->limits[j].types))
962 goto nla_put_failure;
963 nla_nest_end(msg, nl_limit);
964 }
965
966 nla_nest_end(msg, nl_limits);
967
David S. Miller9360ffd2012-03-29 04:41:26 -0400968 if (c->beacon_int_infra_match &&
969 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
970 goto nla_put_failure;
971 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
972 c->num_different_channels) ||
973 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
974 c->max_interfaces))
975 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100976 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200977 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
978 c->radar_detect_widths) ||
979 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
980 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100981 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200982
983 nla_nest_end(msg, nl_combi);
984 }
985
986 nla_nest_end(msg, nl_combis);
987
988 return 0;
989nla_put_failure:
990 return -ENOBUFS;
991}
992
Johannes Berg3713b4e2013-02-14 16:19:38 +0100993#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100994static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
995 struct sk_buff *msg)
996{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200997 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100998 struct nlattr *nl_tcp;
999
1000 if (!tcp)
1001 return 0;
1002
1003 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1004 if (!nl_tcp)
1005 return -ENOBUFS;
1006
1007 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1008 tcp->data_payload_max))
1009 return -ENOBUFS;
1010
1011 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1012 tcp->data_payload_max))
1013 return -ENOBUFS;
1014
1015 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1016 return -ENOBUFS;
1017
1018 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1019 sizeof(*tcp->tok), tcp->tok))
1020 return -ENOBUFS;
1021
1022 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1023 tcp->data_interval_max))
1024 return -ENOBUFS;
1025
1026 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1027 tcp->wake_payload_max))
1028 return -ENOBUFS;
1029
1030 nla_nest_end(msg, nl_tcp);
1031 return 0;
1032}
1033
Johannes Berg3713b4e2013-02-14 16:19:38 +01001034static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001035 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001036 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001037{
1038 struct nlattr *nl_wowlan;
1039
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001040 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001041 return 0;
1042
1043 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1044 if (!nl_wowlan)
1045 return -ENOBUFS;
1046
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001047 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001049 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001052 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001053 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001055 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001056 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001057 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001058 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001061 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001062 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1063 return -ENOBUFS;
1064
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001066 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1068 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1069 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1070 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071 };
1072
1073 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1074 sizeof(pat), &pat))
1075 return -ENOBUFS;
1076 }
1077
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001078 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001079 return -ENOBUFS;
1080
Johannes Berg3713b4e2013-02-14 16:19:38 +01001081 nla_nest_end(msg, nl_wowlan);
1082
1083 return 0;
1084}
1085#endif
1086
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001087static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001089{
1090 struct nl80211_coalesce_rule_support rule;
1091
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001092 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001093 return 0;
1094
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001095 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1096 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1097 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1098 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1099 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1100 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001101
1102 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1103 return -ENOBUFS;
1104
1105 return 0;
1106}
1107
Johannes Berg3713b4e2013-02-14 16:19:38 +01001108static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1109 struct ieee80211_supported_band *sband)
1110{
1111 struct nlattr *nl_rates, *nl_rate;
1112 struct ieee80211_rate *rate;
1113 int i;
1114
1115 /* add HT info */
1116 if (sband->ht_cap.ht_supported &&
1117 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1118 sizeof(sband->ht_cap.mcs),
1119 &sband->ht_cap.mcs) ||
1120 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1121 sband->ht_cap.cap) ||
1122 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1123 sband->ht_cap.ampdu_factor) ||
1124 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1125 sband->ht_cap.ampdu_density)))
1126 return -ENOBUFS;
1127
1128 /* add VHT info */
1129 if (sband->vht_cap.vht_supported &&
1130 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1131 sizeof(sband->vht_cap.vht_mcs),
1132 &sband->vht_cap.vht_mcs) ||
1133 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1134 sband->vht_cap.cap)))
1135 return -ENOBUFS;
1136
1137 /* add bitrates */
1138 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1139 if (!nl_rates)
1140 return -ENOBUFS;
1141
1142 for (i = 0; i < sband->n_bitrates; i++) {
1143 nl_rate = nla_nest_start(msg, i);
1144 if (!nl_rate)
1145 return -ENOBUFS;
1146
1147 rate = &sband->bitrates[i];
1148 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1149 rate->bitrate))
1150 return -ENOBUFS;
1151 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1152 nla_put_flag(msg,
1153 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1154 return -ENOBUFS;
1155
1156 nla_nest_end(msg, nl_rate);
1157 }
1158
1159 nla_nest_end(msg, nl_rates);
1160
1161 return 0;
1162}
1163
1164static int
1165nl80211_send_mgmt_stypes(struct sk_buff *msg,
1166 const struct ieee80211_txrx_stypes *mgmt_stypes)
1167{
1168 u16 stypes;
1169 struct nlattr *nl_ftypes, *nl_ifs;
1170 enum nl80211_iftype ift;
1171 int i;
1172
1173 if (!mgmt_stypes)
1174 return 0;
1175
1176 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1177 if (!nl_ifs)
1178 return -ENOBUFS;
1179
1180 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1181 nl_ftypes = nla_nest_start(msg, ift);
1182 if (!nl_ftypes)
1183 return -ENOBUFS;
1184 i = 0;
1185 stypes = mgmt_stypes[ift].tx;
1186 while (stypes) {
1187 if ((stypes & 1) &&
1188 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1189 (i << 4) | IEEE80211_FTYPE_MGMT))
1190 return -ENOBUFS;
1191 stypes >>= 1;
1192 i++;
1193 }
1194 nla_nest_end(msg, nl_ftypes);
1195 }
1196
1197 nla_nest_end(msg, nl_ifs);
1198
1199 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1200 if (!nl_ifs)
1201 return -ENOBUFS;
1202
1203 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1204 nl_ftypes = nla_nest_start(msg, ift);
1205 if (!nl_ftypes)
1206 return -ENOBUFS;
1207 i = 0;
1208 stypes = mgmt_stypes[ift].rx;
1209 while (stypes) {
1210 if ((stypes & 1) &&
1211 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1212 (i << 4) | IEEE80211_FTYPE_MGMT))
1213 return -ENOBUFS;
1214 stypes >>= 1;
1215 i++;
1216 }
1217 nla_nest_end(msg, nl_ftypes);
1218 }
1219 nla_nest_end(msg, nl_ifs);
1220
1221 return 0;
1222}
1223
Johannes Berg86e8cf92013-06-19 10:57:22 +02001224struct nl80211_dump_wiphy_state {
1225 s64 filter_wiphy;
1226 long start;
1227 long split_start, band_start, chan_start;
1228 bool split;
1229};
1230
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001231static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001232 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001233 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001234 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001235{
1236 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001237 struct nlattr *nl_bands, *nl_band;
1238 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001239 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001240 enum ieee80211_band band;
1241 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001242 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001243 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001244 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001245 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001246
Johannes Berg3bb20552014-05-26 13:52:25 +02001247 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001248 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001249 return -ENOBUFS;
1250
Johannes Berg86e8cf92013-06-19 10:57:22 +02001251 if (WARN_ON(!state))
1252 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001253
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001254 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001256 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001257 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001258 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001259 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001260
Johannes Berg3bb20552014-05-26 13:52:25 +02001261 if (cmd != NL80211_CMD_NEW_WIPHY)
1262 goto finish;
1263
Johannes Berg86e8cf92013-06-19 10:57:22 +02001264 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001265 case 0:
1266 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001269 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001271 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001274 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001279 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001285 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001286 goto nla_put_failure;
1287
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1290 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001291 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1293 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1296 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001297 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1299 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1302 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001303 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001305 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001306 state->split_start++;
1307 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 break;
1309 case 1:
1310 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1312 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001313 goto nla_put_failure;
1314
Johannes Berg3713b4e2013-02-14 16:19:38 +01001315 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001317 goto nla_put_failure;
1318
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1321 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001322
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001326 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001328
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001333
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.available_antennas_tx ||
1335 rdev->wiphy.available_antennas_rx) &&
1336 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 u32 tx_ant = 0, rx_ant = 0;
1338 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001340 if (!res) {
1341 if (nla_put_u32(msg,
1342 NL80211_ATTR_WIPHY_ANTENNA_TX,
1343 tx_ant) ||
1344 nla_put_u32(msg,
1345 NL80211_ATTR_WIPHY_ANTENNA_RX,
1346 rx_ant))
1347 goto nla_put_failure;
1348 }
Johannes Bergee688b002008-01-24 19:38:39 +01001349 }
1350
Johannes Berg86e8cf92013-06-19 10:57:22 +02001351 state->split_start++;
1352 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 break;
1354 case 2:
1355 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001356 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001358 state->split_start++;
1359 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 break;
1361 case 3:
1362 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1363 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001364 goto nla_put_failure;
1365
Johannes Berg86e8cf92013-06-19 10:57:22 +02001366 for (band = state->band_start;
1367 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001368 struct ieee80211_supported_band *sband;
1369
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001370 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371
1372 if (!sband)
1373 continue;
1374
1375 nl_band = nla_nest_start(msg, band);
1376 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001377 goto nla_put_failure;
1378
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001380 case 0:
1381 if (nl80211_send_band_rateinfo(msg, sband))
1382 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001383 state->chan_start++;
1384 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385 break;
1386 default:
1387 /* add frequencies */
1388 nl_freqs = nla_nest_start(
1389 msg, NL80211_BAND_ATTR_FREQS);
1390 if (!nl_freqs)
1391 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001392
Johannes Berg86e8cf92013-06-19 10:57:22 +02001393 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 i < sband->n_channels;
1395 i++) {
1396 nl_freq = nla_nest_start(msg, i);
1397 if (!nl_freq)
1398 goto nla_put_failure;
1399
1400 chan = &sband->channels[i];
1401
Johannes Berg86e8cf92013-06-19 10:57:22 +02001402 if (nl80211_msg_put_channel(
1403 msg, chan,
1404 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001405 goto nla_put_failure;
1406
1407 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001408 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001409 break;
1410 }
1411 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001412 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001413 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001414 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 nla_nest_end(msg, nl_freqs);
1416 }
1417
1418 nla_nest_end(msg, nl_band);
1419
Johannes Berg86e8cf92013-06-19 10:57:22 +02001420 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001421 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423 band--;
1424 break;
1425 }
Johannes Bergee688b002008-01-24 19:38:39 +01001426 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001428
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001430 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001432 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001433
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 if (state->band_start == 0 && state->chan_start == 0)
1436 state->split_start++;
1437 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 break;
1439 case 4:
1440 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1441 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001442 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443
1444 i = 0;
1445#define CMD(op, n) \
1446 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001447 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 i++; \
1449 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1450 goto nla_put_failure; \
1451 } \
1452 } while (0)
1453
1454 CMD(add_virtual_intf, NEW_INTERFACE);
1455 CMD(change_virtual_intf, SET_INTERFACE);
1456 CMD(add_key, NEW_KEY);
1457 CMD(start_ap, START_AP);
1458 CMD(add_station, NEW_STATION);
1459 CMD(add_mpath, NEW_MPATH);
1460 CMD(update_mesh_config, SET_MESH_CONFIG);
1461 CMD(change_bss, SET_BSS);
1462 CMD(auth, AUTHENTICATE);
1463 CMD(assoc, ASSOCIATE);
1464 CMD(deauth, DEAUTHENTICATE);
1465 CMD(disassoc, DISASSOCIATE);
1466 CMD(join_ibss, JOIN_IBSS);
1467 CMD(join_mesh, JOIN_MESH);
1468 CMD(set_pmksa, SET_PMKSA);
1469 CMD(del_pmksa, DEL_PMKSA);
1470 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001471 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1473 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1474 CMD(mgmt_tx, FRAME);
1475 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001476 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 i++;
1478 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1479 goto nla_put_failure;
1480 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001481 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1482 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 i++;
1484 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1485 goto nla_put_failure;
1486 }
1487 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001488 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001489 CMD(tdls_mgmt, TDLS_MGMT);
1490 CMD(tdls_oper, TDLS_OPER);
1491 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001492 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 CMD(sched_scan_start, START_SCHED_SCAN);
1494 CMD(probe_client, PROBE_CLIENT);
1495 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001496 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 i++;
1498 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1499 goto nla_put_failure;
1500 }
1501 CMD(start_p2p_device, START_P2P_DEVICE);
1502 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001503#ifdef CONFIG_NL80211_TESTMODE
1504 CMD(testmode_cmd, TESTMODE);
1505#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001506 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001507 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1508 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001509 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001510 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001511 CMD(set_qos_map, SET_QOS_MAP);
Arend van Spriel5de17982013-04-18 15:49:00 +02001512 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001513 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001514#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001515
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001516 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001517 i++;
1518 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001519 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001520 }
1521
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 i++;
1524 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1525 goto nla_put_failure;
1526 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001527
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001529 state->split_start++;
1530 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 break;
1532 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001533 if (rdev->ops->remain_on_channel &&
1534 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 nla_put_u32(msg,
1536 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001537 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001538 goto nla_put_failure;
1539
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1542 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001543
Johannes Berg3713b4e2013-02-14 16:19:38 +01001544 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1545 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001546 state->split_start++;
1547 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 break;
1549 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001550#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001551 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001553 state->split_start++;
1554 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555 break;
1556#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001557 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001558#endif
1559 case 7:
1560 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001561 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001562 goto nla_put_failure;
1563
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001564 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001565 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001567
Johannes Berg86e8cf92013-06-19 10:57:22 +02001568 state->split_start++;
1569 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570 break;
1571 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001572 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001574 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575 goto nla_put_failure;
1576
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001578 /*
1579 * We can only add the per-channel limit information if the
1580 * dump is split, otherwise it makes it too big. Therefore
1581 * only advertise it in that case.
1582 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001584 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1585 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 goto nla_put_failure;
1587
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001590 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1591 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 goto nla_put_failure;
1593
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001594 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1595 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001597 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001598 goto nla_put_failure;
1599
1600 /*
1601 * Any information below this point is only available to
1602 * applications that can deal with it being split. This
1603 * helps ensure that newly added capabilities don't break
1604 * older tools by overrunning their buffers.
1605 *
1606 * We still increment split_start so that in the split
1607 * case we'll continue with more data in the next round,
1608 * but break unconditionally so unsplit data stops here.
1609 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001610 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 break;
1612 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001614 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 rdev->wiphy.extended_capabilities_len,
1616 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001617 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001618 rdev->wiphy.extended_capabilities_len,
1619 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001620 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001621
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001623 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001624 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1625 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001626 goto nla_put_failure;
1627
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001628 state->split_start++;
1629 break;
1630 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001632 goto nla_put_failure;
1633
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001634 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001635 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1636 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1637 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001638
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001640 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001641 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001642 goto nla_put_failure;
1643
Johannes Bergad7e7182013-11-13 13:37:47 +01001644 state->split_start++;
1645 break;
1646 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001648 const struct nl80211_vendor_cmd_info *info;
1649 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001650
Johannes Berg567ffc32013-12-18 14:43:31 +01001651 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1652 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001653 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001654
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1656 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001657 if (nla_put(msg, i + 1, sizeof(*info), info))
1658 goto nla_put_failure;
1659 }
1660 nla_nest_end(msg, nested);
1661 }
1662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001664 const struct nl80211_vendor_cmd_info *info;
1665 struct nlattr *nested;
1666
1667 nested = nla_nest_start(msg,
1668 NL80211_ATTR_VENDOR_EVENTS);
1669 if (!nested)
1670 goto nla_put_failure;
1671
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001672 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1673 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001674 if (nla_put(msg, i + 1, sizeof(*info), info))
1675 goto nla_put_failure;
1676 }
1677 nla_nest_end(msg, nested);
1678 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001679 state->split_start++;
1680 break;
1681 case 12:
1682 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1683 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1684 rdev->wiphy.max_num_csa_counters))
1685 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001686
Johannes Berg3713b4e2013-02-14 16:19:38 +01001687 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001688 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001689 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001690 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001691 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001692 return genlmsg_end(msg, hdr);
1693
1694 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001695 genlmsg_cancel(msg, hdr);
1696 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001697}
1698
Johannes Berg86e8cf92013-06-19 10:57:22 +02001699static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1700 struct netlink_callback *cb,
1701 struct nl80211_dump_wiphy_state *state)
1702{
1703 struct nlattr **tb = nl80211_fam.attrbuf;
1704 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1705 tb, nl80211_fam.maxattr, nl80211_policy);
1706 /* ignore parse errors for backward compatibility */
1707 if (ret)
1708 return 0;
1709
1710 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1711 if (tb[NL80211_ATTR_WIPHY])
1712 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1713 if (tb[NL80211_ATTR_WDEV])
1714 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1715 if (tb[NL80211_ATTR_IFINDEX]) {
1716 struct net_device *netdev;
1717 struct cfg80211_registered_device *rdev;
1718 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1719
Ying Xue7f2b8562014-01-15 10:23:45 +08001720 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001721 if (!netdev)
1722 return -ENODEV;
1723 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001724 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001725 netdev->ieee80211_ptr->wiphy);
1726 state->filter_wiphy = rdev->wiphy_idx;
1727 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001728 }
1729
1730 return 0;
1731}
1732
Johannes Berg55682962007-09-20 13:09:35 -04001733static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1734{
Johannes Berg645e77d2013-03-01 14:03:49 +01001735 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001736 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001737 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001738
Johannes Berg5fe231e2013-05-08 21:45:15 +02001739 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001740 if (!state) {
1741 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001742 if (!state) {
1743 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001744 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001745 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001746 state->filter_wiphy = -1;
1747 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1748 if (ret) {
1749 kfree(state);
1750 rtnl_unlock();
1751 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001752 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001753 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001754 }
1755
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001756 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1757 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001758 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001760 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001761 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001762 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001763 continue;
1764 /* attempt to fit multiple wiphy data chunks into the skb */
1765 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001766 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1767 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001768 NETLINK_CB(cb->skb).portid,
1769 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001770 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001771 if (ret < 0) {
1772 /*
1773 * If sending the wiphy data didn't fit (ENOBUFS
1774 * or EMSGSIZE returned), this SKB is still
1775 * empty (so it's not too big because another
1776 * wiphy dataset is already in the skb) and
1777 * we've not tried to adjust the dump allocation
1778 * yet ... then adjust the alloc size to be
1779 * bigger, and return 1 but with the empty skb.
1780 * This results in an empty message being RX'ed
1781 * in userspace, but that is ignored.
1782 *
1783 * We can then retry with the larger buffer.
1784 */
1785 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001786 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001787 cb->min_dump_alloc < 4096) {
1788 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001789 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001790 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001791 return 1;
1792 }
1793 idx--;
1794 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001795 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001796 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001797 break;
Johannes Berg55682962007-09-20 13:09:35 -04001798 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001799 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001800
Johannes Berg86e8cf92013-06-19 10:57:22 +02001801 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001802
1803 return skb->len;
1804}
1805
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1807{
1808 kfree((void *)cb->args[0]);
1809 return 0;
1810}
1811
Johannes Berg55682962007-09-20 13:09:35 -04001812static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1813{
1814 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001816 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001817
Johannes Berg645e77d2013-03-01 14:03:49 +01001818 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001819 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001820 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001821
Johannes Berg3bb20552014-05-26 13:52:25 +02001822 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1823 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001824 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001825 nlmsg_free(msg);
1826 return -ENOBUFS;
1827 }
Johannes Berg55682962007-09-20 13:09:35 -04001828
Johannes Berg134e6372009-07-10 09:51:34 +00001829 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001830}
1831
Jouni Malinen31888482008-10-30 16:59:24 +02001832static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1833 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1834 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1835 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1836 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1837 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1838};
1839
1840static int parse_txq_params(struct nlattr *tb[],
1841 struct ieee80211_txq_params *txq_params)
1842{
Johannes Berga3304b02012-03-28 11:04:24 +02001843 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001844 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1845 !tb[NL80211_TXQ_ATTR_AIFS])
1846 return -EINVAL;
1847
Johannes Berga3304b02012-03-28 11:04:24 +02001848 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001849 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1850 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1851 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1852 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1853
Johannes Berga3304b02012-03-28 11:04:24 +02001854 if (txq_params->ac >= NL80211_NUM_ACS)
1855 return -EINVAL;
1856
Jouni Malinen31888482008-10-30 16:59:24 +02001857 return 0;
1858}
1859
Johannes Bergf444de02010-05-05 15:25:02 +02001860static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1861{
1862 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001863 * You can only set the channel explicitly for WDS interfaces,
1864 * all others have their channel managed via their respective
1865 * "establish a connection" command (connect, join, ...)
1866 *
1867 * For AP/GO and mesh mode, the channel can be set with the
1868 * channel userspace API, but is only stored and passed to the
1869 * low-level driver when the AP starts or the mesh is joined.
1870 * This is for backward compatibility, userspace can also give
1871 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001872 *
1873 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001874 * whatever else is going on, so they have their own special
1875 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001876 */
1877 return !wdev ||
1878 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001879 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001880 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1881 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001882}
1883
Johannes Berg683b6d32012-11-08 21:25:48 +01001884static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1885 struct genl_info *info,
1886 struct cfg80211_chan_def *chandef)
1887{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301888 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001889
1890 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1891 return -EINVAL;
1892
1893 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1894
1895 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001896 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1897 chandef->center_freq1 = control_freq;
1898 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001899
1900 /* Primary channel not allowed */
1901 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1902 return -EINVAL;
1903
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001904 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1905 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001906
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001907 chantype = nla_get_u32(
1908 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1909
1910 switch (chantype) {
1911 case NL80211_CHAN_NO_HT:
1912 case NL80211_CHAN_HT20:
1913 case NL80211_CHAN_HT40PLUS:
1914 case NL80211_CHAN_HT40MINUS:
1915 cfg80211_chandef_create(chandef, chandef->chan,
1916 chantype);
1917 break;
1918 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001919 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001920 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001921 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1922 chandef->width =
1923 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1924 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1925 chandef->center_freq1 =
1926 nla_get_u32(
1927 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1928 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1929 chandef->center_freq2 =
1930 nla_get_u32(
1931 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1932 }
1933
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001934 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001935 return -EINVAL;
1936
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001937 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1938 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001939 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001940
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001941 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1942 chandef->width == NL80211_CHAN_WIDTH_10) &&
1943 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1944 return -EINVAL;
1945
Johannes Berg683b6d32012-11-08 21:25:48 +01001946 return 0;
1947}
1948
Johannes Bergf444de02010-05-05 15:25:02 +02001949static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001950 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001951 struct genl_info *info)
1952{
Johannes Berg683b6d32012-11-08 21:25:48 +01001953 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001954 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001955 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001956 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001957
Jouni Malinene16821b2014-04-28 11:22:08 +03001958 if (dev)
1959 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001960 if (!nl80211_can_set_dev_channel(wdev))
1961 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001962 if (wdev)
1963 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001964
Johannes Berg683b6d32012-11-08 21:25:48 +01001965 result = nl80211_parse_chandef(rdev, info, &chandef);
1966 if (result)
1967 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001968
Johannes Berge8c9bd52012-06-06 08:18:22 +02001969 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001970 case NL80211_IFTYPE_AP:
1971 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001972 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001973 result = -EINVAL;
1974 break;
1975 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001976 if (wdev->beacon_interval) {
1977 if (!dev || !rdev->ops->set_ap_chanwidth ||
1978 !(rdev->wiphy.features &
1979 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1980 result = -EBUSY;
1981 break;
1982 }
1983
1984 /* Only allow dynamic channel width changes */
1985 if (chandef.chan != wdev->preset_chandef.chan) {
1986 result = -EBUSY;
1987 break;
1988 }
1989 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1990 if (result)
1991 break;
1992 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001993 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001994 result = 0;
1995 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001996 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001997 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001998 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001999 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002000 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002001 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002002 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002003 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002004 }
Johannes Bergf444de02010-05-05 15:25:02 +02002005
2006 return result;
2007}
2008
2009static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2010{
Johannes Berg4c476992010-10-04 21:36:35 +02002011 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2012 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002013
Jouni Malinene16821b2014-04-28 11:22:08 +03002014 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002015}
2016
Bill Jordane8347eb2010-10-01 13:54:28 -04002017static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2018{
Johannes Berg43b19952010-10-07 13:10:30 +02002019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2020 struct net_device *dev = info->user_ptr[1];
2021 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002022 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002023
2024 if (!info->attrs[NL80211_ATTR_MAC])
2025 return -EINVAL;
2026
Johannes Berg43b19952010-10-07 13:10:30 +02002027 if (netif_running(dev))
2028 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002029
Johannes Berg43b19952010-10-07 13:10:30 +02002030 if (!rdev->ops->set_wds_peer)
2031 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002032
Johannes Berg43b19952010-10-07 13:10:30 +02002033 if (wdev->iftype != NL80211_IFTYPE_WDS)
2034 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002035
2036 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002037 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002038}
2039
2040
Johannes Berg55682962007-09-20 13:09:35 -04002041static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2042{
2043 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002044 struct net_device *netdev = NULL;
2045 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002046 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002047 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002048 u32 changed;
2049 u8 retry_short = 0, retry_long = 0;
2050 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002051 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002052
Johannes Berg5fe231e2013-05-08 21:45:15 +02002053 ASSERT_RTNL();
2054
Johannes Bergf444de02010-05-05 15:25:02 +02002055 /*
2056 * Try to find the wiphy and netdev. Normally this
2057 * function shouldn't need the netdev, but this is
2058 * done for backward compatibility -- previously
2059 * setting the channel was done per wiphy, but now
2060 * it is per netdev. Previous userland like hostapd
2061 * also passed a netdev to set_wiphy, so that it is
2062 * possible to let that go to the right netdev!
2063 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002064
Johannes Bergf444de02010-05-05 15:25:02 +02002065 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2066 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2067
Ying Xue7f2b8562014-01-15 10:23:45 +08002068 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002069 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002070 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002071 else
Johannes Bergf444de02010-05-05 15:25:02 +02002072 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002073 }
2074
Johannes Bergf444de02010-05-05 15:25:02 +02002075 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002076 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2077 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002078 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002079 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002080 wdev = NULL;
2081 netdev = NULL;
2082 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002083 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002084 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002085
2086 /*
2087 * end workaround code, by now the rdev is available
2088 * and locked, and wdev may or may not be NULL.
2089 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002090
2091 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002092 result = cfg80211_dev_rename(
2093 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002094
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002095 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002096 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002097
Jouni Malinen31888482008-10-30 16:59:24 +02002098 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2099 struct ieee80211_txq_params txq_params;
2100 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2101
Ying Xue7f2b8562014-01-15 10:23:45 +08002102 if (!rdev->ops->set_txq_params)
2103 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002104
Ying Xue7f2b8562014-01-15 10:23:45 +08002105 if (!netdev)
2106 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002107
Johannes Berg133a3ff2011-11-03 14:50:13 +01002108 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002109 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2110 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002111
Ying Xue7f2b8562014-01-15 10:23:45 +08002112 if (!netif_running(netdev))
2113 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002114
Jouni Malinen31888482008-10-30 16:59:24 +02002115 nla_for_each_nested(nl_txq_params,
2116 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2117 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002118 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2119 nla_data(nl_txq_params),
2120 nla_len(nl_txq_params),
2121 txq_params_policy);
2122 if (result)
2123 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002124 result = parse_txq_params(tb, &txq_params);
2125 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002126 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002127
Hila Gonene35e4d22012-06-27 17:19:42 +03002128 result = rdev_set_txq_params(rdev, netdev,
2129 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002130 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002131 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002132 }
2133 }
2134
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002135 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002136 result = __nl80211_set_channel(
2137 rdev,
2138 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2139 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002140 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002141 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002142 }
2143
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002144 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002145 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002146 enum nl80211_tx_power_setting type;
2147 int idx, mbm = 0;
2148
Johannes Bergc8442112012-10-24 10:17:18 +02002149 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2150 txp_wdev = NULL;
2151
Ying Xue7f2b8562014-01-15 10:23:45 +08002152 if (!rdev->ops->set_tx_power)
2153 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002154
2155 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2156 type = nla_get_u32(info->attrs[idx]);
2157
2158 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002159 (type != NL80211_TX_POWER_AUTOMATIC))
2160 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002161
2162 if (type != NL80211_TX_POWER_AUTOMATIC) {
2163 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2164 mbm = nla_get_u32(info->attrs[idx]);
2165 }
2166
Johannes Bergc8442112012-10-24 10:17:18 +02002167 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002168 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002169 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002170 }
2171
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002172 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2173 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2174 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002175 if ((!rdev->wiphy.available_antennas_tx &&
2176 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002177 !rdev->ops->set_antenna)
2178 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002179
2180 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2181 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2182
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002183 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002184 * available antenna masks, except for the "all" mask */
2185 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002186 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2187 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002188
Bruno Randolf7f531e02010-12-16 11:30:22 +09002189 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2190 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002191
Hila Gonene35e4d22012-06-27 17:19:42 +03002192 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002193 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002195 }
2196
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002197 changed = 0;
2198
2199 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2200 retry_short = nla_get_u8(
2201 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002202 if (retry_short == 0)
2203 return -EINVAL;
2204
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002205 changed |= WIPHY_PARAM_RETRY_SHORT;
2206 }
2207
2208 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2209 retry_long = nla_get_u8(
2210 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002211 if (retry_long == 0)
2212 return -EINVAL;
2213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002214 changed |= WIPHY_PARAM_RETRY_LONG;
2215 }
2216
2217 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2218 frag_threshold = nla_get_u32(
2219 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002220 if (frag_threshold < 256)
2221 return -EINVAL;
2222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002223 if (frag_threshold != (u32) -1) {
2224 /*
2225 * Fragments (apart from the last one) are required to
2226 * have even length. Make the fragmentation code
2227 * simpler by stripping LSB should someone try to use
2228 * odd threshold value.
2229 */
2230 frag_threshold &= ~0x1;
2231 }
2232 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2233 }
2234
2235 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2236 rts_threshold = nla_get_u32(
2237 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2238 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2239 }
2240
Lukáš Turek81077e82009-12-21 22:50:47 +01002241 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2242 coverage_class = nla_get_u8(
2243 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2244 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2245 }
2246
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002247 if (changed) {
2248 u8 old_retry_short, old_retry_long;
2249 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002250 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002251
Ying Xue7f2b8562014-01-15 10:23:45 +08002252 if (!rdev->ops->set_wiphy_params)
2253 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002254
2255 old_retry_short = rdev->wiphy.retry_short;
2256 old_retry_long = rdev->wiphy.retry_long;
2257 old_frag_threshold = rdev->wiphy.frag_threshold;
2258 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002259 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002260
2261 if (changed & WIPHY_PARAM_RETRY_SHORT)
2262 rdev->wiphy.retry_short = retry_short;
2263 if (changed & WIPHY_PARAM_RETRY_LONG)
2264 rdev->wiphy.retry_long = retry_long;
2265 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2266 rdev->wiphy.frag_threshold = frag_threshold;
2267 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2268 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002269 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2270 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002271
Hila Gonene35e4d22012-06-27 17:19:42 +03002272 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002273 if (result) {
2274 rdev->wiphy.retry_short = old_retry_short;
2275 rdev->wiphy.retry_long = old_retry_long;
2276 rdev->wiphy.frag_threshold = old_frag_threshold;
2277 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002278 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002279 }
2280 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002281 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002282}
2283
Johannes Berg71bbc992012-06-15 15:30:18 +02002284static inline u64 wdev_id(struct wireless_dev *wdev)
2285{
2286 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002287 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002288}
Johannes Berg55682962007-09-20 13:09:35 -04002289
Johannes Berg683b6d32012-11-08 21:25:48 +01002290static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002291 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002292{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002293 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002294
Johannes Berg683b6d32012-11-08 21:25:48 +01002295 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2296 chandef->chan->center_freq))
2297 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002298 switch (chandef->width) {
2299 case NL80211_CHAN_WIDTH_20_NOHT:
2300 case NL80211_CHAN_WIDTH_20:
2301 case NL80211_CHAN_WIDTH_40:
2302 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2303 cfg80211_get_chandef_type(chandef)))
2304 return -ENOBUFS;
2305 break;
2306 default:
2307 break;
2308 }
2309 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2310 return -ENOBUFS;
2311 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2312 return -ENOBUFS;
2313 if (chandef->center_freq2 &&
2314 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002315 return -ENOBUFS;
2316 return 0;
2317}
2318
Eric W. Biederman15e47302012-09-07 20:12:54 +00002319static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002320 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002321 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002322{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002323 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002324 void *hdr;
2325
Eric W. Biederman15e47302012-09-07 20:12:54 +00002326 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002327 if (!hdr)
2328 return -1;
2329
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002330 if (dev &&
2331 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002332 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002333 goto nla_put_failure;
2334
2335 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2336 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002337 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002338 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002339 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2340 rdev->devlist_generation ^
2341 (cfg80211_rdev_list_generation << 2)))
2342 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002343
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002344 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002345 int ret;
2346 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002347
Johannes Berg683b6d32012-11-08 21:25:48 +01002348 ret = rdev_get_channel(rdev, wdev, &chandef);
2349 if (ret == 0) {
2350 if (nl80211_send_chandef(msg, &chandef))
2351 goto nla_put_failure;
2352 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002353 }
2354
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002355 if (wdev->ssid_len) {
2356 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2357 goto nla_put_failure;
2358 }
2359
Johannes Berg55682962007-09-20 13:09:35 -04002360 return genlmsg_end(msg, hdr);
2361
2362 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002363 genlmsg_cancel(msg, hdr);
2364 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002365}
2366
2367static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2368{
2369 int wp_idx = 0;
2370 int if_idx = 0;
2371 int wp_start = cb->args[0];
2372 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002373 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002374 struct wireless_dev *wdev;
2375
Johannes Berg5fe231e2013-05-08 21:45:15 +02002376 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002377 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2378 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002379 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002380 if (wp_idx < wp_start) {
2381 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002382 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002383 }
Johannes Berg55682962007-09-20 13:09:35 -04002384 if_idx = 0;
2385
Johannes Berg89a54e42012-06-15 14:33:17 +02002386 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002387 if (if_idx < if_start) {
2388 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002389 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002390 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002391 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002392 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002393 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002394 goto out;
2395 }
2396 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002397 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002398
2399 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002400 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002401 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002402 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002403
2404 cb->args[0] = wp_idx;
2405 cb->args[1] = if_idx;
2406
2407 return skb->len;
2408}
2409
2410static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2411{
2412 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002414 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002415
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002416 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002417 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002418 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002419
Eric W. Biederman15e47302012-09-07 20:12:54 +00002420 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002421 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002422 nlmsg_free(msg);
2423 return -ENOBUFS;
2424 }
Johannes Berg55682962007-09-20 13:09:35 -04002425
Johannes Berg134e6372009-07-10 09:51:34 +00002426 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002427}
2428
Michael Wu66f7ac52008-01-31 19:48:22 +01002429static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2430 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2431 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2432 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2433 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2434 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002435 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002436};
2437
2438static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2439{
2440 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2441 int flag;
2442
2443 *mntrflags = 0;
2444
2445 if (!nla)
2446 return -EINVAL;
2447
2448 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2449 nla, mntr_flags_policy))
2450 return -EINVAL;
2451
2452 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2453 if (flags[flag])
2454 *mntrflags |= (1<<flag);
2455
2456 return 0;
2457}
2458
Johannes Berg9bc383d2009-11-19 11:55:19 +01002459static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002460 struct net_device *netdev, u8 use_4addr,
2461 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002462{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002463 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002464 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002465 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002466 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002467 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002468
2469 switch (iftype) {
2470 case NL80211_IFTYPE_AP_VLAN:
2471 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2472 return 0;
2473 break;
2474 case NL80211_IFTYPE_STATION:
2475 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2476 return 0;
2477 break;
2478 default:
2479 break;
2480 }
2481
2482 return -EOPNOTSUPP;
2483}
2484
Johannes Berg55682962007-09-20 13:09:35 -04002485static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2486{
Johannes Berg4c476992010-10-04 21:36:35 +02002487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002488 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002489 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002490 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002491 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002492 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002493 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002494
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002495 memset(&params, 0, sizeof(params));
2496
Johannes Berg04a773a2009-04-19 21:24:32 +02002497 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002498
Johannes Berg723b0382008-09-16 20:22:09 +02002499 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002500 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002501 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002502 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002503 if (ntype > NL80211_IFTYPE_MAX)
2504 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002505 }
2506
Johannes Berg92ffe052008-09-16 20:39:36 +02002507 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002508 struct wireless_dev *wdev = dev->ieee80211_ptr;
2509
Johannes Berg4c476992010-10-04 21:36:35 +02002510 if (ntype != NL80211_IFTYPE_MESH_POINT)
2511 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002512 if (netif_running(dev))
2513 return -EBUSY;
2514
2515 wdev_lock(wdev);
2516 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2517 IEEE80211_MAX_MESH_ID_LEN);
2518 wdev->mesh_id_up_len =
2519 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2520 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2521 wdev->mesh_id_up_len);
2522 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002523 }
2524
Felix Fietkau8b787642009-11-10 18:53:10 +01002525 if (info->attrs[NL80211_ATTR_4ADDR]) {
2526 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2527 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002528 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002529 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002530 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002531 } else {
2532 params.use_4addr = -1;
2533 }
2534
Johannes Berg92ffe052008-09-16 20:39:36 +02002535 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002536 if (ntype != NL80211_IFTYPE_MONITOR)
2537 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002538 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2539 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002540 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002541 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002542
2543 flags = &_flags;
2544 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002545 }
Johannes Berg3b858752009-03-12 09:55:09 +01002546
Luciano Coelho18003292013-08-29 13:26:57 +03002547 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002548 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2549 return -EOPNOTSUPP;
2550
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002551 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002552 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002553 else
2554 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002555
Johannes Berg9bc383d2009-11-19 11:55:19 +01002556 if (!err && params.use_4addr != -1)
2557 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2558
Johannes Berg55682962007-09-20 13:09:35 -04002559 return err;
2560}
2561
2562static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2563{
Johannes Berg4c476992010-10-04 21:36:35 +02002564 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002565 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002566 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002567 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002568 int err;
2569 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002570 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002571
Johannes Berg78f22b62014-03-24 17:57:27 +01002572 /* to avoid failing a new interface creation due to pending removal */
2573 cfg80211_destroy_ifaces(rdev);
2574
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002575 memset(&params, 0, sizeof(params));
2576
Johannes Berg55682962007-09-20 13:09:35 -04002577 if (!info->attrs[NL80211_ATTR_IFNAME])
2578 return -EINVAL;
2579
2580 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2581 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2582 if (type > NL80211_IFTYPE_MAX)
2583 return -EINVAL;
2584 }
2585
Johannes Berg79c97e92009-07-07 03:56:12 +02002586 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002587 !(rdev->wiphy.interface_modes & (1 << type)))
2588 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002589
Arend van Spriel1c18f142013-01-08 10:17:27 +01002590 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2591 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2592 ETH_ALEN);
2593 if (!is_valid_ether_addr(params.macaddr))
2594 return -EADDRNOTAVAIL;
2595 }
2596
Johannes Berg9bc383d2009-11-19 11:55:19 +01002597 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002598 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002599 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002600 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002601 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002602 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002603
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2605 if (!msg)
2606 return -ENOMEM;
2607
Michael Wu66f7ac52008-01-31 19:48:22 +01002608 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2609 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2610 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002611
Luciano Coelho18003292013-08-29 13:26:57 +03002612 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002613 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2614 return -EOPNOTSUPP;
2615
Hila Gonene35e4d22012-06-27 17:19:42 +03002616 wdev = rdev_add_virtual_intf(rdev,
2617 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2618 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002619 if (IS_ERR(wdev)) {
2620 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002621 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002622 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002623
Johannes Berg78f22b62014-03-24 17:57:27 +01002624 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2625 wdev->owner_nlportid = info->snd_portid;
2626
Johannes Berg98104fde2012-06-16 00:19:54 +02002627 switch (type) {
2628 case NL80211_IFTYPE_MESH_POINT:
2629 if (!info->attrs[NL80211_ATTR_MESH_ID])
2630 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002631 wdev_lock(wdev);
2632 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2633 IEEE80211_MAX_MESH_ID_LEN);
2634 wdev->mesh_id_up_len =
2635 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2636 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2637 wdev->mesh_id_up_len);
2638 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002639 break;
2640 case NL80211_IFTYPE_P2P_DEVICE:
2641 /*
2642 * P2P Device doesn't have a netdev, so doesn't go
2643 * through the netdev notifier and must be added here
2644 */
2645 mutex_init(&wdev->mtx);
2646 INIT_LIST_HEAD(&wdev->event_list);
2647 spin_lock_init(&wdev->event_lock);
2648 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2649 spin_lock_init(&wdev->mgmt_registrations_lock);
2650
Johannes Berg98104fde2012-06-16 00:19:54 +02002651 wdev->identifier = ++rdev->wdev_id;
2652 list_add_rcu(&wdev->list, &rdev->wdev_list);
2653 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002654 break;
2655 default:
2656 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002657 }
2658
Eric W. Biederman15e47302012-09-07 20:12:54 +00002659 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002660 rdev, wdev) < 0) {
2661 nlmsg_free(msg);
2662 return -ENOBUFS;
2663 }
2664
2665 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002666}
2667
2668static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2669{
Johannes Berg4c476992010-10-04 21:36:35 +02002670 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002671 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002672
Johannes Berg4c476992010-10-04 21:36:35 +02002673 if (!rdev->ops->del_virtual_intf)
2674 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002675
Johannes Berg84efbb82012-06-16 00:00:26 +02002676 /*
2677 * If we remove a wireless device without a netdev then clear
2678 * user_ptr[1] so that nl80211_post_doit won't dereference it
2679 * to check if it needs to do dev_put(). Otherwise it crashes
2680 * since the wdev has been freed, unlike with a netdev where
2681 * we need the dev_put() for the netdev to really be freed.
2682 */
2683 if (!wdev->netdev)
2684 info->user_ptr[1] = NULL;
2685
Hila Gonene35e4d22012-06-27 17:19:42 +03002686 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002687}
2688
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002689static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2690{
2691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2692 struct net_device *dev = info->user_ptr[1];
2693 u16 noack_map;
2694
2695 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2696 return -EINVAL;
2697
2698 if (!rdev->ops->set_noack_map)
2699 return -EOPNOTSUPP;
2700
2701 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2702
Hila Gonene35e4d22012-06-27 17:19:42 +03002703 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002704}
2705
Johannes Berg41ade002007-12-19 02:03:29 +01002706struct get_key_cookie {
2707 struct sk_buff *msg;
2708 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002709 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002710};
2711
2712static void get_key_callback(void *c, struct key_params *params)
2713{
Johannes Bergb9454e82009-07-08 13:29:08 +02002714 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002715 struct get_key_cookie *cookie = c;
2716
David S. Miller9360ffd2012-03-29 04:41:26 -04002717 if ((params->key &&
2718 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2719 params->key_len, params->key)) ||
2720 (params->seq &&
2721 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2722 params->seq_len, params->seq)) ||
2723 (params->cipher &&
2724 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2725 params->cipher)))
2726 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002727
Johannes Bergb9454e82009-07-08 13:29:08 +02002728 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2729 if (!key)
2730 goto nla_put_failure;
2731
David S. Miller9360ffd2012-03-29 04:41:26 -04002732 if ((params->key &&
2733 nla_put(cookie->msg, NL80211_KEY_DATA,
2734 params->key_len, params->key)) ||
2735 (params->seq &&
2736 nla_put(cookie->msg, NL80211_KEY_SEQ,
2737 params->seq_len, params->seq)) ||
2738 (params->cipher &&
2739 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2740 params->cipher)))
2741 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002742
David S. Miller9360ffd2012-03-29 04:41:26 -04002743 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2744 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002745
2746 nla_nest_end(cookie->msg, key);
2747
Johannes Berg41ade002007-12-19 02:03:29 +01002748 return;
2749 nla_put_failure:
2750 cookie->error = 1;
2751}
2752
2753static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2754{
Johannes Berg4c476992010-10-04 21:36:35 +02002755 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002756 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002757 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002758 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002759 const u8 *mac_addr = NULL;
2760 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002761 struct get_key_cookie cookie = {
2762 .error = 0,
2763 };
2764 void *hdr;
2765 struct sk_buff *msg;
2766
2767 if (info->attrs[NL80211_ATTR_KEY_IDX])
2768 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2769
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002770 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002771 return -EINVAL;
2772
2773 if (info->attrs[NL80211_ATTR_MAC])
2774 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2775
Johannes Berge31b8212010-10-05 19:39:30 +02002776 pairwise = !!mac_addr;
2777 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2778 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2779 if (kt >= NUM_NL80211_KEYTYPES)
2780 return -EINVAL;
2781 if (kt != NL80211_KEYTYPE_GROUP &&
2782 kt != NL80211_KEYTYPE_PAIRWISE)
2783 return -EINVAL;
2784 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2785 }
2786
Johannes Berg4c476992010-10-04 21:36:35 +02002787 if (!rdev->ops->get_key)
2788 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002789
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002790 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002791 if (!msg)
2792 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002793
Eric W. Biederman15e47302012-09-07 20:12:54 +00002794 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002795 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002796 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002797 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002798
2799 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002800 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002801
David S. Miller9360ffd2012-03-29 04:41:26 -04002802 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2803 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2804 goto nla_put_failure;
2805 if (mac_addr &&
2806 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2807 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002808
Johannes Berge31b8212010-10-05 19:39:30 +02002809 if (pairwise && mac_addr &&
2810 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2811 return -ENOENT;
2812
Hila Gonene35e4d22012-06-27 17:19:42 +03002813 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2814 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002815
2816 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002817 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002818
2819 if (cookie.error)
2820 goto nla_put_failure;
2821
2822 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002823 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002824
2825 nla_put_failure:
2826 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002827 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002828 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002829 return err;
2830}
2831
2832static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2833{
Johannes Berg4c476992010-10-04 21:36:35 +02002834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002835 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002836 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002837 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002838
Johannes Bergb9454e82009-07-08 13:29:08 +02002839 err = nl80211_parse_key(info, &key);
2840 if (err)
2841 return err;
2842
2843 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002844 return -EINVAL;
2845
Johannes Bergb9454e82009-07-08 13:29:08 +02002846 /* only support setting default key */
2847 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002848 return -EINVAL;
2849
Johannes Bergfffd0932009-07-08 14:22:54 +02002850 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002851
2852 if (key.def) {
2853 if (!rdev->ops->set_default_key) {
2854 err = -EOPNOTSUPP;
2855 goto out;
2856 }
2857
2858 err = nl80211_key_allowed(dev->ieee80211_ptr);
2859 if (err)
2860 goto out;
2861
Hila Gonene35e4d22012-06-27 17:19:42 +03002862 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002863 key.def_uni, key.def_multi);
2864
2865 if (err)
2866 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002867
Johannes Berg3d23e342009-09-29 23:27:28 +02002868#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002869 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002870#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002871 } else {
2872 if (key.def_uni || !key.def_multi) {
2873 err = -EINVAL;
2874 goto out;
2875 }
2876
2877 if (!rdev->ops->set_default_mgmt_key) {
2878 err = -EOPNOTSUPP;
2879 goto out;
2880 }
2881
2882 err = nl80211_key_allowed(dev->ieee80211_ptr);
2883 if (err)
2884 goto out;
2885
Hila Gonene35e4d22012-06-27 17:19:42 +03002886 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002887 if (err)
2888 goto out;
2889
2890#ifdef CONFIG_CFG80211_WEXT
2891 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2892#endif
2893 }
2894
2895 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002896 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002897
Johannes Berg41ade002007-12-19 02:03:29 +01002898 return err;
2899}
2900
2901static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2902{
Johannes Berg4c476992010-10-04 21:36:35 +02002903 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002904 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002905 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002906 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002907 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002908
Johannes Bergb9454e82009-07-08 13:29:08 +02002909 err = nl80211_parse_key(info, &key);
2910 if (err)
2911 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002912
Johannes Bergb9454e82009-07-08 13:29:08 +02002913 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return -EINVAL;
2915
Johannes Berg41ade002007-12-19 02:03:29 +01002916 if (info->attrs[NL80211_ATTR_MAC])
2917 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2918
Johannes Berge31b8212010-10-05 19:39:30 +02002919 if (key.type == -1) {
2920 if (mac_addr)
2921 key.type = NL80211_KEYTYPE_PAIRWISE;
2922 else
2923 key.type = NL80211_KEYTYPE_GROUP;
2924 }
2925
2926 /* for now */
2927 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2928 key.type != NL80211_KEYTYPE_GROUP)
2929 return -EINVAL;
2930
Johannes Berg4c476992010-10-04 21:36:35 +02002931 if (!rdev->ops->add_key)
2932 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002933
Johannes Berge31b8212010-10-05 19:39:30 +02002934 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2935 key.type == NL80211_KEYTYPE_PAIRWISE,
2936 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002937 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002938
2939 wdev_lock(dev->ieee80211_ptr);
2940 err = nl80211_key_allowed(dev->ieee80211_ptr);
2941 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002942 err = rdev_add_key(rdev, dev, key.idx,
2943 key.type == NL80211_KEYTYPE_PAIRWISE,
2944 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002945 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002946
Johannes Berg41ade002007-12-19 02:03:29 +01002947 return err;
2948}
2949
2950static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2951{
Johannes Berg4c476992010-10-04 21:36:35 +02002952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002953 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002954 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002955 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002956 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002957
Johannes Bergb9454e82009-07-08 13:29:08 +02002958 err = nl80211_parse_key(info, &key);
2959 if (err)
2960 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002961
2962 if (info->attrs[NL80211_ATTR_MAC])
2963 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2964
Johannes Berge31b8212010-10-05 19:39:30 +02002965 if (key.type == -1) {
2966 if (mac_addr)
2967 key.type = NL80211_KEYTYPE_PAIRWISE;
2968 else
2969 key.type = NL80211_KEYTYPE_GROUP;
2970 }
2971
2972 /* for now */
2973 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2974 key.type != NL80211_KEYTYPE_GROUP)
2975 return -EINVAL;
2976
Johannes Berg4c476992010-10-04 21:36:35 +02002977 if (!rdev->ops->del_key)
2978 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002979
Johannes Bergfffd0932009-07-08 14:22:54 +02002980 wdev_lock(dev->ieee80211_ptr);
2981 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002982
2983 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2984 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2985 err = -ENOENT;
2986
Johannes Bergfffd0932009-07-08 14:22:54 +02002987 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002988 err = rdev_del_key(rdev, dev, key.idx,
2989 key.type == NL80211_KEYTYPE_PAIRWISE,
2990 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002991
Johannes Berg3d23e342009-09-29 23:27:28 +02002992#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002993 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002994 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002995 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002996 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002997 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2998 }
2999#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003000 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003001
Johannes Berg41ade002007-12-19 02:03:29 +01003002 return err;
3003}
3004
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303005/* This function returns an error or the number of nested attributes */
3006static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3007{
3008 struct nlattr *attr;
3009 int n_entries = 0, tmp;
3010
3011 nla_for_each_nested(attr, nl_attr, tmp) {
3012 if (nla_len(attr) != ETH_ALEN)
3013 return -EINVAL;
3014
3015 n_entries++;
3016 }
3017
3018 return n_entries;
3019}
3020
3021/*
3022 * This function parses ACL information and allocates memory for ACL data.
3023 * On successful return, the calling function is responsible to free the
3024 * ACL buffer returned by this function.
3025 */
3026static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3027 struct genl_info *info)
3028{
3029 enum nl80211_acl_policy acl_policy;
3030 struct nlattr *attr;
3031 struct cfg80211_acl_data *acl;
3032 int i = 0, n_entries, tmp;
3033
3034 if (!wiphy->max_acl_mac_addrs)
3035 return ERR_PTR(-EOPNOTSUPP);
3036
3037 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3038 return ERR_PTR(-EINVAL);
3039
3040 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3041 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3042 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3043 return ERR_PTR(-EINVAL);
3044
3045 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3046 return ERR_PTR(-EINVAL);
3047
3048 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3049 if (n_entries < 0)
3050 return ERR_PTR(n_entries);
3051
3052 if (n_entries > wiphy->max_acl_mac_addrs)
3053 return ERR_PTR(-ENOTSUPP);
3054
3055 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3056 GFP_KERNEL);
3057 if (!acl)
3058 return ERR_PTR(-ENOMEM);
3059
3060 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3061 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3062 i++;
3063 }
3064
3065 acl->n_acl_entries = n_entries;
3066 acl->acl_policy = acl_policy;
3067
3068 return acl;
3069}
3070
3071static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3072{
3073 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3074 struct net_device *dev = info->user_ptr[1];
3075 struct cfg80211_acl_data *acl;
3076 int err;
3077
3078 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3079 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3080 return -EOPNOTSUPP;
3081
3082 if (!dev->ieee80211_ptr->beacon_interval)
3083 return -EINVAL;
3084
3085 acl = parse_acl_data(&rdev->wiphy, info);
3086 if (IS_ERR(acl))
3087 return PTR_ERR(acl);
3088
3089 err = rdev_set_mac_acl(rdev, dev, acl);
3090
3091 kfree(acl);
3092
3093 return err;
3094}
3095
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003096static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003097 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003098{
Johannes Berg88600202012-02-13 15:17:18 +01003099 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003100
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003101 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3102 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3103 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3104 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003105 return -EINVAL;
3106
Johannes Berg88600202012-02-13 15:17:18 +01003107 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003108
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003109 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3110 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3111 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003112 if (!bcn->head_len)
3113 return -EINVAL;
3114 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003115 }
3116
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003117 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3118 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3119 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003120 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003121 }
3122
Johannes Berg4c476992010-10-04 21:36:35 +02003123 if (!haveinfo)
3124 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003125
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003126 if (attrs[NL80211_ATTR_IE]) {
3127 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3128 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003129 }
3130
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003131 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003132 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003133 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003134 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003135 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003136 }
3137
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003138 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003139 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003140 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003141 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003142 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003143 }
3144
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003145 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3146 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3147 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003148 }
3149
Johannes Berg88600202012-02-13 15:17:18 +01003150 return 0;
3151}
3152
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003153static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3154 struct cfg80211_ap_settings *params)
3155{
3156 struct wireless_dev *wdev;
3157 bool ret = false;
3158
Johannes Berg89a54e42012-06-15 14:33:17 +02003159 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003160 if (wdev->iftype != NL80211_IFTYPE_AP &&
3161 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3162 continue;
3163
Johannes Berg683b6d32012-11-08 21:25:48 +01003164 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003165 continue;
3166
Johannes Berg683b6d32012-11-08 21:25:48 +01003167 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003168 ret = true;
3169 break;
3170 }
3171
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003172 return ret;
3173}
3174
Jouni Malinene39e5b52012-09-30 19:29:39 +03003175static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3176 enum nl80211_auth_type auth_type,
3177 enum nl80211_commands cmd)
3178{
3179 if (auth_type > NL80211_AUTHTYPE_MAX)
3180 return false;
3181
3182 switch (cmd) {
3183 case NL80211_CMD_AUTHENTICATE:
3184 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3185 auth_type == NL80211_AUTHTYPE_SAE)
3186 return false;
3187 return true;
3188 case NL80211_CMD_CONNECT:
3189 case NL80211_CMD_START_AP:
3190 /* SAE not supported yet */
3191 if (auth_type == NL80211_AUTHTYPE_SAE)
3192 return false;
3193 return true;
3194 default:
3195 return false;
3196 }
3197}
3198
Johannes Berg88600202012-02-13 15:17:18 +01003199static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3200{
3201 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3202 struct net_device *dev = info->user_ptr[1];
3203 struct wireless_dev *wdev = dev->ieee80211_ptr;
3204 struct cfg80211_ap_settings params;
3205 int err;
3206
3207 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3208 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3209 return -EOPNOTSUPP;
3210
3211 if (!rdev->ops->start_ap)
3212 return -EOPNOTSUPP;
3213
3214 if (wdev->beacon_interval)
3215 return -EALREADY;
3216
3217 memset(&params, 0, sizeof(params));
3218
3219 /* these are required for START_AP */
3220 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3221 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3222 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3223 return -EINVAL;
3224
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003225 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003226 if (err)
3227 return err;
3228
3229 params.beacon_interval =
3230 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3231 params.dtim_period =
3232 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3233
3234 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3235 if (err)
3236 return err;
3237
3238 /*
3239 * In theory, some of these attributes should be required here
3240 * but since they were not used when the command was originally
3241 * added, keep them optional for old user space programs to let
3242 * them continue to work with drivers that do not need the
3243 * additional information -- drivers must check!
3244 */
3245 if (info->attrs[NL80211_ATTR_SSID]) {
3246 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3247 params.ssid_len =
3248 nla_len(info->attrs[NL80211_ATTR_SSID]);
3249 if (params.ssid_len == 0 ||
3250 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3251 return -EINVAL;
3252 }
3253
3254 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3255 params.hidden_ssid = nla_get_u32(
3256 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3257 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3258 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3259 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3260 return -EINVAL;
3261 }
3262
3263 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3264
3265 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3266 params.auth_type = nla_get_u32(
3267 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003268 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3269 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003270 return -EINVAL;
3271 } else
3272 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3273
3274 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3275 NL80211_MAX_NR_CIPHER_SUITES);
3276 if (err)
3277 return err;
3278
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303279 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3280 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3281 return -EOPNOTSUPP;
3282 params.inactivity_timeout = nla_get_u16(
3283 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3284 }
3285
Johannes Berg53cabad2012-11-14 15:17:28 +01003286 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3287 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3288 return -EINVAL;
3289 params.p2p_ctwindow =
3290 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3291 if (params.p2p_ctwindow > 127)
3292 return -EINVAL;
3293 if (params.p2p_ctwindow != 0 &&
3294 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3295 return -EINVAL;
3296 }
3297
3298 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3299 u8 tmp;
3300
3301 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3302 return -EINVAL;
3303 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3304 if (tmp > 1)
3305 return -EINVAL;
3306 params.p2p_opp_ps = tmp;
3307 if (params.p2p_opp_ps != 0 &&
3308 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3309 return -EINVAL;
3310 }
3311
Johannes Bergaa430da2012-05-16 23:50:18 +02003312 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003313 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3314 if (err)
3315 return err;
3316 } else if (wdev->preset_chandef.chan) {
3317 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003318 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003319 return -EINVAL;
3320
Ilan Peer174e0cd2014-02-23 09:13:01 +02003321 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3322 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003323 return -EINVAL;
3324
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303325 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3326 params.acl = parse_acl_data(&rdev->wiphy, info);
3327 if (IS_ERR(params.acl))
3328 return PTR_ERR(params.acl);
3329 }
3330
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003331 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003332 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003333 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003334 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003335 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003336 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003337 wdev->ssid_len = params.ssid_len;
3338 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003339 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003340 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303341
3342 kfree(params.acl);
3343
Johannes Berg56d18932011-05-09 18:41:15 +02003344 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003345}
3346
Johannes Berg88600202012-02-13 15:17:18 +01003347static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3348{
3349 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3350 struct net_device *dev = info->user_ptr[1];
3351 struct wireless_dev *wdev = dev->ieee80211_ptr;
3352 struct cfg80211_beacon_data params;
3353 int err;
3354
3355 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3356 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3357 return -EOPNOTSUPP;
3358
3359 if (!rdev->ops->change_beacon)
3360 return -EOPNOTSUPP;
3361
3362 if (!wdev->beacon_interval)
3363 return -EINVAL;
3364
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003365 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003366 if (err)
3367 return err;
3368
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003369 wdev_lock(wdev);
3370 err = rdev_change_beacon(rdev, dev, &params);
3371 wdev_unlock(wdev);
3372
3373 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003374}
3375
3376static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003377{
Johannes Berg4c476992010-10-04 21:36:35 +02003378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3379 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003380
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003381 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003382}
3383
Johannes Berg5727ef12007-12-19 02:03:34 +01003384static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3385 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3386 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3387 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003388 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003389 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003390 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003391};
3392
Johannes Bergeccb8e82009-05-11 21:57:56 +03003393static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003394 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003395 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003396{
3397 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003398 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003399 int flag;
3400
Johannes Bergeccb8e82009-05-11 21:57:56 +03003401 /*
3402 * Try parsing the new attribute first so userspace
3403 * can specify both for older kernels.
3404 */
3405 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3406 if (nla) {
3407 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003408
Johannes Bergeccb8e82009-05-11 21:57:56 +03003409 sta_flags = nla_data(nla);
3410 params->sta_flags_mask = sta_flags->mask;
3411 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003412 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003413 if ((params->sta_flags_mask |
3414 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3415 return -EINVAL;
3416 return 0;
3417 }
3418
3419 /* if present, parse the old attribute */
3420
3421 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003422 if (!nla)
3423 return 0;
3424
3425 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3426 nla, sta_flags_policy))
3427 return -EINVAL;
3428
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003429 /*
3430 * Only allow certain flags for interface types so that
3431 * other attributes are silently ignored. Remember that
3432 * this is backward compatibility code with old userspace
3433 * and shouldn't be hit in other cases anyway.
3434 */
3435 switch (iftype) {
3436 case NL80211_IFTYPE_AP:
3437 case NL80211_IFTYPE_AP_VLAN:
3438 case NL80211_IFTYPE_P2P_GO:
3439 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3440 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3441 BIT(NL80211_STA_FLAG_WME) |
3442 BIT(NL80211_STA_FLAG_MFP);
3443 break;
3444 case NL80211_IFTYPE_P2P_CLIENT:
3445 case NL80211_IFTYPE_STATION:
3446 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3447 BIT(NL80211_STA_FLAG_TDLS_PEER);
3448 break;
3449 case NL80211_IFTYPE_MESH_POINT:
3450 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3451 BIT(NL80211_STA_FLAG_MFP) |
3452 BIT(NL80211_STA_FLAG_AUTHORIZED);
3453 default:
3454 return -EINVAL;
3455 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003456
Johannes Berg3383b5a2012-05-10 20:14:43 +02003457 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3458 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003459 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003460
Johannes Berg3383b5a2012-05-10 20:14:43 +02003461 /* no longer support new API additions in old API */
3462 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3463 return -EINVAL;
3464 }
3465 }
3466
Johannes Berg5727ef12007-12-19 02:03:34 +01003467 return 0;
3468}
3469
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003470static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3471 int attr)
3472{
3473 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003474 u32 bitrate;
3475 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003476
3477 rate = nla_nest_start(msg, attr);
3478 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003479 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003480
3481 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3482 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003483 /* report 16-bit bitrate only if we can */
3484 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003485 if (bitrate > 0 &&
3486 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3487 return false;
3488 if (bitrate_compat > 0 &&
3489 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3490 return false;
3491
3492 if (info->flags & RATE_INFO_FLAGS_MCS) {
3493 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3494 return false;
3495 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3496 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3497 return false;
3498 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3499 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3500 return false;
3501 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3502 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3503 return false;
3504 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3505 return false;
3506 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3507 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3508 return false;
3509 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3510 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3511 return false;
3512 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3513 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3514 return false;
3515 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3516 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3517 return false;
3518 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3519 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3520 return false;
3521 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003522
3523 nla_nest_end(msg, rate);
3524 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003525}
3526
Felix Fietkau119363c2013-04-22 16:29:30 +02003527static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3528 int id)
3529{
3530 void *attr;
3531 int i = 0;
3532
3533 if (!mask)
3534 return true;
3535
3536 attr = nla_nest_start(msg, id);
3537 if (!attr)
3538 return false;
3539
3540 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3541 if (!(mask & BIT(i)))
3542 continue;
3543
3544 if (nla_put_u8(msg, i, signal[i]))
3545 return false;
3546 }
3547
3548 nla_nest_end(msg, attr);
3549
3550 return true;
3551}
3552
Eric W. Biederman15e47302012-09-07 20:12:54 +00003553static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003554 int flags,
3555 struct cfg80211_registered_device *rdev,
3556 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003557 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003558{
3559 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003560 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003561
Eric W. Biederman15e47302012-09-07 20:12:54 +00003562 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003563 if (!hdr)
3564 return -1;
3565
David S. Miller9360ffd2012-03-29 04:41:26 -04003566 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3567 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3568 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3569 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003570
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003571 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3572 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003573 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003574 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3575 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3576 sinfo->connected_time))
3577 goto nla_put_failure;
3578 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3579 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3580 sinfo->inactive_time))
3581 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003582 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3583 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003584 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003585 (u32)sinfo->rx_bytes))
3586 goto nla_put_failure;
3587 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003588 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003589 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3590 (u32)sinfo->tx_bytes))
3591 goto nla_put_failure;
3592 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3593 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003594 sinfo->rx_bytes))
3595 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003596 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3597 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003598 sinfo->tx_bytes))
3599 goto nla_put_failure;
3600 if ((sinfo->filled & STATION_INFO_LLID) &&
3601 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3602 goto nla_put_failure;
3603 if ((sinfo->filled & STATION_INFO_PLID) &&
3604 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3605 goto nla_put_failure;
3606 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3607 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3608 sinfo->plink_state))
3609 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003610 switch (rdev->wiphy.signal_type) {
3611 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003612 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3613 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3614 sinfo->signal))
3615 goto nla_put_failure;
3616 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3617 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3618 sinfo->signal_avg))
3619 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003620 break;
3621 default:
3622 break;
3623 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003624 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3625 if (!nl80211_put_signal(msg, sinfo->chains,
3626 sinfo->chain_signal,
3627 NL80211_STA_INFO_CHAIN_SIGNAL))
3628 goto nla_put_failure;
3629 }
3630 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3631 if (!nl80211_put_signal(msg, sinfo->chains,
3632 sinfo->chain_signal_avg,
3633 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3634 goto nla_put_failure;
3635 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003636 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003637 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3638 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003639 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003640 }
3641 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3642 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3643 NL80211_STA_INFO_RX_BITRATE))
3644 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003645 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003646 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3647 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3648 sinfo->rx_packets))
3649 goto nla_put_failure;
3650 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3651 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3652 sinfo->tx_packets))
3653 goto nla_put_failure;
3654 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3655 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3656 sinfo->tx_retries))
3657 goto nla_put_failure;
3658 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3659 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3660 sinfo->tx_failed))
3661 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003662 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3663 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3664 sinfo->expected_throughput))
3665 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003666 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3667 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3668 sinfo->beacon_loss_count))
3669 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003670 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3671 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3672 sinfo->local_pm))
3673 goto nla_put_failure;
3674 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3675 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3676 sinfo->peer_pm))
3677 goto nla_put_failure;
3678 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3679 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3680 sinfo->nonpeer_pm))
3681 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003682 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3683 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3684 if (!bss_param)
3685 goto nla_put_failure;
3686
David S. Miller9360ffd2012-03-29 04:41:26 -04003687 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3688 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3689 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3690 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3691 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3692 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3693 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3694 sinfo->bss_param.dtim_period) ||
3695 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3696 sinfo->bss_param.beacon_interval))
3697 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003698
3699 nla_nest_end(msg, bss_param);
3700 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003701 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3702 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3703 sizeof(struct nl80211_sta_flag_update),
3704 &sinfo->sta_flags))
3705 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003706 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3707 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3708 sinfo->t_offset))
3709 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003710 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003711
David S. Miller9360ffd2012-03-29 04:41:26 -04003712 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3713 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3714 sinfo->assoc_req_ies))
3715 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003716
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003717 return genlmsg_end(msg, hdr);
3718
3719 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003720 genlmsg_cancel(msg, hdr);
3721 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003722}
3723
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003724static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003725 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003726{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003727 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003728 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003729 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003730 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003731 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003732 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003733
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003734 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003735 if (err)
3736 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003737
Johannes Berg97990a02013-04-19 01:02:55 +02003738 if (!wdev->netdev) {
3739 err = -EINVAL;
3740 goto out_err;
3741 }
3742
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003743 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003744 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003745 goto out_err;
3746 }
3747
Johannes Bergbba95fe2008-07-29 13:22:51 +02003748 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003749 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003750 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003751 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003752 if (err == -ENOENT)
3753 break;
3754 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003755 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003756
3757 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003758 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003759 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003760 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003761 &sinfo) < 0)
3762 goto out;
3763
3764 sta_idx++;
3765 }
3766
3767
3768 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003769 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003770 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003771 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003772 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003773
3774 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003775}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003776
Johannes Berg5727ef12007-12-19 02:03:34 +01003777static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3778{
Johannes Berg4c476992010-10-04 21:36:35 +02003779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3780 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003781 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003782 struct sk_buff *msg;
3783 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003784 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003785
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003786 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003787
3788 if (!info->attrs[NL80211_ATTR_MAC])
3789 return -EINVAL;
3790
3791 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3792
Johannes Berg4c476992010-10-04 21:36:35 +02003793 if (!rdev->ops->get_station)
3794 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003795
Hila Gonene35e4d22012-06-27 17:19:42 +03003796 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003797 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003798 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003799
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003800 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003801 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003802 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003803
Eric W. Biederman15e47302012-09-07 20:12:54 +00003804 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003805 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003806 nlmsg_free(msg);
3807 return -ENOBUFS;
3808 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003809
Johannes Berg4c476992010-10-04 21:36:35 +02003810 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003811}
3812
Johannes Berg77ee7c82013-02-15 00:48:33 +01003813int cfg80211_check_station_change(struct wiphy *wiphy,
3814 struct station_parameters *params,
3815 enum cfg80211_station_type statype)
3816{
3817 if (params->listen_interval != -1)
3818 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003819 if (params->aid &&
3820 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003821 return -EINVAL;
3822
3823 /* When you run into this, adjust the code below for the new flag */
3824 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3825
3826 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003827 case CFG80211_STA_MESH_PEER_KERNEL:
3828 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003829 /*
3830 * No ignoring the TDLS flag here -- the userspace mesh
3831 * code doesn't have the bug of including TDLS in the
3832 * mask everywhere.
3833 */
3834 if (params->sta_flags_mask &
3835 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3836 BIT(NL80211_STA_FLAG_MFP) |
3837 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3838 return -EINVAL;
3839 break;
3840 case CFG80211_STA_TDLS_PEER_SETUP:
3841 case CFG80211_STA_TDLS_PEER_ACTIVE:
3842 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3843 return -EINVAL;
3844 /* ignore since it can't change */
3845 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3846 break;
3847 default:
3848 /* disallow mesh-specific things */
3849 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3850 return -EINVAL;
3851 if (params->local_pm)
3852 return -EINVAL;
3853 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3854 return -EINVAL;
3855 }
3856
3857 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3858 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3859 /* TDLS can't be set, ... */
3860 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3861 return -EINVAL;
3862 /*
3863 * ... but don't bother the driver with it. This works around
3864 * a hostapd/wpa_supplicant issue -- it always includes the
3865 * TLDS_PEER flag in the mask even for AP mode.
3866 */
3867 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3868 }
3869
3870 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3871 /* reject other things that can't change */
3872 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3873 return -EINVAL;
3874 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3875 return -EINVAL;
3876 if (params->supported_rates)
3877 return -EINVAL;
3878 if (params->ext_capab || params->ht_capa || params->vht_capa)
3879 return -EINVAL;
3880 }
3881
3882 if (statype != CFG80211_STA_AP_CLIENT) {
3883 if (params->vlan)
3884 return -EINVAL;
3885 }
3886
3887 switch (statype) {
3888 case CFG80211_STA_AP_MLME_CLIENT:
3889 /* Use this only for authorizing/unauthorizing a station */
3890 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3891 return -EOPNOTSUPP;
3892 break;
3893 case CFG80211_STA_AP_CLIENT:
3894 /* accept only the listed bits */
3895 if (params->sta_flags_mask &
3896 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3897 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3898 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3899 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3900 BIT(NL80211_STA_FLAG_WME) |
3901 BIT(NL80211_STA_FLAG_MFP)))
3902 return -EINVAL;
3903
3904 /* but authenticated/associated only if driver handles it */
3905 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3906 params->sta_flags_mask &
3907 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3908 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3909 return -EINVAL;
3910 break;
3911 case CFG80211_STA_IBSS:
3912 case CFG80211_STA_AP_STA:
3913 /* reject any changes other than AUTHORIZED */
3914 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3915 return -EINVAL;
3916 break;
3917 case CFG80211_STA_TDLS_PEER_SETUP:
3918 /* reject any changes other than AUTHORIZED or WME */
3919 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3920 BIT(NL80211_STA_FLAG_WME)))
3921 return -EINVAL;
3922 /* force (at least) rates when authorizing */
3923 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3924 !params->supported_rates)
3925 return -EINVAL;
3926 break;
3927 case CFG80211_STA_TDLS_PEER_ACTIVE:
3928 /* reject any changes */
3929 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003930 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003931 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3932 return -EINVAL;
3933 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003934 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003935 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3936 return -EINVAL;
3937 break;
3938 }
3939
3940 return 0;
3941}
3942EXPORT_SYMBOL(cfg80211_check_station_change);
3943
Johannes Berg5727ef12007-12-19 02:03:34 +01003944/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003945 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003946 */
Johannes Berg80b99892011-11-18 16:23:01 +01003947static struct net_device *get_vlan(struct genl_info *info,
3948 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003949{
Johannes Berg463d0182009-07-14 00:33:35 +02003950 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003951 struct net_device *v;
3952 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003953
Johannes Berg80b99892011-11-18 16:23:01 +01003954 if (!vlanattr)
3955 return NULL;
3956
3957 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3958 if (!v)
3959 return ERR_PTR(-ENODEV);
3960
3961 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3962 ret = -EINVAL;
3963 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003964 }
Johannes Berg80b99892011-11-18 16:23:01 +01003965
Johannes Berg77ee7c82013-02-15 00:48:33 +01003966 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3967 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3968 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3969 ret = -EINVAL;
3970 goto error;
3971 }
3972
Johannes Berg80b99892011-11-18 16:23:01 +01003973 if (!netif_running(v)) {
3974 ret = -ENETDOWN;
3975 goto error;
3976 }
3977
3978 return v;
3979 error:
3980 dev_put(v);
3981 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003982}
3983
Johannes Berg94e860f2014-01-20 23:58:15 +01003984static const struct nla_policy
3985nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003986 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3987 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3988};
3989
Johannes Bergff276692013-02-15 00:09:01 +01003990static int nl80211_parse_sta_wme(struct genl_info *info,
3991 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003992{
Jouni Malinendf881292013-02-14 21:10:54 +02003993 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3994 struct nlattr *nla;
3995 int err;
3996
Jouni Malinendf881292013-02-14 21:10:54 +02003997 /* parse WME attributes if present */
3998 if (!info->attrs[NL80211_ATTR_STA_WME])
3999 return 0;
4000
4001 nla = info->attrs[NL80211_ATTR_STA_WME];
4002 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4003 nl80211_sta_wme_policy);
4004 if (err)
4005 return err;
4006
4007 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4008 params->uapsd_queues = nla_get_u8(
4009 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4010 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4011 return -EINVAL;
4012
4013 if (tb[NL80211_STA_WME_MAX_SP])
4014 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4015
4016 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4017 return -EINVAL;
4018
4019 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4020
4021 return 0;
4022}
4023
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304024static int nl80211_parse_sta_channel_info(struct genl_info *info,
4025 struct station_parameters *params)
4026{
4027 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4028 params->supported_channels =
4029 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4030 params->supported_channels_len =
4031 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4032 /*
4033 * Need to include at least one (first channel, number of
4034 * channels) tuple for each subband, and must have proper
4035 * tuples for the rest of the data as well.
4036 */
4037 if (params->supported_channels_len < 2)
4038 return -EINVAL;
4039 if (params->supported_channels_len % 2)
4040 return -EINVAL;
4041 }
4042
4043 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4044 params->supported_oper_classes =
4045 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4046 params->supported_oper_classes_len =
4047 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4048 /*
4049 * The value of the Length field of the Supported Operating
4050 * Classes element is between 2 and 253.
4051 */
4052 if (params->supported_oper_classes_len < 2 ||
4053 params->supported_oper_classes_len > 253)
4054 return -EINVAL;
4055 }
4056 return 0;
4057}
4058
Johannes Bergff276692013-02-15 00:09:01 +01004059static int nl80211_set_station_tdls(struct genl_info *info,
4060 struct station_parameters *params)
4061{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304062 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004063 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004064 if (info->attrs[NL80211_ATTR_PEER_AID])
4065 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004066 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4067 params->ht_capa =
4068 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4069 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4070 params->vht_capa =
4071 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4072
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304073 err = nl80211_parse_sta_channel_info(info, params);
4074 if (err)
4075 return err;
4076
Johannes Bergff276692013-02-15 00:09:01 +01004077 return nl80211_parse_sta_wme(info, params);
4078}
4079
Johannes Berg5727ef12007-12-19 02:03:34 +01004080static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4081{
Johannes Berg4c476992010-10-04 21:36:35 +02004082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004083 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004084 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004085 u8 *mac_addr;
4086 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004087
4088 memset(&params, 0, sizeof(params));
4089
4090 params.listen_interval = -1;
4091
Johannes Berg77ee7c82013-02-15 00:48:33 +01004092 if (!rdev->ops->change_station)
4093 return -EOPNOTSUPP;
4094
Johannes Berg5727ef12007-12-19 02:03:34 +01004095 if (info->attrs[NL80211_ATTR_STA_AID])
4096 return -EINVAL;
4097
4098 if (!info->attrs[NL80211_ATTR_MAC])
4099 return -EINVAL;
4100
4101 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4102
4103 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4104 params.supported_rates =
4105 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4106 params.supported_rates_len =
4107 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4108 }
4109
Jouni Malinen9d62a982013-02-14 21:10:13 +02004110 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4111 params.capability =
4112 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4113 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4114 }
4115
4116 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4117 params.ext_capab =
4118 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4119 params.ext_capab_len =
4120 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4121 }
4122
Jouni Malinendf881292013-02-14 21:10:54 +02004123 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004124 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004125
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004126 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004127 return -EINVAL;
4128
Johannes Bergf8bacc22013-02-14 23:27:01 +01004129 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004130 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004131 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4132 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4133 return -EINVAL;
4134 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004135
Johannes Bergf8bacc22013-02-14 23:27:01 +01004136 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004137 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004138 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4139 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4140 return -EINVAL;
4141 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4142 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004143
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004144 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4145 enum nl80211_mesh_power_mode pm = nla_get_u32(
4146 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4147
4148 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4149 pm > NL80211_MESH_POWER_MAX)
4150 return -EINVAL;
4151
4152 params.local_pm = pm;
4153 }
4154
Johannes Berg77ee7c82013-02-15 00:48:33 +01004155 /* Include parameters for TDLS peer (will check later) */
4156 err = nl80211_set_station_tdls(info, &params);
4157 if (err)
4158 return err;
4159
4160 params.vlan = get_vlan(info, rdev);
4161 if (IS_ERR(params.vlan))
4162 return PTR_ERR(params.vlan);
4163
Johannes Berga97f4422009-06-18 17:23:43 +02004164 switch (dev->ieee80211_ptr->iftype) {
4165 case NL80211_IFTYPE_AP:
4166 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004167 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004168 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004169 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004170 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004171 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004172 break;
4173 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004174 err = -EOPNOTSUPP;
4175 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004176 }
4177
Johannes Berg77ee7c82013-02-15 00:48:33 +01004178 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004179 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004180
Johannes Berg77ee7c82013-02-15 00:48:33 +01004181 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004182 if (params.vlan)
4183 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004184
Johannes Berg5727ef12007-12-19 02:03:34 +01004185 return err;
4186}
4187
4188static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4189{
Johannes Berg4c476992010-10-04 21:36:35 +02004190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004191 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004192 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004193 struct station_parameters params;
4194 u8 *mac_addr = NULL;
4195
4196 memset(&params, 0, sizeof(params));
4197
Johannes Berg984c3112013-02-14 23:43:25 +01004198 if (!rdev->ops->add_station)
4199 return -EOPNOTSUPP;
4200
Johannes Berg5727ef12007-12-19 02:03:34 +01004201 if (!info->attrs[NL80211_ATTR_MAC])
4202 return -EINVAL;
4203
Johannes Berg5727ef12007-12-19 02:03:34 +01004204 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4205 return -EINVAL;
4206
4207 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4208 return -EINVAL;
4209
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004210 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4211 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004212 return -EINVAL;
4213
Johannes Berg5727ef12007-12-19 02:03:34 +01004214 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4215 params.supported_rates =
4216 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4217 params.supported_rates_len =
4218 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4219 params.listen_interval =
4220 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004221
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004222 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004223 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004224 else
4225 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004226 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4227 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004228
Jouni Malinen9d62a982013-02-14 21:10:13 +02004229 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4230 params.capability =
4231 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4232 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4233 }
4234
4235 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4236 params.ext_capab =
4237 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4238 params.ext_capab_len =
4239 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4240 }
4241
Jouni Malinen36aedc92008-08-25 11:58:58 +03004242 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4243 params.ht_capa =
4244 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004245
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004246 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4247 params.vht_capa =
4248 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4249
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004250 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4251 params.opmode_notif_used = true;
4252 params.opmode_notif =
4253 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4254 }
4255
Johannes Bergf8bacc22013-02-14 23:27:01 +01004256 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004257 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004258 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4259 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4260 return -EINVAL;
4261 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004262
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304263 err = nl80211_parse_sta_channel_info(info, &params);
4264 if (err)
4265 return err;
4266
Johannes Bergff276692013-02-15 00:09:01 +01004267 err = nl80211_parse_sta_wme(info, &params);
4268 if (err)
4269 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004270
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004271 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004272 return -EINVAL;
4273
Johannes Berg77ee7c82013-02-15 00:48:33 +01004274 /* When you run into this, adjust the code below for the new flag */
4275 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4276
Johannes Bergbdd90d52011-12-14 12:20:27 +01004277 switch (dev->ieee80211_ptr->iftype) {
4278 case NL80211_IFTYPE_AP:
4279 case NL80211_IFTYPE_AP_VLAN:
4280 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004281 /* ignore WME attributes if iface/sta is not capable */
4282 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4283 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4284 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004285
Johannes Bergbdd90d52011-12-14 12:20:27 +01004286 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004287 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4288 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004289 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004290 /* but don't bother the driver with it */
4291 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004292
Johannes Bergd582cff2012-10-26 17:53:44 +02004293 /* allow authenticated/associated only if driver handles it */
4294 if (!(rdev->wiphy.features &
4295 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4296 params.sta_flags_mask &
4297 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4298 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4299 return -EINVAL;
4300
Johannes Bergbdd90d52011-12-14 12:20:27 +01004301 /* must be last in here for error handling */
4302 params.vlan = get_vlan(info, rdev);
4303 if (IS_ERR(params.vlan))
4304 return PTR_ERR(params.vlan);
4305 break;
4306 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004307 /* ignore uAPSD data */
4308 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4309
Johannes Bergd582cff2012-10-26 17:53:44 +02004310 /* associated is disallowed */
4311 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4312 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004313 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004314 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4315 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004316 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004317 break;
4318 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004319 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004320 /* ignore uAPSD data */
4321 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4322
Johannes Berg77ee7c82013-02-15 00:48:33 +01004323 /* these are disallowed */
4324 if (params.sta_flags_mask &
4325 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4326 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004327 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004328 /* Only TDLS peers can be added */
4329 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4330 return -EINVAL;
4331 /* Can only add if TDLS ... */
4332 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4333 return -EOPNOTSUPP;
4334 /* ... with external setup is supported */
4335 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4336 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004337 /*
4338 * Older wpa_supplicant versions always mark the TDLS peer
4339 * as authorized, but it shouldn't yet be.
4340 */
4341 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004342 break;
4343 default:
4344 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004345 }
4346
Johannes Bergbdd90d52011-12-14 12:20:27 +01004347 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004348
Hila Gonene35e4d22012-06-27 17:19:42 +03004349 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004350
Johannes Berg5727ef12007-12-19 02:03:34 +01004351 if (params.vlan)
4352 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004353 return err;
4354}
4355
4356static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4357{
Johannes Berg4c476992010-10-04 21:36:35 +02004358 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4359 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004360 u8 *mac_addr = NULL;
4361
4362 if (info->attrs[NL80211_ATTR_MAC])
4363 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4364
Johannes Berge80cf852009-05-11 14:43:13 +02004365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004366 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004367 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004368 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4369 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004370
Johannes Berg4c476992010-10-04 21:36:35 +02004371 if (!rdev->ops->del_station)
4372 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004373
Hila Gonene35e4d22012-06-27 17:19:42 +03004374 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004375}
4376
Eric W. Biederman15e47302012-09-07 20:12:54 +00004377static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004378 int flags, struct net_device *dev,
4379 u8 *dst, u8 *next_hop,
4380 struct mpath_info *pinfo)
4381{
4382 void *hdr;
4383 struct nlattr *pinfoattr;
4384
Eric W. Biederman15e47302012-09-07 20:12:54 +00004385 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004386 if (!hdr)
4387 return -1;
4388
David S. Miller9360ffd2012-03-29 04:41:26 -04004389 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4390 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4391 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4392 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4393 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004394
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004395 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4396 if (!pinfoattr)
4397 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004398 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4399 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4400 pinfo->frame_qlen))
4401 goto nla_put_failure;
4402 if (((pinfo->filled & MPATH_INFO_SN) &&
4403 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4404 ((pinfo->filled & MPATH_INFO_METRIC) &&
4405 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4406 pinfo->metric)) ||
4407 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4408 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4409 pinfo->exptime)) ||
4410 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4411 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4412 pinfo->flags)) ||
4413 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4414 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4415 pinfo->discovery_timeout)) ||
4416 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4417 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4418 pinfo->discovery_retries)))
4419 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004420
4421 nla_nest_end(msg, pinfoattr);
4422
4423 return genlmsg_end(msg, hdr);
4424
4425 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004426 genlmsg_cancel(msg, hdr);
4427 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004428}
4429
4430static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004431 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004432{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004433 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004434 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004435 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004436 u8 dst[ETH_ALEN];
4437 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004438 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004440
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004441 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004442 if (err)
4443 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004444
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004445 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004446 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004447 goto out_err;
4448 }
4449
Johannes Berg97990a02013-04-19 01:02:55 +02004450 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004451 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004452 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004453 }
4454
Johannes Bergbba95fe2008-07-29 13:22:51 +02004455 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004456 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004457 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004458 if (err == -ENOENT)
4459 break;
4460 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004461 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004462
Eric W. Biederman15e47302012-09-07 20:12:54 +00004463 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004464 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004465 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004466 &pinfo) < 0)
4467 goto out;
4468
4469 path_idx++;
4470 }
4471
4472
4473 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004474 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004475 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004476 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004477 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004478 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004479}
4480
4481static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4482{
Johannes Berg4c476992010-10-04 21:36:35 +02004483 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004484 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004485 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004486 struct mpath_info pinfo;
4487 struct sk_buff *msg;
4488 u8 *dst = NULL;
4489 u8 next_hop[ETH_ALEN];
4490
4491 memset(&pinfo, 0, sizeof(pinfo));
4492
4493 if (!info->attrs[NL80211_ATTR_MAC])
4494 return -EINVAL;
4495
4496 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4497
Johannes Berg4c476992010-10-04 21:36:35 +02004498 if (!rdev->ops->get_mpath)
4499 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004500
Johannes Berg4c476992010-10-04 21:36:35 +02004501 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4502 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004503
Hila Gonene35e4d22012-06-27 17:19:42 +03004504 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004505 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004506 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004507
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004508 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004509 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004510 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004511
Eric W. Biederman15e47302012-09-07 20:12:54 +00004512 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004513 dev, dst, next_hop, &pinfo) < 0) {
4514 nlmsg_free(msg);
4515 return -ENOBUFS;
4516 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004517
Johannes Berg4c476992010-10-04 21:36:35 +02004518 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004519}
4520
4521static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4522{
Johannes Berg4c476992010-10-04 21:36:35 +02004523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4524 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004525 u8 *dst = NULL;
4526 u8 *next_hop = NULL;
4527
4528 if (!info->attrs[NL80211_ATTR_MAC])
4529 return -EINVAL;
4530
4531 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4532 return -EINVAL;
4533
4534 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4535 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4536
Johannes Berg4c476992010-10-04 21:36:35 +02004537 if (!rdev->ops->change_mpath)
4538 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004539
Johannes Berg4c476992010-10-04 21:36:35 +02004540 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4541 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004542
Hila Gonene35e4d22012-06-27 17:19:42 +03004543 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004544}
Johannes Berg4c476992010-10-04 21:36:35 +02004545
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004546static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4547{
Johannes Berg4c476992010-10-04 21:36:35 +02004548 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4549 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004550 u8 *dst = NULL;
4551 u8 *next_hop = NULL;
4552
4553 if (!info->attrs[NL80211_ATTR_MAC])
4554 return -EINVAL;
4555
4556 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4557 return -EINVAL;
4558
4559 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4560 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4561
Johannes Berg4c476992010-10-04 21:36:35 +02004562 if (!rdev->ops->add_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;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004567
Hila Gonene35e4d22012-06-27 17:19:42 +03004568 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004569}
4570
4571static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4572{
Johannes Berg4c476992010-10-04 21:36:35 +02004573 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4574 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004575 u8 *dst = NULL;
4576
4577 if (info->attrs[NL80211_ATTR_MAC])
4578 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4579
Johannes Berg4c476992010-10-04 21:36:35 +02004580 if (!rdev->ops->del_mpath)
4581 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004582
Hila Gonene35e4d22012-06-27 17:19:42 +03004583 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004584}
4585
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004586static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4587{
Johannes Berg4c476992010-10-04 21:36:35 +02004588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4589 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004590 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004591 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004592 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004593
4594 memset(&params, 0, sizeof(params));
4595 /* default to not changing parameters */
4596 params.use_cts_prot = -1;
4597 params.use_short_preamble = -1;
4598 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004599 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004600 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004601 params.p2p_ctwindow = -1;
4602 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004603
4604 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4605 params.use_cts_prot =
4606 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4607 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4608 params.use_short_preamble =
4609 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4610 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4611 params.use_short_slot_time =
4612 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004613 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4614 params.basic_rates =
4615 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4616 params.basic_rates_len =
4617 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4618 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004619 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4620 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004621 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4622 params.ht_opmode =
4623 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004624
Johannes Berg53cabad2012-11-14 15:17:28 +01004625 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4626 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4627 return -EINVAL;
4628 params.p2p_ctwindow =
4629 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4630 if (params.p2p_ctwindow < 0)
4631 return -EINVAL;
4632 if (params.p2p_ctwindow != 0 &&
4633 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4634 return -EINVAL;
4635 }
4636
4637 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4638 u8 tmp;
4639
4640 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4641 return -EINVAL;
4642 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4643 if (tmp > 1)
4644 return -EINVAL;
4645 params.p2p_opp_ps = tmp;
4646 if (params.p2p_opp_ps &&
4647 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4648 return -EINVAL;
4649 }
4650
Johannes Berg4c476992010-10-04 21:36:35 +02004651 if (!rdev->ops->change_bss)
4652 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004653
Johannes Berg074ac8d2010-09-16 14:58:22 +02004654 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004655 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4656 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004657
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004658 wdev_lock(wdev);
4659 err = rdev_change_bss(rdev, dev, &params);
4660 wdev_unlock(wdev);
4661
4662 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004663}
4664
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004665static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004666 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4667 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4668 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4669 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4670 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4671 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004672 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004673};
4674
4675static int parse_reg_rule(struct nlattr *tb[],
4676 struct ieee80211_reg_rule *reg_rule)
4677{
4678 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4679 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4680
4681 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4682 return -EINVAL;
4683 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4684 return -EINVAL;
4685 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4686 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004687 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4688 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004689 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4690 return -EINVAL;
4691
4692 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4693
4694 freq_range->start_freq_khz =
4695 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4696 freq_range->end_freq_khz =
4697 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004698 freq_range->max_bandwidth_khz =
4699 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004700
4701 power_rule->max_eirp =
4702 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4703
4704 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4705 power_rule->max_antenna_gain =
4706 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4707
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004708 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4709 reg_rule->dfs_cac_ms =
4710 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4711
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004712 return 0;
4713}
4714
4715static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4716{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004717 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004718 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004719
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004720 /*
4721 * You should only get this when cfg80211 hasn't yet initialized
4722 * completely when built-in to the kernel right between the time
4723 * window between nl80211_init() and regulatory_init(), if that is
4724 * even possible.
4725 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004726 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004727 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004728
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004729 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4730 user_reg_hint_type =
4731 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4732 else
4733 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4734
4735 switch (user_reg_hint_type) {
4736 case NL80211_USER_REG_HINT_USER:
4737 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004738 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4739 return -EINVAL;
4740
4741 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4742 return regulatory_hint_user(data, user_reg_hint_type);
4743 case NL80211_USER_REG_HINT_INDOOR:
4744 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004745 default:
4746 return -EINVAL;
4747 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004748}
4749
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004750static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004751 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004752{
Johannes Berg4c476992010-10-04 21:36:35 +02004753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004754 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004755 struct wireless_dev *wdev = dev->ieee80211_ptr;
4756 struct mesh_config cur_params;
4757 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004758 void *hdr;
4759 struct nlattr *pinfoattr;
4760 struct sk_buff *msg;
4761
Johannes Berg29cbe682010-12-03 09:20:44 +01004762 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4763 return -EOPNOTSUPP;
4764
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004765 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004766 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004767
Johannes Berg29cbe682010-12-03 09:20:44 +01004768 wdev_lock(wdev);
4769 /* If not connected, get default parameters */
4770 if (!wdev->mesh_id_len)
4771 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4772 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004773 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004774 wdev_unlock(wdev);
4775
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004776 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004777 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004778
4779 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004780 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004781 if (!msg)
4782 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004783 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004784 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004785 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004786 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004787 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004788 if (!pinfoattr)
4789 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004790 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4791 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4792 cur_params.dot11MeshRetryTimeout) ||
4793 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4794 cur_params.dot11MeshConfirmTimeout) ||
4795 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4796 cur_params.dot11MeshHoldingTimeout) ||
4797 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4798 cur_params.dot11MeshMaxPeerLinks) ||
4799 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4800 cur_params.dot11MeshMaxRetries) ||
4801 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4802 cur_params.dot11MeshTTL) ||
4803 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4804 cur_params.element_ttl) ||
4805 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4806 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004807 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4808 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004809 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4810 cur_params.dot11MeshHWMPmaxPREQretries) ||
4811 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4812 cur_params.path_refresh_time) ||
4813 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4814 cur_params.min_discovery_timeout) ||
4815 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4816 cur_params.dot11MeshHWMPactivePathTimeout) ||
4817 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4818 cur_params.dot11MeshHWMPpreqMinInterval) ||
4819 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4820 cur_params.dot11MeshHWMPperrMinInterval) ||
4821 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4822 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4823 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4824 cur_params.dot11MeshHWMPRootMode) ||
4825 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4826 cur_params.dot11MeshHWMPRannInterval) ||
4827 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4828 cur_params.dot11MeshGateAnnouncementProtocol) ||
4829 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4830 cur_params.dot11MeshForwarding) ||
4831 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004832 cur_params.rssi_threshold) ||
4833 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004834 cur_params.ht_opmode) ||
4835 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4836 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4837 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004838 cur_params.dot11MeshHWMProotInterval) ||
4839 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004840 cur_params.dot11MeshHWMPconfirmationInterval) ||
4841 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4842 cur_params.power_mode) ||
4843 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004844 cur_params.dot11MeshAwakeWindowDuration) ||
4845 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4846 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004847 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004848 nla_nest_end(msg, pinfoattr);
4849 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004850 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004851
Johannes Berg3b858752009-03-12 09:55:09 +01004852 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004853 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004854 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004855 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004856 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004857}
4858
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004859static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004860 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4861 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4862 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4863 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4864 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4865 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004866 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004867 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004868 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004869 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4870 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4871 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4872 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4873 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004874 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004875 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004876 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004877 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004878 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004879 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004880 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4881 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004882 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4883 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004884 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004885 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4886 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004887 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004888};
4889
Javier Cardonac80d5452010-12-16 17:37:49 -08004890static const struct nla_policy
4891 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004892 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004893 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4894 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004895 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004896 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004897 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004898 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004899 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004900 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004901};
4902
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004903static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004904 struct mesh_config *cfg,
4905 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004906{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004907 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004908 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004909
Marco Porschea54fba2013-01-07 16:04:48 +01004910#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4911do { \
4912 if (tb[attr]) { \
4913 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4914 return -EINVAL; \
4915 cfg->param = fn(tb[attr]); \
4916 mask |= (1 << (attr - 1)); \
4917 } \
4918} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004919
4920
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004921 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004922 return -EINVAL;
4923 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004924 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004925 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004926 return -EINVAL;
4927
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004928 /* This makes sure that there aren't more than 32 mesh config
4929 * parameters (otherwise our bitfield scheme would not work.) */
4930 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4931
4932 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004934 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4935 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004936 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004937 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4938 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004939 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004940 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4941 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004942 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004943 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4944 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004945 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004946 mask, NL80211_MESHCONF_MAX_RETRIES,
4947 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004948 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004949 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004950 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004951 mask, NL80211_MESHCONF_ELEMENT_TTL,
4952 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004953 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004954 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4955 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4957 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004958 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4959 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004960 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004961 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4962 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004963 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004964 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4965 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004966 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004967 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4968 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004969 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4970 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004971 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4972 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004973 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004974 1, 65535, mask,
4975 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004976 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004977 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004978 1, 65535, mask,
4979 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004980 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004981 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004982 dot11MeshHWMPnetDiameterTraversalTime,
4983 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004984 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4985 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004986 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4987 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4988 nla_get_u8);
4989 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4990 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004991 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004992 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004993 dot11MeshGateAnnouncementProtocol, 0, 1,
4994 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004995 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004996 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004997 mask, NL80211_MESHCONF_FORWARDING,
4998 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004999 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005000 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005001 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005002 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005003 mask, NL80211_MESHCONF_HT_OPMODE,
5004 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005005 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005006 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005007 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5008 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005009 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005010 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5011 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005012 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005013 dot11MeshHWMPconfirmationInterval,
5014 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005015 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5016 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005017 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5018 NL80211_MESH_POWER_ACTIVE,
5019 NL80211_MESH_POWER_MAX,
5020 mask, NL80211_MESHCONF_POWER_MODE,
5021 nla_get_u32);
5022 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5023 0, 65535, mask,
5024 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005025 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5026 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5027 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005028 if (mask_out)
5029 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005030
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005031 return 0;
5032
5033#undef FILL_IN_MESH_PARAM_IF_SET
5034}
5035
Javier Cardonac80d5452010-12-16 17:37:49 -08005036static int nl80211_parse_mesh_setup(struct genl_info *info,
5037 struct mesh_setup *setup)
5038{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005040 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5041
5042 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5043 return -EINVAL;
5044 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5045 info->attrs[NL80211_ATTR_MESH_SETUP],
5046 nl80211_mesh_setup_params_policy))
5047 return -EINVAL;
5048
Javier Cardonad299a1f2012-03-31 11:31:33 -07005049 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5050 setup->sync_method =
5051 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5052 IEEE80211_SYNC_METHOD_VENDOR :
5053 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5054
Javier Cardonac80d5452010-12-16 17:37:49 -08005055 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5056 setup->path_sel_proto =
5057 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5058 IEEE80211_PATH_PROTOCOL_VENDOR :
5059 IEEE80211_PATH_PROTOCOL_HWMP;
5060
5061 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5062 setup->path_metric =
5063 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5064 IEEE80211_PATH_METRIC_VENDOR :
5065 IEEE80211_PATH_METRIC_AIRTIME;
5066
Javier Cardona581a8b02011-04-07 15:08:27 -07005067
5068 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005069 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005070 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005071 if (!is_valid_ie_attr(ieattr))
5072 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005073 setup->ie = nla_data(ieattr);
5074 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005075 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005076 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5077 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5078 return -EINVAL;
5079 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005080 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5081 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005082 if (setup->is_secure)
5083 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005084
Colleen Twitty6e16d902013-05-08 11:45:59 -07005085 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5086 if (!setup->user_mpm)
5087 return -EINVAL;
5088 setup->auth_id =
5089 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5090 }
5091
Javier Cardonac80d5452010-12-16 17:37:49 -08005092 return 0;
5093}
5094
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005095static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005096 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005097{
5098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5099 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005100 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005101 struct mesh_config cfg;
5102 u32 mask;
5103 int err;
5104
Johannes Berg29cbe682010-12-03 09:20:44 +01005105 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5106 return -EOPNOTSUPP;
5107
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005108 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005109 return -EOPNOTSUPP;
5110
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005111 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005112 if (err)
5113 return err;
5114
Johannes Berg29cbe682010-12-03 09:20:44 +01005115 wdev_lock(wdev);
5116 if (!wdev->mesh_id_len)
5117 err = -ENOLINK;
5118
5119 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005120 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005121
5122 wdev_unlock(wdev);
5123
5124 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005125}
5126
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005127static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5128{
Johannes Berg458f4f92012-12-06 15:47:38 +01005129 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005130 struct sk_buff *msg;
5131 void *hdr = NULL;
5132 struct nlattr *nl_reg_rules;
5133 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005134
5135 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005136 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005137
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005138 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005139 if (!msg)
5140 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005141
Eric W. Biederman15e47302012-09-07 20:12:54 +00005142 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005143 NL80211_CMD_GET_REG);
5144 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005145 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005146
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005147 if (reg_last_request_cell_base() &&
5148 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5149 NL80211_USER_REG_HINT_CELL_BASE))
5150 goto nla_put_failure;
5151
Johannes Berg458f4f92012-12-06 15:47:38 +01005152 rcu_read_lock();
5153 regdom = rcu_dereference(cfg80211_regdomain);
5154
5155 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5156 (regdom->dfs_region &&
5157 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5158 goto nla_put_failure_rcu;
5159
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005160 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5161 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005162 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005163
Johannes Berg458f4f92012-12-06 15:47:38 +01005164 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005165 struct nlattr *nl_reg_rule;
5166 const struct ieee80211_reg_rule *reg_rule;
5167 const struct ieee80211_freq_range *freq_range;
5168 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005169 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005170
Johannes Berg458f4f92012-12-06 15:47:38 +01005171 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005172 freq_range = &reg_rule->freq_range;
5173 power_rule = &reg_rule->power_rule;
5174
5175 nl_reg_rule = nla_nest_start(msg, i);
5176 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005177 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005178
Janusz Dziedzic97524822014-01-30 09:52:20 +01005179 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5180 if (!max_bandwidth_khz)
5181 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5182 reg_rule);
5183
David S. Miller9360ffd2012-03-29 04:41:26 -04005184 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5185 reg_rule->flags) ||
5186 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5187 freq_range->start_freq_khz) ||
5188 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5189 freq_range->end_freq_khz) ||
5190 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005191 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005192 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5193 power_rule->max_antenna_gain) ||
5194 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005195 power_rule->max_eirp) ||
5196 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5197 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005198 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005199
5200 nla_nest_end(msg, nl_reg_rule);
5201 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005202 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005203
5204 nla_nest_end(msg, nl_reg_rules);
5205
5206 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005207 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005208
Johannes Berg458f4f92012-12-06 15:47:38 +01005209nla_put_failure_rcu:
5210 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005211nla_put_failure:
5212 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005213put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005214 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005215 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005216}
5217
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005218static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5219{
5220 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5221 struct nlattr *nl_reg_rule;
5222 char *alpha2 = NULL;
5223 int rem_reg_rules = 0, r = 0;
5224 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005225 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005226 struct ieee80211_regdomain *rd = NULL;
5227
5228 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5229 return -EINVAL;
5230
5231 if (!info->attrs[NL80211_ATTR_REG_RULES])
5232 return -EINVAL;
5233
5234 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5235
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005236 if (info->attrs[NL80211_ATTR_DFS_REGION])
5237 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5238
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005239 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005240 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005241 num_rules++;
5242 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005243 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005244 }
5245
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005246 if (!reg_is_valid_request(alpha2))
5247 return -EINVAL;
5248
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005249 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005250 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005251
5252 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005253 if (!rd)
5254 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005255
5256 rd->n_reg_rules = num_rules;
5257 rd->alpha2[0] = alpha2[0];
5258 rd->alpha2[1] = alpha2[1];
5259
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005260 /*
5261 * Disable DFS master mode if the DFS region was
5262 * not supported or known on this kernel.
5263 */
5264 if (reg_supported_dfs_region(dfs_region))
5265 rd->dfs_region = dfs_region;
5266
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005267 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005268 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005269 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5270 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5271 reg_rule_policy);
5272 if (r)
5273 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005274 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5275 if (r)
5276 goto bad_reg;
5277
5278 rule_idx++;
5279
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005280 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5281 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005282 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005283 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005284 }
5285
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005286 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005287 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005288 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005289
Johannes Bergd2372b32008-10-24 20:32:20 +02005290 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005291 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005292 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005293}
5294
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005295static int validate_scan_freqs(struct nlattr *freqs)
5296{
5297 struct nlattr *attr1, *attr2;
5298 int n_channels = 0, tmp1, tmp2;
5299
5300 nla_for_each_nested(attr1, freqs, tmp1) {
5301 n_channels++;
5302 /*
5303 * Some hardware has a limited channel list for
5304 * scanning, and it is pretty much nonsensical
5305 * to scan for a channel twice, so disallow that
5306 * and don't require drivers to check that the
5307 * channel list they get isn't longer than what
5308 * they can scan, as long as they can scan all
5309 * the channels they registered at once.
5310 */
5311 nla_for_each_nested(attr2, freqs, tmp2)
5312 if (attr1 != attr2 &&
5313 nla_get_u32(attr1) == nla_get_u32(attr2))
5314 return 0;
5315 }
5316
5317 return n_channels;
5318}
5319
Johannes Berg2a519312009-02-10 21:25:55 +01005320static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5321{
Johannes Berg4c476992010-10-04 21:36:35 +02005322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005323 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005324 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005325 struct nlattr *attr;
5326 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005327 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005328 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005329
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005330 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5331 return -EINVAL;
5332
Johannes Berg79c97e92009-07-07 03:56:12 +02005333 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005334
Johannes Berg4c476992010-10-04 21:36:35 +02005335 if (!rdev->ops->scan)
5336 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005337
Johannes Bergf9d15d12014-01-22 11:14:19 +02005338 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005339 err = -EBUSY;
5340 goto unlock;
5341 }
Johannes Berg2a519312009-02-10 21:25:55 +01005342
5343 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005344 n_channels = validate_scan_freqs(
5345 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005346 if (!n_channels) {
5347 err = -EINVAL;
5348 goto unlock;
5349 }
Johannes Berg2a519312009-02-10 21:25:55 +01005350 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005351 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005352 }
5353
5354 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5355 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5356 n_ssids++;
5357
Johannes Bergf9f47522013-03-19 15:04:07 +01005358 if (n_ssids > wiphy->max_scan_ssids) {
5359 err = -EINVAL;
5360 goto unlock;
5361 }
Johannes Berg2a519312009-02-10 21:25:55 +01005362
Jouni Malinen70692ad2009-02-16 19:39:13 +02005363 if (info->attrs[NL80211_ATTR_IE])
5364 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5365 else
5366 ie_len = 0;
5367
Johannes Bergf9f47522013-03-19 15:04:07 +01005368 if (ie_len > wiphy->max_scan_ie_len) {
5369 err = -EINVAL;
5370 goto unlock;
5371 }
Johannes Berg18a83652009-03-31 12:12:05 +02005372
Johannes Berg2a519312009-02-10 21:25:55 +01005373 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005374 + sizeof(*request->ssids) * n_ssids
5375 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005376 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005377 if (!request) {
5378 err = -ENOMEM;
5379 goto unlock;
5380 }
Johannes Berg2a519312009-02-10 21:25:55 +01005381
Johannes Berg2a519312009-02-10 21:25:55 +01005382 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005383 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005384 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005385 if (ie_len) {
5386 if (request->ssids)
5387 request->ie = (void *)(request->ssids + n_ssids);
5388 else
5389 request->ie = (void *)(request->channels + n_channels);
5390 }
Johannes Berg2a519312009-02-10 21:25:55 +01005391
Johannes Berg584991d2009-11-02 13:32:03 +01005392 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005393 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5394 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005395 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005396 struct ieee80211_channel *chan;
5397
5398 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5399
5400 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005401 err = -EINVAL;
5402 goto out_free;
5403 }
Johannes Berg584991d2009-11-02 13:32:03 +01005404
5405 /* ignore disabled channels */
5406 if (chan->flags & IEEE80211_CHAN_DISABLED)
5407 continue;
5408
5409 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005410 i++;
5411 }
5412 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005413 enum ieee80211_band band;
5414
Johannes Berg2a519312009-02-10 21:25:55 +01005415 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005416 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5417 int j;
5418 if (!wiphy->bands[band])
5419 continue;
5420 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005421 struct ieee80211_channel *chan;
5422
5423 chan = &wiphy->bands[band]->channels[j];
5424
5425 if (chan->flags & IEEE80211_CHAN_DISABLED)
5426 continue;
5427
5428 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005429 i++;
5430 }
5431 }
5432 }
5433
Johannes Berg584991d2009-11-02 13:32:03 +01005434 if (!i) {
5435 err = -EINVAL;
5436 goto out_free;
5437 }
5438
5439 request->n_channels = i;
5440
Johannes Berg2a519312009-02-10 21:25:55 +01005441 i = 0;
5442 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5443 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005444 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005445 err = -EINVAL;
5446 goto out_free;
5447 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005448 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005449 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005450 i++;
5451 }
5452 }
5453
Jouni Malinen70692ad2009-02-16 19:39:13 +02005454 if (info->attrs[NL80211_ATTR_IE]) {
5455 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005456 memcpy((void *)request->ie,
5457 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005458 request->ie_len);
5459 }
5460
Johannes Berg34850ab2011-07-18 18:08:35 +02005461 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005462 if (wiphy->bands[i])
5463 request->rates[i] =
5464 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005465
5466 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5467 nla_for_each_nested(attr,
5468 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5469 tmp) {
5470 enum ieee80211_band band = nla_type(attr);
5471
Dan Carpenter84404622011-07-29 11:52:18 +03005472 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005473 err = -EINVAL;
5474 goto out_free;
5475 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005476
5477 if (!wiphy->bands[band])
5478 continue;
5479
Johannes Berg34850ab2011-07-18 18:08:35 +02005480 err = ieee80211_get_ratemask(wiphy->bands[band],
5481 nla_data(attr),
5482 nla_len(attr),
5483 &request->rates[band]);
5484 if (err)
5485 goto out_free;
5486 }
5487 }
5488
Sam Leffler46856bb2012-10-11 21:03:32 -07005489 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005490 request->flags = nla_get_u32(
5491 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005492 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5493 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005494 err = -EOPNOTSUPP;
5495 goto out_free;
5496 }
5497 }
Sam Lefflered4737712012-10-11 21:03:31 -07005498
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305499 request->no_cck =
5500 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5501
Johannes Bergfd014282012-06-18 19:17:03 +02005502 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005503 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005504 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005505
Johannes Berg79c97e92009-07-07 03:56:12 +02005506 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005507 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005508
Johannes Berg463d0182009-07-14 00:33:35 +02005509 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005510 nl80211_send_scan_start(rdev, wdev);
5511 if (wdev->netdev)
5512 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005513 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005514 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005515 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005516 kfree(request);
5517 }
Johannes Berg3b858752009-03-12 09:55:09 +01005518
Johannes Bergf9f47522013-03-19 15:04:07 +01005519 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005520 return err;
5521}
5522
Luciano Coelho807f8a82011-05-11 17:09:35 +03005523static int nl80211_start_sched_scan(struct sk_buff *skb,
5524 struct genl_info *info)
5525{
5526 struct cfg80211_sched_scan_request *request;
5527 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5528 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005529 struct nlattr *attr;
5530 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005531 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005532 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005533 enum ieee80211_band band;
5534 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005535 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005536 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005537
5538 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5539 !rdev->ops->sched_scan_start)
5540 return -EOPNOTSUPP;
5541
5542 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5543 return -EINVAL;
5544
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005545 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5546 return -EINVAL;
5547
5548 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5549 if (interval == 0)
5550 return -EINVAL;
5551
Luciano Coelho807f8a82011-05-11 17:09:35 +03005552 wiphy = &rdev->wiphy;
5553
5554 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5555 n_channels = validate_scan_freqs(
5556 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5557 if (!n_channels)
5558 return -EINVAL;
5559 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005560 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005561 }
5562
5563 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5564 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5565 tmp)
5566 n_ssids++;
5567
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005568 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005569 return -EINVAL;
5570
Johannes Bergea73cbc2014-01-24 10:53:53 +01005571 /*
5572 * First, count the number of 'real' matchsets. Due to an issue with
5573 * the old implementation, matchsets containing only the RSSI attribute
5574 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5575 * RSSI for all matchsets, rather than their own matchset for reporting
5576 * all APs with a strong RSSI. This is needed to be compatible with
5577 * older userspace that treated a matchset with only the RSSI as the
5578 * global RSSI for all other matchsets - if there are other matchsets.
5579 */
5580 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005581 nla_for_each_nested(attr,
5582 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005583 tmp) {
5584 struct nlattr *rssi;
5585
5586 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5587 nla_data(attr), nla_len(attr),
5588 nl80211_match_policy);
5589 if (err)
5590 return err;
5591 /* add other standalone attributes here */
5592 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5593 n_match_sets++;
5594 continue;
5595 }
5596 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5597 if (rssi)
5598 default_match_rssi = nla_get_s32(rssi);
5599 }
5600 }
5601
5602 /* However, if there's no other matchset, add the RSSI one */
5603 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5604 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005605
5606 if (n_match_sets > wiphy->max_match_sets)
5607 return -EINVAL;
5608
Luciano Coelho807f8a82011-05-11 17:09:35 +03005609 if (info->attrs[NL80211_ATTR_IE])
5610 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5611 else
5612 ie_len = 0;
5613
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005614 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005615 return -EINVAL;
5616
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005617 if (rdev->sched_scan_req) {
5618 err = -EINPROGRESS;
5619 goto out;
5620 }
5621
Luciano Coelho807f8a82011-05-11 17:09:35 +03005622 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005623 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005624 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005625 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005626 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005627 if (!request) {
5628 err = -ENOMEM;
5629 goto out;
5630 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005631
5632 if (n_ssids)
5633 request->ssids = (void *)&request->channels[n_channels];
5634 request->n_ssids = n_ssids;
5635 if (ie_len) {
5636 if (request->ssids)
5637 request->ie = (void *)(request->ssids + n_ssids);
5638 else
5639 request->ie = (void *)(request->channels + n_channels);
5640 }
5641
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005642 if (n_match_sets) {
5643 if (request->ie)
5644 request->match_sets = (void *)(request->ie + ie_len);
5645 else if (request->ssids)
5646 request->match_sets =
5647 (void *)(request->ssids + n_ssids);
5648 else
5649 request->match_sets =
5650 (void *)(request->channels + n_channels);
5651 }
5652 request->n_match_sets = n_match_sets;
5653
Luciano Coelho807f8a82011-05-11 17:09:35 +03005654 i = 0;
5655 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5656 /* user specified, bail out if channel not found */
5657 nla_for_each_nested(attr,
5658 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5659 tmp) {
5660 struct ieee80211_channel *chan;
5661
5662 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5663
5664 if (!chan) {
5665 err = -EINVAL;
5666 goto out_free;
5667 }
5668
5669 /* ignore disabled channels */
5670 if (chan->flags & IEEE80211_CHAN_DISABLED)
5671 continue;
5672
5673 request->channels[i] = chan;
5674 i++;
5675 }
5676 } else {
5677 /* all channels */
5678 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5679 int j;
5680 if (!wiphy->bands[band])
5681 continue;
5682 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5683 struct ieee80211_channel *chan;
5684
5685 chan = &wiphy->bands[band]->channels[j];
5686
5687 if (chan->flags & IEEE80211_CHAN_DISABLED)
5688 continue;
5689
5690 request->channels[i] = chan;
5691 i++;
5692 }
5693 }
5694 }
5695
5696 if (!i) {
5697 err = -EINVAL;
5698 goto out_free;
5699 }
5700
5701 request->n_channels = i;
5702
5703 i = 0;
5704 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5705 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5706 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005707 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005708 err = -EINVAL;
5709 goto out_free;
5710 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005711 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005712 memcpy(request->ssids[i].ssid, nla_data(attr),
5713 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005714 i++;
5715 }
5716 }
5717
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005718 i = 0;
5719 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5720 nla_for_each_nested(attr,
5721 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5722 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005723 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005724
Johannes Bergae811e22014-01-24 10:17:47 +01005725 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5726 nla_data(attr), nla_len(attr),
5727 nl80211_match_policy);
5728 if (err)
5729 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005730 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005731 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005732 if (WARN_ON(i >= n_match_sets)) {
5733 /* this indicates a programming error,
5734 * the loop above should have verified
5735 * things properly
5736 */
5737 err = -EINVAL;
5738 goto out_free;
5739 }
5740
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005741 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5742 err = -EINVAL;
5743 goto out_free;
5744 }
5745 memcpy(request->match_sets[i].ssid.ssid,
5746 nla_data(ssid), nla_len(ssid));
5747 request->match_sets[i].ssid.ssid_len =
5748 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005749 /* special attribute - old implemenation w/a */
5750 request->match_sets[i].rssi_thold =
5751 default_match_rssi;
5752 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5753 if (rssi)
5754 request->match_sets[i].rssi_thold =
5755 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005756 }
5757 i++;
5758 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005759
5760 /* there was no other matchset, so the RSSI one is alone */
5761 if (i == 0)
5762 request->match_sets[0].rssi_thold = default_match_rssi;
5763
5764 request->min_rssi_thold = INT_MAX;
5765 for (i = 0; i < n_match_sets; i++)
5766 request->min_rssi_thold =
5767 min(request->match_sets[i].rssi_thold,
5768 request->min_rssi_thold);
5769 } else {
5770 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005771 }
5772
Johannes Berg9900e482014-02-04 21:01:25 +01005773 if (ie_len) {
5774 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005775 memcpy((void *)request->ie,
5776 nla_data(info->attrs[NL80211_ATTR_IE]),
5777 request->ie_len);
5778 }
5779
Sam Leffler46856bb2012-10-11 21:03:32 -07005780 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005781 request->flags = nla_get_u32(
5782 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005783 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5784 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005785 err = -EOPNOTSUPP;
5786 goto out_free;
5787 }
5788 }
Sam Lefflered4737712012-10-11 21:03:31 -07005789
Luciano Coelho807f8a82011-05-11 17:09:35 +03005790 request->dev = dev;
5791 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005792 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005793 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005794
Hila Gonene35e4d22012-06-27 17:19:42 +03005795 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005796 if (!err) {
5797 rdev->sched_scan_req = request;
5798 nl80211_send_sched_scan(rdev, dev,
5799 NL80211_CMD_START_SCHED_SCAN);
5800 goto out;
5801 }
5802
5803out_free:
5804 kfree(request);
5805out:
5806 return err;
5807}
5808
5809static int nl80211_stop_sched_scan(struct sk_buff *skb,
5810 struct genl_info *info)
5811{
5812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5813
5814 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5815 !rdev->ops->sched_scan_stop)
5816 return -EOPNOTSUPP;
5817
Johannes Berg5fe231e2013-05-08 21:45:15 +02005818 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005819}
5820
Simon Wunderlich04f39042013-02-08 18:16:19 +01005821static int nl80211_start_radar_detection(struct sk_buff *skb,
5822 struct genl_info *info)
5823{
5824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5825 struct net_device *dev = info->user_ptr[1];
5826 struct wireless_dev *wdev = dev->ieee80211_ptr;
5827 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005828 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005829 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005830 int err;
5831
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005832 dfs_region = reg_get_dfs_region(wdev->wiphy);
5833 if (dfs_region == NL80211_DFS_UNSET)
5834 return -EINVAL;
5835
Simon Wunderlich04f39042013-02-08 18:16:19 +01005836 err = nl80211_parse_chandef(rdev, info, &chandef);
5837 if (err)
5838 return err;
5839
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005840 if (netif_carrier_ok(dev))
5841 return -EBUSY;
5842
Simon Wunderlich04f39042013-02-08 18:16:19 +01005843 if (wdev->cac_started)
5844 return -EBUSY;
5845
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02005846 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03005847 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005848 if (err < 0)
5849 return err;
5850
5851 if (err == 0)
5852 return -EINVAL;
5853
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005854 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005855 return -EINVAL;
5856
5857 if (!rdev->ops->start_radar_detection)
5858 return -EOPNOTSUPP;
5859
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005860 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5861 if (WARN_ON(!cac_time_ms))
5862 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5863
5864 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5865 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005866 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005867 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005868 wdev->cac_started = true;
5869 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005870 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005871 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005872 return err;
5873}
5874
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005875static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5876{
5877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5878 struct net_device *dev = info->user_ptr[1];
5879 struct wireless_dev *wdev = dev->ieee80211_ptr;
5880 struct cfg80211_csa_settings params;
5881 /* csa_attrs is defined static to avoid waste of stack size - this
5882 * function is called under RTNL lock, so this should not be a problem.
5883 */
5884 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5885 u8 radar_detect_width = 0;
5886 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005887 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005888 int len, i;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005889
5890 if (!rdev->ops->channel_switch ||
5891 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5892 return -EOPNOTSUPP;
5893
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005894 switch (dev->ieee80211_ptr->iftype) {
5895 case NL80211_IFTYPE_AP:
5896 case NL80211_IFTYPE_P2P_GO:
5897 need_new_beacon = true;
5898
5899 /* useless if AP is not running */
5900 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005901 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005902 break;
5903 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005904 if (!wdev->ssid_len)
5905 return -ENOTCONN;
5906 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005907 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005908 if (!wdev->mesh_id_len)
5909 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005910 break;
5911 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005912 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005913 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005914
5915 memset(&params, 0, sizeof(params));
5916
5917 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5918 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5919 return -EINVAL;
5920
5921 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005922 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005923 return -EINVAL;
5924
5925 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5926
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005927 if (!need_new_beacon)
5928 goto skip_beacons;
5929
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005930 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5931 if (err)
5932 return err;
5933
5934 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5935 info->attrs[NL80211_ATTR_CSA_IES],
5936 nl80211_policy);
5937 if (err)
5938 return err;
5939
5940 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5941 if (err)
5942 return err;
5943
5944 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5945 return -EINVAL;
5946
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005947 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5948 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005949 return -EINVAL;
5950
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005951 params.n_counter_offsets_beacon = len / sizeof(u16);
5952 if (rdev->wiphy.max_num_csa_counters &&
5953 (params.n_counter_offsets_beacon >
5954 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005955 return -EINVAL;
5956
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005957 params.counter_offsets_beacon =
5958 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5959
5960 /* sanity checks - counters should fit and be the same */
5961 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
5962 u16 offset = params.counter_offsets_beacon[i];
5963
5964 if (offset >= params.beacon_csa.tail_len)
5965 return -EINVAL;
5966
5967 if (params.beacon_csa.tail[offset] != params.count)
5968 return -EINVAL;
5969 }
5970
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005971 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005972 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5973 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005974 return -EINVAL;
5975
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005976 params.n_counter_offsets_presp = len / sizeof(u16);
5977 if (rdev->wiphy.max_num_csa_counters &&
5978 (params.n_counter_offsets_beacon >
5979 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005980 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005981
5982 params.counter_offsets_presp =
5983 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5984
5985 /* sanity checks - counters should fit and be the same */
5986 for (i = 0; i < params.n_counter_offsets_presp; i++) {
5987 u16 offset = params.counter_offsets_presp[i];
5988
5989 if (offset >= params.beacon_csa.probe_resp_len)
5990 return -EINVAL;
5991
5992 if (params.beacon_csa.probe_resp[offset] !=
5993 params.count)
5994 return -EINVAL;
5995 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005996 }
5997
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005998skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005999 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6000 if (err)
6001 return err;
6002
Ilan Peer174e0cd2014-02-23 09:13:01 +02006003 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6004 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006005 return -EINVAL;
6006
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006007 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6008 &params.chandef,
6009 wdev->iftype);
6010 if (err < 0)
6011 return err;
6012
6013 if (err > 0) {
6014 radar_detect_width = BIT(params.chandef.width);
6015 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006016 }
6017
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006018 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6019 params.block_tx = true;
6020
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006021 wdev_lock(wdev);
6022 err = rdev_channel_switch(rdev, dev, &params);
6023 wdev_unlock(wdev);
6024
6025 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006026}
6027
Johannes Berg9720bb32011-06-21 09:45:33 +02006028static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6029 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006030 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006031 struct wireless_dev *wdev,
6032 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006033{
Johannes Berg48ab9052009-07-10 18:42:31 +02006034 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006035 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006036 void *hdr;
6037 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006038
6039 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006040
Eric W. Biederman15e47302012-09-07 20:12:54 +00006041 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006042 NL80211_CMD_NEW_SCAN_RESULTS);
6043 if (!hdr)
6044 return -1;
6045
Johannes Berg9720bb32011-06-21 09:45:33 +02006046 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6047
Johannes Berg97990a02013-04-19 01:02:55 +02006048 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6049 goto nla_put_failure;
6050 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006051 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6052 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006053 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6054 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006055
6056 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6057 if (!bss)
6058 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006059 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006060 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006061 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006062
6063 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006064 /* indicate whether we have probe response data or not */
6065 if (rcu_access_pointer(res->proberesp_ies) &&
6066 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6067 goto fail_unlock_rcu;
6068
6069 /* this pointer prefers to be pointed to probe response data
6070 * but is always valid
6071 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006072 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006073 if (ies) {
6074 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6075 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006076 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6077 ies->len, ies->data))
6078 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006079 }
Johannes Berg0e227082014-08-12 20:34:30 +02006080
6081 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006082 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006083 if (ies && ies->from_beacon) {
6084 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006085 goto fail_unlock_rcu;
6086 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6087 ies->len, ies->data))
6088 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006089 }
6090 rcu_read_unlock();
6091
David S. Miller9360ffd2012-03-29 04:41:26 -04006092 if (res->beacon_interval &&
6093 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6094 goto nla_put_failure;
6095 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6096 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006097 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006098 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6099 jiffies_to_msecs(jiffies - intbss->ts)))
6100 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006101
Johannes Berg77965c92009-02-18 18:45:06 +01006102 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006103 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006104 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6105 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006106 break;
6107 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006108 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6109 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006110 break;
6111 default:
6112 break;
6113 }
6114
Johannes Berg48ab9052009-07-10 18:42:31 +02006115 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006116 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006117 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006118 if (intbss == wdev->current_bss &&
6119 nla_put_u32(msg, NL80211_BSS_STATUS,
6120 NL80211_BSS_STATUS_ASSOCIATED))
6121 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006122 break;
6123 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006124 if (intbss == wdev->current_bss &&
6125 nla_put_u32(msg, NL80211_BSS_STATUS,
6126 NL80211_BSS_STATUS_IBSS_JOINED))
6127 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006128 break;
6129 default:
6130 break;
6131 }
6132
Johannes Berg2a519312009-02-10 21:25:55 +01006133 nla_nest_end(msg, bss);
6134
6135 return genlmsg_end(msg, hdr);
6136
Johannes Berg8cef2c92013-02-05 16:54:31 +01006137 fail_unlock_rcu:
6138 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006139 nla_put_failure:
6140 genlmsg_cancel(msg, hdr);
6141 return -EMSGSIZE;
6142}
6143
Johannes Berg97990a02013-04-19 01:02:55 +02006144static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006145{
Johannes Berg48ab9052009-07-10 18:42:31 +02006146 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006147 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006148 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006149 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006150 int err;
6151
Johannes Berg97990a02013-04-19 01:02:55 +02006152 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006153 if (err)
6154 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006155
Johannes Berg48ab9052009-07-10 18:42:31 +02006156 wdev_lock(wdev);
6157 spin_lock_bh(&rdev->bss_lock);
6158 cfg80211_bss_expire(rdev);
6159
Johannes Berg9720bb32011-06-21 09:45:33 +02006160 cb->seq = rdev->bss_generation;
6161
Johannes Berg48ab9052009-07-10 18:42:31 +02006162 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006163 if (++idx <= start)
6164 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006165 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006166 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006167 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006168 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006169 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006170 }
6171 }
6172
Johannes Berg48ab9052009-07-10 18:42:31 +02006173 spin_unlock_bh(&rdev->bss_lock);
6174 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006175
Johannes Berg97990a02013-04-19 01:02:55 +02006176 cb->args[2] = idx;
6177 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006178
Johannes Berg67748892010-10-04 21:14:06 +02006179 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006180}
6181
Eric W. Biederman15e47302012-09-07 20:12:54 +00006182static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006183 int flags, struct net_device *dev,
6184 struct survey_info *survey)
6185{
6186 void *hdr;
6187 struct nlattr *infoattr;
6188
Eric W. Biederman15e47302012-09-07 20:12:54 +00006189 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006190 NL80211_CMD_NEW_SURVEY_RESULTS);
6191 if (!hdr)
6192 return -ENOMEM;
6193
David S. Miller9360ffd2012-03-29 04:41:26 -04006194 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6195 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006196
6197 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6198 if (!infoattr)
6199 goto nla_put_failure;
6200
David S. Miller9360ffd2012-03-29 04:41:26 -04006201 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6202 survey->channel->center_freq))
6203 goto nla_put_failure;
6204
6205 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6206 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6207 goto nla_put_failure;
6208 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6209 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6210 goto nla_put_failure;
6211 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6212 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6213 survey->channel_time))
6214 goto nla_put_failure;
6215 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6216 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6217 survey->channel_time_busy))
6218 goto nla_put_failure;
6219 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6220 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6221 survey->channel_time_ext_busy))
6222 goto nla_put_failure;
6223 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6224 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6225 survey->channel_time_rx))
6226 goto nla_put_failure;
6227 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6228 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6229 survey->channel_time_tx))
6230 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006231
6232 nla_nest_end(msg, infoattr);
6233
6234 return genlmsg_end(msg, hdr);
6235
6236 nla_put_failure:
6237 genlmsg_cancel(msg, hdr);
6238 return -EMSGSIZE;
6239}
6240
6241static int nl80211_dump_survey(struct sk_buff *skb,
6242 struct netlink_callback *cb)
6243{
6244 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006245 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006246 struct wireless_dev *wdev;
6247 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006248 int res;
6249
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006250 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006251 if (res)
6252 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006253
Johannes Berg97990a02013-04-19 01:02:55 +02006254 if (!wdev->netdev) {
6255 res = -EINVAL;
6256 goto out_err;
6257 }
6258
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006259 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006260 res = -EOPNOTSUPP;
6261 goto out_err;
6262 }
6263
6264 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006265 struct ieee80211_channel *chan;
6266
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006267 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006268 if (res == -ENOENT)
6269 break;
6270 if (res)
6271 goto out_err;
6272
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006273 /* Survey without a channel doesn't make sense */
6274 if (!survey.channel) {
6275 res = -EINVAL;
6276 goto out;
6277 }
6278
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006279 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006280 survey.channel->center_freq);
6281 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6282 survey_idx++;
6283 continue;
6284 }
6285
Holger Schurig61fa7132009-11-11 12:25:40 +01006286 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006287 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006288 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006289 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006290 goto out;
6291 survey_idx++;
6292 }
6293
6294 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006295 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006296 res = skb->len;
6297 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006298 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006299 return res;
6300}
6301
Samuel Ortizb23aa672009-07-01 21:26:54 +02006302static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6303{
6304 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6305 NL80211_WPA_VERSION_2));
6306}
6307
Jouni Malinen636a5d32009-03-19 13:39:22 +02006308static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6309{
Johannes Berg4c476992010-10-04 21:36:35 +02006310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6311 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006312 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006313 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6314 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006315 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006316 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006317 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006318
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006319 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6320 return -EINVAL;
6321
6322 if (!info->attrs[NL80211_ATTR_MAC])
6323 return -EINVAL;
6324
Jouni Malinen17780922009-03-27 20:52:47 +02006325 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6326 return -EINVAL;
6327
Johannes Berg19957bb2009-07-02 17:20:43 +02006328 if (!info->attrs[NL80211_ATTR_SSID])
6329 return -EINVAL;
6330
6331 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6332 return -EINVAL;
6333
Johannes Bergfffd0932009-07-08 14:22:54 +02006334 err = nl80211_parse_key(info, &key);
6335 if (err)
6336 return err;
6337
6338 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006339 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6340 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006341 if (!key.p.key || !key.p.key_len)
6342 return -EINVAL;
6343 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6344 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6345 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6346 key.p.key_len != WLAN_KEY_LEN_WEP104))
6347 return -EINVAL;
6348 if (key.idx > 4)
6349 return -EINVAL;
6350 } else {
6351 key.p.key_len = 0;
6352 key.p.key = NULL;
6353 }
6354
Johannes Bergafea0b72010-08-10 09:46:42 +02006355 if (key.idx >= 0) {
6356 int i;
6357 bool ok = false;
6358 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6359 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6360 ok = true;
6361 break;
6362 }
6363 }
Johannes Berg4c476992010-10-04 21:36:35 +02006364 if (!ok)
6365 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006366 }
6367
Johannes Berg4c476992010-10-04 21:36:35 +02006368 if (!rdev->ops->auth)
6369 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006370
Johannes Berg074ac8d2010-09-16 14:58:22 +02006371 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006372 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6373 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006374
Johannes Berg19957bb2009-07-02 17:20:43 +02006375 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006376 chan = nl80211_get_valid_chan(&rdev->wiphy,
6377 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6378 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006379 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006380
Johannes Berg19957bb2009-07-02 17:20:43 +02006381 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6382 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6383
6384 if (info->attrs[NL80211_ATTR_IE]) {
6385 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6386 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6387 }
6388
6389 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006390 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006391 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006392
Jouni Malinene39e5b52012-09-30 19:29:39 +03006393 if (auth_type == NL80211_AUTHTYPE_SAE &&
6394 !info->attrs[NL80211_ATTR_SAE_DATA])
6395 return -EINVAL;
6396
6397 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6398 if (auth_type != NL80211_AUTHTYPE_SAE)
6399 return -EINVAL;
6400 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6401 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6402 /* need to include at least Auth Transaction and Status Code */
6403 if (sae_data_len < 4)
6404 return -EINVAL;
6405 }
6406
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006407 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6408
Johannes Berg95de8172012-01-20 13:55:25 +01006409 /*
6410 * Since we no longer track auth state, ignore
6411 * requests to only change local state.
6412 */
6413 if (local_state_change)
6414 return 0;
6415
Johannes Berg91bf9b22013-05-15 17:44:01 +02006416 wdev_lock(dev->ieee80211_ptr);
6417 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6418 ssid, ssid_len, ie, ie_len,
6419 key.p.key, key.p.key_len, key.idx,
6420 sae_data, sae_data_len);
6421 wdev_unlock(dev->ieee80211_ptr);
6422 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006423}
6424
Johannes Bergc0692b82010-08-27 14:26:53 +03006425static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6426 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006427 struct cfg80211_crypto_settings *settings,
6428 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006429{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006430 memset(settings, 0, sizeof(*settings));
6431
Samuel Ortizb23aa672009-07-01 21:26:54 +02006432 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6433
Johannes Bergc0692b82010-08-27 14:26:53 +03006434 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6435 u16 proto;
6436 proto = nla_get_u16(
6437 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6438 settings->control_port_ethertype = cpu_to_be16(proto);
6439 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6440 proto != ETH_P_PAE)
6441 return -EINVAL;
6442 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6443 settings->control_port_no_encrypt = true;
6444 } else
6445 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6446
Samuel Ortizb23aa672009-07-01 21:26:54 +02006447 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6448 void *data;
6449 int len, i;
6450
6451 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6452 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6453 settings->n_ciphers_pairwise = len / sizeof(u32);
6454
6455 if (len % sizeof(u32))
6456 return -EINVAL;
6457
Johannes Berg3dc27d22009-07-02 21:36:37 +02006458 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006459 return -EINVAL;
6460
6461 memcpy(settings->ciphers_pairwise, data, len);
6462
6463 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006464 if (!cfg80211_supported_cipher_suite(
6465 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006466 settings->ciphers_pairwise[i]))
6467 return -EINVAL;
6468 }
6469
6470 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6471 settings->cipher_group =
6472 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006473 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6474 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006475 return -EINVAL;
6476 }
6477
6478 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6479 settings->wpa_versions =
6480 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6481 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6482 return -EINVAL;
6483 }
6484
6485 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6486 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006487 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006488
6489 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6490 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6491 settings->n_akm_suites = len / sizeof(u32);
6492
6493 if (len % sizeof(u32))
6494 return -EINVAL;
6495
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006496 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6497 return -EINVAL;
6498
Samuel Ortizb23aa672009-07-01 21:26:54 +02006499 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006500 }
6501
6502 return 0;
6503}
6504
Jouni Malinen636a5d32009-03-19 13:39:22 +02006505static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6506{
Johannes Berg4c476992010-10-04 21:36:35 +02006507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6508 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006509 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006510 struct cfg80211_assoc_request req = {};
6511 const u8 *bssid, *ssid;
6512 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006513
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006514 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6515 return -EINVAL;
6516
6517 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006518 !info->attrs[NL80211_ATTR_SSID] ||
6519 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006520 return -EINVAL;
6521
Johannes Berg4c476992010-10-04 21:36:35 +02006522 if (!rdev->ops->assoc)
6523 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006524
Johannes Berg074ac8d2010-09-16 14:58:22 +02006525 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006526 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6527 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006528
Johannes Berg19957bb2009-07-02 17:20:43 +02006529 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006530
Jouni Malinen664834d2014-01-15 00:01:44 +02006531 chan = nl80211_get_valid_chan(&rdev->wiphy,
6532 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6533 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006534 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006535
Johannes Berg19957bb2009-07-02 17:20:43 +02006536 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6537 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006538
6539 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006540 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6541 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006542 }
6543
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006544 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006545 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006546 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006547 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006548 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006549 else if (mfp != NL80211_MFP_NO)
6550 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03006551 }
6552
Johannes Berg3e5d7642009-07-07 14:37:26 +02006553 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006554 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006555
Ben Greear7e7c8922011-11-18 11:31:59 -08006556 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006557 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006558
6559 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006560 memcpy(&req.ht_capa_mask,
6561 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6562 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006563
6564 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006565 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006566 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006567 memcpy(&req.ht_capa,
6568 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6569 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006570 }
6571
Johannes Bergee2aca32013-02-21 17:36:01 +01006572 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006573 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006574
6575 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006576 memcpy(&req.vht_capa_mask,
6577 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6578 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006579
6580 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006581 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006582 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006583 memcpy(&req.vht_capa,
6584 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6585 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006586 }
6587
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006588 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6589 if (!(rdev->wiphy.features &
6590 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6591 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6592 return -EINVAL;
6593 req.flags |= ASSOC_REQ_USE_RRM;
6594 }
6595
Johannes Bergf62fab72013-02-21 20:09:09 +01006596 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006597 if (!err) {
6598 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006599 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6600 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006601 wdev_unlock(dev->ieee80211_ptr);
6602 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006603
Jouni Malinen636a5d32009-03-19 13:39:22 +02006604 return err;
6605}
6606
6607static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6608{
Johannes Berg4c476992010-10-04 21:36:35 +02006609 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6610 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006611 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006612 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006613 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006614 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006615
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006616 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6617 return -EINVAL;
6618
6619 if (!info->attrs[NL80211_ATTR_MAC])
6620 return -EINVAL;
6621
6622 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6623 return -EINVAL;
6624
Johannes Berg4c476992010-10-04 21:36:35 +02006625 if (!rdev->ops->deauth)
6626 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006627
Johannes Berg074ac8d2010-09-16 14:58:22 +02006628 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006629 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6630 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006631
Johannes Berg19957bb2009-07-02 17:20:43 +02006632 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006633
Johannes Berg19957bb2009-07-02 17:20:43 +02006634 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6635 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006636 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006637 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006638 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006639
6640 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006641 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6642 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006643 }
6644
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006645 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6646
Johannes Berg91bf9b22013-05-15 17:44:01 +02006647 wdev_lock(dev->ieee80211_ptr);
6648 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6649 local_state_change);
6650 wdev_unlock(dev->ieee80211_ptr);
6651 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006652}
6653
6654static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6655{
Johannes Berg4c476992010-10-04 21:36:35 +02006656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6657 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006658 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006659 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006660 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006661 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006662
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006663 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6664 return -EINVAL;
6665
6666 if (!info->attrs[NL80211_ATTR_MAC])
6667 return -EINVAL;
6668
6669 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6670 return -EINVAL;
6671
Johannes Berg4c476992010-10-04 21:36:35 +02006672 if (!rdev->ops->disassoc)
6673 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006674
Johannes Berg074ac8d2010-09-16 14:58:22 +02006675 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006676 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6677 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006678
Johannes Berg19957bb2009-07-02 17:20:43 +02006679 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006680
Johannes Berg19957bb2009-07-02 17:20:43 +02006681 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6682 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006683 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006684 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006685 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006686
6687 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006688 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6689 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006690 }
6691
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006692 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6693
Johannes Berg91bf9b22013-05-15 17:44:01 +02006694 wdev_lock(dev->ieee80211_ptr);
6695 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6696 local_state_change);
6697 wdev_unlock(dev->ieee80211_ptr);
6698 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006699}
6700
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006701static bool
6702nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6703 int mcast_rate[IEEE80211_NUM_BANDS],
6704 int rateval)
6705{
6706 struct wiphy *wiphy = &rdev->wiphy;
6707 bool found = false;
6708 int band, i;
6709
6710 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6711 struct ieee80211_supported_band *sband;
6712
6713 sband = wiphy->bands[band];
6714 if (!sband)
6715 continue;
6716
6717 for (i = 0; i < sband->n_bitrates; i++) {
6718 if (sband->bitrates[i].bitrate == rateval) {
6719 mcast_rate[band] = i + 1;
6720 found = true;
6721 break;
6722 }
6723 }
6724 }
6725
6726 return found;
6727}
6728
Johannes Berg04a773a2009-04-19 21:24:32 +02006729static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6730{
Johannes Berg4c476992010-10-04 21:36:35 +02006731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6732 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006733 struct cfg80211_ibss_params ibss;
6734 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006735 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006736 int err;
6737
Johannes Berg8e30bc52009-04-22 17:45:38 +02006738 memset(&ibss, 0, sizeof(ibss));
6739
Johannes Berg04a773a2009-04-19 21:24:32 +02006740 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6741 return -EINVAL;
6742
Johannes Berg683b6d32012-11-08 21:25:48 +01006743 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006744 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6745 return -EINVAL;
6746
Johannes Berg8e30bc52009-04-22 17:45:38 +02006747 ibss.beacon_interval = 100;
6748
6749 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6750 ibss.beacon_interval =
6751 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6752 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6753 return -EINVAL;
6754 }
6755
Johannes Berg4c476992010-10-04 21:36:35 +02006756 if (!rdev->ops->join_ibss)
6757 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006758
Johannes Berg4c476992010-10-04 21:36:35 +02006759 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6760 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006761
Johannes Berg79c97e92009-07-07 03:56:12 +02006762 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006763
Johannes Berg39193492011-09-16 13:45:25 +02006764 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006765 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006766
6767 if (!is_valid_ether_addr(ibss.bssid))
6768 return -EINVAL;
6769 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006770 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6771 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6772
6773 if (info->attrs[NL80211_ATTR_IE]) {
6774 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6775 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6776 }
6777
Johannes Berg683b6d32012-11-08 21:25:48 +01006778 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6779 if (err)
6780 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006781
Ilan Peer174e0cd2014-02-23 09:13:01 +02006782 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6783 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006784 return -EINVAL;
6785
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006786 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006787 case NL80211_CHAN_WIDTH_5:
6788 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006789 case NL80211_CHAN_WIDTH_20_NOHT:
6790 break;
6791 case NL80211_CHAN_WIDTH_20:
6792 case NL80211_CHAN_WIDTH_40:
6793 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6794 break;
6795 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006796 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006797 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006798
Johannes Berg04a773a2009-04-19 21:24:32 +02006799 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006800 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006801
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006802 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6803 u8 *rates =
6804 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6805 int n_rates =
6806 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6807 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006808 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006809
Johannes Berg34850ab2011-07-18 18:08:35 +02006810 err = ieee80211_get_ratemask(sband, rates, n_rates,
6811 &ibss.basic_rates);
6812 if (err)
6813 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006814 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006815
Simon Wunderlich803768f2013-06-28 10:39:58 +02006816 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6817 memcpy(&ibss.ht_capa_mask,
6818 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6819 sizeof(ibss.ht_capa_mask));
6820
6821 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6822 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6823 return -EINVAL;
6824 memcpy(&ibss.ht_capa,
6825 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6826 sizeof(ibss.ht_capa));
6827 }
6828
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006829 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6830 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6831 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6832 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006833
Johannes Berg4c476992010-10-04 21:36:35 +02006834 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306835 bool no_ht = false;
6836
Johannes Berg4c476992010-10-04 21:36:35 +02006837 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306838 info->attrs[NL80211_ATTR_KEYS],
6839 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006840 if (IS_ERR(connkeys))
6841 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306842
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006843 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6844 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306845 kfree(connkeys);
6846 return -EINVAL;
6847 }
Johannes Berg4c476992010-10-04 21:36:35 +02006848 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006849
Antonio Quartulli267335d2012-01-31 20:25:47 +01006850 ibss.control_port =
6851 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6852
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006853 ibss.userspace_handles_dfs =
6854 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6855
Johannes Berg4c476992010-10-04 21:36:35 +02006856 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006857 if (err)
6858 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006859 return err;
6860}
6861
6862static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6863{
Johannes Berg4c476992010-10-04 21:36:35 +02006864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6865 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006866
Johannes Berg4c476992010-10-04 21:36:35 +02006867 if (!rdev->ops->leave_ibss)
6868 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006869
Johannes Berg4c476992010-10-04 21:36:35 +02006870 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6871 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006872
Johannes Berg4c476992010-10-04 21:36:35 +02006873 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006874}
6875
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006876static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6877{
6878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6879 struct net_device *dev = info->user_ptr[1];
6880 int mcast_rate[IEEE80211_NUM_BANDS];
6881 u32 nla_rate;
6882 int err;
6883
6884 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6885 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6886 return -EOPNOTSUPP;
6887
6888 if (!rdev->ops->set_mcast_rate)
6889 return -EOPNOTSUPP;
6890
6891 memset(mcast_rate, 0, sizeof(mcast_rate));
6892
6893 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6894 return -EINVAL;
6895
6896 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6897 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6898 return -EINVAL;
6899
6900 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6901
6902 return err;
6903}
6904
Johannes Bergad7e7182013-11-13 13:37:47 +01006905static struct sk_buff *
6906__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6907 int approxlen, u32 portid, u32 seq,
6908 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006909 enum nl80211_attrs attr,
6910 const struct nl80211_vendor_cmd_info *info,
6911 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006912{
6913 struct sk_buff *skb;
6914 void *hdr;
6915 struct nlattr *data;
6916
6917 skb = nlmsg_new(approxlen + 100, gfp);
6918 if (!skb)
6919 return NULL;
6920
6921 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6922 if (!hdr) {
6923 kfree_skb(skb);
6924 return NULL;
6925 }
6926
6927 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6928 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006929
6930 if (info) {
6931 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6932 info->vendor_id))
6933 goto nla_put_failure;
6934 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6935 info->subcmd))
6936 goto nla_put_failure;
6937 }
6938
Johannes Bergad7e7182013-11-13 13:37:47 +01006939 data = nla_nest_start(skb, attr);
6940
6941 ((void **)skb->cb)[0] = rdev;
6942 ((void **)skb->cb)[1] = hdr;
6943 ((void **)skb->cb)[2] = data;
6944
6945 return skb;
6946
6947 nla_put_failure:
6948 kfree_skb(skb);
6949 return NULL;
6950}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006951
Johannes Berge03ad6e2014-01-01 17:22:30 +01006952struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6953 enum nl80211_commands cmd,
6954 enum nl80211_attrs attr,
6955 int vendor_event_idx,
6956 int approxlen, gfp_t gfp)
6957{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006958 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006959 const struct nl80211_vendor_cmd_info *info;
6960
6961 switch (cmd) {
6962 case NL80211_CMD_TESTMODE:
6963 if (WARN_ON(vendor_event_idx != -1))
6964 return NULL;
6965 info = NULL;
6966 break;
6967 case NL80211_CMD_VENDOR:
6968 if (WARN_ON(vendor_event_idx < 0 ||
6969 vendor_event_idx >= wiphy->n_vendor_events))
6970 return NULL;
6971 info = &wiphy->vendor_events[vendor_event_idx];
6972 break;
6973 default:
6974 WARN_ON(1);
6975 return NULL;
6976 }
6977
6978 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6979 cmd, attr, info, gfp);
6980}
6981EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6982
6983void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6984{
6985 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6986 void *hdr = ((void **)skb->cb)[1];
6987 struct nlattr *data = ((void **)skb->cb)[2];
6988 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6989
6990 nla_nest_end(skb, data);
6991 genlmsg_end(skb, hdr);
6992
6993 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6994 mcgrp = NL80211_MCGRP_VENDOR;
6995
6996 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6997 mcgrp, gfp);
6998}
6999EXPORT_SYMBOL(__cfg80211_send_event_skb);
7000
Johannes Bergaff89a92009-07-01 21:26:51 +02007001#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007002static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7003{
Johannes Berg4c476992010-10-04 21:36:35 +02007004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007005 struct wireless_dev *wdev =
7006 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007007 int err;
7008
David Spinadelfc73f112013-07-31 18:04:15 +03007009 if (!rdev->ops->testmode_cmd)
7010 return -EOPNOTSUPP;
7011
7012 if (IS_ERR(wdev)) {
7013 err = PTR_ERR(wdev);
7014 if (err != -EINVAL)
7015 return err;
7016 wdev = NULL;
7017 } else if (wdev->wiphy != &rdev->wiphy) {
7018 return -EINVAL;
7019 }
7020
Johannes Bergaff89a92009-07-01 21:26:51 +02007021 if (!info->attrs[NL80211_ATTR_TESTDATA])
7022 return -EINVAL;
7023
Johannes Bergad7e7182013-11-13 13:37:47 +01007024 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007025 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007026 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7027 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007028 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007029
Johannes Bergaff89a92009-07-01 21:26:51 +02007030 return err;
7031}
7032
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007033static int nl80211_testmode_dump(struct sk_buff *skb,
7034 struct netlink_callback *cb)
7035{
Johannes Berg00918d32011-12-13 17:22:05 +01007036 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007037 int err;
7038 long phy_idx;
7039 void *data = NULL;
7040 int data_len = 0;
7041
Johannes Berg5fe231e2013-05-08 21:45:15 +02007042 rtnl_lock();
7043
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007044 if (cb->args[0]) {
7045 /*
7046 * 0 is a valid index, but not valid for args[0],
7047 * so we need to offset by 1.
7048 */
7049 phy_idx = cb->args[0] - 1;
7050 } else {
7051 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7052 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7053 nl80211_policy);
7054 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007055 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007056
Johannes Berg2bd7e352012-06-15 14:23:16 +02007057 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7058 nl80211_fam.attrbuf);
7059 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007060 err = PTR_ERR(rdev);
7061 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007062 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007063 phy_idx = rdev->wiphy_idx;
7064 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007065
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007066 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7067 cb->args[1] =
7068 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7069 }
7070
7071 if (cb->args[1]) {
7072 data = nla_data((void *)cb->args[1]);
7073 data_len = nla_len((void *)cb->args[1]);
7074 }
7075
Johannes Berg00918d32011-12-13 17:22:05 +01007076 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7077 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007078 err = -ENOENT;
7079 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007080 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007081
Johannes Berg00918d32011-12-13 17:22:05 +01007082 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007083 err = -EOPNOTSUPP;
7084 goto out_err;
7085 }
7086
7087 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007088 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007089 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7090 NL80211_CMD_TESTMODE);
7091 struct nlattr *tmdata;
7092
Dan Carpentercb35fba2013-08-14 14:50:01 +03007093 if (!hdr)
7094 break;
7095
David S. Miller9360ffd2012-03-29 04:41:26 -04007096 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007097 genlmsg_cancel(skb, hdr);
7098 break;
7099 }
7100
7101 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7102 if (!tmdata) {
7103 genlmsg_cancel(skb, hdr);
7104 break;
7105 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007106 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007107 nla_nest_end(skb, tmdata);
7108
7109 if (err == -ENOBUFS || err == -ENOENT) {
7110 genlmsg_cancel(skb, hdr);
7111 break;
7112 } else if (err) {
7113 genlmsg_cancel(skb, hdr);
7114 goto out_err;
7115 }
7116
7117 genlmsg_end(skb, hdr);
7118 }
7119
7120 err = skb->len;
7121 /* see above */
7122 cb->args[0] = phy_idx + 1;
7123 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007124 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007125 return err;
7126}
Johannes Bergaff89a92009-07-01 21:26:51 +02007127#endif
7128
Samuel Ortizb23aa672009-07-01 21:26:54 +02007129static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7130{
Johannes Berg4c476992010-10-04 21:36:35 +02007131 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7132 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007133 struct cfg80211_connect_params connect;
7134 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007135 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007136 int err;
7137
7138 memset(&connect, 0, sizeof(connect));
7139
7140 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7141 return -EINVAL;
7142
7143 if (!info->attrs[NL80211_ATTR_SSID] ||
7144 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7145 return -EINVAL;
7146
7147 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7148 connect.auth_type =
7149 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007150 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7151 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007152 return -EINVAL;
7153 } else
7154 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7155
7156 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7157
Johannes Bergc0692b82010-08-27 14:26:53 +03007158 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007159 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007160 if (err)
7161 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007162
Johannes Berg074ac8d2010-09-16 14:58:22 +02007163 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007164 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7165 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007166
Johannes Berg79c97e92009-07-07 03:56:12 +02007167 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007168
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307169 connect.bg_scan_period = -1;
7170 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7171 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7172 connect.bg_scan_period =
7173 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7174 }
7175
Samuel Ortizb23aa672009-07-01 21:26:54 +02007176 if (info->attrs[NL80211_ATTR_MAC])
7177 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007178 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7179 connect.bssid_hint =
7180 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007181 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7182 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7183
7184 if (info->attrs[NL80211_ATTR_IE]) {
7185 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7186 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7187 }
7188
Jouni Malinencee00a92013-01-15 17:15:57 +02007189 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7190 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7191 if (connect.mfp != NL80211_MFP_REQUIRED &&
7192 connect.mfp != NL80211_MFP_NO)
7193 return -EINVAL;
7194 } else {
7195 connect.mfp = NL80211_MFP_NO;
7196 }
7197
Samuel Ortizb23aa672009-07-01 21:26:54 +02007198 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007199 connect.channel = nl80211_get_valid_chan(
7200 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7201 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007202 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007203 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007204 connect.channel_hint = nl80211_get_valid_chan(
7205 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7206 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007207 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007208 }
7209
Johannes Bergfffd0932009-07-08 14:22:54 +02007210 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7211 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307212 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007213 if (IS_ERR(connkeys))
7214 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007215 }
7216
Ben Greear7e7c8922011-11-18 11:31:59 -08007217 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7218 connect.flags |= ASSOC_REQ_DISABLE_HT;
7219
7220 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7221 memcpy(&connect.ht_capa_mask,
7222 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7223 sizeof(connect.ht_capa_mask));
7224
7225 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007226 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7227 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007228 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007229 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007230 memcpy(&connect.ht_capa,
7231 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7232 sizeof(connect.ht_capa));
7233 }
7234
Johannes Bergee2aca32013-02-21 17:36:01 +01007235 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7236 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7237
7238 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7239 memcpy(&connect.vht_capa_mask,
7240 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7241 sizeof(connect.vht_capa_mask));
7242
7243 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7244 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7245 kfree(connkeys);
7246 return -EINVAL;
7247 }
7248 memcpy(&connect.vht_capa,
7249 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7250 sizeof(connect.vht_capa));
7251 }
7252
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007253 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7254 if (!(rdev->wiphy.features &
7255 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7256 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7257 return -EINVAL;
7258 connect.flags |= ASSOC_REQ_USE_RRM;
7259 }
7260
Johannes Berg83739b02013-05-15 17:44:01 +02007261 wdev_lock(dev->ieee80211_ptr);
7262 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7263 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007264 if (err)
7265 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007266 return err;
7267}
7268
7269static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7270{
Johannes Berg4c476992010-10-04 21:36:35 +02007271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7272 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007273 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007274 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007275
7276 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7277 reason = WLAN_REASON_DEAUTH_LEAVING;
7278 else
7279 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7280
7281 if (reason == 0)
7282 return -EINVAL;
7283
Johannes Berg074ac8d2010-09-16 14:58:22 +02007284 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007285 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7286 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007287
Johannes Berg83739b02013-05-15 17:44:01 +02007288 wdev_lock(dev->ieee80211_ptr);
7289 ret = cfg80211_disconnect(rdev, dev, reason, true);
7290 wdev_unlock(dev->ieee80211_ptr);
7291 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007292}
7293
Johannes Berg463d0182009-07-14 00:33:35 +02007294static int nl80211_wiphy_netns(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];
Johannes Berg463d0182009-07-14 00:33:35 +02007297 struct net *net;
7298 int err;
7299 u32 pid;
7300
7301 if (!info->attrs[NL80211_ATTR_PID])
7302 return -EINVAL;
7303
7304 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7305
Johannes Berg463d0182009-07-14 00:33:35 +02007306 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007307 if (IS_ERR(net))
7308 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007309
7310 err = 0;
7311
7312 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007313 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7314 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007315
Johannes Berg463d0182009-07-14 00:33:35 +02007316 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007317 return err;
7318}
7319
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007320static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7321{
Johannes Berg4c476992010-10-04 21:36:35 +02007322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007323 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7324 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007325 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007326 struct cfg80211_pmksa pmksa;
7327
7328 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7329
7330 if (!info->attrs[NL80211_ATTR_MAC])
7331 return -EINVAL;
7332
7333 if (!info->attrs[NL80211_ATTR_PMKID])
7334 return -EINVAL;
7335
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007336 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7337 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7338
Johannes Berg074ac8d2010-09-16 14:58:22 +02007339 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007340 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7341 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007342
7343 switch (info->genlhdr->cmd) {
7344 case NL80211_CMD_SET_PMKSA:
7345 rdev_ops = rdev->ops->set_pmksa;
7346 break;
7347 case NL80211_CMD_DEL_PMKSA:
7348 rdev_ops = rdev->ops->del_pmksa;
7349 break;
7350 default:
7351 WARN_ON(1);
7352 break;
7353 }
7354
Johannes Berg4c476992010-10-04 21:36:35 +02007355 if (!rdev_ops)
7356 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007357
Johannes Berg4c476992010-10-04 21:36:35 +02007358 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007359}
7360
7361static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7362{
Johannes Berg4c476992010-10-04 21:36:35 +02007363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7364 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007365
Johannes Berg074ac8d2010-09-16 14:58:22 +02007366 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007367 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7368 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007369
Johannes Berg4c476992010-10-04 21:36:35 +02007370 if (!rdev->ops->flush_pmksa)
7371 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007372
Hila Gonene35e4d22012-06-27 17:19:42 +03007373 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007374}
7375
Arik Nemtsov109086c2011-09-28 14:12:50 +03007376static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7377{
7378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7379 struct net_device *dev = info->user_ptr[1];
7380 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307381 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007382 u16 status_code;
7383 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007384 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007385
7386 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7387 !rdev->ops->tdls_mgmt)
7388 return -EOPNOTSUPP;
7389
7390 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7391 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7392 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7393 !info->attrs[NL80211_ATTR_IE] ||
7394 !info->attrs[NL80211_ATTR_MAC])
7395 return -EINVAL;
7396
7397 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7398 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7399 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7400 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007401 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307402 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7403 peer_capability =
7404 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007405
Hila Gonene35e4d22012-06-27 17:19:42 +03007406 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307407 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007408 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007409 nla_data(info->attrs[NL80211_ATTR_IE]),
7410 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007411}
7412
7413static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7414{
7415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7416 struct net_device *dev = info->user_ptr[1];
7417 enum nl80211_tdls_operation operation;
7418 u8 *peer;
7419
7420 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7421 !rdev->ops->tdls_oper)
7422 return -EOPNOTSUPP;
7423
7424 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7425 !info->attrs[NL80211_ATTR_MAC])
7426 return -EINVAL;
7427
7428 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7429 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7430
Hila Gonene35e4d22012-06-27 17:19:42 +03007431 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007432}
7433
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007434static int nl80211_remain_on_channel(struct sk_buff *skb,
7435 struct genl_info *info)
7436{
Johannes Berg4c476992010-10-04 21:36:35 +02007437 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007438 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007439 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007440 struct sk_buff *msg;
7441 void *hdr;
7442 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007443 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007444 int err;
7445
7446 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7447 !info->attrs[NL80211_ATTR_DURATION])
7448 return -EINVAL;
7449
7450 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7451
Johannes Berg7c4ef712011-11-18 15:33:48 +01007452 if (!rdev->ops->remain_on_channel ||
7453 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007454 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007455
Johannes Bergebf348f2012-06-01 12:50:54 +02007456 /*
7457 * We should be on that channel for at least a minimum amount of
7458 * time (10ms) but no longer than the driver supports.
7459 */
7460 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7461 duration > rdev->wiphy.max_remain_on_channel_duration)
7462 return -EINVAL;
7463
Johannes Berg683b6d32012-11-08 21:25:48 +01007464 err = nl80211_parse_chandef(rdev, info, &chandef);
7465 if (err)
7466 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007467
7468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007469 if (!msg)
7470 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007471
Eric W. Biederman15e47302012-09-07 20:12:54 +00007472 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007473 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007474 if (!hdr) {
7475 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007476 goto free_msg;
7477 }
7478
Johannes Berg683b6d32012-11-08 21:25:48 +01007479 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7480 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007481
7482 if (err)
7483 goto free_msg;
7484
David S. Miller9360ffd2012-03-29 04:41:26 -04007485 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7486 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007487
7488 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007489
7490 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007491
7492 nla_put_failure:
7493 err = -ENOBUFS;
7494 free_msg:
7495 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007496 return err;
7497}
7498
7499static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7500 struct genl_info *info)
7501{
Johannes Berg4c476992010-10-04 21:36:35 +02007502 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007503 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007504 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007505
7506 if (!info->attrs[NL80211_ATTR_COOKIE])
7507 return -EINVAL;
7508
Johannes Berg4c476992010-10-04 21:36:35 +02007509 if (!rdev->ops->cancel_remain_on_channel)
7510 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007511
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007512 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7513
Hila Gonene35e4d22012-06-27 17:19:42 +03007514 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007515}
7516
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007517static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7518 u8 *rates, u8 rates_len)
7519{
7520 u8 i;
7521 u32 mask = 0;
7522
7523 for (i = 0; i < rates_len; i++) {
7524 int rate = (rates[i] & 0x7f) * 5;
7525 int ridx;
7526 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7527 struct ieee80211_rate *srate =
7528 &sband->bitrates[ridx];
7529 if (rate == srate->bitrate) {
7530 mask |= 1 << ridx;
7531 break;
7532 }
7533 }
7534 if (ridx == sband->n_bitrates)
7535 return 0; /* rate not found */
7536 }
7537
7538 return mask;
7539}
7540
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007541static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7542 u8 *rates, u8 rates_len,
7543 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7544{
7545 u8 i;
7546
7547 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7548
7549 for (i = 0; i < rates_len; i++) {
7550 int ridx, rbit;
7551
7552 ridx = rates[i] / 8;
7553 rbit = BIT(rates[i] % 8);
7554
7555 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007556 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007557 return false;
7558
7559 /* check availability */
7560 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7561 mcs[ridx] |= rbit;
7562 else
7563 return false;
7564 }
7565
7566 return true;
7567}
7568
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007569static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7570{
7571 u16 mcs_mask = 0;
7572
7573 switch (vht_mcs_map) {
7574 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7575 break;
7576 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7577 mcs_mask = 0x00FF;
7578 break;
7579 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7580 mcs_mask = 0x01FF;
7581 break;
7582 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7583 mcs_mask = 0x03FF;
7584 break;
7585 default:
7586 break;
7587 }
7588
7589 return mcs_mask;
7590}
7591
7592static void vht_build_mcs_mask(u16 vht_mcs_map,
7593 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7594{
7595 u8 nss;
7596
7597 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7598 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7599 vht_mcs_map >>= 2;
7600 }
7601}
7602
7603static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7604 struct nl80211_txrate_vht *txrate,
7605 u16 mcs[NL80211_VHT_NSS_MAX])
7606{
7607 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7608 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7609 u8 i;
7610
7611 if (!sband->vht_cap.vht_supported)
7612 return false;
7613
7614 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7615
7616 /* Build vht_mcs_mask from VHT capabilities */
7617 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7618
7619 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7620 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7621 mcs[i] = txrate->mcs[i];
7622 else
7623 return false;
7624 }
7625
7626 return true;
7627}
7628
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007629static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007630 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7631 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007632 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7633 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007634 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007635 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007636};
7637
7638static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7639 struct genl_info *info)
7640{
7641 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007643 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007644 int rem, i;
7645 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007646 struct nlattr *tx_rates;
7647 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007648 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007649
Johannes Berg4c476992010-10-04 21:36:35 +02007650 if (!rdev->ops->set_bitrate_mask)
7651 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007652
7653 memset(&mask, 0, sizeof(mask));
7654 /* Default to all rates enabled */
7655 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7656 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007657
7658 if (!sband)
7659 continue;
7660
7661 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007662 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007663 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007664 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007665
7666 if (!sband->vht_cap.vht_supported)
7667 continue;
7668
7669 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7670 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007671 }
7672
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007673 /* if no rates are given set it back to the defaults */
7674 if (!info->attrs[NL80211_ATTR_TX_RATES])
7675 goto out;
7676
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007677 /*
7678 * The nested attribute uses enum nl80211_band as the index. This maps
7679 * directly to the enum ieee80211_band values used in cfg80211.
7680 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007681 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007682 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007683 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007684 int err;
7685
Johannes Berg4c476992010-10-04 21:36:35 +02007686 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7687 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007688 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007689 if (sband == NULL)
7690 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007691 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7692 nla_len(tx_rates), nl80211_txattr_policy);
7693 if (err)
7694 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007695 if (tb[NL80211_TXRATE_LEGACY]) {
7696 mask.control[band].legacy = rateset_to_mask(
7697 sband,
7698 nla_data(tb[NL80211_TXRATE_LEGACY]),
7699 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307700 if ((mask.control[band].legacy == 0) &&
7701 nla_len(tb[NL80211_TXRATE_LEGACY]))
7702 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007703 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007704 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007705 if (!ht_rateset_to_mask(
7706 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007707 nla_data(tb[NL80211_TXRATE_HT]),
7708 nla_len(tb[NL80211_TXRATE_HT]),
7709 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007710 return -EINVAL;
7711 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007712 if (tb[NL80211_TXRATE_VHT]) {
7713 if (!vht_set_mcs_mask(
7714 sband,
7715 nla_data(tb[NL80211_TXRATE_VHT]),
7716 mask.control[band].vht_mcs))
7717 return -EINVAL;
7718 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007719 if (tb[NL80211_TXRATE_GI]) {
7720 mask.control[band].gi =
7721 nla_get_u8(tb[NL80211_TXRATE_GI]);
7722 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7723 return -EINVAL;
7724 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007725
7726 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007727 /* don't allow empty legacy rates if HT or VHT
7728 * are not even supported.
7729 */
7730 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7731 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007732 return -EINVAL;
7733
7734 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007735 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007736 goto out;
7737
7738 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7739 if (mask.control[band].vht_mcs[i])
7740 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007741
7742 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007743 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007744 }
7745 }
7746
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007747out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007748 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007749}
7750
Johannes Berg2e161f72010-08-12 15:38:38 +02007751static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007752{
Johannes Berg4c476992010-10-04 21:36:35 +02007753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007754 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007755 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007756
7757 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7758 return -EINVAL;
7759
Johannes Berg2e161f72010-08-12 15:38:38 +02007760 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7761 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007762
Johannes Berg71bbc992012-06-15 15:30:18 +02007763 switch (wdev->iftype) {
7764 case NL80211_IFTYPE_STATION:
7765 case NL80211_IFTYPE_ADHOC:
7766 case NL80211_IFTYPE_P2P_CLIENT:
7767 case NL80211_IFTYPE_AP:
7768 case NL80211_IFTYPE_AP_VLAN:
7769 case NL80211_IFTYPE_MESH_POINT:
7770 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007771 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007772 break;
7773 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007774 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007775 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007776
7777 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007778 if (!rdev->ops->mgmt_tx)
7779 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007780
Eric W. Biederman15e47302012-09-07 20:12:54 +00007781 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007782 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7783 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007784}
7785
Johannes Berg2e161f72010-08-12 15:38:38 +02007786static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007787{
Johannes Berg4c476992010-10-04 21:36:35 +02007788 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007789 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007790 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007791 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007792 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007793 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007794 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007795 struct cfg80211_mgmt_tx_params params = {
7796 .dont_wait_for_ack =
7797 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7798 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007799
Johannes Berg683b6d32012-11-08 21:25:48 +01007800 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007801 return -EINVAL;
7802
Johannes Berg4c476992010-10-04 21:36:35 +02007803 if (!rdev->ops->mgmt_tx)
7804 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007805
Johannes Berg71bbc992012-06-15 15:30:18 +02007806 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007807 case NL80211_IFTYPE_P2P_DEVICE:
7808 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7809 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007810 case NL80211_IFTYPE_STATION:
7811 case NL80211_IFTYPE_ADHOC:
7812 case NL80211_IFTYPE_P2P_CLIENT:
7813 case NL80211_IFTYPE_AP:
7814 case NL80211_IFTYPE_AP_VLAN:
7815 case NL80211_IFTYPE_MESH_POINT:
7816 case NL80211_IFTYPE_P2P_GO:
7817 break;
7818 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007819 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007820 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007821
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007822 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007823 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007824 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007825 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007826
7827 /*
7828 * We should wait on the channel for at least a minimum amount
7829 * of time (10ms) but no longer than the driver supports.
7830 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007831 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7832 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007833 return -EINVAL;
7834
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007835 }
7836
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007837 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007838
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007839 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007840 return -EINVAL;
7841
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007842 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307843
Antonio Quartulliea141b752013-06-11 14:20:03 +02007844 /* get the channel if any has been specified, otherwise pass NULL to
7845 * the driver. The latter will use the current one
7846 */
7847 chandef.chan = NULL;
7848 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7849 err = nl80211_parse_chandef(rdev, info, &chandef);
7850 if (err)
7851 return err;
7852 }
7853
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007854 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007855 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007856
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03007857 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7858 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7859
7860 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
7861 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7862 int i;
7863
7864 if (len % sizeof(u16))
7865 return -EINVAL;
7866
7867 params.n_csa_offsets = len / sizeof(u16);
7868 params.csa_offsets =
7869 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7870
7871 /* check that all the offsets fit the frame */
7872 for (i = 0; i < params.n_csa_offsets; i++) {
7873 if (params.csa_offsets[i] >= params.len)
7874 return -EINVAL;
7875 }
7876 }
7877
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007878 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007879 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7880 if (!msg)
7881 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007882
Eric W. Biederman15e47302012-09-07 20:12:54 +00007883 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007884 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007885 if (!hdr) {
7886 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007887 goto free_msg;
7888 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007889 }
Johannes Berge247bd902011-11-04 11:18:21 +01007890
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007891 params.chan = chandef.chan;
7892 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007893 if (err)
7894 goto free_msg;
7895
Johannes Berge247bd902011-11-04 11:18:21 +01007896 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007897 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7898 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007899
Johannes Berge247bd902011-11-04 11:18:21 +01007900 genlmsg_end(msg, hdr);
7901 return genlmsg_reply(msg, info);
7902 }
7903
7904 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007905
7906 nla_put_failure:
7907 err = -ENOBUFS;
7908 free_msg:
7909 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007910 return err;
7911}
7912
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007913static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7914{
7915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007916 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007917 u64 cookie;
7918
7919 if (!info->attrs[NL80211_ATTR_COOKIE])
7920 return -EINVAL;
7921
7922 if (!rdev->ops->mgmt_tx_cancel_wait)
7923 return -EOPNOTSUPP;
7924
Johannes Berg71bbc992012-06-15 15:30:18 +02007925 switch (wdev->iftype) {
7926 case NL80211_IFTYPE_STATION:
7927 case NL80211_IFTYPE_ADHOC:
7928 case NL80211_IFTYPE_P2P_CLIENT:
7929 case NL80211_IFTYPE_AP:
7930 case NL80211_IFTYPE_AP_VLAN:
7931 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007932 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007933 break;
7934 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007935 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007936 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007937
7938 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7939
Hila Gonene35e4d22012-06-27 17:19:42 +03007940 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007941}
7942
Kalle Valoffb9eb32010-02-17 17:58:10 +02007943static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7944{
Johannes Berg4c476992010-10-04 21:36:35 +02007945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007946 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007947 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007948 u8 ps_state;
7949 bool state;
7950 int err;
7951
Johannes Berg4c476992010-10-04 21:36:35 +02007952 if (!info->attrs[NL80211_ATTR_PS_STATE])
7953 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007954
7955 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7956
Johannes Berg4c476992010-10-04 21:36:35 +02007957 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7958 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007959
7960 wdev = dev->ieee80211_ptr;
7961
Johannes Berg4c476992010-10-04 21:36:35 +02007962 if (!rdev->ops->set_power_mgmt)
7963 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007964
7965 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7966
7967 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007968 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007969
Hila Gonene35e4d22012-06-27 17:19:42 +03007970 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007971 if (!err)
7972 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007973 return err;
7974}
7975
7976static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7977{
Johannes Berg4c476992010-10-04 21:36:35 +02007978 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007979 enum nl80211_ps_state ps_state;
7980 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007981 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007982 struct sk_buff *msg;
7983 void *hdr;
7984 int err;
7985
Kalle Valoffb9eb32010-02-17 17:58:10 +02007986 wdev = dev->ieee80211_ptr;
7987
Johannes Berg4c476992010-10-04 21:36:35 +02007988 if (!rdev->ops->set_power_mgmt)
7989 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007990
7991 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007992 if (!msg)
7993 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007994
Eric W. Biederman15e47302012-09-07 20:12:54 +00007995 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007996 NL80211_CMD_GET_POWER_SAVE);
7997 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007998 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007999 goto free_msg;
8000 }
8001
8002 if (wdev->ps)
8003 ps_state = NL80211_PS_ENABLED;
8004 else
8005 ps_state = NL80211_PS_DISABLED;
8006
David S. Miller9360ffd2012-03-29 04:41:26 -04008007 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8008 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008009
8010 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008011 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008012
Johannes Berg4c476992010-10-04 21:36:35 +02008013 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008014 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008015 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008016 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008017 return err;
8018}
8019
Johannes Berg94e860f2014-01-20 23:58:15 +01008020static const struct nla_policy
8021nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008022 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8023 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8024 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008025 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8026 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8027 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008028};
8029
Thomas Pedersen84f10702012-07-12 16:17:33 -07008030static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008031 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008032{
8033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008034 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008035 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008036
Johannes Bergd9d8b012012-11-26 12:51:52 +01008037 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008038 return -EINVAL;
8039
Thomas Pedersen84f10702012-07-12 16:17:33 -07008040 if (!rdev->ops->set_cqm_txe_config)
8041 return -EOPNOTSUPP;
8042
8043 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8044 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8045 return -EOPNOTSUPP;
8046
Hila Gonene35e4d22012-06-27 17:19:42 +03008047 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008048}
8049
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008050static int nl80211_set_cqm_rssi(struct genl_info *info,
8051 s32 threshold, u32 hysteresis)
8052{
Johannes Berg4c476992010-10-04 21:36:35 +02008053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008054 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008055 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008056
8057 if (threshold > 0)
8058 return -EINVAL;
8059
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008060 /* disabling - hysteresis should also be zero then */
8061 if (threshold == 0)
8062 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008063
Johannes Berg4c476992010-10-04 21:36:35 +02008064 if (!rdev->ops->set_cqm_rssi_config)
8065 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008066
Johannes Berg074ac8d2010-09-16 14:58:22 +02008067 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008068 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8069 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008070
Hila Gonene35e4d22012-06-27 17:19:42 +03008071 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008072}
8073
8074static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8075{
8076 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8077 struct nlattr *cqm;
8078 int err;
8079
8080 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008081 if (!cqm)
8082 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008083
8084 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8085 nl80211_attr_cqm_policy);
8086 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008087 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008088
8089 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8090 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008091 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8092 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008093
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008094 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8095 }
8096
8097 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8098 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8099 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8100 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8101 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8102 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8103
8104 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8105 }
8106
8107 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008108}
8109
Johannes Berg29cbe682010-12-03 09:20:44 +01008110static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8111{
8112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8113 struct net_device *dev = info->user_ptr[1];
8114 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008115 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008116 int err;
8117
8118 /* start with default */
8119 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008120 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008121
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008122 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008123 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008124 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008125 if (err)
8126 return err;
8127 }
8128
8129 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8130 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8131 return -EINVAL;
8132
Javier Cardonac80d5452010-12-16 17:37:49 -08008133 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8134 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8135
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008136 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8137 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8138 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8139 return -EINVAL;
8140
Marco Porsch9bdbf042013-01-07 16:04:51 +01008141 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8142 setup.beacon_interval =
8143 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8144 if (setup.beacon_interval < 10 ||
8145 setup.beacon_interval > 10000)
8146 return -EINVAL;
8147 }
8148
8149 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8150 setup.dtim_period =
8151 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8152 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8153 return -EINVAL;
8154 }
8155
Javier Cardonac80d5452010-12-16 17:37:49 -08008156 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8157 /* parse additional setup parameters if given */
8158 err = nl80211_parse_mesh_setup(info, &setup);
8159 if (err)
8160 return err;
8161 }
8162
Thomas Pedersend37bb182013-03-04 13:06:13 -08008163 if (setup.user_mpm)
8164 cfg.auto_open_plinks = false;
8165
Johannes Bergcc1d2802012-05-16 23:50:20 +02008166 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008167 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8168 if (err)
8169 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008170 } else {
8171 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008172 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008173 }
8174
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008175 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8176 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8177 int n_rates =
8178 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8179 struct ieee80211_supported_band *sband;
8180
8181 if (!setup.chandef.chan)
8182 return -EINVAL;
8183
8184 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8185
8186 err = ieee80211_get_ratemask(sband, rates, n_rates,
8187 &setup.basic_rates);
8188 if (err)
8189 return err;
8190 }
8191
Javier Cardonac80d5452010-12-16 17:37:49 -08008192 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008193}
8194
8195static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8196{
8197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8198 struct net_device *dev = info->user_ptr[1];
8199
8200 return cfg80211_leave_mesh(rdev, dev);
8201}
8202
Johannes Bergdfb89c52012-06-27 09:23:48 +02008203#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008204static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8205 struct cfg80211_registered_device *rdev)
8206{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008207 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008208 struct nlattr *nl_pats, *nl_pat;
8209 int i, pat_len;
8210
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008211 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008212 return 0;
8213
8214 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8215 if (!nl_pats)
8216 return -ENOBUFS;
8217
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008218 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008219 nl_pat = nla_nest_start(msg, i + 1);
8220 if (!nl_pat)
8221 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008222 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008223 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008224 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008225 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8226 wowlan->patterns[i].pattern) ||
8227 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008228 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008229 return -ENOBUFS;
8230 nla_nest_end(msg, nl_pat);
8231 }
8232 nla_nest_end(msg, nl_pats);
8233
8234 return 0;
8235}
8236
Johannes Berg2a0e0472013-01-23 22:57:40 +01008237static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8238 struct cfg80211_wowlan_tcp *tcp)
8239{
8240 struct nlattr *nl_tcp;
8241
8242 if (!tcp)
8243 return 0;
8244
8245 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8246 if (!nl_tcp)
8247 return -ENOBUFS;
8248
8249 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8250 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8251 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8252 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8253 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8254 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8255 tcp->payload_len, tcp->payload) ||
8256 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8257 tcp->data_interval) ||
8258 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8259 tcp->wake_len, tcp->wake_data) ||
8260 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8261 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8262 return -ENOBUFS;
8263
8264 if (tcp->payload_seq.len &&
8265 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8266 sizeof(tcp->payload_seq), &tcp->payload_seq))
8267 return -ENOBUFS;
8268
8269 if (tcp->payload_tok.len &&
8270 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8271 sizeof(tcp->payload_tok) + tcp->tokens_size,
8272 &tcp->payload_tok))
8273 return -ENOBUFS;
8274
Johannes Berge248ad32013-05-16 10:24:28 +02008275 nla_nest_end(msg, nl_tcp);
8276
Johannes Berg2a0e0472013-01-23 22:57:40 +01008277 return 0;
8278}
8279
Johannes Bergff1b6e62011-05-04 15:37:28 +02008280static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8281{
8282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8283 struct sk_buff *msg;
8284 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008285 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008286
Johannes Berg964dc9e2013-06-03 17:25:34 +02008287 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008288 return -EOPNOTSUPP;
8289
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008290 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008291 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008292 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8293 rdev->wiphy.wowlan_config->tcp->payload_len +
8294 rdev->wiphy.wowlan_config->tcp->wake_len +
8295 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008296 }
8297
8298 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008299 if (!msg)
8300 return -ENOMEM;
8301
Eric W. Biederman15e47302012-09-07 20:12:54 +00008302 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008303 NL80211_CMD_GET_WOWLAN);
8304 if (!hdr)
8305 goto nla_put_failure;
8306
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008307 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008308 struct nlattr *nl_wowlan;
8309
8310 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8311 if (!nl_wowlan)
8312 goto nla_put_failure;
8313
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008314 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008315 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008316 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008317 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008318 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008319 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008320 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008321 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008322 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008323 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008324 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008325 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008326 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008327 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8328 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008329
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008330 if (nl80211_send_wowlan_patterns(msg, rdev))
8331 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008332
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008333 if (nl80211_send_wowlan_tcp(msg,
8334 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008335 goto nla_put_failure;
8336
Johannes Bergff1b6e62011-05-04 15:37:28 +02008337 nla_nest_end(msg, nl_wowlan);
8338 }
8339
8340 genlmsg_end(msg, hdr);
8341 return genlmsg_reply(msg, info);
8342
8343nla_put_failure:
8344 nlmsg_free(msg);
8345 return -ENOBUFS;
8346}
8347
Johannes Berg2a0e0472013-01-23 22:57:40 +01008348static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8349 struct nlattr *attr,
8350 struct cfg80211_wowlan *trig)
8351{
8352 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8353 struct cfg80211_wowlan_tcp *cfg;
8354 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8355 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8356 u32 size;
8357 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8358 int err, port;
8359
Johannes Berg964dc9e2013-06-03 17:25:34 +02008360 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008361 return -EINVAL;
8362
8363 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8364 nla_data(attr), nla_len(attr),
8365 nl80211_wowlan_tcp_policy);
8366 if (err)
8367 return err;
8368
8369 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8370 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8371 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8372 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8373 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8374 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8375 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8376 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8377 return -EINVAL;
8378
8379 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008380 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008381 return -EINVAL;
8382
8383 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008384 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008385 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008386 return -EINVAL;
8387
8388 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008389 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008390 return -EINVAL;
8391
8392 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8393 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8394 return -EINVAL;
8395
8396 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8397 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8398
8399 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8400 tokens_size = tokln - sizeof(*tok);
8401
8402 if (!tok->len || tokens_size % tok->len)
8403 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008404 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008405 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008406 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008407 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008408 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008409 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008410 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008411 return -EINVAL;
8412 if (tok->offset + tok->len > data_size)
8413 return -EINVAL;
8414 }
8415
8416 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8417 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008418 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008419 return -EINVAL;
8420 if (seq->len == 0 || seq->len > 4)
8421 return -EINVAL;
8422 if (seq->len + seq->offset > data_size)
8423 return -EINVAL;
8424 }
8425
8426 size = sizeof(*cfg);
8427 size += data_size;
8428 size += wake_size + wake_mask_size;
8429 size += tokens_size;
8430
8431 cfg = kzalloc(size, GFP_KERNEL);
8432 if (!cfg)
8433 return -ENOMEM;
8434 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8435 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8436 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8437 ETH_ALEN);
8438 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8439 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8440 else
8441 port = 0;
8442#ifdef CONFIG_INET
8443 /* allocate a socket and port for it and use it */
8444 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8445 IPPROTO_TCP, &cfg->sock, 1);
8446 if (err) {
8447 kfree(cfg);
8448 return err;
8449 }
8450 if (inet_csk_get_port(cfg->sock->sk, port)) {
8451 sock_release(cfg->sock);
8452 kfree(cfg);
8453 return -EADDRINUSE;
8454 }
8455 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8456#else
8457 if (!port) {
8458 kfree(cfg);
8459 return -EINVAL;
8460 }
8461 cfg->src_port = port;
8462#endif
8463
8464 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8465 cfg->payload_len = data_size;
8466 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8467 memcpy((void *)cfg->payload,
8468 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8469 data_size);
8470 if (seq)
8471 cfg->payload_seq = *seq;
8472 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8473 cfg->wake_len = wake_size;
8474 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8475 memcpy((void *)cfg->wake_data,
8476 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8477 wake_size);
8478 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8479 data_size + wake_size;
8480 memcpy((void *)cfg->wake_mask,
8481 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8482 wake_mask_size);
8483 if (tok) {
8484 cfg->tokens_size = tokens_size;
8485 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8486 }
8487
8488 trig->tcp = cfg;
8489
8490 return 0;
8491}
8492
Johannes Bergff1b6e62011-05-04 15:37:28 +02008493static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8494{
8495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8496 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008497 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008498 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008499 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008500 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008501 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008502
Johannes Berg964dc9e2013-06-03 17:25:34 +02008503 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008504 return -EOPNOTSUPP;
8505
Johannes Bergae33bd82012-07-12 16:25:02 +02008506 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8507 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008508 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008509 goto set_wakeup;
8510 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008511
8512 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8513 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8514 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8515 nl80211_wowlan_policy);
8516 if (err)
8517 return err;
8518
8519 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8520 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8521 return -EINVAL;
8522 new_triggers.any = true;
8523 }
8524
8525 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8526 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8527 return -EINVAL;
8528 new_triggers.disconnect = true;
8529 }
8530
8531 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8532 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8533 return -EINVAL;
8534 new_triggers.magic_pkt = true;
8535 }
8536
Johannes Berg77dbbb12011-07-13 10:48:55 +02008537 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8538 return -EINVAL;
8539
8540 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8541 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8542 return -EINVAL;
8543 new_triggers.gtk_rekey_failure = true;
8544 }
8545
8546 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8547 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8548 return -EINVAL;
8549 new_triggers.eap_identity_req = true;
8550 }
8551
8552 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8553 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8554 return -EINVAL;
8555 new_triggers.four_way_handshake = true;
8556 }
8557
8558 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8559 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8560 return -EINVAL;
8561 new_triggers.rfkill_release = true;
8562 }
8563
Johannes Bergff1b6e62011-05-04 15:37:28 +02008564 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8565 struct nlattr *pat;
8566 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008567 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008568 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008569
8570 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8571 rem)
8572 n_patterns++;
8573 if (n_patterns > wowlan->n_patterns)
8574 return -EINVAL;
8575
8576 new_triggers.patterns = kcalloc(n_patterns,
8577 sizeof(new_triggers.patterns[0]),
8578 GFP_KERNEL);
8579 if (!new_triggers.patterns)
8580 return -ENOMEM;
8581
8582 new_triggers.n_patterns = n_patterns;
8583 i = 0;
8584
8585 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8586 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008587 u8 *mask_pat;
8588
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008589 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8590 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008591 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008592 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8593 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008594 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008595 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008596 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008597 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008598 goto error;
8599 if (pat_len > wowlan->pattern_max_len ||
8600 pat_len < wowlan->pattern_min_len)
8601 goto error;
8602
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008603 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008604 pkt_offset = 0;
8605 else
8606 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008607 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008608 if (pkt_offset > wowlan->max_pkt_offset)
8609 goto error;
8610 new_triggers.patterns[i].pkt_offset = pkt_offset;
8611
Johannes Berg922bd802014-05-19 17:59:50 +02008612 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8613 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008614 err = -ENOMEM;
8615 goto error;
8616 }
Johannes Berg922bd802014-05-19 17:59:50 +02008617 new_triggers.patterns[i].mask = mask_pat;
8618 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008619 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008620 mask_pat += mask_len;
8621 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008622 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008623 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008624 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008625 pat_len);
8626 i++;
8627 }
8628 }
8629
Johannes Berg2a0e0472013-01-23 22:57:40 +01008630 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8631 err = nl80211_parse_wowlan_tcp(
8632 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8633 &new_triggers);
8634 if (err)
8635 goto error;
8636 }
8637
Johannes Bergae33bd82012-07-12 16:25:02 +02008638 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8639 if (!ntrig) {
8640 err = -ENOMEM;
8641 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008642 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008643 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008644 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008645
Johannes Bergae33bd82012-07-12 16:25:02 +02008646 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008647 if (rdev->ops->set_wakeup &&
8648 prev_enabled != !!rdev->wiphy.wowlan_config)
8649 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008650
Johannes Bergff1b6e62011-05-04 15:37:28 +02008651 return 0;
8652 error:
8653 for (i = 0; i < new_triggers.n_patterns; i++)
8654 kfree(new_triggers.patterns[i].mask);
8655 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008656 if (new_triggers.tcp && new_triggers.tcp->sock)
8657 sock_release(new_triggers.tcp->sock);
8658 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008659 return err;
8660}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008661#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008662
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008663static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8664 struct cfg80211_registered_device *rdev)
8665{
8666 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8667 int i, j, pat_len;
8668 struct cfg80211_coalesce_rules *rule;
8669
8670 if (!rdev->coalesce->n_rules)
8671 return 0;
8672
8673 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8674 if (!nl_rules)
8675 return -ENOBUFS;
8676
8677 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8678 nl_rule = nla_nest_start(msg, i + 1);
8679 if (!nl_rule)
8680 return -ENOBUFS;
8681
8682 rule = &rdev->coalesce->rules[i];
8683 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8684 rule->delay))
8685 return -ENOBUFS;
8686
8687 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8688 rule->condition))
8689 return -ENOBUFS;
8690
8691 nl_pats = nla_nest_start(msg,
8692 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8693 if (!nl_pats)
8694 return -ENOBUFS;
8695
8696 for (j = 0; j < rule->n_patterns; j++) {
8697 nl_pat = nla_nest_start(msg, j + 1);
8698 if (!nl_pat)
8699 return -ENOBUFS;
8700 pat_len = rule->patterns[j].pattern_len;
8701 if (nla_put(msg, NL80211_PKTPAT_MASK,
8702 DIV_ROUND_UP(pat_len, 8),
8703 rule->patterns[j].mask) ||
8704 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8705 rule->patterns[j].pattern) ||
8706 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8707 rule->patterns[j].pkt_offset))
8708 return -ENOBUFS;
8709 nla_nest_end(msg, nl_pat);
8710 }
8711 nla_nest_end(msg, nl_pats);
8712 nla_nest_end(msg, nl_rule);
8713 }
8714 nla_nest_end(msg, nl_rules);
8715
8716 return 0;
8717}
8718
8719static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8720{
8721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8722 struct sk_buff *msg;
8723 void *hdr;
8724
8725 if (!rdev->wiphy.coalesce)
8726 return -EOPNOTSUPP;
8727
8728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8729 if (!msg)
8730 return -ENOMEM;
8731
8732 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8733 NL80211_CMD_GET_COALESCE);
8734 if (!hdr)
8735 goto nla_put_failure;
8736
8737 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8738 goto nla_put_failure;
8739
8740 genlmsg_end(msg, hdr);
8741 return genlmsg_reply(msg, info);
8742
8743nla_put_failure:
8744 nlmsg_free(msg);
8745 return -ENOBUFS;
8746}
8747
8748void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8749{
8750 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8751 int i, j;
8752 struct cfg80211_coalesce_rules *rule;
8753
8754 if (!coalesce)
8755 return;
8756
8757 for (i = 0; i < coalesce->n_rules; i++) {
8758 rule = &coalesce->rules[i];
8759 for (j = 0; j < rule->n_patterns; j++)
8760 kfree(rule->patterns[j].mask);
8761 kfree(rule->patterns);
8762 }
8763 kfree(coalesce->rules);
8764 kfree(coalesce);
8765 rdev->coalesce = NULL;
8766}
8767
8768static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8769 struct nlattr *rule,
8770 struct cfg80211_coalesce_rules *new_rule)
8771{
8772 int err, i;
8773 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8774 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8775 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8776 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8777
8778 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8779 nla_len(rule), nl80211_coalesce_policy);
8780 if (err)
8781 return err;
8782
8783 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8784 new_rule->delay =
8785 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8786 if (new_rule->delay > coalesce->max_delay)
8787 return -EINVAL;
8788
8789 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8790 new_rule->condition =
8791 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8792 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8793 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8794 return -EINVAL;
8795
8796 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8797 return -EINVAL;
8798
8799 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8800 rem)
8801 n_patterns++;
8802 if (n_patterns > coalesce->n_patterns)
8803 return -EINVAL;
8804
8805 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8806 GFP_KERNEL);
8807 if (!new_rule->patterns)
8808 return -ENOMEM;
8809
8810 new_rule->n_patterns = n_patterns;
8811 i = 0;
8812
8813 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8814 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008815 u8 *mask_pat;
8816
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008817 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8818 nla_len(pat), NULL);
8819 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8820 !pat_tb[NL80211_PKTPAT_PATTERN])
8821 return -EINVAL;
8822 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8823 mask_len = DIV_ROUND_UP(pat_len, 8);
8824 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8825 return -EINVAL;
8826 if (pat_len > coalesce->pattern_max_len ||
8827 pat_len < coalesce->pattern_min_len)
8828 return -EINVAL;
8829
8830 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8831 pkt_offset = 0;
8832 else
8833 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8834 if (pkt_offset > coalesce->max_pkt_offset)
8835 return -EINVAL;
8836 new_rule->patterns[i].pkt_offset = pkt_offset;
8837
Johannes Berg922bd802014-05-19 17:59:50 +02008838 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8839 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008840 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02008841
8842 new_rule->patterns[i].mask = mask_pat;
8843 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8844 mask_len);
8845
8846 mask_pat += mask_len;
8847 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008848 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008849 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8850 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008851 i++;
8852 }
8853
8854 return 0;
8855}
8856
8857static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8858{
8859 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8860 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8861 struct cfg80211_coalesce new_coalesce = {};
8862 struct cfg80211_coalesce *n_coalesce;
8863 int err, rem_rule, n_rules = 0, i, j;
8864 struct nlattr *rule;
8865 struct cfg80211_coalesce_rules *tmp_rule;
8866
8867 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8868 return -EOPNOTSUPP;
8869
8870 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8871 cfg80211_rdev_free_coalesce(rdev);
8872 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8873 return 0;
8874 }
8875
8876 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8877 rem_rule)
8878 n_rules++;
8879 if (n_rules > coalesce->n_rules)
8880 return -EINVAL;
8881
8882 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8883 GFP_KERNEL);
8884 if (!new_coalesce.rules)
8885 return -ENOMEM;
8886
8887 new_coalesce.n_rules = n_rules;
8888 i = 0;
8889
8890 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8891 rem_rule) {
8892 err = nl80211_parse_coalesce_rule(rdev, rule,
8893 &new_coalesce.rules[i]);
8894 if (err)
8895 goto error;
8896
8897 i++;
8898 }
8899
8900 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8901 if (err)
8902 goto error;
8903
8904 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8905 if (!n_coalesce) {
8906 err = -ENOMEM;
8907 goto error;
8908 }
8909 cfg80211_rdev_free_coalesce(rdev);
8910 rdev->coalesce = n_coalesce;
8911
8912 return 0;
8913error:
8914 for (i = 0; i < new_coalesce.n_rules; i++) {
8915 tmp_rule = &new_coalesce.rules[i];
8916 for (j = 0; j < tmp_rule->n_patterns; j++)
8917 kfree(tmp_rule->patterns[j].mask);
8918 kfree(tmp_rule->patterns);
8919 }
8920 kfree(new_coalesce.rules);
8921
8922 return err;
8923}
8924
Johannes Berge5497d72011-07-05 16:35:40 +02008925static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8926{
8927 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8928 struct net_device *dev = info->user_ptr[1];
8929 struct wireless_dev *wdev = dev->ieee80211_ptr;
8930 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8931 struct cfg80211_gtk_rekey_data rekey_data;
8932 int err;
8933
8934 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8935 return -EINVAL;
8936
8937 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8938 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8939 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8940 nl80211_rekey_policy);
8941 if (err)
8942 return err;
8943
8944 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8945 return -ERANGE;
8946 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8947 return -ERANGE;
8948 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8949 return -ERANGE;
8950
8951 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8952 NL80211_KEK_LEN);
8953 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8954 NL80211_KCK_LEN);
8955 memcpy(rekey_data.replay_ctr,
8956 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8957 NL80211_REPLAY_CTR_LEN);
8958
8959 wdev_lock(wdev);
8960 if (!wdev->current_bss) {
8961 err = -ENOTCONN;
8962 goto out;
8963 }
8964
8965 if (!rdev->ops->set_rekey_data) {
8966 err = -EOPNOTSUPP;
8967 goto out;
8968 }
8969
Hila Gonene35e4d22012-06-27 17:19:42 +03008970 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008971 out:
8972 wdev_unlock(wdev);
8973 return err;
8974}
8975
Johannes Berg28946da2011-11-04 11:18:12 +01008976static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8977 struct genl_info *info)
8978{
8979 struct net_device *dev = info->user_ptr[1];
8980 struct wireless_dev *wdev = dev->ieee80211_ptr;
8981
8982 if (wdev->iftype != NL80211_IFTYPE_AP &&
8983 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8984 return -EINVAL;
8985
Eric W. Biederman15e47302012-09-07 20:12:54 +00008986 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008987 return -EBUSY;
8988
Eric W. Biederman15e47302012-09-07 20:12:54 +00008989 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008990 return 0;
8991}
8992
Johannes Berg7f6cf312011-11-04 11:18:15 +01008993static int nl80211_probe_client(struct sk_buff *skb,
8994 struct genl_info *info)
8995{
8996 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8997 struct net_device *dev = info->user_ptr[1];
8998 struct wireless_dev *wdev = dev->ieee80211_ptr;
8999 struct sk_buff *msg;
9000 void *hdr;
9001 const u8 *addr;
9002 u64 cookie;
9003 int err;
9004
9005 if (wdev->iftype != NL80211_IFTYPE_AP &&
9006 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9007 return -EOPNOTSUPP;
9008
9009 if (!info->attrs[NL80211_ATTR_MAC])
9010 return -EINVAL;
9011
9012 if (!rdev->ops->probe_client)
9013 return -EOPNOTSUPP;
9014
9015 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9016 if (!msg)
9017 return -ENOMEM;
9018
Eric W. Biederman15e47302012-09-07 20:12:54 +00009019 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009020 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009021 if (!hdr) {
9022 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009023 goto free_msg;
9024 }
9025
9026 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9027
Hila Gonene35e4d22012-06-27 17:19:42 +03009028 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009029 if (err)
9030 goto free_msg;
9031
David S. Miller9360ffd2012-03-29 04:41:26 -04009032 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9033 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009034
9035 genlmsg_end(msg, hdr);
9036
9037 return genlmsg_reply(msg, info);
9038
9039 nla_put_failure:
9040 err = -ENOBUFS;
9041 free_msg:
9042 nlmsg_free(msg);
9043 return err;
9044}
9045
Johannes Berg5e760232011-11-04 11:18:17 +01009046static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9047{
9048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009049 struct cfg80211_beacon_registration *reg, *nreg;
9050 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009051
9052 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9053 return -EOPNOTSUPP;
9054
Ben Greear37c73b52012-10-26 14:49:25 -07009055 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9056 if (!nreg)
9057 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009058
Ben Greear37c73b52012-10-26 14:49:25 -07009059 /* First, check if already registered. */
9060 spin_lock_bh(&rdev->beacon_registrations_lock);
9061 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9062 if (reg->nlportid == info->snd_portid) {
9063 rv = -EALREADY;
9064 goto out_err;
9065 }
9066 }
9067 /* Add it to the list */
9068 nreg->nlportid = info->snd_portid;
9069 list_add(&nreg->list, &rdev->beacon_registrations);
9070
9071 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009072
9073 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009074out_err:
9075 spin_unlock_bh(&rdev->beacon_registrations_lock);
9076 kfree(nreg);
9077 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009078}
9079
Johannes Berg98104fde2012-06-16 00:19:54 +02009080static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9081{
9082 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9083 struct wireless_dev *wdev = info->user_ptr[1];
9084 int err;
9085
9086 if (!rdev->ops->start_p2p_device)
9087 return -EOPNOTSUPP;
9088
9089 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9090 return -EOPNOTSUPP;
9091
9092 if (wdev->p2p_started)
9093 return 0;
9094
Luciano Coelhob6a55012014-02-27 11:07:21 +02009095 if (rfkill_blocked(rdev->rfkill))
9096 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009097
Johannes Bergeeb126e2012-10-23 15:16:50 +02009098 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009099 if (err)
9100 return err;
9101
9102 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009103 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009104
9105 return 0;
9106}
9107
9108static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9109{
9110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9111 struct wireless_dev *wdev = info->user_ptr[1];
9112
9113 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9114 return -EOPNOTSUPP;
9115
9116 if (!rdev->ops->stop_p2p_device)
9117 return -EOPNOTSUPP;
9118
Johannes Bergf9f47522013-03-19 15:04:07 +01009119 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009120
9121 return 0;
9122}
9123
Johannes Berg3713b4e2013-02-14 16:19:38 +01009124static int nl80211_get_protocol_features(struct sk_buff *skb,
9125 struct genl_info *info)
9126{
9127 void *hdr;
9128 struct sk_buff *msg;
9129
9130 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9131 if (!msg)
9132 return -ENOMEM;
9133
9134 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9135 NL80211_CMD_GET_PROTOCOL_FEATURES);
9136 if (!hdr)
9137 goto nla_put_failure;
9138
9139 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9140 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9141 goto nla_put_failure;
9142
9143 genlmsg_end(msg, hdr);
9144 return genlmsg_reply(msg, info);
9145
9146 nla_put_failure:
9147 kfree_skb(msg);
9148 return -ENOBUFS;
9149}
9150
Jouni Malinen355199e2013-02-27 17:14:27 +02009151static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9152{
9153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9154 struct cfg80211_update_ft_ies_params ft_params;
9155 struct net_device *dev = info->user_ptr[1];
9156
9157 if (!rdev->ops->update_ft_ies)
9158 return -EOPNOTSUPP;
9159
9160 if (!info->attrs[NL80211_ATTR_MDID] ||
9161 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9162 return -EINVAL;
9163
9164 memset(&ft_params, 0, sizeof(ft_params));
9165 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9166 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9167 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9168
9169 return rdev_update_ft_ies(rdev, dev, &ft_params);
9170}
9171
Arend van Spriel5de17982013-04-18 15:49:00 +02009172static int nl80211_crit_protocol_start(struct sk_buff *skb,
9173 struct genl_info *info)
9174{
9175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9176 struct wireless_dev *wdev = info->user_ptr[1];
9177 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9178 u16 duration;
9179 int ret;
9180
9181 if (!rdev->ops->crit_proto_start)
9182 return -EOPNOTSUPP;
9183
9184 if (WARN_ON(!rdev->ops->crit_proto_stop))
9185 return -EINVAL;
9186
9187 if (rdev->crit_proto_nlportid)
9188 return -EBUSY;
9189
9190 /* determine protocol if provided */
9191 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9192 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9193
9194 if (proto >= NUM_NL80211_CRIT_PROTO)
9195 return -EINVAL;
9196
9197 /* timeout must be provided */
9198 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9199 return -EINVAL;
9200
9201 duration =
9202 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9203
9204 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9205 return -ERANGE;
9206
9207 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9208 if (!ret)
9209 rdev->crit_proto_nlportid = info->snd_portid;
9210
9211 return ret;
9212}
9213
9214static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9215 struct genl_info *info)
9216{
9217 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9218 struct wireless_dev *wdev = info->user_ptr[1];
9219
9220 if (!rdev->ops->crit_proto_stop)
9221 return -EOPNOTSUPP;
9222
9223 if (rdev->crit_proto_nlportid) {
9224 rdev->crit_proto_nlportid = 0;
9225 rdev_crit_proto_stop(rdev, wdev);
9226 }
9227 return 0;
9228}
9229
Johannes Bergad7e7182013-11-13 13:37:47 +01009230static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9231{
9232 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9233 struct wireless_dev *wdev =
9234 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9235 int i, err;
9236 u32 vid, subcmd;
9237
9238 if (!rdev->wiphy.vendor_commands)
9239 return -EOPNOTSUPP;
9240
9241 if (IS_ERR(wdev)) {
9242 err = PTR_ERR(wdev);
9243 if (err != -EINVAL)
9244 return err;
9245 wdev = NULL;
9246 } else if (wdev->wiphy != &rdev->wiphy) {
9247 return -EINVAL;
9248 }
9249
9250 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9251 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9252 return -EINVAL;
9253
9254 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9255 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9256 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9257 const struct wiphy_vendor_command *vcmd;
9258 void *data = NULL;
9259 int len = 0;
9260
9261 vcmd = &rdev->wiphy.vendor_commands[i];
9262
9263 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9264 continue;
9265
9266 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9267 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9268 if (!wdev)
9269 return -EINVAL;
9270 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9271 !wdev->netdev)
9272 return -EINVAL;
9273
9274 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9275 if (wdev->netdev &&
9276 !netif_running(wdev->netdev))
9277 return -ENETDOWN;
9278 if (!wdev->netdev && !wdev->p2p_started)
9279 return -ENETDOWN;
9280 }
9281 } else {
9282 wdev = NULL;
9283 }
9284
9285 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9286 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9287 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9288 }
9289
9290 rdev->cur_cmd_info = info;
9291 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9292 data, len);
9293 rdev->cur_cmd_info = NULL;
9294 return err;
9295 }
9296
9297 return -EOPNOTSUPP;
9298}
9299
9300struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9301 enum nl80211_commands cmd,
9302 enum nl80211_attrs attr,
9303 int approxlen)
9304{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009305 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009306
9307 if (WARN_ON(!rdev->cur_cmd_info))
9308 return NULL;
9309
9310 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9311 rdev->cur_cmd_info->snd_portid,
9312 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009313 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009314}
9315EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9316
9317int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9318{
9319 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9320 void *hdr = ((void **)skb->cb)[1];
9321 struct nlattr *data = ((void **)skb->cb)[2];
9322
9323 if (WARN_ON(!rdev->cur_cmd_info)) {
9324 kfree_skb(skb);
9325 return -EINVAL;
9326 }
9327
9328 nla_nest_end(skb, data);
9329 genlmsg_end(skb, hdr);
9330 return genlmsg_reply(skb, rdev->cur_cmd_info);
9331}
9332EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9333
9334
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009335static int nl80211_set_qos_map(struct sk_buff *skb,
9336 struct genl_info *info)
9337{
9338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9339 struct cfg80211_qos_map *qos_map = NULL;
9340 struct net_device *dev = info->user_ptr[1];
9341 u8 *pos, len, num_des, des_len, des;
9342 int ret;
9343
9344 if (!rdev->ops->set_qos_map)
9345 return -EOPNOTSUPP;
9346
9347 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9348 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9349 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9350
9351 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9352 len > IEEE80211_QOS_MAP_LEN_MAX)
9353 return -EINVAL;
9354
9355 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9356 if (!qos_map)
9357 return -ENOMEM;
9358
9359 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9360 if (num_des) {
9361 des_len = num_des *
9362 sizeof(struct cfg80211_dscp_exception);
9363 memcpy(qos_map->dscp_exception, pos, des_len);
9364 qos_map->num_des = num_des;
9365 for (des = 0; des < num_des; des++) {
9366 if (qos_map->dscp_exception[des].up > 7) {
9367 kfree(qos_map);
9368 return -EINVAL;
9369 }
9370 }
9371 pos += des_len;
9372 }
9373 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9374 }
9375
9376 wdev_lock(dev->ieee80211_ptr);
9377 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9378 if (!ret)
9379 ret = rdev_set_qos_map(rdev, dev, qos_map);
9380 wdev_unlock(dev->ieee80211_ptr);
9381
9382 kfree(qos_map);
9383 return ret;
9384}
9385
Johannes Berg4c476992010-10-04 21:36:35 +02009386#define NL80211_FLAG_NEED_WIPHY 0x01
9387#define NL80211_FLAG_NEED_NETDEV 0x02
9388#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009389#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9390#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9391 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009392#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009393/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009394#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9395 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009396
Johannes Bergf84f7712013-11-14 17:14:45 +01009397static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009398 struct genl_info *info)
9399{
9400 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009401 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009402 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009403 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9404
9405 if (rtnl)
9406 rtnl_lock();
9407
9408 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009409 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009410 if (IS_ERR(rdev)) {
9411 if (rtnl)
9412 rtnl_unlock();
9413 return PTR_ERR(rdev);
9414 }
9415 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009416 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9417 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009418 ASSERT_RTNL();
9419
Johannes Berg89a54e42012-06-15 14:33:17 +02009420 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9421 info->attrs);
9422 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009423 if (rtnl)
9424 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009425 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009426 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009427
Johannes Berg89a54e42012-06-15 14:33:17 +02009428 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009429 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009430
Johannes Berg1bf614e2012-06-15 15:23:36 +02009431 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9432 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009433 if (rtnl)
9434 rtnl_unlock();
9435 return -EINVAL;
9436 }
9437
9438 info->user_ptr[1] = dev;
9439 } else {
9440 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009441 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009442
Johannes Berg1bf614e2012-06-15 15:23:36 +02009443 if (dev) {
9444 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9445 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009446 if (rtnl)
9447 rtnl_unlock();
9448 return -ENETDOWN;
9449 }
9450
9451 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009452 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9453 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009454 if (rtnl)
9455 rtnl_unlock();
9456 return -ENETDOWN;
9457 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009458 }
9459
Johannes Berg4c476992010-10-04 21:36:35 +02009460 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009461 }
9462
9463 return 0;
9464}
9465
Johannes Bergf84f7712013-11-14 17:14:45 +01009466static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009467 struct genl_info *info)
9468{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009469 if (info->user_ptr[1]) {
9470 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9471 struct wireless_dev *wdev = info->user_ptr[1];
9472
9473 if (wdev->netdev)
9474 dev_put(wdev->netdev);
9475 } else {
9476 dev_put(info->user_ptr[1]);
9477 }
9478 }
Johannes Berg4c476992010-10-04 21:36:35 +02009479 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9480 rtnl_unlock();
9481}
9482
Johannes Berg4534de82013-11-14 17:14:46 +01009483static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009484 {
9485 .cmd = NL80211_CMD_GET_WIPHY,
9486 .doit = nl80211_get_wiphy,
9487 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009488 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009489 .policy = nl80211_policy,
9490 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009491 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9492 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009493 },
9494 {
9495 .cmd = NL80211_CMD_SET_WIPHY,
9496 .doit = nl80211_set_wiphy,
9497 .policy = nl80211_policy,
9498 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009499 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009500 },
9501 {
9502 .cmd = NL80211_CMD_GET_INTERFACE,
9503 .doit = nl80211_get_interface,
9504 .dumpit = nl80211_dump_interface,
9505 .policy = nl80211_policy,
9506 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009507 .internal_flags = NL80211_FLAG_NEED_WDEV |
9508 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009509 },
9510 {
9511 .cmd = NL80211_CMD_SET_INTERFACE,
9512 .doit = nl80211_set_interface,
9513 .policy = nl80211_policy,
9514 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009515 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9516 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009517 },
9518 {
9519 .cmd = NL80211_CMD_NEW_INTERFACE,
9520 .doit = nl80211_new_interface,
9521 .policy = nl80211_policy,
9522 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009523 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9524 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009525 },
9526 {
9527 .cmd = NL80211_CMD_DEL_INTERFACE,
9528 .doit = nl80211_del_interface,
9529 .policy = nl80211_policy,
9530 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009531 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009532 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009533 },
Johannes Berg41ade002007-12-19 02:03:29 +01009534 {
9535 .cmd = NL80211_CMD_GET_KEY,
9536 .doit = nl80211_get_key,
9537 .policy = nl80211_policy,
9538 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009539 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009540 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009541 },
9542 {
9543 .cmd = NL80211_CMD_SET_KEY,
9544 .doit = nl80211_set_key,
9545 .policy = nl80211_policy,
9546 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009547 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009548 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009549 },
9550 {
9551 .cmd = NL80211_CMD_NEW_KEY,
9552 .doit = nl80211_new_key,
9553 .policy = nl80211_policy,
9554 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009556 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009557 },
9558 {
9559 .cmd = NL80211_CMD_DEL_KEY,
9560 .doit = nl80211_del_key,
9561 .policy = nl80211_policy,
9562 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009564 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009565 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009566 {
9567 .cmd = NL80211_CMD_SET_BEACON,
9568 .policy = nl80211_policy,
9569 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009570 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009571 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009572 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009573 },
9574 {
Johannes Berg88600202012-02-13 15:17:18 +01009575 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009576 .policy = nl80211_policy,
9577 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009578 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009580 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009581 },
9582 {
Johannes Berg88600202012-02-13 15:17:18 +01009583 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009584 .policy = nl80211_policy,
9585 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009586 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009587 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009588 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009589 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009590 {
9591 .cmd = NL80211_CMD_GET_STATION,
9592 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009593 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009594 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009595 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9596 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009597 },
9598 {
9599 .cmd = NL80211_CMD_SET_STATION,
9600 .doit = nl80211_set_station,
9601 .policy = nl80211_policy,
9602 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009603 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009604 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009605 },
9606 {
9607 .cmd = NL80211_CMD_NEW_STATION,
9608 .doit = nl80211_new_station,
9609 .policy = nl80211_policy,
9610 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009612 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009613 },
9614 {
9615 .cmd = NL80211_CMD_DEL_STATION,
9616 .doit = nl80211_del_station,
9617 .policy = nl80211_policy,
9618 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009620 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009621 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009622 {
9623 .cmd = NL80211_CMD_GET_MPATH,
9624 .doit = nl80211_get_mpath,
9625 .dumpit = nl80211_dump_mpath,
9626 .policy = nl80211_policy,
9627 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009628 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009629 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009630 },
9631 {
9632 .cmd = NL80211_CMD_SET_MPATH,
9633 .doit = nl80211_set_mpath,
9634 .policy = nl80211_policy,
9635 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009636 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009637 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009638 },
9639 {
9640 .cmd = NL80211_CMD_NEW_MPATH,
9641 .doit = nl80211_new_mpath,
9642 .policy = nl80211_policy,
9643 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009644 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009645 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009646 },
9647 {
9648 .cmd = NL80211_CMD_DEL_MPATH,
9649 .doit = nl80211_del_mpath,
9650 .policy = nl80211_policy,
9651 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009652 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009653 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009654 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009655 {
9656 .cmd = NL80211_CMD_SET_BSS,
9657 .doit = nl80211_set_bss,
9658 .policy = nl80211_policy,
9659 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009660 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009661 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009662 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009663 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009664 .cmd = NL80211_CMD_GET_REG,
9665 .doit = nl80211_get_reg,
9666 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009667 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009668 /* can be retrieved by unprivileged users */
9669 },
9670 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009671 .cmd = NL80211_CMD_SET_REG,
9672 .doit = nl80211_set_reg,
9673 .policy = nl80211_policy,
9674 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009675 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009676 },
9677 {
9678 .cmd = NL80211_CMD_REQ_SET_REG,
9679 .doit = nl80211_req_set_reg,
9680 .policy = nl80211_policy,
9681 .flags = GENL_ADMIN_PERM,
9682 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009683 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009684 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9685 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009686 .policy = nl80211_policy,
9687 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009689 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009690 },
9691 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009692 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9693 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009694 .policy = nl80211_policy,
9695 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009696 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009697 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009698 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009699 {
Johannes Berg2a519312009-02-10 21:25:55 +01009700 .cmd = NL80211_CMD_TRIGGER_SCAN,
9701 .doit = nl80211_trigger_scan,
9702 .policy = nl80211_policy,
9703 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009704 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009705 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009706 },
9707 {
9708 .cmd = NL80211_CMD_GET_SCAN,
9709 .policy = nl80211_policy,
9710 .dumpit = nl80211_dump_scan,
9711 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009712 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009713 .cmd = NL80211_CMD_START_SCHED_SCAN,
9714 .doit = nl80211_start_sched_scan,
9715 .policy = nl80211_policy,
9716 .flags = GENL_ADMIN_PERM,
9717 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9718 NL80211_FLAG_NEED_RTNL,
9719 },
9720 {
9721 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9722 .doit = nl80211_stop_sched_scan,
9723 .policy = nl80211_policy,
9724 .flags = GENL_ADMIN_PERM,
9725 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9726 NL80211_FLAG_NEED_RTNL,
9727 },
9728 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009729 .cmd = NL80211_CMD_AUTHENTICATE,
9730 .doit = nl80211_authenticate,
9731 .policy = nl80211_policy,
9732 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009733 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009734 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009735 },
9736 {
9737 .cmd = NL80211_CMD_ASSOCIATE,
9738 .doit = nl80211_associate,
9739 .policy = nl80211_policy,
9740 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009741 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009742 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009743 },
9744 {
9745 .cmd = NL80211_CMD_DEAUTHENTICATE,
9746 .doit = nl80211_deauthenticate,
9747 .policy = nl80211_policy,
9748 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009749 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009750 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009751 },
9752 {
9753 .cmd = NL80211_CMD_DISASSOCIATE,
9754 .doit = nl80211_disassociate,
9755 .policy = nl80211_policy,
9756 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009757 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009758 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009759 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009760 {
9761 .cmd = NL80211_CMD_JOIN_IBSS,
9762 .doit = nl80211_join_ibss,
9763 .policy = nl80211_policy,
9764 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009765 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009766 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009767 },
9768 {
9769 .cmd = NL80211_CMD_LEAVE_IBSS,
9770 .doit = nl80211_leave_ibss,
9771 .policy = nl80211_policy,
9772 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009773 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009774 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009775 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009776#ifdef CONFIG_NL80211_TESTMODE
9777 {
9778 .cmd = NL80211_CMD_TESTMODE,
9779 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009780 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009781 .policy = nl80211_policy,
9782 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009783 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9784 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009785 },
9786#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009787 {
9788 .cmd = NL80211_CMD_CONNECT,
9789 .doit = nl80211_connect,
9790 .policy = nl80211_policy,
9791 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009792 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009793 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009794 },
9795 {
9796 .cmd = NL80211_CMD_DISCONNECT,
9797 .doit = nl80211_disconnect,
9798 .policy = nl80211_policy,
9799 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009801 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009802 },
Johannes Berg463d0182009-07-14 00:33:35 +02009803 {
9804 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9805 .doit = nl80211_wiphy_netns,
9806 .policy = nl80211_policy,
9807 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009808 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9809 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009810 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009811 {
9812 .cmd = NL80211_CMD_GET_SURVEY,
9813 .policy = nl80211_policy,
9814 .dumpit = nl80211_dump_survey,
9815 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009816 {
9817 .cmd = NL80211_CMD_SET_PMKSA,
9818 .doit = nl80211_setdel_pmksa,
9819 .policy = nl80211_policy,
9820 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009821 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009822 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009823 },
9824 {
9825 .cmd = NL80211_CMD_DEL_PMKSA,
9826 .doit = nl80211_setdel_pmksa,
9827 .policy = nl80211_policy,
9828 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009830 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009831 },
9832 {
9833 .cmd = NL80211_CMD_FLUSH_PMKSA,
9834 .doit = nl80211_flush_pmksa,
9835 .policy = nl80211_policy,
9836 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009837 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009838 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009839 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009840 {
9841 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9842 .doit = nl80211_remain_on_channel,
9843 .policy = nl80211_policy,
9844 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009845 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009846 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009847 },
9848 {
9849 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9850 .doit = nl80211_cancel_remain_on_channel,
9851 .policy = nl80211_policy,
9852 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009853 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009854 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009855 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009856 {
9857 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9858 .doit = nl80211_set_tx_bitrate_mask,
9859 .policy = nl80211_policy,
9860 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009861 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9862 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009863 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009864 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009865 .cmd = NL80211_CMD_REGISTER_FRAME,
9866 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009867 .policy = nl80211_policy,
9868 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009869 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009870 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009871 },
9872 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009873 .cmd = NL80211_CMD_FRAME,
9874 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009875 .policy = nl80211_policy,
9876 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009877 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009878 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009879 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009880 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009881 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9882 .doit = nl80211_tx_mgmt_cancel_wait,
9883 .policy = nl80211_policy,
9884 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009885 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009886 NL80211_FLAG_NEED_RTNL,
9887 },
9888 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009889 .cmd = NL80211_CMD_SET_POWER_SAVE,
9890 .doit = nl80211_set_power_save,
9891 .policy = nl80211_policy,
9892 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009893 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9894 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009895 },
9896 {
9897 .cmd = NL80211_CMD_GET_POWER_SAVE,
9898 .doit = nl80211_get_power_save,
9899 .policy = nl80211_policy,
9900 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009901 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9902 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009903 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009904 {
9905 .cmd = NL80211_CMD_SET_CQM,
9906 .doit = nl80211_set_cqm,
9907 .policy = nl80211_policy,
9908 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009909 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9910 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009911 },
Johannes Bergf444de02010-05-05 15:25:02 +02009912 {
9913 .cmd = NL80211_CMD_SET_CHANNEL,
9914 .doit = nl80211_set_channel,
9915 .policy = nl80211_policy,
9916 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009917 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9918 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009919 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009920 {
9921 .cmd = NL80211_CMD_SET_WDS_PEER,
9922 .doit = nl80211_set_wds_peer,
9923 .policy = nl80211_policy,
9924 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009925 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9926 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009927 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009928 {
9929 .cmd = NL80211_CMD_JOIN_MESH,
9930 .doit = nl80211_join_mesh,
9931 .policy = nl80211_policy,
9932 .flags = GENL_ADMIN_PERM,
9933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9934 NL80211_FLAG_NEED_RTNL,
9935 },
9936 {
9937 .cmd = NL80211_CMD_LEAVE_MESH,
9938 .doit = nl80211_leave_mesh,
9939 .policy = nl80211_policy,
9940 .flags = GENL_ADMIN_PERM,
9941 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9942 NL80211_FLAG_NEED_RTNL,
9943 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009944#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009945 {
9946 .cmd = NL80211_CMD_GET_WOWLAN,
9947 .doit = nl80211_get_wowlan,
9948 .policy = nl80211_policy,
9949 /* can be retrieved by unprivileged users */
9950 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9951 NL80211_FLAG_NEED_RTNL,
9952 },
9953 {
9954 .cmd = NL80211_CMD_SET_WOWLAN,
9955 .doit = nl80211_set_wowlan,
9956 .policy = nl80211_policy,
9957 .flags = GENL_ADMIN_PERM,
9958 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9959 NL80211_FLAG_NEED_RTNL,
9960 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009961#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009962 {
9963 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9964 .doit = nl80211_set_rekey_data,
9965 .policy = nl80211_policy,
9966 .flags = GENL_ADMIN_PERM,
9967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9968 NL80211_FLAG_NEED_RTNL,
9969 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009970 {
9971 .cmd = NL80211_CMD_TDLS_MGMT,
9972 .doit = nl80211_tdls_mgmt,
9973 .policy = nl80211_policy,
9974 .flags = GENL_ADMIN_PERM,
9975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9976 NL80211_FLAG_NEED_RTNL,
9977 },
9978 {
9979 .cmd = NL80211_CMD_TDLS_OPER,
9980 .doit = nl80211_tdls_oper,
9981 .policy = nl80211_policy,
9982 .flags = GENL_ADMIN_PERM,
9983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9984 NL80211_FLAG_NEED_RTNL,
9985 },
Johannes Berg28946da2011-11-04 11:18:12 +01009986 {
9987 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9988 .doit = nl80211_register_unexpected_frame,
9989 .policy = nl80211_policy,
9990 .flags = GENL_ADMIN_PERM,
9991 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9992 NL80211_FLAG_NEED_RTNL,
9993 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009994 {
9995 .cmd = NL80211_CMD_PROBE_CLIENT,
9996 .doit = nl80211_probe_client,
9997 .policy = nl80211_policy,
9998 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009999 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010000 NL80211_FLAG_NEED_RTNL,
10001 },
Johannes Berg5e760232011-11-04 11:18:17 +010010002 {
10003 .cmd = NL80211_CMD_REGISTER_BEACONS,
10004 .doit = nl80211_register_beacons,
10005 .policy = nl80211_policy,
10006 .flags = GENL_ADMIN_PERM,
10007 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10008 NL80211_FLAG_NEED_RTNL,
10009 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010010 {
10011 .cmd = NL80211_CMD_SET_NOACK_MAP,
10012 .doit = nl80211_set_noack_map,
10013 .policy = nl80211_policy,
10014 .flags = GENL_ADMIN_PERM,
10015 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10016 NL80211_FLAG_NEED_RTNL,
10017 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010018 {
10019 .cmd = NL80211_CMD_START_P2P_DEVICE,
10020 .doit = nl80211_start_p2p_device,
10021 .policy = nl80211_policy,
10022 .flags = GENL_ADMIN_PERM,
10023 .internal_flags = NL80211_FLAG_NEED_WDEV |
10024 NL80211_FLAG_NEED_RTNL,
10025 },
10026 {
10027 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10028 .doit = nl80211_stop_p2p_device,
10029 .policy = nl80211_policy,
10030 .flags = GENL_ADMIN_PERM,
10031 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10032 NL80211_FLAG_NEED_RTNL,
10033 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010034 {
10035 .cmd = NL80211_CMD_SET_MCAST_RATE,
10036 .doit = nl80211_set_mcast_rate,
10037 .policy = nl80211_policy,
10038 .flags = GENL_ADMIN_PERM,
10039 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10040 NL80211_FLAG_NEED_RTNL,
10041 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010042 {
10043 .cmd = NL80211_CMD_SET_MAC_ACL,
10044 .doit = nl80211_set_mac_acl,
10045 .policy = nl80211_policy,
10046 .flags = GENL_ADMIN_PERM,
10047 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10048 NL80211_FLAG_NEED_RTNL,
10049 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010050 {
10051 .cmd = NL80211_CMD_RADAR_DETECT,
10052 .doit = nl80211_start_radar_detection,
10053 .policy = nl80211_policy,
10054 .flags = GENL_ADMIN_PERM,
10055 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10056 NL80211_FLAG_NEED_RTNL,
10057 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010058 {
10059 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10060 .doit = nl80211_get_protocol_features,
10061 .policy = nl80211_policy,
10062 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010063 {
10064 .cmd = NL80211_CMD_UPDATE_FT_IES,
10065 .doit = nl80211_update_ft_ies,
10066 .policy = nl80211_policy,
10067 .flags = GENL_ADMIN_PERM,
10068 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10069 NL80211_FLAG_NEED_RTNL,
10070 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010071 {
10072 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10073 .doit = nl80211_crit_protocol_start,
10074 .policy = nl80211_policy,
10075 .flags = GENL_ADMIN_PERM,
10076 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10077 NL80211_FLAG_NEED_RTNL,
10078 },
10079 {
10080 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10081 .doit = nl80211_crit_protocol_stop,
10082 .policy = nl80211_policy,
10083 .flags = GENL_ADMIN_PERM,
10084 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10085 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010086 },
10087 {
10088 .cmd = NL80211_CMD_GET_COALESCE,
10089 .doit = nl80211_get_coalesce,
10090 .policy = nl80211_policy,
10091 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10092 NL80211_FLAG_NEED_RTNL,
10093 },
10094 {
10095 .cmd = NL80211_CMD_SET_COALESCE,
10096 .doit = nl80211_set_coalesce,
10097 .policy = nl80211_policy,
10098 .flags = GENL_ADMIN_PERM,
10099 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10100 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010101 },
10102 {
10103 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10104 .doit = nl80211_channel_switch,
10105 .policy = nl80211_policy,
10106 .flags = GENL_ADMIN_PERM,
10107 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10108 NL80211_FLAG_NEED_RTNL,
10109 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010110 {
10111 .cmd = NL80211_CMD_VENDOR,
10112 .doit = nl80211_vendor_cmd,
10113 .policy = nl80211_policy,
10114 .flags = GENL_ADMIN_PERM,
10115 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10116 NL80211_FLAG_NEED_RTNL,
10117 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010118 {
10119 .cmd = NL80211_CMD_SET_QOS_MAP,
10120 .doit = nl80211_set_qos_map,
10121 .policy = nl80211_policy,
10122 .flags = GENL_ADMIN_PERM,
10123 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10124 NL80211_FLAG_NEED_RTNL,
10125 },
Johannes Berg55682962007-09-20 13:09:35 -040010126};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010127
Johannes Berg55682962007-09-20 13:09:35 -040010128/* notification functions */
10129
Johannes Berg3bb20552014-05-26 13:52:25 +020010130void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10131 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010132{
10133 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010134 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010135
Johannes Berg3bb20552014-05-26 13:52:25 +020010136 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10137 cmd != NL80211_CMD_DEL_WIPHY);
10138
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010139 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010140 if (!msg)
10141 return;
10142
Johannes Berg3bb20552014-05-26 13:52:25 +020010143 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010144 nlmsg_free(msg);
10145 return;
10146 }
10147
Johannes Berg68eb5502013-11-19 15:19:38 +010010148 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010149 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010150}
10151
Johannes Berg362a4152009-05-24 16:43:15 +020010152static int nl80211_add_scan_req(struct sk_buff *msg,
10153 struct cfg80211_registered_device *rdev)
10154{
10155 struct cfg80211_scan_request *req = rdev->scan_req;
10156 struct nlattr *nest;
10157 int i;
10158
10159 if (WARN_ON(!req))
10160 return 0;
10161
10162 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10163 if (!nest)
10164 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010165 for (i = 0; i < req->n_ssids; i++) {
10166 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10167 goto nla_put_failure;
10168 }
Johannes Berg362a4152009-05-24 16:43:15 +020010169 nla_nest_end(msg, nest);
10170
10171 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10172 if (!nest)
10173 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010174 for (i = 0; i < req->n_channels; i++) {
10175 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10176 goto nla_put_failure;
10177 }
Johannes Berg362a4152009-05-24 16:43:15 +020010178 nla_nest_end(msg, nest);
10179
David S. Miller9360ffd2012-03-29 04:41:26 -040010180 if (req->ie &&
10181 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10182 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010183
Johannes Bergae917c92013-10-25 11:05:22 +020010184 if (req->flags &&
10185 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10186 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010187
Johannes Berg362a4152009-05-24 16:43:15 +020010188 return 0;
10189 nla_put_failure:
10190 return -ENOBUFS;
10191}
10192
Johannes Berga538e2d2009-06-16 19:56:42 +020010193static int nl80211_send_scan_msg(struct sk_buff *msg,
10194 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010195 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010196 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010197 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010198{
10199 void *hdr;
10200
Eric W. Biederman15e47302012-09-07 20:12:54 +000010201 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010202 if (!hdr)
10203 return -1;
10204
David S. Miller9360ffd2012-03-29 04:41:26 -040010205 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010206 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10207 wdev->netdev->ifindex)) ||
10208 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010209 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010210
Johannes Berg362a4152009-05-24 16:43:15 +020010211 /* ignore errors and send incomplete event anyway */
10212 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010213
10214 return genlmsg_end(msg, hdr);
10215
10216 nla_put_failure:
10217 genlmsg_cancel(msg, hdr);
10218 return -EMSGSIZE;
10219}
10220
Luciano Coelho807f8a82011-05-11 17:09:35 +030010221static int
10222nl80211_send_sched_scan_msg(struct sk_buff *msg,
10223 struct cfg80211_registered_device *rdev,
10224 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010225 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010226{
10227 void *hdr;
10228
Eric W. Biederman15e47302012-09-07 20:12:54 +000010229 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010230 if (!hdr)
10231 return -1;
10232
David S. Miller9360ffd2012-03-29 04:41:26 -040010233 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10234 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10235 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010236
10237 return genlmsg_end(msg, hdr);
10238
10239 nla_put_failure:
10240 genlmsg_cancel(msg, hdr);
10241 return -EMSGSIZE;
10242}
10243
Johannes Berga538e2d2009-06-16 19:56:42 +020010244void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010245 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010246{
10247 struct sk_buff *msg;
10248
Thomas Graf58050fc2012-06-28 03:57:45 +000010249 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010250 if (!msg)
10251 return;
10252
Johannes Bergfd014282012-06-18 19:17:03 +020010253 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010254 NL80211_CMD_TRIGGER_SCAN) < 0) {
10255 nlmsg_free(msg);
10256 return;
10257 }
10258
Johannes Berg68eb5502013-11-19 15:19:38 +010010259 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010260 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010261}
10262
Johannes Bergf9d15d12014-01-22 11:14:19 +020010263struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10264 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010265{
10266 struct sk_buff *msg;
10267
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010268 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010269 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010270 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010271
Johannes Bergfd014282012-06-18 19:17:03 +020010272 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010273 aborted ? NL80211_CMD_SCAN_ABORTED :
10274 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010275 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010276 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010277 }
10278
Johannes Bergf9d15d12014-01-22 11:14:19 +020010279 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010280}
10281
Johannes Bergf9d15d12014-01-22 11:14:19 +020010282void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10283 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010284{
Johannes Berg2a519312009-02-10 21:25:55 +010010285 if (!msg)
10286 return;
10287
Johannes Berg68eb5502013-11-19 15:19:38 +010010288 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010289 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010290}
10291
Luciano Coelho807f8a82011-05-11 17:09:35 +030010292void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10293 struct net_device *netdev)
10294{
10295 struct sk_buff *msg;
10296
10297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10298 if (!msg)
10299 return;
10300
10301 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10302 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10303 nlmsg_free(msg);
10304 return;
10305 }
10306
Johannes Berg68eb5502013-11-19 15:19:38 +010010307 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010308 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010309}
10310
10311void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10312 struct net_device *netdev, u32 cmd)
10313{
10314 struct sk_buff *msg;
10315
Thomas Graf58050fc2012-06-28 03:57:45 +000010316 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010317 if (!msg)
10318 return;
10319
10320 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10321 nlmsg_free(msg);
10322 return;
10323 }
10324
Johannes Berg68eb5502013-11-19 15:19:38 +010010325 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010326 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010327}
10328
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010329/*
10330 * This can happen on global regulatory changes or device specific settings
10331 * based on custom world regulatory domains.
10332 */
10333void nl80211_send_reg_change_event(struct regulatory_request *request)
10334{
10335 struct sk_buff *msg;
10336 void *hdr;
10337
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010338 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010339 if (!msg)
10340 return;
10341
10342 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10343 if (!hdr) {
10344 nlmsg_free(msg);
10345 return;
10346 }
10347
10348 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010349 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10350 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010351
David S. Miller9360ffd2012-03-29 04:41:26 -040010352 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10353 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10354 NL80211_REGDOM_TYPE_WORLD))
10355 goto nla_put_failure;
10356 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10357 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10358 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10359 goto nla_put_failure;
10360 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10361 request->intersect) {
10362 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10363 NL80211_REGDOM_TYPE_INTERSECTION))
10364 goto nla_put_failure;
10365 } else {
10366 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10367 NL80211_REGDOM_TYPE_COUNTRY) ||
10368 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10369 request->alpha2))
10370 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010371 }
10372
Johannes Bergf4173762012-12-03 18:23:37 +010010373 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010374 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10375 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010376
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010377 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010378
Johannes Bergbc43b282009-07-25 10:54:13 +020010379 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010380 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010381 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010382 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010383
10384 return;
10385
10386nla_put_failure:
10387 genlmsg_cancel(msg, hdr);
10388 nlmsg_free(msg);
10389}
10390
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010391static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10392 struct net_device *netdev,
10393 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010394 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010395{
10396 struct sk_buff *msg;
10397 void *hdr;
10398
Johannes Berge6d6e342009-07-01 21:26:47 +020010399 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010400 if (!msg)
10401 return;
10402
10403 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10404 if (!hdr) {
10405 nlmsg_free(msg);
10406 return;
10407 }
10408
David S. Miller9360ffd2012-03-29 04:41:26 -040010409 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10410 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10411 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10412 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010413
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010414 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010415
Johannes Berg68eb5502013-11-19 15:19:38 +010010416 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010417 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010418 return;
10419
10420 nla_put_failure:
10421 genlmsg_cancel(msg, hdr);
10422 nlmsg_free(msg);
10423}
10424
10425void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010426 struct net_device *netdev, const u8 *buf,
10427 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010428{
10429 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010430 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010431}
10432
10433void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10434 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010435 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010436{
Johannes Berge6d6e342009-07-01 21:26:47 +020010437 nl80211_send_mlme_event(rdev, netdev, buf, len,
10438 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010439}
10440
Jouni Malinen53b46b82009-03-27 20:53:56 +020010441void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010442 struct net_device *netdev, const u8 *buf,
10443 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010444{
10445 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010446 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010447}
10448
Jouni Malinen53b46b82009-03-27 20:53:56 +020010449void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10450 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010451 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010452{
10453 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010454 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010455}
10456
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010457void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10458 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010459{
Johannes Berg947add32013-02-22 22:05:20 +010010460 struct wireless_dev *wdev = dev->ieee80211_ptr;
10461 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010462 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010463 const struct ieee80211_mgmt *mgmt = (void *)buf;
10464 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010465
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010466 if (WARN_ON(len < 2))
10467 return;
10468
10469 if (ieee80211_is_deauth(mgmt->frame_control))
10470 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10471 else
10472 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10473
10474 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10475 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010476}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010477EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010478
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010479static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10480 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010481 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010482{
10483 struct sk_buff *msg;
10484 void *hdr;
10485
Johannes Berge6d6e342009-07-01 21:26:47 +020010486 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010487 if (!msg)
10488 return;
10489
10490 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10491 if (!hdr) {
10492 nlmsg_free(msg);
10493 return;
10494 }
10495
David S. Miller9360ffd2012-03-29 04:41:26 -040010496 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10497 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10498 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10499 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10500 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010501
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010502 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010503
Johannes Berg68eb5502013-11-19 15:19:38 +010010504 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010505 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010506 return;
10507
10508 nla_put_failure:
10509 genlmsg_cancel(msg, hdr);
10510 nlmsg_free(msg);
10511}
10512
10513void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010514 struct net_device *netdev, const u8 *addr,
10515 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010516{
10517 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010518 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010519}
10520
10521void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010522 struct net_device *netdev, const u8 *addr,
10523 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010524{
Johannes Berge6d6e342009-07-01 21:26:47 +020010525 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10526 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010527}
10528
Samuel Ortizb23aa672009-07-01 21:26:54 +020010529void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10530 struct net_device *netdev, const u8 *bssid,
10531 const u8 *req_ie, size_t req_ie_len,
10532 const u8 *resp_ie, size_t resp_ie_len,
10533 u16 status, gfp_t gfp)
10534{
10535 struct sk_buff *msg;
10536 void *hdr;
10537
Thomas Graf58050fc2012-06-28 03:57:45 +000010538 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010539 if (!msg)
10540 return;
10541
10542 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10543 if (!hdr) {
10544 nlmsg_free(msg);
10545 return;
10546 }
10547
David S. Miller9360ffd2012-03-29 04:41:26 -040010548 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10549 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10550 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10551 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10552 (req_ie &&
10553 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10554 (resp_ie &&
10555 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10556 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010557
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010558 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010559
Johannes Berg68eb5502013-11-19 15:19:38 +010010560 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010561 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010562 return;
10563
10564 nla_put_failure:
10565 genlmsg_cancel(msg, hdr);
10566 nlmsg_free(msg);
10567
10568}
10569
10570void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10571 struct net_device *netdev, const u8 *bssid,
10572 const u8 *req_ie, size_t req_ie_len,
10573 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10574{
10575 struct sk_buff *msg;
10576 void *hdr;
10577
Thomas Graf58050fc2012-06-28 03:57:45 +000010578 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010579 if (!msg)
10580 return;
10581
10582 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10583 if (!hdr) {
10584 nlmsg_free(msg);
10585 return;
10586 }
10587
David S. Miller9360ffd2012-03-29 04:41:26 -040010588 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10589 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10590 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10591 (req_ie &&
10592 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10593 (resp_ie &&
10594 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10595 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010596
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010597 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010598
Johannes Berg68eb5502013-11-19 15:19:38 +010010599 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010600 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010601 return;
10602
10603 nla_put_failure:
10604 genlmsg_cancel(msg, hdr);
10605 nlmsg_free(msg);
10606
10607}
10608
10609void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10610 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020010611 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010612{
10613 struct sk_buff *msg;
10614 void *hdr;
10615
Thomas Graf58050fc2012-06-28 03:57:45 +000010616 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010617 if (!msg)
10618 return;
10619
10620 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10621 if (!hdr) {
10622 nlmsg_free(msg);
10623 return;
10624 }
10625
David S. Miller9360ffd2012-03-29 04:41:26 -040010626 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10627 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10628 (from_ap && reason &&
10629 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10630 (from_ap &&
10631 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10632 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10633 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010634
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010635 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010636
Johannes Berg68eb5502013-11-19 15:19:38 +010010637 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010638 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010639 return;
10640
10641 nla_put_failure:
10642 genlmsg_cancel(msg, hdr);
10643 nlmsg_free(msg);
10644
10645}
10646
Johannes Berg04a773a2009-04-19 21:24:32 +020010647void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10648 struct net_device *netdev, const u8 *bssid,
10649 gfp_t gfp)
10650{
10651 struct sk_buff *msg;
10652 void *hdr;
10653
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010654 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010655 if (!msg)
10656 return;
10657
10658 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10659 if (!hdr) {
10660 nlmsg_free(msg);
10661 return;
10662 }
10663
David S. Miller9360ffd2012-03-29 04:41:26 -040010664 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10665 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10666 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10667 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010668
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010669 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010670
Johannes Berg68eb5502013-11-19 15:19:38 +010010671 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010672 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010673 return;
10674
10675 nla_put_failure:
10676 genlmsg_cancel(msg, hdr);
10677 nlmsg_free(msg);
10678}
10679
Johannes Berg947add32013-02-22 22:05:20 +010010680void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10681 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010682{
Johannes Berg947add32013-02-22 22:05:20 +010010683 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010684 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010685 struct sk_buff *msg;
10686 void *hdr;
10687
Johannes Berg947add32013-02-22 22:05:20 +010010688 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10689 return;
10690
10691 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10692
Javier Cardonac93b5e72011-04-07 15:08:34 -070010693 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10694 if (!msg)
10695 return;
10696
10697 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10698 if (!hdr) {
10699 nlmsg_free(msg);
10700 return;
10701 }
10702
David S. Miller9360ffd2012-03-29 04:41:26 -040010703 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010704 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10705 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010706 (ie_len && ie &&
10707 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10708 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010709
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010710 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010711
Johannes Berg68eb5502013-11-19 15:19:38 +010010712 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010713 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010714 return;
10715
10716 nla_put_failure:
10717 genlmsg_cancel(msg, hdr);
10718 nlmsg_free(msg);
10719}
Johannes Berg947add32013-02-22 22:05:20 +010010720EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010721
Jouni Malinena3b8b052009-03-27 21:59:49 +020010722void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10723 struct net_device *netdev, const u8 *addr,
10724 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010725 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010726{
10727 struct sk_buff *msg;
10728 void *hdr;
10729
Johannes Berge6d6e342009-07-01 21:26:47 +020010730 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010731 if (!msg)
10732 return;
10733
10734 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10735 if (!hdr) {
10736 nlmsg_free(msg);
10737 return;
10738 }
10739
David S. Miller9360ffd2012-03-29 04:41:26 -040010740 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10741 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10742 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10743 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10744 (key_id != -1 &&
10745 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10746 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10747 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010748
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010749 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010750
Johannes Berg68eb5502013-11-19 15:19:38 +010010751 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010752 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010753 return;
10754
10755 nla_put_failure:
10756 genlmsg_cancel(msg, hdr);
10757 nlmsg_free(msg);
10758}
10759
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010760void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10761 struct ieee80211_channel *channel_before,
10762 struct ieee80211_channel *channel_after)
10763{
10764 struct sk_buff *msg;
10765 void *hdr;
10766 struct nlattr *nl_freq;
10767
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010768 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010769 if (!msg)
10770 return;
10771
10772 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10773 if (!hdr) {
10774 nlmsg_free(msg);
10775 return;
10776 }
10777
10778 /*
10779 * Since we are applying the beacon hint to a wiphy we know its
10780 * wiphy_idx is valid
10781 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010782 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10783 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010784
10785 /* Before */
10786 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10787 if (!nl_freq)
10788 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010789 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010790 goto nla_put_failure;
10791 nla_nest_end(msg, nl_freq);
10792
10793 /* After */
10794 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10795 if (!nl_freq)
10796 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010797 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010798 goto nla_put_failure;
10799 nla_nest_end(msg, nl_freq);
10800
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010801 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010802
Johannes Berg463d0182009-07-14 00:33:35 +020010803 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010804 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010805 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010806 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010807
10808 return;
10809
10810nla_put_failure:
10811 genlmsg_cancel(msg, hdr);
10812 nlmsg_free(msg);
10813}
10814
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010815static void nl80211_send_remain_on_chan_event(
10816 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010817 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010818 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010819 unsigned int duration, gfp_t gfp)
10820{
10821 struct sk_buff *msg;
10822 void *hdr;
10823
10824 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10825 if (!msg)
10826 return;
10827
10828 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10829 if (!hdr) {
10830 nlmsg_free(msg);
10831 return;
10832 }
10833
David S. Miller9360ffd2012-03-29 04:41:26 -040010834 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010835 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10836 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010837 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010838 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010839 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10840 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010841 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10842 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010843
David S. Miller9360ffd2012-03-29 04:41:26 -040010844 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10845 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10846 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010847
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010848 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010849
Johannes Berg68eb5502013-11-19 15:19:38 +010010850 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010851 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010852 return;
10853
10854 nla_put_failure:
10855 genlmsg_cancel(msg, hdr);
10856 nlmsg_free(msg);
10857}
10858
Johannes Berg947add32013-02-22 22:05:20 +010010859void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10860 struct ieee80211_channel *chan,
10861 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010862{
Johannes Berg947add32013-02-22 22:05:20 +010010863 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010864 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010865
10866 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010867 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010868 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010869 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010870}
Johannes Berg947add32013-02-22 22:05:20 +010010871EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010872
Johannes Berg947add32013-02-22 22:05:20 +010010873void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10874 struct ieee80211_channel *chan,
10875 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010876{
Johannes Berg947add32013-02-22 22:05:20 +010010877 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010878 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010879
10880 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010881 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010882 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010883}
Johannes Berg947add32013-02-22 22:05:20 +010010884EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010885
Johannes Berg947add32013-02-22 22:05:20 +010010886void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10887 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010888{
Johannes Berg947add32013-02-22 22:05:20 +010010889 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010890 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010891 struct sk_buff *msg;
10892
Johannes Berg947add32013-02-22 22:05:20 +010010893 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10894
Thomas Graf58050fc2012-06-28 03:57:45 +000010895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010896 if (!msg)
10897 return;
10898
John W. Linville66266b32012-03-15 13:25:41 -040010899 if (nl80211_send_station(msg, 0, 0, 0,
10900 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010901 nlmsg_free(msg);
10902 return;
10903 }
10904
Johannes Berg68eb5502013-11-19 15:19:38 +010010905 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010906 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010907}
Johannes Berg947add32013-02-22 22:05:20 +010010908EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010909
Johannes Berg947add32013-02-22 22:05:20 +010010910void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010911{
Johannes Berg947add32013-02-22 22:05:20 +010010912 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010913 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010914 struct sk_buff *msg;
10915 void *hdr;
10916
Johannes Berg947add32013-02-22 22:05:20 +010010917 trace_cfg80211_del_sta(dev, mac_addr);
10918
Thomas Graf58050fc2012-06-28 03:57:45 +000010919 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010920 if (!msg)
10921 return;
10922
10923 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10924 if (!hdr) {
10925 nlmsg_free(msg);
10926 return;
10927 }
10928
David S. Miller9360ffd2012-03-29 04:41:26 -040010929 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10930 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10931 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010932
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010933 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010934
Johannes Berg68eb5502013-11-19 15:19:38 +010010935 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010936 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010937 return;
10938
10939 nla_put_failure:
10940 genlmsg_cancel(msg, hdr);
10941 nlmsg_free(msg);
10942}
Johannes Berg947add32013-02-22 22:05:20 +010010943EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010944
Johannes Berg947add32013-02-22 22:05:20 +010010945void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10946 enum nl80211_connect_failed_reason reason,
10947 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010948{
Johannes Berg947add32013-02-22 22:05:20 +010010949 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010950 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010951 struct sk_buff *msg;
10952 void *hdr;
10953
10954 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10955 if (!msg)
10956 return;
10957
10958 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10959 if (!hdr) {
10960 nlmsg_free(msg);
10961 return;
10962 }
10963
10964 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10965 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10966 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10967 goto nla_put_failure;
10968
10969 genlmsg_end(msg, hdr);
10970
Johannes Berg68eb5502013-11-19 15:19:38 +010010971 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010972 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010973 return;
10974
10975 nla_put_failure:
10976 genlmsg_cancel(msg, hdr);
10977 nlmsg_free(msg);
10978}
Johannes Berg947add32013-02-22 22:05:20 +010010979EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010980
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010981static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10982 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010983{
10984 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010985 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010986 struct sk_buff *msg;
10987 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010988 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010989
Eric W. Biederman15e47302012-09-07 20:12:54 +000010990 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010991 return false;
10992
10993 msg = nlmsg_new(100, gfp);
10994 if (!msg)
10995 return true;
10996
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010997 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010998 if (!hdr) {
10999 nlmsg_free(msg);
11000 return true;
11001 }
11002
David S. Miller9360ffd2012-03-29 04:41:26 -040011003 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11004 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11005 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11006 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011007
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011008 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011009 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011010 return true;
11011
11012 nla_put_failure:
11013 genlmsg_cancel(msg, hdr);
11014 nlmsg_free(msg);
11015 return true;
11016}
11017
Johannes Berg947add32013-02-22 22:05:20 +010011018bool cfg80211_rx_spurious_frame(struct net_device *dev,
11019 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011020{
Johannes Berg947add32013-02-22 22:05:20 +010011021 struct wireless_dev *wdev = dev->ieee80211_ptr;
11022 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011023
Johannes Berg947add32013-02-22 22:05:20 +010011024 trace_cfg80211_rx_spurious_frame(dev, addr);
11025
11026 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11027 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11028 trace_cfg80211_return_bool(false);
11029 return false;
11030 }
11031 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11032 addr, gfp);
11033 trace_cfg80211_return_bool(ret);
11034 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011035}
Johannes Berg947add32013-02-22 22:05:20 +010011036EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11037
11038bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11039 const u8 *addr, gfp_t gfp)
11040{
11041 struct wireless_dev *wdev = dev->ieee80211_ptr;
11042 bool ret;
11043
11044 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11045
11046 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11047 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11048 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11049 trace_cfg80211_return_bool(false);
11050 return false;
11051 }
11052 ret = __nl80211_unexpected_frame(dev,
11053 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11054 addr, gfp);
11055 trace_cfg80211_return_bool(ret);
11056 return ret;
11057}
11058EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011059
Johannes Berg2e161f72010-08-12 15:38:38 +020011060int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011061 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011062 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011063 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011064{
Johannes Berg71bbc992012-06-15 15:30:18 +020011065 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011066 struct sk_buff *msg;
11067 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011068
11069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11070 if (!msg)
11071 return -ENOMEM;
11072
Johannes Berg2e161f72010-08-12 15:38:38 +020011073 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011074 if (!hdr) {
11075 nlmsg_free(msg);
11076 return -ENOMEM;
11077 }
11078
David S. Miller9360ffd2012-03-29 04:41:26 -040011079 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011080 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11081 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011082 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011083 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11084 (sig_dbm &&
11085 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011086 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11087 (flags &&
11088 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011089 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011090
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011091 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011092
Eric W. Biederman15e47302012-09-07 20:12:54 +000011093 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011094
11095 nla_put_failure:
11096 genlmsg_cancel(msg, hdr);
11097 nlmsg_free(msg);
11098 return -ENOBUFS;
11099}
11100
Johannes Berg947add32013-02-22 22:05:20 +010011101void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11102 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011103{
Johannes Berg947add32013-02-22 22:05:20 +010011104 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011105 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011106 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011107 struct sk_buff *msg;
11108 void *hdr;
11109
Johannes Berg947add32013-02-22 22:05:20 +010011110 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11111
Jouni Malinen026331c2010-02-15 12:53:10 +020011112 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11113 if (!msg)
11114 return;
11115
Johannes Berg2e161f72010-08-12 15:38:38 +020011116 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011117 if (!hdr) {
11118 nlmsg_free(msg);
11119 return;
11120 }
11121
David S. Miller9360ffd2012-03-29 04:41:26 -040011122 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011123 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11124 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011125 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011126 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11127 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11128 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11129 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011130
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011131 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011132
Johannes Berg68eb5502013-11-19 15:19:38 +010011133 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011134 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011135 return;
11136
11137 nla_put_failure:
11138 genlmsg_cancel(msg, hdr);
11139 nlmsg_free(msg);
11140}
Johannes Berg947add32013-02-22 22:05:20 +010011141EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011142
Johannes Berg947add32013-02-22 22:05:20 +010011143void cfg80211_cqm_rssi_notify(struct net_device *dev,
11144 enum nl80211_cqm_rssi_threshold_event rssi_event,
11145 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011146{
Johannes Berg947add32013-02-22 22:05:20 +010011147 struct wireless_dev *wdev = dev->ieee80211_ptr;
11148 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011149 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011150 struct sk_buff *msg;
11151 struct nlattr *pinfoattr;
11152 void *hdr;
11153
Johannes Berg947add32013-02-22 22:05:20 +010011154 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11155
Thomas Graf58050fc2012-06-28 03:57:45 +000011156 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011157 if (!msg)
11158 return;
11159
11160 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11161 if (!hdr) {
11162 nlmsg_free(msg);
11163 return;
11164 }
11165
David S. Miller9360ffd2012-03-29 04:41:26 -040011166 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011167 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011168 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011169
11170 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11171 if (!pinfoattr)
11172 goto nla_put_failure;
11173
David S. Miller9360ffd2012-03-29 04:41:26 -040011174 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11175 rssi_event))
11176 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011177
11178 nla_nest_end(msg, pinfoattr);
11179
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011180 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011181
Johannes Berg68eb5502013-11-19 15:19:38 +010011182 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011183 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011184 return;
11185
11186 nla_put_failure:
11187 genlmsg_cancel(msg, hdr);
11188 nlmsg_free(msg);
11189}
Johannes Berg947add32013-02-22 22:05:20 +010011190EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011191
Johannes Berg947add32013-02-22 22:05:20 +010011192static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11193 struct net_device *netdev, const u8 *bssid,
11194 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011195{
11196 struct sk_buff *msg;
11197 struct nlattr *rekey_attr;
11198 void *hdr;
11199
Thomas Graf58050fc2012-06-28 03:57:45 +000011200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011201 if (!msg)
11202 return;
11203
11204 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11205 if (!hdr) {
11206 nlmsg_free(msg);
11207 return;
11208 }
11209
David S. Miller9360ffd2012-03-29 04:41:26 -040011210 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11211 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11212 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11213 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011214
11215 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11216 if (!rekey_attr)
11217 goto nla_put_failure;
11218
David S. Miller9360ffd2012-03-29 04:41:26 -040011219 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11220 NL80211_REPLAY_CTR_LEN, replay_ctr))
11221 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011222
11223 nla_nest_end(msg, rekey_attr);
11224
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011225 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011226
Johannes Berg68eb5502013-11-19 15:19:38 +010011227 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011228 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011229 return;
11230
11231 nla_put_failure:
11232 genlmsg_cancel(msg, hdr);
11233 nlmsg_free(msg);
11234}
11235
Johannes Berg947add32013-02-22 22:05:20 +010011236void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11237 const u8 *replay_ctr, gfp_t gfp)
11238{
11239 struct wireless_dev *wdev = dev->ieee80211_ptr;
11240 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011241 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011242
11243 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11244 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11245}
11246EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11247
11248static void
11249nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11250 struct net_device *netdev, int index,
11251 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011252{
11253 struct sk_buff *msg;
11254 struct nlattr *attr;
11255 void *hdr;
11256
Thomas Graf58050fc2012-06-28 03:57:45 +000011257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011258 if (!msg)
11259 return;
11260
11261 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11262 if (!hdr) {
11263 nlmsg_free(msg);
11264 return;
11265 }
11266
David S. Miller9360ffd2012-03-29 04:41:26 -040011267 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11268 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11269 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011270
11271 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11272 if (!attr)
11273 goto nla_put_failure;
11274
David S. Miller9360ffd2012-03-29 04:41:26 -040011275 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11276 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11277 (preauth &&
11278 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11279 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011280
11281 nla_nest_end(msg, attr);
11282
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011283 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011284
Johannes Berg68eb5502013-11-19 15:19:38 +010011285 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011286 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011287 return;
11288
11289 nla_put_failure:
11290 genlmsg_cancel(msg, hdr);
11291 nlmsg_free(msg);
11292}
11293
Johannes Berg947add32013-02-22 22:05:20 +010011294void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11295 const u8 *bssid, bool preauth, gfp_t gfp)
11296{
11297 struct wireless_dev *wdev = dev->ieee80211_ptr;
11298 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011299 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011300
11301 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11302 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11303}
11304EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11305
11306static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11307 struct net_device *netdev,
11308 struct cfg80211_chan_def *chandef,
11309 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011310{
11311 struct sk_buff *msg;
11312 void *hdr;
11313
Thomas Graf58050fc2012-06-28 03:57:45 +000011314 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011315 if (!msg)
11316 return;
11317
11318 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11319 if (!hdr) {
11320 nlmsg_free(msg);
11321 return;
11322 }
11323
Johannes Berg683b6d32012-11-08 21:25:48 +010011324 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11325 goto nla_put_failure;
11326
11327 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011328 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011329
11330 genlmsg_end(msg, hdr);
11331
Johannes Berg68eb5502013-11-19 15:19:38 +010011332 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011333 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011334 return;
11335
11336 nla_put_failure:
11337 genlmsg_cancel(msg, hdr);
11338 nlmsg_free(msg);
11339}
11340
Johannes Berg947add32013-02-22 22:05:20 +010011341void cfg80211_ch_switch_notify(struct net_device *dev,
11342 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011343{
Johannes Berg947add32013-02-22 22:05:20 +010011344 struct wireless_dev *wdev = dev->ieee80211_ptr;
11345 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011346 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011347
Simon Wunderliche487eae2013-11-21 18:19:51 +010011348 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011349
Simon Wunderliche487eae2013-11-21 18:19:51 +010011350 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011351
11352 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011353 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011354 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11355 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011356 return;
Johannes Berg947add32013-02-22 22:05:20 +010011357
Michal Kazior9e0e2962014-01-29 14:22:27 +010011358 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011359 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011360 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011361}
11362EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11363
11364void cfg80211_cqm_txe_notify(struct net_device *dev,
11365 const u8 *peer, u32 num_packets,
11366 u32 rate, u32 intvl, gfp_t gfp)
11367{
11368 struct wireless_dev *wdev = dev->ieee80211_ptr;
11369 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011370 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011371 struct sk_buff *msg;
11372 struct nlattr *pinfoattr;
11373 void *hdr;
11374
11375 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11376 if (!msg)
11377 return;
11378
11379 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11380 if (!hdr) {
11381 nlmsg_free(msg);
11382 return;
11383 }
11384
11385 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011386 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011387 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11388 goto nla_put_failure;
11389
11390 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11391 if (!pinfoattr)
11392 goto nla_put_failure;
11393
11394 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11395 goto nla_put_failure;
11396
11397 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11398 goto nla_put_failure;
11399
11400 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11401 goto nla_put_failure;
11402
11403 nla_nest_end(msg, pinfoattr);
11404
11405 genlmsg_end(msg, hdr);
11406
Johannes Berg68eb5502013-11-19 15:19:38 +010011407 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011408 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011409 return;
11410
11411 nla_put_failure:
11412 genlmsg_cancel(msg, hdr);
11413 nlmsg_free(msg);
11414}
Johannes Berg947add32013-02-22 22:05:20 +010011415EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011416
11417void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011418nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011419 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011420 enum nl80211_radar_event event,
11421 struct net_device *netdev, gfp_t gfp)
11422{
11423 struct sk_buff *msg;
11424 void *hdr;
11425
11426 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11427 if (!msg)
11428 return;
11429
11430 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11431 if (!hdr) {
11432 nlmsg_free(msg);
11433 return;
11434 }
11435
11436 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11437 goto nla_put_failure;
11438
11439 /* NOP and radar events don't need a netdev parameter */
11440 if (netdev) {
11441 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11442
11443 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11444 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11445 goto nla_put_failure;
11446 }
11447
11448 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11449 goto nla_put_failure;
11450
11451 if (nl80211_send_chandef(msg, chandef))
11452 goto nla_put_failure;
11453
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011454 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011455
Johannes Berg68eb5502013-11-19 15:19:38 +010011456 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011457 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011458 return;
11459
11460 nla_put_failure:
11461 genlmsg_cancel(msg, hdr);
11462 nlmsg_free(msg);
11463}
11464
Johannes Berg947add32013-02-22 22:05:20 +010011465void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11466 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011467{
Johannes Berg947add32013-02-22 22:05:20 +010011468 struct wireless_dev *wdev = dev->ieee80211_ptr;
11469 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011470 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011471 struct sk_buff *msg;
11472 struct nlattr *pinfoattr;
11473 void *hdr;
11474
Johannes Berg947add32013-02-22 22:05:20 +010011475 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11476
Thomas Graf58050fc2012-06-28 03:57:45 +000011477 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011478 if (!msg)
11479 return;
11480
11481 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11482 if (!hdr) {
11483 nlmsg_free(msg);
11484 return;
11485 }
11486
David S. Miller9360ffd2012-03-29 04:41:26 -040011487 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011488 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011489 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11490 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011491
11492 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11493 if (!pinfoattr)
11494 goto nla_put_failure;
11495
David S. Miller9360ffd2012-03-29 04:41:26 -040011496 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11497 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011498
11499 nla_nest_end(msg, pinfoattr);
11500
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011501 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011502
Johannes Berg68eb5502013-11-19 15:19:38 +010011503 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011504 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011505 return;
11506
11507 nla_put_failure:
11508 genlmsg_cancel(msg, hdr);
11509 nlmsg_free(msg);
11510}
Johannes Berg947add32013-02-22 22:05:20 +010011511EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011512
Johannes Berg7f6cf312011-11-04 11:18:15 +010011513void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11514 u64 cookie, bool acked, gfp_t gfp)
11515{
11516 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011517 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011518 struct sk_buff *msg;
11519 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011520
Beni Lev4ee3e062012-08-27 12:49:39 +030011521 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11522
Thomas Graf58050fc2012-06-28 03:57:45 +000011523 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011524
Johannes Berg7f6cf312011-11-04 11:18:15 +010011525 if (!msg)
11526 return;
11527
11528 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11529 if (!hdr) {
11530 nlmsg_free(msg);
11531 return;
11532 }
11533
David S. Miller9360ffd2012-03-29 04:41:26 -040011534 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11535 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11536 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11537 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11538 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11539 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011540
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011541 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011542
Johannes Berg68eb5502013-11-19 15:19:38 +010011543 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011544 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011545 return;
11546
11547 nla_put_failure:
11548 genlmsg_cancel(msg, hdr);
11549 nlmsg_free(msg);
11550}
11551EXPORT_SYMBOL(cfg80211_probe_status);
11552
Johannes Berg5e760232011-11-04 11:18:17 +010011553void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11554 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011555 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011556{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011557 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011558 struct sk_buff *msg;
11559 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011560 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011561
Beni Lev4ee3e062012-08-27 12:49:39 +030011562 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11563
Ben Greear37c73b52012-10-26 14:49:25 -070011564 spin_lock_bh(&rdev->beacon_registrations_lock);
11565 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11566 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11567 if (!msg) {
11568 spin_unlock_bh(&rdev->beacon_registrations_lock);
11569 return;
11570 }
Johannes Berg5e760232011-11-04 11:18:17 +010011571
Ben Greear37c73b52012-10-26 14:49:25 -070011572 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11573 if (!hdr)
11574 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011575
Ben Greear37c73b52012-10-26 14:49:25 -070011576 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11577 (freq &&
11578 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11579 (sig_dbm &&
11580 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11581 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11582 goto nla_put_failure;
11583
11584 genlmsg_end(msg, hdr);
11585
11586 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011587 }
Ben Greear37c73b52012-10-26 14:49:25 -070011588 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011589 return;
11590
11591 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011592 spin_unlock_bh(&rdev->beacon_registrations_lock);
11593 if (hdr)
11594 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011595 nlmsg_free(msg);
11596}
11597EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11598
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011599#ifdef CONFIG_PM
11600void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11601 struct cfg80211_wowlan_wakeup *wakeup,
11602 gfp_t gfp)
11603{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011604 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011605 struct sk_buff *msg;
11606 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011607 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011608
11609 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11610
11611 if (wakeup)
11612 size += wakeup->packet_present_len;
11613
11614 msg = nlmsg_new(size, gfp);
11615 if (!msg)
11616 return;
11617
11618 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11619 if (!hdr)
11620 goto free_msg;
11621
11622 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11623 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11624 goto free_msg;
11625
11626 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11627 wdev->netdev->ifindex))
11628 goto free_msg;
11629
11630 if (wakeup) {
11631 struct nlattr *reasons;
11632
11633 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011634 if (!reasons)
11635 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011636
11637 if (wakeup->disconnect &&
11638 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11639 goto free_msg;
11640 if (wakeup->magic_pkt &&
11641 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11642 goto free_msg;
11643 if (wakeup->gtk_rekey_failure &&
11644 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11645 goto free_msg;
11646 if (wakeup->eap_identity_req &&
11647 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11648 goto free_msg;
11649 if (wakeup->four_way_handshake &&
11650 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11651 goto free_msg;
11652 if (wakeup->rfkill_release &&
11653 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11654 goto free_msg;
11655
11656 if (wakeup->pattern_idx >= 0 &&
11657 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11658 wakeup->pattern_idx))
11659 goto free_msg;
11660
Johannes Bergae917c92013-10-25 11:05:22 +020011661 if (wakeup->tcp_match &&
11662 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11663 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011664
Johannes Bergae917c92013-10-25 11:05:22 +020011665 if (wakeup->tcp_connlost &&
11666 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11667 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011668
Johannes Bergae917c92013-10-25 11:05:22 +020011669 if (wakeup->tcp_nomoretokens &&
11670 nla_put_flag(msg,
11671 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11672 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011673
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011674 if (wakeup->packet) {
11675 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11676 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11677
11678 if (!wakeup->packet_80211) {
11679 pkt_attr =
11680 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11681 len_attr =
11682 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11683 }
11684
11685 if (wakeup->packet_len &&
11686 nla_put_u32(msg, len_attr, wakeup->packet_len))
11687 goto free_msg;
11688
11689 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11690 wakeup->packet))
11691 goto free_msg;
11692 }
11693
11694 nla_nest_end(msg, reasons);
11695 }
11696
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011697 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011698
Johannes Berg68eb5502013-11-19 15:19:38 +010011699 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011700 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011701 return;
11702
11703 free_msg:
11704 nlmsg_free(msg);
11705}
11706EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11707#endif
11708
Jouni Malinen3475b092012-11-16 22:49:57 +020011709void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11710 enum nl80211_tdls_operation oper,
11711 u16 reason_code, gfp_t gfp)
11712{
11713 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011714 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011715 struct sk_buff *msg;
11716 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011717
11718 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11719 reason_code);
11720
11721 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11722 if (!msg)
11723 return;
11724
11725 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11726 if (!hdr) {
11727 nlmsg_free(msg);
11728 return;
11729 }
11730
11731 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11732 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11733 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11734 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11735 (reason_code > 0 &&
11736 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11737 goto nla_put_failure;
11738
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011739 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011740
Johannes Berg68eb5502013-11-19 15:19:38 +010011741 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011742 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011743 return;
11744
11745 nla_put_failure:
11746 genlmsg_cancel(msg, hdr);
11747 nlmsg_free(msg);
11748}
11749EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11750
Jouni Malinen026331c2010-02-15 12:53:10 +020011751static int nl80211_netlink_notify(struct notifier_block * nb,
11752 unsigned long state,
11753 void *_notify)
11754{
11755 struct netlink_notify *notify = _notify;
11756 struct cfg80211_registered_device *rdev;
11757 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011758 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011759
11760 if (state != NETLINK_URELEASE)
11761 return NOTIFY_DONE;
11762
11763 rcu_read_lock();
11764
Johannes Berg5e760232011-11-04 11:18:17 +010011765 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011766 bool schedule_destroy_work = false;
11767
11768 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011769 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011770
Johannes Berg78f22b62014-03-24 17:57:27 +010011771 if (wdev->owner_nlportid == notify->portid)
11772 schedule_destroy_work = true;
11773 }
11774
Ben Greear37c73b52012-10-26 14:49:25 -070011775 spin_lock_bh(&rdev->beacon_registrations_lock);
11776 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11777 list) {
11778 if (reg->nlportid == notify->portid) {
11779 list_del(&reg->list);
11780 kfree(reg);
11781 break;
11782 }
11783 }
11784 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011785
11786 if (schedule_destroy_work) {
11787 struct cfg80211_iface_destroy *destroy;
11788
11789 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11790 if (destroy) {
11791 destroy->nlportid = notify->portid;
11792 spin_lock(&rdev->destroy_list_lock);
11793 list_add(&destroy->list, &rdev->destroy_list);
11794 spin_unlock(&rdev->destroy_list_lock);
11795 schedule_work(&rdev->destroy_work);
11796 }
11797 }
Johannes Berg5e760232011-11-04 11:18:17 +010011798 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011799
11800 rcu_read_unlock();
11801
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011802 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011803}
11804
11805static struct notifier_block nl80211_netlink_notifier = {
11806 .notifier_call = nl80211_netlink_notify,
11807};
11808
Jouni Malinen355199e2013-02-27 17:14:27 +020011809void cfg80211_ft_event(struct net_device *netdev,
11810 struct cfg80211_ft_event_params *ft_event)
11811{
11812 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011813 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011814 struct sk_buff *msg;
11815 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011816
11817 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11818
11819 if (!ft_event->target_ap)
11820 return;
11821
11822 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11823 if (!msg)
11824 return;
11825
11826 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011827 if (!hdr)
11828 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011829
Johannes Bergae917c92013-10-25 11:05:22 +020011830 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11831 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11832 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11833 goto out;
11834
11835 if (ft_event->ies &&
11836 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11837 goto out;
11838 if (ft_event->ric_ies &&
11839 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11840 ft_event->ric_ies))
11841 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011842
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011843 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011844
Johannes Berg68eb5502013-11-19 15:19:38 +010011845 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011846 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011847 return;
11848 out:
11849 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011850}
11851EXPORT_SYMBOL(cfg80211_ft_event);
11852
Arend van Spriel5de17982013-04-18 15:49:00 +020011853void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11854{
11855 struct cfg80211_registered_device *rdev;
11856 struct sk_buff *msg;
11857 void *hdr;
11858 u32 nlportid;
11859
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011860 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011861 if (!rdev->crit_proto_nlportid)
11862 return;
11863
11864 nlportid = rdev->crit_proto_nlportid;
11865 rdev->crit_proto_nlportid = 0;
11866
11867 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11868 if (!msg)
11869 return;
11870
11871 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11872 if (!hdr)
11873 goto nla_put_failure;
11874
11875 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11876 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11877 goto nla_put_failure;
11878
11879 genlmsg_end(msg, hdr);
11880
11881 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11882 return;
11883
11884 nla_put_failure:
11885 if (hdr)
11886 genlmsg_cancel(msg, hdr);
11887 nlmsg_free(msg);
11888
11889}
11890EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11891
Johannes Berg348baf02014-01-24 14:06:29 +010011892void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11893{
11894 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011895 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011896 struct sk_buff *msg;
11897 void *hdr;
11898
11899 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11900 if (!msg)
11901 return;
11902
11903 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11904 if (!hdr)
11905 goto out;
11906
11907 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11908 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11909 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11910 goto out;
11911
11912 genlmsg_end(msg, hdr);
11913
11914 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11915 NL80211_MCGRP_MLME, GFP_KERNEL);
11916 return;
11917 out:
11918 nlmsg_free(msg);
11919}
11920
Johannes Berg55682962007-09-20 13:09:35 -040011921/* initialisation/exit functions */
11922
11923int nl80211_init(void)
11924{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011925 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011926
Johannes Berg2a94fe42013-11-19 15:19:39 +010011927 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11928 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011929 if (err)
11930 return err;
11931
Jouni Malinen026331c2010-02-15 12:53:10 +020011932 err = netlink_register_notifier(&nl80211_netlink_notifier);
11933 if (err)
11934 goto err_out;
11935
Johannes Berg55682962007-09-20 13:09:35 -040011936 return 0;
11937 err_out:
11938 genl_unregister_family(&nl80211_fam);
11939 return err;
11940}
11941
11942void nl80211_exit(void)
11943{
Jouni Malinen026331c2010-02-15 12:53:10 +020011944 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011945 genl_unregister_family(&nl80211_fam);
11946}