blob: d876146498ddb009487756e312614bf76caee8c9 [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 Malinendc6382c2009-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 },
Johannes Berg55682962007-09-20 13:09:35 -0400392};
393
Johannes Berge31b8212010-10-05 19:39:30 +0200394/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000395static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200396 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200397 [NL80211_KEY_IDX] = { .type = NLA_U8 },
398 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200399 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200400 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
401 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200402 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100403 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
404};
405
406/* policy for the key default flags */
407static const struct nla_policy
408nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
409 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
410 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200411};
412
Johannes Bergff1b6e62011-05-04 15:37:28 +0200413/* policy for WoWLAN attributes */
414static const struct nla_policy
415nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
416 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
417 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
418 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
419 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200420 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
421 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
422 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
423 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100424 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
425};
426
427static const struct nla_policy
428nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
429 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
430 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
431 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
432 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
433 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
434 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
435 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
436 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
437 },
438 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
439 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
440 },
441 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
442 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
443 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200444};
445
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700446/* policy for coalesce rule attributes */
447static const struct nla_policy
448nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
449 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
450 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
451 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
452};
453
Johannes Berge5497d72011-07-05 16:35:40 +0200454/* policy for GTK rekey offload attributes */
455static const struct nla_policy
456nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
457 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
458 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
459 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
460};
461
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300462static const struct nla_policy
463nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200464 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300465 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700466 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300467};
468
Johannes Berg97990a02013-04-19 01:02:55 +0200469static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
470 struct netlink_callback *cb,
471 struct cfg80211_registered_device **rdev,
472 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100473{
Johannes Berg67748892010-10-04 21:14:06 +0200474 int err;
475
Johannes Berg67748892010-10-04 21:14:06 +0200476 rtnl_lock();
477
Johannes Berg97990a02013-04-19 01:02:55 +0200478 if (!cb->args[0]) {
479 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
480 nl80211_fam.attrbuf, nl80211_fam.maxattr,
481 nl80211_policy);
482 if (err)
483 goto out_unlock;
484
485 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
486 nl80211_fam.attrbuf);
487 if (IS_ERR(*wdev)) {
488 err = PTR_ERR(*wdev);
489 goto out_unlock;
490 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800491 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200492 /* 0 is the first index - add 1 to parse only once */
493 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200494 cb->args[1] = (*wdev)->identifier;
495 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200496 /* subtract the 1 again here */
497 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200498 struct wireless_dev *tmp;
499
500 if (!wiphy) {
501 err = -ENODEV;
502 goto out_unlock;
503 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800504 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200505 *wdev = NULL;
506
Johannes Berg97990a02013-04-19 01:02:55 +0200507 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
508 if (tmp->identifier == cb->args[1]) {
509 *wdev = tmp;
510 break;
511 }
512 }
Johannes Berg97990a02013-04-19 01:02:55 +0200513
514 if (!*wdev) {
515 err = -ENODEV;
516 goto out_unlock;
517 }
Johannes Berg67748892010-10-04 21:14:06 +0200518 }
519
Johannes Berg67748892010-10-04 21:14:06 +0200520 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200521 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200522 rtnl_unlock();
523 return err;
524}
525
Johannes Berg97990a02013-04-19 01:02:55 +0200526static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200527{
Johannes Berg67748892010-10-04 21:14:06 +0200528 rtnl_unlock();
529}
530
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100531/* IE validation */
532static bool is_valid_ie_attr(const struct nlattr *attr)
533{
534 const u8 *pos;
535 int len;
536
537 if (!attr)
538 return true;
539
540 pos = nla_data(attr);
541 len = nla_len(attr);
542
543 while (len) {
544 u8 elemlen;
545
546 if (len < 2)
547 return false;
548 len -= 2;
549
550 elemlen = pos[1];
551 if (elemlen > len)
552 return false;
553
554 len -= elemlen;
555 pos += 2 + elemlen;
556 }
557
558 return true;
559}
560
Johannes Berg55682962007-09-20 13:09:35 -0400561/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000562static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400563 int flags, u8 cmd)
564{
565 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000566 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400567}
568
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400569static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100570 struct ieee80211_channel *chan,
571 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400572{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200573 /* Some channels must be completely excluded from the
574 * list to protect old user-space tools from breaking
575 */
576 if (!large && chan->flags &
577 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
578 return 0;
579
David S. Miller9360ffd2012-03-29 04:41:26 -0400580 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
581 chan->center_freq))
582 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400583
David S. Miller9360ffd2012-03-29 04:41:26 -0400584 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
585 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
586 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200587 if (chan->flags & IEEE80211_CHAN_NO_IR) {
588 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
589 goto nla_put_failure;
590 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
591 goto nla_put_failure;
592 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100593 if (chan->flags & IEEE80211_CHAN_RADAR) {
594 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
595 goto nla_put_failure;
596 if (large) {
597 u32 time;
598
599 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
600
601 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
602 chan->dfs_state))
603 goto nla_put_failure;
604 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
605 time))
606 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100607 if (nla_put_u32(msg,
608 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
609 chan->dfs_cac_ms))
610 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100611 }
612 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400613
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100614 if (large) {
615 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
616 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
617 goto nla_put_failure;
618 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
619 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
620 goto nla_put_failure;
621 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
622 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
623 goto nla_put_failure;
624 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
625 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
626 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200627 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
632 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200633 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
638 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100639 }
640
David S. Miller9360ffd2012-03-29 04:41:26 -0400641 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
642 DBM_TO_MBM(chan->max_power)))
643 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400644
645 return 0;
646
647 nla_put_failure:
648 return -ENOBUFS;
649}
650
Johannes Berg55682962007-09-20 13:09:35 -0400651/* netlink command implementations */
652
Johannes Bergb9454e82009-07-08 13:29:08 +0200653struct key_parse {
654 struct key_params p;
655 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200656 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200657 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100658 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200659};
660
661static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
662{
663 struct nlattr *tb[NL80211_KEY_MAX + 1];
664 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
665 nl80211_key_policy);
666 if (err)
667 return err;
668
669 k->def = !!tb[NL80211_KEY_DEFAULT];
670 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
671
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100672 if (k->def) {
673 k->def_uni = true;
674 k->def_multi = true;
675 }
676 if (k->defmgmt)
677 k->def_multi = true;
678
Johannes Bergb9454e82009-07-08 13:29:08 +0200679 if (tb[NL80211_KEY_IDX])
680 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
681
682 if (tb[NL80211_KEY_DATA]) {
683 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
684 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
685 }
686
687 if (tb[NL80211_KEY_SEQ]) {
688 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
689 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
690 }
691
692 if (tb[NL80211_KEY_CIPHER])
693 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
694
Johannes Berge31b8212010-10-05 19:39:30 +0200695 if (tb[NL80211_KEY_TYPE]) {
696 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
697 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
698 return -EINVAL;
699 }
700
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100701 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
702 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100703 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
704 tb[NL80211_KEY_DEFAULT_TYPES],
705 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100706 if (err)
707 return err;
708
709 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
710 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
711 }
712
Johannes Bergb9454e82009-07-08 13:29:08 +0200713 return 0;
714}
715
716static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
717{
718 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
719 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
720 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
721 }
722
723 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
724 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
725 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
726 }
727
728 if (info->attrs[NL80211_ATTR_KEY_IDX])
729 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
730
731 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
732 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
733
734 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
735 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
736
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100737 if (k->def) {
738 k->def_uni = true;
739 k->def_multi = true;
740 }
741 if (k->defmgmt)
742 k->def_multi = true;
743
Johannes Berge31b8212010-10-05 19:39:30 +0200744 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
745 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
746 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
747 return -EINVAL;
748 }
749
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100750 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
751 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
752 int err = nla_parse_nested(
753 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
754 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
755 nl80211_key_default_policy);
756 if (err)
757 return err;
758
759 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
760 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
761 }
762
Johannes Bergb9454e82009-07-08 13:29:08 +0200763 return 0;
764}
765
766static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
767{
768 int err;
769
770 memset(k, 0, sizeof(*k));
771 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200772 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200773
774 if (info->attrs[NL80211_ATTR_KEY])
775 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
776 else
777 err = nl80211_parse_key_old(info, k);
778
779 if (err)
780 return err;
781
782 if (k->def && k->defmgmt)
783 return -EINVAL;
784
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100785 if (k->defmgmt) {
786 if (k->def_uni || !k->def_multi)
787 return -EINVAL;
788 }
789
Johannes Bergb9454e82009-07-08 13:29:08 +0200790 if (k->idx != -1) {
791 if (k->defmgmt) {
792 if (k->idx < 4 || k->idx > 5)
793 return -EINVAL;
794 } else if (k->def) {
795 if (k->idx < 0 || k->idx > 3)
796 return -EINVAL;
797 } else {
798 if (k->idx < 0 || k->idx > 5)
799 return -EINVAL;
800 }
801 }
802
803 return 0;
804}
805
Johannes Bergfffd0932009-07-08 14:22:54 +0200806static struct cfg80211_cached_keys *
807nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530808 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200809{
810 struct key_parse parse;
811 struct nlattr *key;
812 struct cfg80211_cached_keys *result;
813 int rem, err, def = 0;
814
815 result = kzalloc(sizeof(*result), GFP_KERNEL);
816 if (!result)
817 return ERR_PTR(-ENOMEM);
818
819 result->def = -1;
820 result->defmgmt = -1;
821
822 nla_for_each_nested(key, keys, rem) {
823 memset(&parse, 0, sizeof(parse));
824 parse.idx = -1;
825
826 err = nl80211_parse_key_new(key, &parse);
827 if (err)
828 goto error;
829 err = -EINVAL;
830 if (!parse.p.key)
831 goto error;
832 if (parse.idx < 0 || parse.idx > 4)
833 goto error;
834 if (parse.def) {
835 if (def)
836 goto error;
837 def = 1;
838 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100839 if (!parse.def_uni || !parse.def_multi)
840 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200841 } else if (parse.defmgmt)
842 goto error;
843 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200844 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200845 if (err)
846 goto error;
847 result->params[parse.idx].cipher = parse.p.cipher;
848 result->params[parse.idx].key_len = parse.p.key_len;
849 result->params[parse.idx].key = result->data[parse.idx];
850 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530851
852 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
853 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
854 if (no_ht)
855 *no_ht = true;
856 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200857 }
858
859 return result;
860 error:
861 kfree(result);
862 return ERR_PTR(err);
863}
864
865static int nl80211_key_allowed(struct wireless_dev *wdev)
866{
867 ASSERT_WDEV_LOCK(wdev);
868
Johannes Bergfffd0932009-07-08 14:22:54 +0200869 switch (wdev->iftype) {
870 case NL80211_IFTYPE_AP:
871 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200872 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700873 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200874 break;
875 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200877 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200878 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200879 return -ENOLINK;
880 break;
881 default:
882 return -EINVAL;
883 }
884
885 return 0;
886}
887
Jouni Malinen664834d2014-01-15 00:01:44 +0200888static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
889 struct nlattr *tb)
890{
891 struct ieee80211_channel *chan;
892
893 if (tb == NULL)
894 return NULL;
895 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
896 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
897 return NULL;
898 return chan;
899}
900
Johannes Berg7527a782011-05-13 10:58:57 +0200901static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
902{
903 struct nlattr *nl_modes = nla_nest_start(msg, attr);
904 int i;
905
906 if (!nl_modes)
907 goto nla_put_failure;
908
909 i = 0;
910 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400911 if ((ifmodes & 1) && nla_put_flag(msg, i))
912 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200913 ifmodes >>= 1;
914 i++;
915 }
916
917 nla_nest_end(msg, nl_modes);
918 return 0;
919
920nla_put_failure:
921 return -ENOBUFS;
922}
923
924static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100925 struct sk_buff *msg,
926 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200927{
928 struct nlattr *nl_combis;
929 int i, j;
930
931 nl_combis = nla_nest_start(msg,
932 NL80211_ATTR_INTERFACE_COMBINATIONS);
933 if (!nl_combis)
934 goto nla_put_failure;
935
936 for (i = 0; i < wiphy->n_iface_combinations; i++) {
937 const struct ieee80211_iface_combination *c;
938 struct nlattr *nl_combi, *nl_limits;
939
940 c = &wiphy->iface_combinations[i];
941
942 nl_combi = nla_nest_start(msg, i + 1);
943 if (!nl_combi)
944 goto nla_put_failure;
945
946 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
947 if (!nl_limits)
948 goto nla_put_failure;
949
950 for (j = 0; j < c->n_limits; j++) {
951 struct nlattr *nl_limit;
952
953 nl_limit = nla_nest_start(msg, j + 1);
954 if (!nl_limit)
955 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400956 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
957 c->limits[j].max))
958 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200959 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
960 c->limits[j].types))
961 goto nla_put_failure;
962 nla_nest_end(msg, nl_limit);
963 }
964
965 nla_nest_end(msg, nl_limits);
966
David S. Miller9360ffd2012-03-29 04:41:26 -0400967 if (c->beacon_int_infra_match &&
968 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
969 goto nla_put_failure;
970 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
971 c->num_different_channels) ||
972 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
973 c->max_interfaces))
974 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100975 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200976 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
977 c->radar_detect_widths) ||
978 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
979 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100980 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200981
982 nla_nest_end(msg, nl_combi);
983 }
984
985 nla_nest_end(msg, nl_combis);
986
987 return 0;
988nla_put_failure:
989 return -ENOBUFS;
990}
991
Johannes Berg3713b4e2013-02-14 16:19:38 +0100992#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100993static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
994 struct sk_buff *msg)
995{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200996 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100997 struct nlattr *nl_tcp;
998
999 if (!tcp)
1000 return 0;
1001
1002 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1003 if (!nl_tcp)
1004 return -ENOBUFS;
1005
1006 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1007 tcp->data_payload_max))
1008 return -ENOBUFS;
1009
1010 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1011 tcp->data_payload_max))
1012 return -ENOBUFS;
1013
1014 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1015 return -ENOBUFS;
1016
1017 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1018 sizeof(*tcp->tok), tcp->tok))
1019 return -ENOBUFS;
1020
1021 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1022 tcp->data_interval_max))
1023 return -ENOBUFS;
1024
1025 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1026 tcp->wake_payload_max))
1027 return -ENOBUFS;
1028
1029 nla_nest_end(msg, nl_tcp);
1030 return 0;
1031}
1032
Johannes Berg3713b4e2013-02-14 16:19:38 +01001033static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001034 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001035 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001036{
1037 struct nlattr *nl_wowlan;
1038
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001039 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001040 return 0;
1041
1042 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1043 if (!nl_wowlan)
1044 return -ENOBUFS;
1045
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001046 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001047 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001048 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001049 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001050 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001054 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001055 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001058 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001059 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001060 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1062 return -ENOBUFS;
1063
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001065 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1067 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1068 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1069 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 };
1071
1072 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1073 sizeof(pat), &pat))
1074 return -ENOBUFS;
1075 }
1076
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001078 return -ENOBUFS;
1079
Johannes Berg3713b4e2013-02-14 16:19:38 +01001080 nla_nest_end(msg, nl_wowlan);
1081
1082 return 0;
1083}
1084#endif
1085
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001086static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001087 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001088{
1089 struct nl80211_coalesce_rule_support rule;
1090
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001091 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001092 return 0;
1093
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001094 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1095 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1096 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1097 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1098 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1099 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001100
1101 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1102 return -ENOBUFS;
1103
1104 return 0;
1105}
1106
Johannes Berg3713b4e2013-02-14 16:19:38 +01001107static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1108 struct ieee80211_supported_band *sband)
1109{
1110 struct nlattr *nl_rates, *nl_rate;
1111 struct ieee80211_rate *rate;
1112 int i;
1113
1114 /* add HT info */
1115 if (sband->ht_cap.ht_supported &&
1116 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1117 sizeof(sband->ht_cap.mcs),
1118 &sband->ht_cap.mcs) ||
1119 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1120 sband->ht_cap.cap) ||
1121 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1122 sband->ht_cap.ampdu_factor) ||
1123 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1124 sband->ht_cap.ampdu_density)))
1125 return -ENOBUFS;
1126
1127 /* add VHT info */
1128 if (sband->vht_cap.vht_supported &&
1129 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1130 sizeof(sband->vht_cap.vht_mcs),
1131 &sband->vht_cap.vht_mcs) ||
1132 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1133 sband->vht_cap.cap)))
1134 return -ENOBUFS;
1135
1136 /* add bitrates */
1137 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1138 if (!nl_rates)
1139 return -ENOBUFS;
1140
1141 for (i = 0; i < sband->n_bitrates; i++) {
1142 nl_rate = nla_nest_start(msg, i);
1143 if (!nl_rate)
1144 return -ENOBUFS;
1145
1146 rate = &sband->bitrates[i];
1147 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1148 rate->bitrate))
1149 return -ENOBUFS;
1150 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1151 nla_put_flag(msg,
1152 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1153 return -ENOBUFS;
1154
1155 nla_nest_end(msg, nl_rate);
1156 }
1157
1158 nla_nest_end(msg, nl_rates);
1159
1160 return 0;
1161}
1162
1163static int
1164nl80211_send_mgmt_stypes(struct sk_buff *msg,
1165 const struct ieee80211_txrx_stypes *mgmt_stypes)
1166{
1167 u16 stypes;
1168 struct nlattr *nl_ftypes, *nl_ifs;
1169 enum nl80211_iftype ift;
1170 int i;
1171
1172 if (!mgmt_stypes)
1173 return 0;
1174
1175 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1176 if (!nl_ifs)
1177 return -ENOBUFS;
1178
1179 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1180 nl_ftypes = nla_nest_start(msg, ift);
1181 if (!nl_ftypes)
1182 return -ENOBUFS;
1183 i = 0;
1184 stypes = mgmt_stypes[ift].tx;
1185 while (stypes) {
1186 if ((stypes & 1) &&
1187 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1188 (i << 4) | IEEE80211_FTYPE_MGMT))
1189 return -ENOBUFS;
1190 stypes >>= 1;
1191 i++;
1192 }
1193 nla_nest_end(msg, nl_ftypes);
1194 }
1195
1196 nla_nest_end(msg, nl_ifs);
1197
1198 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1199 if (!nl_ifs)
1200 return -ENOBUFS;
1201
1202 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1203 nl_ftypes = nla_nest_start(msg, ift);
1204 if (!nl_ftypes)
1205 return -ENOBUFS;
1206 i = 0;
1207 stypes = mgmt_stypes[ift].rx;
1208 while (stypes) {
1209 if ((stypes & 1) &&
1210 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1211 (i << 4) | IEEE80211_FTYPE_MGMT))
1212 return -ENOBUFS;
1213 stypes >>= 1;
1214 i++;
1215 }
1216 nla_nest_end(msg, nl_ftypes);
1217 }
1218 nla_nest_end(msg, nl_ifs);
1219
1220 return 0;
1221}
1222
Johannes Berg86e8cf92013-06-19 10:57:22 +02001223struct nl80211_dump_wiphy_state {
1224 s64 filter_wiphy;
1225 long start;
1226 long split_start, band_start, chan_start;
1227 bool split;
1228};
1229
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001230static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001231 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001232 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001233 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001234{
1235 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001236 struct nlattr *nl_bands, *nl_band;
1237 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001238 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001239 enum ieee80211_band band;
1240 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001241 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001242 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001243 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001244 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001245
Johannes Berg3bb20552014-05-26 13:52:25 +02001246 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001247 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001248 return -ENOBUFS;
1249
Johannes Berg86e8cf92013-06-19 10:57:22 +02001250 if (WARN_ON(!state))
1251 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001252
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001253 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001254 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001255 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001256 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001257 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001258 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001259
Johannes Berg3bb20552014-05-26 13:52:25 +02001260 if (cmd != NL80211_CMD_NEW_WIPHY)
1261 goto finish;
1262
Johannes Berg86e8cf92013-06-19 10:57:22 +02001263 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 case 0:
1265 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001266 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001267 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001268 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001269 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001270 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001272 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001273 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001274 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001275 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001276 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001280 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001285 goto nla_put_failure;
1286
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001287 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1289 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1292 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1295 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1298 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1301 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001304 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001305 state->split_start++;
1306 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001307 break;
1308 case 1:
1309 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001310 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1311 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001312 goto nla_put_failure;
1313
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001316 goto nla_put_failure;
1317
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001318 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1320 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001321
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001327
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001328 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001330 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001331 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001332
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001333 if ((rdev->wiphy.available_antennas_tx ||
1334 rdev->wiphy.available_antennas_rx) &&
1335 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001336 u32 tx_ant = 0, rx_ant = 0;
1337 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001338 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 if (!res) {
1340 if (nla_put_u32(msg,
1341 NL80211_ATTR_WIPHY_ANTENNA_TX,
1342 tx_ant) ||
1343 nla_put_u32(msg,
1344 NL80211_ATTR_WIPHY_ANTENNA_RX,
1345 rx_ant))
1346 goto nla_put_failure;
1347 }
Johannes Bergee688b002008-01-24 19:38:39 +01001348 }
1349
Johannes Berg86e8cf92013-06-19 10:57:22 +02001350 state->split_start++;
1351 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001352 break;
1353 case 2:
1354 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001356 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001357 state->split_start++;
1358 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001359 break;
1360 case 3:
1361 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1362 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001363 goto nla_put_failure;
1364
Johannes Berg86e8cf92013-06-19 10:57:22 +02001365 for (band = state->band_start;
1366 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 struct ieee80211_supported_band *sband;
1368
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001369 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370
1371 if (!sband)
1372 continue;
1373
1374 nl_band = nla_nest_start(msg, band);
1375 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001376 goto nla_put_failure;
1377
Johannes Berg86e8cf92013-06-19 10:57:22 +02001378 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 case 0:
1380 if (nl80211_send_band_rateinfo(msg, sband))
1381 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001382 state->chan_start++;
1383 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001384 break;
1385 default:
1386 /* add frequencies */
1387 nl_freqs = nla_nest_start(
1388 msg, NL80211_BAND_ATTR_FREQS);
1389 if (!nl_freqs)
1390 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001391
Johannes Berg86e8cf92013-06-19 10:57:22 +02001392 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393 i < sband->n_channels;
1394 i++) {
1395 nl_freq = nla_nest_start(msg, i);
1396 if (!nl_freq)
1397 goto nla_put_failure;
1398
1399 chan = &sband->channels[i];
1400
Johannes Berg86e8cf92013-06-19 10:57:22 +02001401 if (nl80211_msg_put_channel(
1402 msg, chan,
1403 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001404 goto nla_put_failure;
1405
1406 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001407 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001408 break;
1409 }
1410 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001411 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001412 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001413 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 nla_nest_end(msg, nl_freqs);
1415 }
1416
1417 nla_nest_end(msg, nl_band);
1418
Johannes Berg86e8cf92013-06-19 10:57:22 +02001419 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001421 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001422 band--;
1423 break;
1424 }
Johannes Bergee688b002008-01-24 19:38:39 +01001425 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001427
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001431 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001432
Johannes Berg3713b4e2013-02-14 16:19:38 +01001433 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001434 if (state->band_start == 0 && state->chan_start == 0)
1435 state->split_start++;
1436 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 break;
1438 case 4:
1439 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1440 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001441 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442
1443 i = 0;
1444#define CMD(op, n) \
1445 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001446 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 i++; \
1448 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1449 goto nla_put_failure; \
1450 } \
1451 } while (0)
1452
1453 CMD(add_virtual_intf, NEW_INTERFACE);
1454 CMD(change_virtual_intf, SET_INTERFACE);
1455 CMD(add_key, NEW_KEY);
1456 CMD(start_ap, START_AP);
1457 CMD(add_station, NEW_STATION);
1458 CMD(add_mpath, NEW_MPATH);
1459 CMD(update_mesh_config, SET_MESH_CONFIG);
1460 CMD(change_bss, SET_BSS);
1461 CMD(auth, AUTHENTICATE);
1462 CMD(assoc, ASSOCIATE);
1463 CMD(deauth, DEAUTHENTICATE);
1464 CMD(disassoc, DISASSOCIATE);
1465 CMD(join_ibss, JOIN_IBSS);
1466 CMD(join_mesh, JOIN_MESH);
1467 CMD(set_pmksa, SET_PMKSA);
1468 CMD(del_pmksa, DEL_PMKSA);
1469 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001470 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1472 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1473 CMD(mgmt_tx, FRAME);
1474 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001475 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001476 i++;
1477 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1478 goto nla_put_failure;
1479 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001480 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1481 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 i++;
1483 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1484 goto nla_put_failure;
1485 }
1486 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001487 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488 CMD(tdls_mgmt, TDLS_MGMT);
1489 CMD(tdls_oper, TDLS_OPER);
1490 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001491 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001492 CMD(sched_scan_start, START_SCHED_SCAN);
1493 CMD(probe_client, PROBE_CLIENT);
1494 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001495 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001496 i++;
1497 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1498 goto nla_put_failure;
1499 }
1500 CMD(start_p2p_device, START_P2P_DEVICE);
1501 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001502#ifdef CONFIG_NL80211_TESTMODE
1503 CMD(testmode_cmd, TESTMODE);
1504#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001505 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001506 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1507 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001508 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001509 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001510 CMD(set_qos_map, SET_QOS_MAP);
Arend van Spriel5de17982013-04-18 15:49:00 +02001511 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001512 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001513#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001514
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001515 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001516 i++;
1517 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001518 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001519 }
1520
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001521 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001522 i++;
1523 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1524 goto nla_put_failure;
1525 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001526
Johannes Berg3713b4e2013-02-14 16:19:38 +01001527 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001528 state->split_start++;
1529 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001530 break;
1531 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001532 if (rdev->ops->remain_on_channel &&
1533 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001534 nla_put_u32(msg,
1535 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001536 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001537 goto nla_put_failure;
1538
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001539 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1541 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001542
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1544 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001545 state->split_start++;
1546 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547 break;
1548 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001549#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001550 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001551 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001552 state->split_start++;
1553 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 break;
1555#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001556 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557#endif
1558 case 7:
1559 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001560 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001561 goto nla_put_failure;
1562
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001563 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001564 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001566
Johannes Berg86e8cf92013-06-19 10:57:22 +02001567 state->split_start++;
1568 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 break;
1570 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001573 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 goto nla_put_failure;
1575
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001576 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001577 /*
1578 * We can only add the per-channel limit information if the
1579 * dump is split, otherwise it makes it too big. Therefore
1580 * only advertise it in that case.
1581 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001582 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001583 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1584 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001585 goto nla_put_failure;
1586
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001587 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1590 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 goto nla_put_failure;
1592
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1594 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 goto nla_put_failure;
1598
1599 /*
1600 * Any information below this point is only available to
1601 * applications that can deal with it being split. This
1602 * helps ensure that newly added capabilities don't break
1603 * older tools by overrunning their buffers.
1604 *
1605 * We still increment split_start so that in the split
1606 * case we'll continue with more data in the next round,
1607 * but break unconditionally so unsplit data stops here.
1608 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 break;
1611 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001613 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 rdev->wiphy.extended_capabilities_len,
1615 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001616 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001617 rdev->wiphy.extended_capabilities_len,
1618 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001619 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001620
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001622 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1624 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001625 goto nla_put_failure;
1626
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001627 state->split_start++;
1628 break;
1629 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001631 goto nla_put_failure;
1632
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001633 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001634 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1635 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1636 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001637
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001638 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001639 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001641 goto nla_put_failure;
1642
Johannes Bergad7e7182013-11-13 13:37:47 +01001643 state->split_start++;
1644 break;
1645 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001647 const struct nl80211_vendor_cmd_info *info;
1648 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001649
Johannes Berg567ffc32013-12-18 14:43:31 +01001650 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1651 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001652 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001653
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001654 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1655 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001656 if (nla_put(msg, i + 1, sizeof(*info), info))
1657 goto nla_put_failure;
1658 }
1659 nla_nest_end(msg, nested);
1660 }
1661
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001662 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001663 const struct nl80211_vendor_cmd_info *info;
1664 struct nlattr *nested;
1665
1666 nested = nla_nest_start(msg,
1667 NL80211_ATTR_VENDOR_EVENTS);
1668 if (!nested)
1669 goto nla_put_failure;
1670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1672 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001673 if (nla_put(msg, i + 1, sizeof(*info), info))
1674 goto nla_put_failure;
1675 }
1676 nla_nest_end(msg, nested);
1677 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001678 state->split_start++;
1679 break;
1680 case 12:
1681 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1682 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1683 rdev->wiphy.max_num_csa_counters))
1684 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001685
Johannes Berg3713b4e2013-02-14 16:19:38 +01001686 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001687 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001688 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001689 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001690 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001691 return genlmsg_end(msg, hdr);
1692
1693 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001694 genlmsg_cancel(msg, hdr);
1695 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001696}
1697
Johannes Berg86e8cf92013-06-19 10:57:22 +02001698static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1699 struct netlink_callback *cb,
1700 struct nl80211_dump_wiphy_state *state)
1701{
1702 struct nlattr **tb = nl80211_fam.attrbuf;
1703 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1704 tb, nl80211_fam.maxattr, nl80211_policy);
1705 /* ignore parse errors for backward compatibility */
1706 if (ret)
1707 return 0;
1708
1709 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1710 if (tb[NL80211_ATTR_WIPHY])
1711 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1712 if (tb[NL80211_ATTR_WDEV])
1713 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1714 if (tb[NL80211_ATTR_IFINDEX]) {
1715 struct net_device *netdev;
1716 struct cfg80211_registered_device *rdev;
1717 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1718
Ying Xue7f2b8562014-01-15 10:23:45 +08001719 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001720 if (!netdev)
1721 return -ENODEV;
1722 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001723 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001724 netdev->ieee80211_ptr->wiphy);
1725 state->filter_wiphy = rdev->wiphy_idx;
1726 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001727 }
1728
1729 return 0;
1730}
1731
Johannes Berg55682962007-09-20 13:09:35 -04001732static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1733{
Johannes Berg645e77d2013-03-01 14:03:49 +01001734 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001735 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001736 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001737
Johannes Berg5fe231e2013-05-08 21:45:15 +02001738 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001739 if (!state) {
1740 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001741 if (!state) {
1742 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001743 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001744 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001745 state->filter_wiphy = -1;
1746 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1747 if (ret) {
1748 kfree(state);
1749 rtnl_unlock();
1750 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001751 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001752 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 }
1754
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001755 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1756 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001757 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001758 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001759 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001760 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001761 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001762 continue;
1763 /* attempt to fit multiple wiphy data chunks into the skb */
1764 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001765 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1766 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001767 NETLINK_CB(cb->skb).portid,
1768 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001769 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001770 if (ret < 0) {
1771 /*
1772 * If sending the wiphy data didn't fit (ENOBUFS
1773 * or EMSGSIZE returned), this SKB is still
1774 * empty (so it's not too big because another
1775 * wiphy dataset is already in the skb) and
1776 * we've not tried to adjust the dump allocation
1777 * yet ... then adjust the alloc size to be
1778 * bigger, and return 1 but with the empty skb.
1779 * This results in an empty message being RX'ed
1780 * in userspace, but that is ignored.
1781 *
1782 * We can then retry with the larger buffer.
1783 */
1784 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001785 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001786 cb->min_dump_alloc < 4096) {
1787 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001788 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001789 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001790 return 1;
1791 }
1792 idx--;
1793 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001794 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001795 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001796 break;
Johannes Berg55682962007-09-20 13:09:35 -04001797 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001798 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001799
Johannes Berg86e8cf92013-06-19 10:57:22 +02001800 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001801
1802 return skb->len;
1803}
1804
Johannes Berg86e8cf92013-06-19 10:57:22 +02001805static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1806{
1807 kfree((void *)cb->args[0]);
1808 return 0;
1809}
1810
Johannes Berg55682962007-09-20 13:09:35 -04001811static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1812{
1813 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001814 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001815 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001816
Johannes Berg645e77d2013-03-01 14:03:49 +01001817 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001818 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001819 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001820
Johannes Berg3bb20552014-05-26 13:52:25 +02001821 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1822 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001823 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001824 nlmsg_free(msg);
1825 return -ENOBUFS;
1826 }
Johannes Berg55682962007-09-20 13:09:35 -04001827
Johannes Berg134e6372009-07-10 09:51:34 +00001828 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001829}
1830
Jouni Malinen31888482008-10-30 16:59:24 +02001831static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1832 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1833 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1834 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1835 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1836 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1837};
1838
1839static int parse_txq_params(struct nlattr *tb[],
1840 struct ieee80211_txq_params *txq_params)
1841{
Johannes Berga3304b02012-03-28 11:04:24 +02001842 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001843 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1844 !tb[NL80211_TXQ_ATTR_AIFS])
1845 return -EINVAL;
1846
Johannes Berga3304b02012-03-28 11:04:24 +02001847 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001848 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1849 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1850 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1851 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1852
Johannes Berga3304b02012-03-28 11:04:24 +02001853 if (txq_params->ac >= NL80211_NUM_ACS)
1854 return -EINVAL;
1855
Jouni Malinen31888482008-10-30 16:59:24 +02001856 return 0;
1857}
1858
Johannes Bergf444de02010-05-05 15:25:02 +02001859static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1860{
1861 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001862 * You can only set the channel explicitly for WDS interfaces,
1863 * all others have their channel managed via their respective
1864 * "establish a connection" command (connect, join, ...)
1865 *
1866 * For AP/GO and mesh mode, the channel can be set with the
1867 * channel userspace API, but is only stored and passed to the
1868 * low-level driver when the AP starts or the mesh is joined.
1869 * This is for backward compatibility, userspace can also give
1870 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001871 *
1872 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001873 * whatever else is going on, so they have their own special
1874 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001875 */
1876 return !wdev ||
1877 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001878 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001879 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1880 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001881}
1882
Johannes Berg683b6d32012-11-08 21:25:48 +01001883static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1884 struct genl_info *info,
1885 struct cfg80211_chan_def *chandef)
1886{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301887 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001888
1889 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1890 return -EINVAL;
1891
1892 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1893
1894 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001895 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1896 chandef->center_freq1 = control_freq;
1897 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001898
1899 /* Primary channel not allowed */
1900 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1901 return -EINVAL;
1902
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001903 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1904 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001905
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001906 chantype = nla_get_u32(
1907 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1908
1909 switch (chantype) {
1910 case NL80211_CHAN_NO_HT:
1911 case NL80211_CHAN_HT20:
1912 case NL80211_CHAN_HT40PLUS:
1913 case NL80211_CHAN_HT40MINUS:
1914 cfg80211_chandef_create(chandef, chandef->chan,
1915 chantype);
1916 break;
1917 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001918 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001919 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001920 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1921 chandef->width =
1922 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1923 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1924 chandef->center_freq1 =
1925 nla_get_u32(
1926 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1927 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1928 chandef->center_freq2 =
1929 nla_get_u32(
1930 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1931 }
1932
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001933 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001934 return -EINVAL;
1935
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001936 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1937 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001939
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001940 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1941 chandef->width == NL80211_CHAN_WIDTH_10) &&
1942 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1943 return -EINVAL;
1944
Johannes Berg683b6d32012-11-08 21:25:48 +01001945 return 0;
1946}
1947
Johannes Bergf444de02010-05-05 15:25:02 +02001948static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001949 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001950 struct genl_info *info)
1951{
Johannes Berg683b6d32012-11-08 21:25:48 +01001952 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001953 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001954 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001955 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001956
Jouni Malinene16821b2014-04-28 11:22:08 +03001957 if (dev)
1958 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001959 if (!nl80211_can_set_dev_channel(wdev))
1960 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001961 if (wdev)
1962 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001963
Johannes Berg683b6d32012-11-08 21:25:48 +01001964 result = nl80211_parse_chandef(rdev, info, &chandef);
1965 if (result)
1966 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001967
Johannes Berge8c9bd52012-06-06 08:18:22 +02001968 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001969 case NL80211_IFTYPE_AP:
1970 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001971 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001972 result = -EINVAL;
1973 break;
1974 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001975 if (wdev->beacon_interval) {
1976 if (!dev || !rdev->ops->set_ap_chanwidth ||
1977 !(rdev->wiphy.features &
1978 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1979 result = -EBUSY;
1980 break;
1981 }
1982
1983 /* Only allow dynamic channel width changes */
1984 if (chandef.chan != wdev->preset_chandef.chan) {
1985 result = -EBUSY;
1986 break;
1987 }
1988 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
1989 if (result)
1990 break;
1991 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001992 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001993 result = 0;
1994 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001995 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001996 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001997 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001998 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001999 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002000 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002001 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002002 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002003 }
Johannes Bergf444de02010-05-05 15:25:02 +02002004
2005 return result;
2006}
2007
2008static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2009{
Johannes Berg4c476992010-10-04 21:36:35 +02002010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2011 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002012
Jouni Malinene16821b2014-04-28 11:22:08 +03002013 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002014}
2015
Bill Jordane8347eb2010-10-01 13:54:28 -04002016static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2017{
Johannes Berg43b19952010-10-07 13:10:30 +02002018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2019 struct net_device *dev = info->user_ptr[1];
2020 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002021 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002022
2023 if (!info->attrs[NL80211_ATTR_MAC])
2024 return -EINVAL;
2025
Johannes Berg43b19952010-10-07 13:10:30 +02002026 if (netif_running(dev))
2027 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002028
Johannes Berg43b19952010-10-07 13:10:30 +02002029 if (!rdev->ops->set_wds_peer)
2030 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002031
Johannes Berg43b19952010-10-07 13:10:30 +02002032 if (wdev->iftype != NL80211_IFTYPE_WDS)
2033 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002034
2035 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002036 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002037}
2038
2039
Johannes Berg55682962007-09-20 13:09:35 -04002040static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2041{
2042 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002043 struct net_device *netdev = NULL;
2044 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002045 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002046 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002047 u32 changed;
2048 u8 retry_short = 0, retry_long = 0;
2049 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002050 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002051
Johannes Berg5fe231e2013-05-08 21:45:15 +02002052 ASSERT_RTNL();
2053
Johannes Bergf444de02010-05-05 15:25:02 +02002054 /*
2055 * Try to find the wiphy and netdev. Normally this
2056 * function shouldn't need the netdev, but this is
2057 * done for backward compatibility -- previously
2058 * setting the channel was done per wiphy, but now
2059 * it is per netdev. Previous userland like hostapd
2060 * also passed a netdev to set_wiphy, so that it is
2061 * possible to let that go to the right netdev!
2062 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002063
Johannes Bergf444de02010-05-05 15:25:02 +02002064 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2065 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2066
Ying Xue7f2b8562014-01-15 10:23:45 +08002067 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002068 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002069 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002070 else
Johannes Bergf444de02010-05-05 15:25:02 +02002071 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002072 }
2073
Johannes Bergf444de02010-05-05 15:25:02 +02002074 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002075 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2076 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002077 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002078 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002079 wdev = NULL;
2080 netdev = NULL;
2081 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002082 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002083 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002084
2085 /*
2086 * end workaround code, by now the rdev is available
2087 * and locked, and wdev may or may not be NULL.
2088 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002089
2090 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002091 result = cfg80211_dev_rename(
2092 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002093
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002094 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002095 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002096
Jouni Malinen31888482008-10-30 16:59:24 +02002097 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2098 struct ieee80211_txq_params txq_params;
2099 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2100
Ying Xue7f2b8562014-01-15 10:23:45 +08002101 if (!rdev->ops->set_txq_params)
2102 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002103
Ying Xue7f2b8562014-01-15 10:23:45 +08002104 if (!netdev)
2105 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002106
Johannes Berg133a3ff2011-11-03 14:50:13 +01002107 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002108 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2109 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002110
Ying Xue7f2b8562014-01-15 10:23:45 +08002111 if (!netif_running(netdev))
2112 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002113
Jouni Malinen31888482008-10-30 16:59:24 +02002114 nla_for_each_nested(nl_txq_params,
2115 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2116 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002117 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2118 nla_data(nl_txq_params),
2119 nla_len(nl_txq_params),
2120 txq_params_policy);
2121 if (result)
2122 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002123 result = parse_txq_params(tb, &txq_params);
2124 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002125 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002126
Hila Gonene35e4d22012-06-27 17:19:42 +03002127 result = rdev_set_txq_params(rdev, netdev,
2128 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002129 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002130 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002131 }
2132 }
2133
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002134 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002135 result = __nl80211_set_channel(
2136 rdev,
2137 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2138 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002139 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002140 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002141 }
2142
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002143 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002144 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002145 enum nl80211_tx_power_setting type;
2146 int idx, mbm = 0;
2147
Johannes Bergc8442112012-10-24 10:17:18 +02002148 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2149 txp_wdev = NULL;
2150
Ying Xue7f2b8562014-01-15 10:23:45 +08002151 if (!rdev->ops->set_tx_power)
2152 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002153
2154 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2155 type = nla_get_u32(info->attrs[idx]);
2156
2157 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002158 (type != NL80211_TX_POWER_AUTOMATIC))
2159 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002160
2161 if (type != NL80211_TX_POWER_AUTOMATIC) {
2162 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2163 mbm = nla_get_u32(info->attrs[idx]);
2164 }
2165
Johannes Bergc8442112012-10-24 10:17:18 +02002166 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002167 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002168 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002169 }
2170
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002171 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2172 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2173 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002174 if ((!rdev->wiphy.available_antennas_tx &&
2175 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002176 !rdev->ops->set_antenna)
2177 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002178
2179 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2180 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2181
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002182 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002183 * available antenna masks, except for the "all" mask */
2184 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002185 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2186 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002187
Bruno Randolf7f531e02010-12-16 11:30:22 +09002188 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2189 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002190
Hila Gonene35e4d22012-06-27 17:19:42 +03002191 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002192 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002193 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002194 }
2195
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002196 changed = 0;
2197
2198 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2199 retry_short = nla_get_u8(
2200 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002201 if (retry_short == 0)
2202 return -EINVAL;
2203
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002204 changed |= WIPHY_PARAM_RETRY_SHORT;
2205 }
2206
2207 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2208 retry_long = nla_get_u8(
2209 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002210 if (retry_long == 0)
2211 return -EINVAL;
2212
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002213 changed |= WIPHY_PARAM_RETRY_LONG;
2214 }
2215
2216 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2217 frag_threshold = nla_get_u32(
2218 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002219 if (frag_threshold < 256)
2220 return -EINVAL;
2221
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002222 if (frag_threshold != (u32) -1) {
2223 /*
2224 * Fragments (apart from the last one) are required to
2225 * have even length. Make the fragmentation code
2226 * simpler by stripping LSB should someone try to use
2227 * odd threshold value.
2228 */
2229 frag_threshold &= ~0x1;
2230 }
2231 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2232 }
2233
2234 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2235 rts_threshold = nla_get_u32(
2236 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2237 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2238 }
2239
Lukáš Turek81077e82009-12-21 22:50:47 +01002240 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2241 coverage_class = nla_get_u8(
2242 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2243 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2244 }
2245
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002246 if (changed) {
2247 u8 old_retry_short, old_retry_long;
2248 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002249 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002250
Ying Xue7f2b8562014-01-15 10:23:45 +08002251 if (!rdev->ops->set_wiphy_params)
2252 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002253
2254 old_retry_short = rdev->wiphy.retry_short;
2255 old_retry_long = rdev->wiphy.retry_long;
2256 old_frag_threshold = rdev->wiphy.frag_threshold;
2257 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002258 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002259
2260 if (changed & WIPHY_PARAM_RETRY_SHORT)
2261 rdev->wiphy.retry_short = retry_short;
2262 if (changed & WIPHY_PARAM_RETRY_LONG)
2263 rdev->wiphy.retry_long = retry_long;
2264 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2265 rdev->wiphy.frag_threshold = frag_threshold;
2266 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2267 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002268 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2269 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002270
Hila Gonene35e4d22012-06-27 17:19:42 +03002271 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002272 if (result) {
2273 rdev->wiphy.retry_short = old_retry_short;
2274 rdev->wiphy.retry_long = old_retry_long;
2275 rdev->wiphy.frag_threshold = old_frag_threshold;
2276 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002277 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002278 }
2279 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002280 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002281}
2282
Johannes Berg71bbc992012-06-15 15:30:18 +02002283static inline u64 wdev_id(struct wireless_dev *wdev)
2284{
2285 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002286 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002287}
Johannes Berg55682962007-09-20 13:09:35 -04002288
Johannes Berg683b6d32012-11-08 21:25:48 +01002289static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002290 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002291{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002292 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002293
Johannes Berg683b6d32012-11-08 21:25:48 +01002294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2295 chandef->chan->center_freq))
2296 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002297 switch (chandef->width) {
2298 case NL80211_CHAN_WIDTH_20_NOHT:
2299 case NL80211_CHAN_WIDTH_20:
2300 case NL80211_CHAN_WIDTH_40:
2301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2302 cfg80211_get_chandef_type(chandef)))
2303 return -ENOBUFS;
2304 break;
2305 default:
2306 break;
2307 }
2308 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2309 return -ENOBUFS;
2310 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2311 return -ENOBUFS;
2312 if (chandef->center_freq2 &&
2313 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002314 return -ENOBUFS;
2315 return 0;
2316}
2317
Eric W. Biederman15e47302012-09-07 20:12:54 +00002318static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002319 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002320 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002321{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002322 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002323 void *hdr;
2324
Eric W. Biederman15e47302012-09-07 20:12:54 +00002325 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002326 if (!hdr)
2327 return -1;
2328
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002329 if (dev &&
2330 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002331 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002332 goto nla_put_failure;
2333
2334 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2335 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002336 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002337 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002338 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2339 rdev->devlist_generation ^
2340 (cfg80211_rdev_list_generation << 2)))
2341 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002342
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002343 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002344 int ret;
2345 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002346
Johannes Berg683b6d32012-11-08 21:25:48 +01002347 ret = rdev_get_channel(rdev, wdev, &chandef);
2348 if (ret == 0) {
2349 if (nl80211_send_chandef(msg, &chandef))
2350 goto nla_put_failure;
2351 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002352 }
2353
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002354 if (wdev->ssid_len) {
2355 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2356 goto nla_put_failure;
2357 }
2358
Johannes Berg55682962007-09-20 13:09:35 -04002359 return genlmsg_end(msg, hdr);
2360
2361 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002362 genlmsg_cancel(msg, hdr);
2363 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002364}
2365
2366static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2367{
2368 int wp_idx = 0;
2369 int if_idx = 0;
2370 int wp_start = cb->args[0];
2371 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002372 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002373 struct wireless_dev *wdev;
2374
Johannes Berg5fe231e2013-05-08 21:45:15 +02002375 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002376 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2377 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002378 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002379 if (wp_idx < wp_start) {
2380 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002381 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002382 }
Johannes Berg55682962007-09-20 13:09:35 -04002383 if_idx = 0;
2384
Johannes Berg89a54e42012-06-15 14:33:17 +02002385 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002386 if (if_idx < if_start) {
2387 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002388 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002389 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002390 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002391 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002392 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002393 goto out;
2394 }
2395 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002396 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002397
2398 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002399 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002400 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002401 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002402
2403 cb->args[0] = wp_idx;
2404 cb->args[1] = if_idx;
2405
2406 return skb->len;
2407}
2408
2409static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2410{
2411 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002412 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002413 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002414
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002415 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002416 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002417 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002418
Eric W. Biederman15e47302012-09-07 20:12:54 +00002419 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002420 rdev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002421 nlmsg_free(msg);
2422 return -ENOBUFS;
2423 }
Johannes Berg55682962007-09-20 13:09:35 -04002424
Johannes Berg134e6372009-07-10 09:51:34 +00002425 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002426}
2427
Michael Wu66f7ac52008-01-31 19:48:22 +01002428static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2429 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2430 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2431 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2432 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2433 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002434 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002435};
2436
2437static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2438{
2439 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2440 int flag;
2441
2442 *mntrflags = 0;
2443
2444 if (!nla)
2445 return -EINVAL;
2446
2447 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2448 nla, mntr_flags_policy))
2449 return -EINVAL;
2450
2451 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2452 if (flags[flag])
2453 *mntrflags |= (1<<flag);
2454
2455 return 0;
2456}
2457
Johannes Berg9bc383d2009-11-19 11:55:19 +01002458static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002459 struct net_device *netdev, u8 use_4addr,
2460 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002461{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002462 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002463 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002464 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002465 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002466 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002467
2468 switch (iftype) {
2469 case NL80211_IFTYPE_AP_VLAN:
2470 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2471 return 0;
2472 break;
2473 case NL80211_IFTYPE_STATION:
2474 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2475 return 0;
2476 break;
2477 default:
2478 break;
2479 }
2480
2481 return -EOPNOTSUPP;
2482}
2483
Johannes Berg55682962007-09-20 13:09:35 -04002484static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2485{
Johannes Berg4c476992010-10-04 21:36:35 +02002486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002487 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002488 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002489 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002490 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002491 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002492 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002493
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002494 memset(&params, 0, sizeof(params));
2495
Johannes Berg04a773a2009-04-19 21:24:32 +02002496 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002497
Johannes Berg723b0382008-09-16 20:22:09 +02002498 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002499 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002500 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002501 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002502 if (ntype > NL80211_IFTYPE_MAX)
2503 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002504 }
2505
Johannes Berg92ffe052008-09-16 20:39:36 +02002506 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002507 struct wireless_dev *wdev = dev->ieee80211_ptr;
2508
Johannes Berg4c476992010-10-04 21:36:35 +02002509 if (ntype != NL80211_IFTYPE_MESH_POINT)
2510 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002511 if (netif_running(dev))
2512 return -EBUSY;
2513
2514 wdev_lock(wdev);
2515 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2516 IEEE80211_MAX_MESH_ID_LEN);
2517 wdev->mesh_id_up_len =
2518 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2519 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2520 wdev->mesh_id_up_len);
2521 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002522 }
2523
Felix Fietkau8b787642009-11-10 18:53:10 +01002524 if (info->attrs[NL80211_ATTR_4ADDR]) {
2525 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2526 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002527 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002528 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002529 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002530 } else {
2531 params.use_4addr = -1;
2532 }
2533
Johannes Berg92ffe052008-09-16 20:39:36 +02002534 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002535 if (ntype != NL80211_IFTYPE_MONITOR)
2536 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002537 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2538 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002539 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002540 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002541
2542 flags = &_flags;
2543 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002544 }
Johannes Berg3b858752009-03-12 09:55:09 +01002545
Luciano Coelho18003292013-08-29 13:26:57 +03002546 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002547 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2548 return -EOPNOTSUPP;
2549
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002550 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002551 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002552 else
2553 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002554
Johannes Berg9bc383d2009-11-19 11:55:19 +01002555 if (!err && params.use_4addr != -1)
2556 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2557
Johannes Berg55682962007-09-20 13:09:35 -04002558 return err;
2559}
2560
2561static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2562{
Johannes Berg4c476992010-10-04 21:36:35 +02002563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002564 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002565 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002566 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002567 int err;
2568 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002569 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002570
Johannes Berg78f22b62014-03-24 17:57:27 +01002571 /* to avoid failing a new interface creation due to pending removal */
2572 cfg80211_destroy_ifaces(rdev);
2573
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002574 memset(&params, 0, sizeof(params));
2575
Johannes Berg55682962007-09-20 13:09:35 -04002576 if (!info->attrs[NL80211_ATTR_IFNAME])
2577 return -EINVAL;
2578
2579 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2580 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2581 if (type > NL80211_IFTYPE_MAX)
2582 return -EINVAL;
2583 }
2584
Johannes Berg79c97e92009-07-07 03:56:12 +02002585 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002586 !(rdev->wiphy.interface_modes & (1 << type)))
2587 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002588
Arend van Spriel1c18f142013-01-08 10:17:27 +01002589 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2590 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2591 ETH_ALEN);
2592 if (!is_valid_ether_addr(params.macaddr))
2593 return -EADDRNOTAVAIL;
2594 }
2595
Johannes Berg9bc383d2009-11-19 11:55:19 +01002596 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002597 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002598 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002599 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002600 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002601 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002602
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002603 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2604 if (!msg)
2605 return -ENOMEM;
2606
Michael Wu66f7ac52008-01-31 19:48:22 +01002607 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2608 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2609 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002610
Luciano Coelho18003292013-08-29 13:26:57 +03002611 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002612 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2613 return -EOPNOTSUPP;
2614
Hila Gonene35e4d22012-06-27 17:19:42 +03002615 wdev = rdev_add_virtual_intf(rdev,
2616 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2617 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002618 if (IS_ERR(wdev)) {
2619 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002620 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002621 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002622
Johannes Berg78f22b62014-03-24 17:57:27 +01002623 if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER])
2624 wdev->owner_nlportid = info->snd_portid;
2625
Johannes Berg98104fde2012-06-16 00:19:54 +02002626 switch (type) {
2627 case NL80211_IFTYPE_MESH_POINT:
2628 if (!info->attrs[NL80211_ATTR_MESH_ID])
2629 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002630 wdev_lock(wdev);
2631 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2632 IEEE80211_MAX_MESH_ID_LEN);
2633 wdev->mesh_id_up_len =
2634 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2635 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2636 wdev->mesh_id_up_len);
2637 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002638 break;
2639 case NL80211_IFTYPE_P2P_DEVICE:
2640 /*
2641 * P2P Device doesn't have a netdev, so doesn't go
2642 * through the netdev notifier and must be added here
2643 */
2644 mutex_init(&wdev->mtx);
2645 INIT_LIST_HEAD(&wdev->event_list);
2646 spin_lock_init(&wdev->event_lock);
2647 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2648 spin_lock_init(&wdev->mgmt_registrations_lock);
2649
Johannes Berg98104fde2012-06-16 00:19:54 +02002650 wdev->identifier = ++rdev->wdev_id;
2651 list_add_rcu(&wdev->list, &rdev->wdev_list);
2652 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002653 break;
2654 default:
2655 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002656 }
2657
Eric W. Biederman15e47302012-09-07 20:12:54 +00002658 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002659 rdev, wdev) < 0) {
2660 nlmsg_free(msg);
2661 return -ENOBUFS;
2662 }
2663
2664 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002665}
2666
2667static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2668{
Johannes Berg4c476992010-10-04 21:36:35 +02002669 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002670 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002671
Johannes Berg4c476992010-10-04 21:36:35 +02002672 if (!rdev->ops->del_virtual_intf)
2673 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002674
Johannes Berg84efbb82012-06-16 00:00:26 +02002675 /*
2676 * If we remove a wireless device without a netdev then clear
2677 * user_ptr[1] so that nl80211_post_doit won't dereference it
2678 * to check if it needs to do dev_put(). Otherwise it crashes
2679 * since the wdev has been freed, unlike with a netdev where
2680 * we need the dev_put() for the netdev to really be freed.
2681 */
2682 if (!wdev->netdev)
2683 info->user_ptr[1] = NULL;
2684
Hila Gonene35e4d22012-06-27 17:19:42 +03002685 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002686}
2687
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002688static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2689{
2690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2691 struct net_device *dev = info->user_ptr[1];
2692 u16 noack_map;
2693
2694 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2695 return -EINVAL;
2696
2697 if (!rdev->ops->set_noack_map)
2698 return -EOPNOTSUPP;
2699
2700 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2701
Hila Gonene35e4d22012-06-27 17:19:42 +03002702 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002703}
2704
Johannes Berg41ade002007-12-19 02:03:29 +01002705struct get_key_cookie {
2706 struct sk_buff *msg;
2707 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002708 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002709};
2710
2711static void get_key_callback(void *c, struct key_params *params)
2712{
Johannes Bergb9454e82009-07-08 13:29:08 +02002713 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002714 struct get_key_cookie *cookie = c;
2715
David S. Miller9360ffd2012-03-29 04:41:26 -04002716 if ((params->key &&
2717 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2718 params->key_len, params->key)) ||
2719 (params->seq &&
2720 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2721 params->seq_len, params->seq)) ||
2722 (params->cipher &&
2723 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2724 params->cipher)))
2725 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002726
Johannes Bergb9454e82009-07-08 13:29:08 +02002727 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2728 if (!key)
2729 goto nla_put_failure;
2730
David S. Miller9360ffd2012-03-29 04:41:26 -04002731 if ((params->key &&
2732 nla_put(cookie->msg, NL80211_KEY_DATA,
2733 params->key_len, params->key)) ||
2734 (params->seq &&
2735 nla_put(cookie->msg, NL80211_KEY_SEQ,
2736 params->seq_len, params->seq)) ||
2737 (params->cipher &&
2738 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2739 params->cipher)))
2740 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002741
David S. Miller9360ffd2012-03-29 04:41:26 -04002742 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2743 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002744
2745 nla_nest_end(cookie->msg, key);
2746
Johannes Berg41ade002007-12-19 02:03:29 +01002747 return;
2748 nla_put_failure:
2749 cookie->error = 1;
2750}
2751
2752static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2753{
Johannes Berg4c476992010-10-04 21:36:35 +02002754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002755 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002756 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002757 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002758 const u8 *mac_addr = NULL;
2759 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002760 struct get_key_cookie cookie = {
2761 .error = 0,
2762 };
2763 void *hdr;
2764 struct sk_buff *msg;
2765
2766 if (info->attrs[NL80211_ATTR_KEY_IDX])
2767 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2768
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002769 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002770 return -EINVAL;
2771
2772 if (info->attrs[NL80211_ATTR_MAC])
2773 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2774
Johannes Berge31b8212010-10-05 19:39:30 +02002775 pairwise = !!mac_addr;
2776 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2777 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2778 if (kt >= NUM_NL80211_KEYTYPES)
2779 return -EINVAL;
2780 if (kt != NL80211_KEYTYPE_GROUP &&
2781 kt != NL80211_KEYTYPE_PAIRWISE)
2782 return -EINVAL;
2783 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2784 }
2785
Johannes Berg4c476992010-10-04 21:36:35 +02002786 if (!rdev->ops->get_key)
2787 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002788
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002789 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002790 if (!msg)
2791 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002792
Eric W. Biederman15e47302012-09-07 20:12:54 +00002793 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002794 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002795 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002796 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002797
2798 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002799 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002800
David S. Miller9360ffd2012-03-29 04:41:26 -04002801 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2802 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2803 goto nla_put_failure;
2804 if (mac_addr &&
2805 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2806 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002807
Johannes Berge31b8212010-10-05 19:39:30 +02002808 if (pairwise && mac_addr &&
2809 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2810 return -ENOENT;
2811
Hila Gonene35e4d22012-06-27 17:19:42 +03002812 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2813 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002814
2815 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002816 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002817
2818 if (cookie.error)
2819 goto nla_put_failure;
2820
2821 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002822 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002823
2824 nla_put_failure:
2825 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002826 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002827 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002828 return err;
2829}
2830
2831static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2832{
Johannes Berg4c476992010-10-04 21:36:35 +02002833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002834 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002835 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002836 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002837
Johannes Bergb9454e82009-07-08 13:29:08 +02002838 err = nl80211_parse_key(info, &key);
2839 if (err)
2840 return err;
2841
2842 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002843 return -EINVAL;
2844
Johannes Bergb9454e82009-07-08 13:29:08 +02002845 /* only support setting default key */
2846 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002847 return -EINVAL;
2848
Johannes Bergfffd0932009-07-08 14:22:54 +02002849 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002850
2851 if (key.def) {
2852 if (!rdev->ops->set_default_key) {
2853 err = -EOPNOTSUPP;
2854 goto out;
2855 }
2856
2857 err = nl80211_key_allowed(dev->ieee80211_ptr);
2858 if (err)
2859 goto out;
2860
Hila Gonene35e4d22012-06-27 17:19:42 +03002861 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002862 key.def_uni, key.def_multi);
2863
2864 if (err)
2865 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002866
Johannes Berg3d23e342009-09-29 23:27:28 +02002867#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002868 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002869#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002870 } else {
2871 if (key.def_uni || !key.def_multi) {
2872 err = -EINVAL;
2873 goto out;
2874 }
2875
2876 if (!rdev->ops->set_default_mgmt_key) {
2877 err = -EOPNOTSUPP;
2878 goto out;
2879 }
2880
2881 err = nl80211_key_allowed(dev->ieee80211_ptr);
2882 if (err)
2883 goto out;
2884
Hila Gonene35e4d22012-06-27 17:19:42 +03002885 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002886 if (err)
2887 goto out;
2888
2889#ifdef CONFIG_CFG80211_WEXT
2890 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2891#endif
2892 }
2893
2894 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002895 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002896
Johannes Berg41ade002007-12-19 02:03:29 +01002897 return err;
2898}
2899
2900static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2901{
Johannes Berg4c476992010-10-04 21:36:35 +02002902 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002903 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002904 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002905 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002906 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002907
Johannes Bergb9454e82009-07-08 13:29:08 +02002908 err = nl80211_parse_key(info, &key);
2909 if (err)
2910 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002911
Johannes Bergb9454e82009-07-08 13:29:08 +02002912 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002913 return -EINVAL;
2914
Johannes Berg41ade002007-12-19 02:03:29 +01002915 if (info->attrs[NL80211_ATTR_MAC])
2916 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2917
Johannes Berge31b8212010-10-05 19:39:30 +02002918 if (key.type == -1) {
2919 if (mac_addr)
2920 key.type = NL80211_KEYTYPE_PAIRWISE;
2921 else
2922 key.type = NL80211_KEYTYPE_GROUP;
2923 }
2924
2925 /* for now */
2926 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2927 key.type != NL80211_KEYTYPE_GROUP)
2928 return -EINVAL;
2929
Johannes Berg4c476992010-10-04 21:36:35 +02002930 if (!rdev->ops->add_key)
2931 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002932
Johannes Berge31b8212010-10-05 19:39:30 +02002933 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2934 key.type == NL80211_KEYTYPE_PAIRWISE,
2935 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002936 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002937
2938 wdev_lock(dev->ieee80211_ptr);
2939 err = nl80211_key_allowed(dev->ieee80211_ptr);
2940 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002941 err = rdev_add_key(rdev, dev, key.idx,
2942 key.type == NL80211_KEYTYPE_PAIRWISE,
2943 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002944 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002945
Johannes Berg41ade002007-12-19 02:03:29 +01002946 return err;
2947}
2948
2949static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2950{
Johannes Berg4c476992010-10-04 21:36:35 +02002951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002952 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002953 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002954 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002955 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002956
Johannes Bergb9454e82009-07-08 13:29:08 +02002957 err = nl80211_parse_key(info, &key);
2958 if (err)
2959 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002960
2961 if (info->attrs[NL80211_ATTR_MAC])
2962 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2963
Johannes Berge31b8212010-10-05 19:39:30 +02002964 if (key.type == -1) {
2965 if (mac_addr)
2966 key.type = NL80211_KEYTYPE_PAIRWISE;
2967 else
2968 key.type = NL80211_KEYTYPE_GROUP;
2969 }
2970
2971 /* for now */
2972 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2973 key.type != NL80211_KEYTYPE_GROUP)
2974 return -EINVAL;
2975
Johannes Berg4c476992010-10-04 21:36:35 +02002976 if (!rdev->ops->del_key)
2977 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002978
Johannes Bergfffd0932009-07-08 14:22:54 +02002979 wdev_lock(dev->ieee80211_ptr);
2980 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002981
2982 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2983 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2984 err = -ENOENT;
2985
Johannes Bergfffd0932009-07-08 14:22:54 +02002986 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002987 err = rdev_del_key(rdev, dev, key.idx,
2988 key.type == NL80211_KEYTYPE_PAIRWISE,
2989 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002990
Johannes Berg3d23e342009-09-29 23:27:28 +02002991#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002992 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002993 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002994 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002995 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002996 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2997 }
2998#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002999 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003000
Johannes Berg41ade002007-12-19 02:03:29 +01003001 return err;
3002}
3003
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303004/* This function returns an error or the number of nested attributes */
3005static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3006{
3007 struct nlattr *attr;
3008 int n_entries = 0, tmp;
3009
3010 nla_for_each_nested(attr, nl_attr, tmp) {
3011 if (nla_len(attr) != ETH_ALEN)
3012 return -EINVAL;
3013
3014 n_entries++;
3015 }
3016
3017 return n_entries;
3018}
3019
3020/*
3021 * This function parses ACL information and allocates memory for ACL data.
3022 * On successful return, the calling function is responsible to free the
3023 * ACL buffer returned by this function.
3024 */
3025static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3026 struct genl_info *info)
3027{
3028 enum nl80211_acl_policy acl_policy;
3029 struct nlattr *attr;
3030 struct cfg80211_acl_data *acl;
3031 int i = 0, n_entries, tmp;
3032
3033 if (!wiphy->max_acl_mac_addrs)
3034 return ERR_PTR(-EOPNOTSUPP);
3035
3036 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3037 return ERR_PTR(-EINVAL);
3038
3039 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3040 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3041 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3042 return ERR_PTR(-EINVAL);
3043
3044 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3045 return ERR_PTR(-EINVAL);
3046
3047 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3048 if (n_entries < 0)
3049 return ERR_PTR(n_entries);
3050
3051 if (n_entries > wiphy->max_acl_mac_addrs)
3052 return ERR_PTR(-ENOTSUPP);
3053
3054 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3055 GFP_KERNEL);
3056 if (!acl)
3057 return ERR_PTR(-ENOMEM);
3058
3059 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3060 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3061 i++;
3062 }
3063
3064 acl->n_acl_entries = n_entries;
3065 acl->acl_policy = acl_policy;
3066
3067 return acl;
3068}
3069
3070static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3071{
3072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3073 struct net_device *dev = info->user_ptr[1];
3074 struct cfg80211_acl_data *acl;
3075 int err;
3076
3077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3078 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3079 return -EOPNOTSUPP;
3080
3081 if (!dev->ieee80211_ptr->beacon_interval)
3082 return -EINVAL;
3083
3084 acl = parse_acl_data(&rdev->wiphy, info);
3085 if (IS_ERR(acl))
3086 return PTR_ERR(acl);
3087
3088 err = rdev_set_mac_acl(rdev, dev, acl);
3089
3090 kfree(acl);
3091
3092 return err;
3093}
3094
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003095static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003096 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003097{
Johannes Berg88600202012-02-13 15:17:18 +01003098 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003099
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003100 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3101 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3102 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3103 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003104 return -EINVAL;
3105
Johannes Berg88600202012-02-13 15:17:18 +01003106 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003107
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003108 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3109 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3110 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003111 if (!bcn->head_len)
3112 return -EINVAL;
3113 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003114 }
3115
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003116 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3117 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3118 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003119 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003120 }
3121
Johannes Berg4c476992010-10-04 21:36:35 +02003122 if (!haveinfo)
3123 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003124
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003125 if (attrs[NL80211_ATTR_IE]) {
3126 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3127 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003128 }
3129
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003130 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003131 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003132 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003133 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003134 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003135 }
3136
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003137 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003138 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003139 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003140 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003141 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003142 }
3143
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003144 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3145 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3146 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003147 }
3148
Johannes Berg88600202012-02-13 15:17:18 +01003149 return 0;
3150}
3151
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003152static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3153 struct cfg80211_ap_settings *params)
3154{
3155 struct wireless_dev *wdev;
3156 bool ret = false;
3157
Johannes Berg89a54e42012-06-15 14:33:17 +02003158 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003159 if (wdev->iftype != NL80211_IFTYPE_AP &&
3160 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3161 continue;
3162
Johannes Berg683b6d32012-11-08 21:25:48 +01003163 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003164 continue;
3165
Johannes Berg683b6d32012-11-08 21:25:48 +01003166 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003167 ret = true;
3168 break;
3169 }
3170
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003171 return ret;
3172}
3173
Jouni Malinene39e5b52012-09-30 19:29:39 +03003174static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3175 enum nl80211_auth_type auth_type,
3176 enum nl80211_commands cmd)
3177{
3178 if (auth_type > NL80211_AUTHTYPE_MAX)
3179 return false;
3180
3181 switch (cmd) {
3182 case NL80211_CMD_AUTHENTICATE:
3183 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3184 auth_type == NL80211_AUTHTYPE_SAE)
3185 return false;
3186 return true;
3187 case NL80211_CMD_CONNECT:
3188 case NL80211_CMD_START_AP:
3189 /* SAE not supported yet */
3190 if (auth_type == NL80211_AUTHTYPE_SAE)
3191 return false;
3192 return true;
3193 default:
3194 return false;
3195 }
3196}
3197
Johannes Berg88600202012-02-13 15:17:18 +01003198static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3199{
3200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3201 struct net_device *dev = info->user_ptr[1];
3202 struct wireless_dev *wdev = dev->ieee80211_ptr;
3203 struct cfg80211_ap_settings params;
3204 int err;
3205
3206 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3207 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3208 return -EOPNOTSUPP;
3209
3210 if (!rdev->ops->start_ap)
3211 return -EOPNOTSUPP;
3212
3213 if (wdev->beacon_interval)
3214 return -EALREADY;
3215
3216 memset(&params, 0, sizeof(params));
3217
3218 /* these are required for START_AP */
3219 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3220 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3221 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3222 return -EINVAL;
3223
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003224 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003225 if (err)
3226 return err;
3227
3228 params.beacon_interval =
3229 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3230 params.dtim_period =
3231 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3232
3233 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3234 if (err)
3235 return err;
3236
3237 /*
3238 * In theory, some of these attributes should be required here
3239 * but since they were not used when the command was originally
3240 * added, keep them optional for old user space programs to let
3241 * them continue to work with drivers that do not need the
3242 * additional information -- drivers must check!
3243 */
3244 if (info->attrs[NL80211_ATTR_SSID]) {
3245 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3246 params.ssid_len =
3247 nla_len(info->attrs[NL80211_ATTR_SSID]);
3248 if (params.ssid_len == 0 ||
3249 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3250 return -EINVAL;
3251 }
3252
3253 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3254 params.hidden_ssid = nla_get_u32(
3255 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3256 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3257 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3258 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3259 return -EINVAL;
3260 }
3261
3262 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3263
3264 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3265 params.auth_type = nla_get_u32(
3266 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003267 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3268 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003269 return -EINVAL;
3270 } else
3271 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3272
3273 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3274 NL80211_MAX_NR_CIPHER_SUITES);
3275 if (err)
3276 return err;
3277
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303278 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3279 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3280 return -EOPNOTSUPP;
3281 params.inactivity_timeout = nla_get_u16(
3282 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3283 }
3284
Johannes Berg53cabad2012-11-14 15:17:28 +01003285 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3286 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3287 return -EINVAL;
3288 params.p2p_ctwindow =
3289 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3290 if (params.p2p_ctwindow > 127)
3291 return -EINVAL;
3292 if (params.p2p_ctwindow != 0 &&
3293 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3294 return -EINVAL;
3295 }
3296
3297 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3298 u8 tmp;
3299
3300 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3301 return -EINVAL;
3302 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3303 if (tmp > 1)
3304 return -EINVAL;
3305 params.p2p_opp_ps = tmp;
3306 if (params.p2p_opp_ps != 0 &&
3307 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3308 return -EINVAL;
3309 }
3310
Johannes Bergaa430da2012-05-16 23:50:18 +02003311 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003312 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3313 if (err)
3314 return err;
3315 } else if (wdev->preset_chandef.chan) {
3316 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003317 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003318 return -EINVAL;
3319
Ilan Peer174e0cd2014-02-23 09:13:01 +02003320 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3321 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003322 return -EINVAL;
3323
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303324 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3325 params.acl = parse_acl_data(&rdev->wiphy, info);
3326 if (IS_ERR(params.acl))
3327 return PTR_ERR(params.acl);
3328 }
3329
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003330 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003331 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003332 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003333 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003334 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003335 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003336 wdev->ssid_len = params.ssid_len;
3337 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003338 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003339 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303340
3341 kfree(params.acl);
3342
Johannes Berg56d18932011-05-09 18:41:15 +02003343 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003344}
3345
Johannes Berg88600202012-02-13 15:17:18 +01003346static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3347{
3348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3349 struct net_device *dev = info->user_ptr[1];
3350 struct wireless_dev *wdev = dev->ieee80211_ptr;
3351 struct cfg80211_beacon_data params;
3352 int err;
3353
3354 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3355 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3356 return -EOPNOTSUPP;
3357
3358 if (!rdev->ops->change_beacon)
3359 return -EOPNOTSUPP;
3360
3361 if (!wdev->beacon_interval)
3362 return -EINVAL;
3363
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003364 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003365 if (err)
3366 return err;
3367
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003368 wdev_lock(wdev);
3369 err = rdev_change_beacon(rdev, dev, &params);
3370 wdev_unlock(wdev);
3371
3372 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003373}
3374
3375static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003376{
Johannes Berg4c476992010-10-04 21:36:35 +02003377 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3378 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003379
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003380 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003381}
3382
Johannes Berg5727ef12007-12-19 02:03:34 +01003383static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3384 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3385 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3386 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003387 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003388 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003389 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003390};
3391
Johannes Bergeccb8e82009-05-11 21:57:56 +03003392static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003393 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003394 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003395{
3396 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003397 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003398 int flag;
3399
Johannes Bergeccb8e82009-05-11 21:57:56 +03003400 /*
3401 * Try parsing the new attribute first so userspace
3402 * can specify both for older kernels.
3403 */
3404 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3405 if (nla) {
3406 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003407
Johannes Bergeccb8e82009-05-11 21:57:56 +03003408 sta_flags = nla_data(nla);
3409 params->sta_flags_mask = sta_flags->mask;
3410 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003411 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003412 if ((params->sta_flags_mask |
3413 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3414 return -EINVAL;
3415 return 0;
3416 }
3417
3418 /* if present, parse the old attribute */
3419
3420 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003421 if (!nla)
3422 return 0;
3423
3424 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3425 nla, sta_flags_policy))
3426 return -EINVAL;
3427
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003428 /*
3429 * Only allow certain flags for interface types so that
3430 * other attributes are silently ignored. Remember that
3431 * this is backward compatibility code with old userspace
3432 * and shouldn't be hit in other cases anyway.
3433 */
3434 switch (iftype) {
3435 case NL80211_IFTYPE_AP:
3436 case NL80211_IFTYPE_AP_VLAN:
3437 case NL80211_IFTYPE_P2P_GO:
3438 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3439 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3440 BIT(NL80211_STA_FLAG_WME) |
3441 BIT(NL80211_STA_FLAG_MFP);
3442 break;
3443 case NL80211_IFTYPE_P2P_CLIENT:
3444 case NL80211_IFTYPE_STATION:
3445 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3446 BIT(NL80211_STA_FLAG_TDLS_PEER);
3447 break;
3448 case NL80211_IFTYPE_MESH_POINT:
3449 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3450 BIT(NL80211_STA_FLAG_MFP) |
3451 BIT(NL80211_STA_FLAG_AUTHORIZED);
3452 default:
3453 return -EINVAL;
3454 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003455
Johannes Berg3383b5a2012-05-10 20:14:43 +02003456 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3457 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003458 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003459
Johannes Berg3383b5a2012-05-10 20:14:43 +02003460 /* no longer support new API additions in old API */
3461 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3462 return -EINVAL;
3463 }
3464 }
3465
Johannes Berg5727ef12007-12-19 02:03:34 +01003466 return 0;
3467}
3468
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003469static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3470 int attr)
3471{
3472 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003473 u32 bitrate;
3474 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003475
3476 rate = nla_nest_start(msg, attr);
3477 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003478 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003479
3480 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3481 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003482 /* report 16-bit bitrate only if we can */
3483 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003484 if (bitrate > 0 &&
3485 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3486 return false;
3487 if (bitrate_compat > 0 &&
3488 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3489 return false;
3490
3491 if (info->flags & RATE_INFO_FLAGS_MCS) {
3492 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3493 return false;
3494 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3495 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3496 return false;
3497 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3498 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3499 return false;
3500 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3501 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3502 return false;
3503 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3504 return false;
3505 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3506 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3507 return false;
3508 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3509 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3510 return false;
3511 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3512 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3513 return false;
3514 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3515 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3516 return false;
3517 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3518 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3519 return false;
3520 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003521
3522 nla_nest_end(msg, rate);
3523 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003524}
3525
Felix Fietkau119363c2013-04-22 16:29:30 +02003526static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3527 int id)
3528{
3529 void *attr;
3530 int i = 0;
3531
3532 if (!mask)
3533 return true;
3534
3535 attr = nla_nest_start(msg, id);
3536 if (!attr)
3537 return false;
3538
3539 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3540 if (!(mask & BIT(i)))
3541 continue;
3542
3543 if (nla_put_u8(msg, i, signal[i]))
3544 return false;
3545 }
3546
3547 nla_nest_end(msg, attr);
3548
3549 return true;
3550}
3551
Eric W. Biederman15e47302012-09-07 20:12:54 +00003552static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003553 int flags,
3554 struct cfg80211_registered_device *rdev,
3555 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003556 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003557{
3558 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003559 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003560
Eric W. Biederman15e47302012-09-07 20:12:54 +00003561 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003562 if (!hdr)
3563 return -1;
3564
David S. Miller9360ffd2012-03-29 04:41:26 -04003565 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3566 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3567 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3568 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003569
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003570 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3571 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003572 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003573 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3574 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3575 sinfo->connected_time))
3576 goto nla_put_failure;
3577 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3578 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3579 sinfo->inactive_time))
3580 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003581 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3582 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003583 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003584 (u32)sinfo->rx_bytes))
3585 goto nla_put_failure;
3586 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003587 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003588 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3589 (u32)sinfo->tx_bytes))
3590 goto nla_put_failure;
3591 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3592 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003593 sinfo->rx_bytes))
3594 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003595 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3596 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003597 sinfo->tx_bytes))
3598 goto nla_put_failure;
3599 if ((sinfo->filled & STATION_INFO_LLID) &&
3600 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3601 goto nla_put_failure;
3602 if ((sinfo->filled & STATION_INFO_PLID) &&
3603 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3604 goto nla_put_failure;
3605 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3606 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3607 sinfo->plink_state))
3608 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003609 switch (rdev->wiphy.signal_type) {
3610 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003611 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3612 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3613 sinfo->signal))
3614 goto nla_put_failure;
3615 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3616 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3617 sinfo->signal_avg))
3618 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003619 break;
3620 default:
3621 break;
3622 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003623 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3624 if (!nl80211_put_signal(msg, sinfo->chains,
3625 sinfo->chain_signal,
3626 NL80211_STA_INFO_CHAIN_SIGNAL))
3627 goto nla_put_failure;
3628 }
3629 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3630 if (!nl80211_put_signal(msg, sinfo->chains,
3631 sinfo->chain_signal_avg,
3632 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3633 goto nla_put_failure;
3634 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003635 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003636 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3637 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003638 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003639 }
3640 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3641 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3642 NL80211_STA_INFO_RX_BITRATE))
3643 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003644 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003645 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3646 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3647 sinfo->rx_packets))
3648 goto nla_put_failure;
3649 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3650 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3651 sinfo->tx_packets))
3652 goto nla_put_failure;
3653 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3654 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3655 sinfo->tx_retries))
3656 goto nla_put_failure;
3657 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3658 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3659 sinfo->tx_failed))
3660 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003661 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3662 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3663 sinfo->expected_throughput))
3664 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003665 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3666 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3667 sinfo->beacon_loss_count))
3668 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003669 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3670 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3671 sinfo->local_pm))
3672 goto nla_put_failure;
3673 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3674 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3675 sinfo->peer_pm))
3676 goto nla_put_failure;
3677 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3678 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3679 sinfo->nonpeer_pm))
3680 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003681 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3682 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3683 if (!bss_param)
3684 goto nla_put_failure;
3685
David S. Miller9360ffd2012-03-29 04:41:26 -04003686 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3687 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3688 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3689 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3690 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3691 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3692 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3693 sinfo->bss_param.dtim_period) ||
3694 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3695 sinfo->bss_param.beacon_interval))
3696 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003697
3698 nla_nest_end(msg, bss_param);
3699 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003700 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3701 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3702 sizeof(struct nl80211_sta_flag_update),
3703 &sinfo->sta_flags))
3704 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003705 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3706 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3707 sinfo->t_offset))
3708 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003709 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003710
David S. Miller9360ffd2012-03-29 04:41:26 -04003711 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3712 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3713 sinfo->assoc_req_ies))
3714 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003715
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003716 return genlmsg_end(msg, hdr);
3717
3718 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003719 genlmsg_cancel(msg, hdr);
3720 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003721}
3722
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003723static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003724 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003725{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003726 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003727 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003728 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003729 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003730 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003731 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003732
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003733 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003734 if (err)
3735 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003736
Johannes Berg97990a02013-04-19 01:02:55 +02003737 if (!wdev->netdev) {
3738 err = -EINVAL;
3739 goto out_err;
3740 }
3741
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003742 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003743 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003744 goto out_err;
3745 }
3746
Johannes Bergbba95fe2008-07-29 13:22:51 +02003747 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003748 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003749 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003750 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003751 if (err == -ENOENT)
3752 break;
3753 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003754 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003755
3756 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003757 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003758 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003759 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003760 &sinfo) < 0)
3761 goto out;
3762
3763 sta_idx++;
3764 }
3765
3766
3767 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003768 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003769 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003770 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003771 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003772
3773 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003774}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003775
Johannes Berg5727ef12007-12-19 02:03:34 +01003776static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3777{
Johannes Berg4c476992010-10-04 21:36:35 +02003778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3779 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003780 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003781 struct sk_buff *msg;
3782 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003783 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003784
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003785 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003786
3787 if (!info->attrs[NL80211_ATTR_MAC])
3788 return -EINVAL;
3789
3790 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3791
Johannes Berg4c476992010-10-04 21:36:35 +02003792 if (!rdev->ops->get_station)
3793 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003794
Hila Gonene35e4d22012-06-27 17:19:42 +03003795 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003796 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003797 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003798
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003799 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003800 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003801 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003802
Eric W. Biederman15e47302012-09-07 20:12:54 +00003803 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003804 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003805 nlmsg_free(msg);
3806 return -ENOBUFS;
3807 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003808
Johannes Berg4c476992010-10-04 21:36:35 +02003809 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003810}
3811
Johannes Berg77ee7c82013-02-15 00:48:33 +01003812int cfg80211_check_station_change(struct wiphy *wiphy,
3813 struct station_parameters *params,
3814 enum cfg80211_station_type statype)
3815{
3816 if (params->listen_interval != -1)
3817 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003818 if (params->aid &&
3819 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003820 return -EINVAL;
3821
3822 /* When you run into this, adjust the code below for the new flag */
3823 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3824
3825 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003826 case CFG80211_STA_MESH_PEER_KERNEL:
3827 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003828 /*
3829 * No ignoring the TDLS flag here -- the userspace mesh
3830 * code doesn't have the bug of including TDLS in the
3831 * mask everywhere.
3832 */
3833 if (params->sta_flags_mask &
3834 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3835 BIT(NL80211_STA_FLAG_MFP) |
3836 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3837 return -EINVAL;
3838 break;
3839 case CFG80211_STA_TDLS_PEER_SETUP:
3840 case CFG80211_STA_TDLS_PEER_ACTIVE:
3841 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3842 return -EINVAL;
3843 /* ignore since it can't change */
3844 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3845 break;
3846 default:
3847 /* disallow mesh-specific things */
3848 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3849 return -EINVAL;
3850 if (params->local_pm)
3851 return -EINVAL;
3852 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3853 return -EINVAL;
3854 }
3855
3856 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3857 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3858 /* TDLS can't be set, ... */
3859 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3860 return -EINVAL;
3861 /*
3862 * ... but don't bother the driver with it. This works around
3863 * a hostapd/wpa_supplicant issue -- it always includes the
3864 * TLDS_PEER flag in the mask even for AP mode.
3865 */
3866 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3867 }
3868
3869 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3870 /* reject other things that can't change */
3871 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3872 return -EINVAL;
3873 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3874 return -EINVAL;
3875 if (params->supported_rates)
3876 return -EINVAL;
3877 if (params->ext_capab || params->ht_capa || params->vht_capa)
3878 return -EINVAL;
3879 }
3880
3881 if (statype != CFG80211_STA_AP_CLIENT) {
3882 if (params->vlan)
3883 return -EINVAL;
3884 }
3885
3886 switch (statype) {
3887 case CFG80211_STA_AP_MLME_CLIENT:
3888 /* Use this only for authorizing/unauthorizing a station */
3889 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3890 return -EOPNOTSUPP;
3891 break;
3892 case CFG80211_STA_AP_CLIENT:
3893 /* accept only the listed bits */
3894 if (params->sta_flags_mask &
3895 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3896 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3897 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3898 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3899 BIT(NL80211_STA_FLAG_WME) |
3900 BIT(NL80211_STA_FLAG_MFP)))
3901 return -EINVAL;
3902
3903 /* but authenticated/associated only if driver handles it */
3904 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3905 params->sta_flags_mask &
3906 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3907 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3908 return -EINVAL;
3909 break;
3910 case CFG80211_STA_IBSS:
3911 case CFG80211_STA_AP_STA:
3912 /* reject any changes other than AUTHORIZED */
3913 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3914 return -EINVAL;
3915 break;
3916 case CFG80211_STA_TDLS_PEER_SETUP:
3917 /* reject any changes other than AUTHORIZED or WME */
3918 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3919 BIT(NL80211_STA_FLAG_WME)))
3920 return -EINVAL;
3921 /* force (at least) rates when authorizing */
3922 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3923 !params->supported_rates)
3924 return -EINVAL;
3925 break;
3926 case CFG80211_STA_TDLS_PEER_ACTIVE:
3927 /* reject any changes */
3928 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003929 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003930 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3931 return -EINVAL;
3932 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003933 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003934 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3935 return -EINVAL;
3936 break;
3937 }
3938
3939 return 0;
3940}
3941EXPORT_SYMBOL(cfg80211_check_station_change);
3942
Johannes Berg5727ef12007-12-19 02:03:34 +01003943/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003944 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003945 */
Johannes Berg80b99892011-11-18 16:23:01 +01003946static struct net_device *get_vlan(struct genl_info *info,
3947 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003948{
Johannes Berg463d0182009-07-14 00:33:35 +02003949 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003950 struct net_device *v;
3951 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003952
Johannes Berg80b99892011-11-18 16:23:01 +01003953 if (!vlanattr)
3954 return NULL;
3955
3956 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3957 if (!v)
3958 return ERR_PTR(-ENODEV);
3959
3960 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3961 ret = -EINVAL;
3962 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003963 }
Johannes Berg80b99892011-11-18 16:23:01 +01003964
Johannes Berg77ee7c82013-02-15 00:48:33 +01003965 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3966 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3967 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3968 ret = -EINVAL;
3969 goto error;
3970 }
3971
Johannes Berg80b99892011-11-18 16:23:01 +01003972 if (!netif_running(v)) {
3973 ret = -ENETDOWN;
3974 goto error;
3975 }
3976
3977 return v;
3978 error:
3979 dev_put(v);
3980 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003981}
3982
Johannes Berg94e860f2014-01-20 23:58:15 +01003983static const struct nla_policy
3984nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02003985 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3986 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3987};
3988
Johannes Bergff276692013-02-15 00:09:01 +01003989static int nl80211_parse_sta_wme(struct genl_info *info,
3990 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003991{
Jouni Malinendf881292013-02-14 21:10:54 +02003992 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3993 struct nlattr *nla;
3994 int err;
3995
Jouni Malinendf881292013-02-14 21:10:54 +02003996 /* parse WME attributes if present */
3997 if (!info->attrs[NL80211_ATTR_STA_WME])
3998 return 0;
3999
4000 nla = info->attrs[NL80211_ATTR_STA_WME];
4001 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4002 nl80211_sta_wme_policy);
4003 if (err)
4004 return err;
4005
4006 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4007 params->uapsd_queues = nla_get_u8(
4008 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4009 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4010 return -EINVAL;
4011
4012 if (tb[NL80211_STA_WME_MAX_SP])
4013 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4014
4015 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4016 return -EINVAL;
4017
4018 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4019
4020 return 0;
4021}
4022
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304023static int nl80211_parse_sta_channel_info(struct genl_info *info,
4024 struct station_parameters *params)
4025{
4026 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4027 params->supported_channels =
4028 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4029 params->supported_channels_len =
4030 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4031 /*
4032 * Need to include at least one (first channel, number of
4033 * channels) tuple for each subband, and must have proper
4034 * tuples for the rest of the data as well.
4035 */
4036 if (params->supported_channels_len < 2)
4037 return -EINVAL;
4038 if (params->supported_channels_len % 2)
4039 return -EINVAL;
4040 }
4041
4042 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4043 params->supported_oper_classes =
4044 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4045 params->supported_oper_classes_len =
4046 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4047 /*
4048 * The value of the Length field of the Supported Operating
4049 * Classes element is between 2 and 253.
4050 */
4051 if (params->supported_oper_classes_len < 2 ||
4052 params->supported_oper_classes_len > 253)
4053 return -EINVAL;
4054 }
4055 return 0;
4056}
4057
Johannes Bergff276692013-02-15 00:09:01 +01004058static int nl80211_set_station_tdls(struct genl_info *info,
4059 struct station_parameters *params)
4060{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304061 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004062 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004063 if (info->attrs[NL80211_ATTR_PEER_AID])
4064 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004065 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4066 params->ht_capa =
4067 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4068 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4069 params->vht_capa =
4070 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4071
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304072 err = nl80211_parse_sta_channel_info(info, params);
4073 if (err)
4074 return err;
4075
Johannes Bergff276692013-02-15 00:09:01 +01004076 return nl80211_parse_sta_wme(info, params);
4077}
4078
Johannes Berg5727ef12007-12-19 02:03:34 +01004079static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4080{
Johannes Berg4c476992010-10-04 21:36:35 +02004081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004082 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004083 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004084 u8 *mac_addr;
4085 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004086
4087 memset(&params, 0, sizeof(params));
4088
4089 params.listen_interval = -1;
4090
Johannes Berg77ee7c82013-02-15 00:48:33 +01004091 if (!rdev->ops->change_station)
4092 return -EOPNOTSUPP;
4093
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 if (info->attrs[NL80211_ATTR_STA_AID])
4095 return -EINVAL;
4096
4097 if (!info->attrs[NL80211_ATTR_MAC])
4098 return -EINVAL;
4099
4100 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4101
4102 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4103 params.supported_rates =
4104 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4105 params.supported_rates_len =
4106 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4107 }
4108
Jouni Malinen9d62a982013-02-14 21:10:13 +02004109 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4110 params.capability =
4111 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4112 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4113 }
4114
4115 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4116 params.ext_capab =
4117 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4118 params.ext_capab_len =
4119 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4120 }
4121
Jouni Malinendf881292013-02-14 21:10:54 +02004122 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004123 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004124
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004125 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004126 return -EINVAL;
4127
Johannes Bergf8bacc22013-02-14 23:27:01 +01004128 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004129 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004130 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4131 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4132 return -EINVAL;
4133 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004134
Johannes Bergf8bacc22013-02-14 23:27:01 +01004135 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004136 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004137 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4138 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4139 return -EINVAL;
4140 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4141 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004142
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004143 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4144 enum nl80211_mesh_power_mode pm = nla_get_u32(
4145 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4146
4147 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4148 pm > NL80211_MESH_POWER_MAX)
4149 return -EINVAL;
4150
4151 params.local_pm = pm;
4152 }
4153
Johannes Berg77ee7c82013-02-15 00:48:33 +01004154 /* Include parameters for TDLS peer (will check later) */
4155 err = nl80211_set_station_tdls(info, &params);
4156 if (err)
4157 return err;
4158
4159 params.vlan = get_vlan(info, rdev);
4160 if (IS_ERR(params.vlan))
4161 return PTR_ERR(params.vlan);
4162
Johannes Berga97f4422009-06-18 17:23:43 +02004163 switch (dev->ieee80211_ptr->iftype) {
4164 case NL80211_IFTYPE_AP:
4165 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004166 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004167 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004168 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004169 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004170 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004171 break;
4172 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004173 err = -EOPNOTSUPP;
4174 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004175 }
4176
Johannes Berg77ee7c82013-02-15 00:48:33 +01004177 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004178 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004179
Johannes Berg77ee7c82013-02-15 00:48:33 +01004180 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004181 if (params.vlan)
4182 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004183
Johannes Berg5727ef12007-12-19 02:03:34 +01004184 return err;
4185}
4186
4187static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4188{
Johannes Berg4c476992010-10-04 21:36:35 +02004189 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004190 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004191 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004192 struct station_parameters params;
4193 u8 *mac_addr = NULL;
4194
4195 memset(&params, 0, sizeof(params));
4196
Johannes Berg984c3112013-02-14 23:43:25 +01004197 if (!rdev->ops->add_station)
4198 return -EOPNOTSUPP;
4199
Johannes Berg5727ef12007-12-19 02:03:34 +01004200 if (!info->attrs[NL80211_ATTR_MAC])
4201 return -EINVAL;
4202
Johannes Berg5727ef12007-12-19 02:03:34 +01004203 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4204 return -EINVAL;
4205
4206 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4207 return -EINVAL;
4208
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004209 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4210 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004211 return -EINVAL;
4212
Johannes Berg5727ef12007-12-19 02:03:34 +01004213 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4214 params.supported_rates =
4215 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4216 params.supported_rates_len =
4217 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4218 params.listen_interval =
4219 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004220
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004221 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004222 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004223 else
4224 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004225 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4226 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004227
Jouni Malinen9d62a982013-02-14 21:10:13 +02004228 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4229 params.capability =
4230 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4231 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4232 }
4233
4234 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4235 params.ext_capab =
4236 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4237 params.ext_capab_len =
4238 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4239 }
4240
Jouni Malinen36aedc92008-08-25 11:58:58 +03004241 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4242 params.ht_capa =
4243 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004244
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004245 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4246 params.vht_capa =
4247 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4248
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004249 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4250 params.opmode_notif_used = true;
4251 params.opmode_notif =
4252 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4253 }
4254
Johannes Bergf8bacc22013-02-14 23:27:01 +01004255 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004256 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004257 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4258 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4259 return -EINVAL;
4260 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004261
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304262 err = nl80211_parse_sta_channel_info(info, &params);
4263 if (err)
4264 return err;
4265
Johannes Bergff276692013-02-15 00:09:01 +01004266 err = nl80211_parse_sta_wme(info, &params);
4267 if (err)
4268 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004269
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004270 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004271 return -EINVAL;
4272
Johannes Berg77ee7c82013-02-15 00:48:33 +01004273 /* When you run into this, adjust the code below for the new flag */
4274 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4275
Johannes Bergbdd90d52011-12-14 12:20:27 +01004276 switch (dev->ieee80211_ptr->iftype) {
4277 case NL80211_IFTYPE_AP:
4278 case NL80211_IFTYPE_AP_VLAN:
4279 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004280 /* ignore WME attributes if iface/sta is not capable */
4281 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4282 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4283 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004284
Johannes Bergbdd90d52011-12-14 12:20:27 +01004285 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004286 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4287 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004288 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004289 /* but don't bother the driver with it */
4290 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004291
Johannes Bergd582cff2012-10-26 17:53:44 +02004292 /* allow authenticated/associated only if driver handles it */
4293 if (!(rdev->wiphy.features &
4294 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4295 params.sta_flags_mask &
4296 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4297 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4298 return -EINVAL;
4299
Johannes Bergbdd90d52011-12-14 12:20:27 +01004300 /* must be last in here for error handling */
4301 params.vlan = get_vlan(info, rdev);
4302 if (IS_ERR(params.vlan))
4303 return PTR_ERR(params.vlan);
4304 break;
4305 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004306 /* ignore uAPSD data */
4307 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4308
Johannes Bergd582cff2012-10-26 17:53:44 +02004309 /* associated is disallowed */
4310 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4311 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004312 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004313 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4314 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004315 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004316 break;
4317 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004318 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004319 /* ignore uAPSD data */
4320 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4321
Johannes Berg77ee7c82013-02-15 00:48:33 +01004322 /* these are disallowed */
4323 if (params.sta_flags_mask &
4324 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4325 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004326 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004327 /* Only TDLS peers can be added */
4328 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4329 return -EINVAL;
4330 /* Can only add if TDLS ... */
4331 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4332 return -EOPNOTSUPP;
4333 /* ... with external setup is supported */
4334 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4335 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004336 /*
4337 * Older wpa_supplicant versions always mark the TDLS peer
4338 * as authorized, but it shouldn't yet be.
4339 */
4340 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004341 break;
4342 default:
4343 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004344 }
4345
Johannes Bergbdd90d52011-12-14 12:20:27 +01004346 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004347
Hila Gonene35e4d22012-06-27 17:19:42 +03004348 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004349
Johannes Berg5727ef12007-12-19 02:03:34 +01004350 if (params.vlan)
4351 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004352 return err;
4353}
4354
4355static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4356{
Johannes Berg4c476992010-10-04 21:36:35 +02004357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4358 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004359 u8 *mac_addr = NULL;
4360
4361 if (info->attrs[NL80211_ATTR_MAC])
4362 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4363
Johannes Berge80cf852009-05-11 14:43:13 +02004364 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004365 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004366 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004367 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4368 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004369
Johannes Berg4c476992010-10-04 21:36:35 +02004370 if (!rdev->ops->del_station)
4371 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004372
Hila Gonene35e4d22012-06-27 17:19:42 +03004373 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004374}
4375
Eric W. Biederman15e47302012-09-07 20:12:54 +00004376static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004377 int flags, struct net_device *dev,
4378 u8 *dst, u8 *next_hop,
4379 struct mpath_info *pinfo)
4380{
4381 void *hdr;
4382 struct nlattr *pinfoattr;
4383
Eric W. Biederman15e47302012-09-07 20:12:54 +00004384 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004385 if (!hdr)
4386 return -1;
4387
David S. Miller9360ffd2012-03-29 04:41:26 -04004388 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4389 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4390 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4391 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4392 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004393
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004394 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4395 if (!pinfoattr)
4396 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004397 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4398 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4399 pinfo->frame_qlen))
4400 goto nla_put_failure;
4401 if (((pinfo->filled & MPATH_INFO_SN) &&
4402 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4403 ((pinfo->filled & MPATH_INFO_METRIC) &&
4404 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4405 pinfo->metric)) ||
4406 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4407 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4408 pinfo->exptime)) ||
4409 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4410 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4411 pinfo->flags)) ||
4412 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4413 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4414 pinfo->discovery_timeout)) ||
4415 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4416 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4417 pinfo->discovery_retries)))
4418 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004419
4420 nla_nest_end(msg, pinfoattr);
4421
4422 return genlmsg_end(msg, hdr);
4423
4424 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004425 genlmsg_cancel(msg, hdr);
4426 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004427}
4428
4429static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004430 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004431{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004432 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004433 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004434 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004435 u8 dst[ETH_ALEN];
4436 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004437 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004438 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004440 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004441 if (err)
4442 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004443
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004444 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004445 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004446 goto out_err;
4447 }
4448
Johannes Berg97990a02013-04-19 01:02:55 +02004449 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004450 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004451 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004452 }
4453
Johannes Bergbba95fe2008-07-29 13:22:51 +02004454 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004455 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004456 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004457 if (err == -ENOENT)
4458 break;
4459 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004460 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004461
Eric W. Biederman15e47302012-09-07 20:12:54 +00004462 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004463 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004464 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004465 &pinfo) < 0)
4466 goto out;
4467
4468 path_idx++;
4469 }
4470
4471
4472 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004473 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004474 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004475 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004476 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004477 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004478}
4479
4480static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4481{
Johannes Berg4c476992010-10-04 21:36:35 +02004482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004483 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004484 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004485 struct mpath_info pinfo;
4486 struct sk_buff *msg;
4487 u8 *dst = NULL;
4488 u8 next_hop[ETH_ALEN];
4489
4490 memset(&pinfo, 0, sizeof(pinfo));
4491
4492 if (!info->attrs[NL80211_ATTR_MAC])
4493 return -EINVAL;
4494
4495 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4496
Johannes Berg4c476992010-10-04 21:36:35 +02004497 if (!rdev->ops->get_mpath)
4498 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004499
Johannes Berg4c476992010-10-04 21:36:35 +02004500 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4501 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004502
Hila Gonene35e4d22012-06-27 17:19:42 +03004503 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004504 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004505 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004508 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004509 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004510
Eric W. Biederman15e47302012-09-07 20:12:54 +00004511 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004512 dev, dst, next_hop, &pinfo) < 0) {
4513 nlmsg_free(msg);
4514 return -ENOBUFS;
4515 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004516
Johannes Berg4c476992010-10-04 21:36:35 +02004517 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004518}
4519
4520static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4521{
Johannes Berg4c476992010-10-04 21:36:35 +02004522 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4523 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004524 u8 *dst = NULL;
4525 u8 *next_hop = NULL;
4526
4527 if (!info->attrs[NL80211_ATTR_MAC])
4528 return -EINVAL;
4529
4530 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4531 return -EINVAL;
4532
4533 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4534 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4535
Johannes Berg4c476992010-10-04 21:36:35 +02004536 if (!rdev->ops->change_mpath)
4537 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004538
Johannes Berg4c476992010-10-04 21:36:35 +02004539 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4540 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004541
Hila Gonene35e4d22012-06-27 17:19:42 +03004542 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543}
Johannes Berg4c476992010-10-04 21:36:35 +02004544
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004545static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4546{
Johannes Berg4c476992010-10-04 21:36:35 +02004547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4548 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004549 u8 *dst = NULL;
4550 u8 *next_hop = NULL;
4551
4552 if (!info->attrs[NL80211_ATTR_MAC])
4553 return -EINVAL;
4554
4555 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4556 return -EINVAL;
4557
4558 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4559 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4560
Johannes Berg4c476992010-10-04 21:36:35 +02004561 if (!rdev->ops->add_mpath)
4562 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004563
Johannes Berg4c476992010-10-04 21:36:35 +02004564 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4565 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004566
Hila Gonene35e4d22012-06-27 17:19:42 +03004567 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004568}
4569
4570static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4571{
Johannes Berg4c476992010-10-04 21:36:35 +02004572 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4573 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004574 u8 *dst = NULL;
4575
4576 if (info->attrs[NL80211_ATTR_MAC])
4577 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4578
Johannes Berg4c476992010-10-04 21:36:35 +02004579 if (!rdev->ops->del_mpath)
4580 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004581
Hila Gonene35e4d22012-06-27 17:19:42 +03004582 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004583}
4584
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004585static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4586{
Johannes Berg4c476992010-10-04 21:36:35 +02004587 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4588 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004589 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004590 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004591 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004592
4593 memset(&params, 0, sizeof(params));
4594 /* default to not changing parameters */
4595 params.use_cts_prot = -1;
4596 params.use_short_preamble = -1;
4597 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004598 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004599 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004600 params.p2p_ctwindow = -1;
4601 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004602
4603 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4604 params.use_cts_prot =
4605 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4606 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4607 params.use_short_preamble =
4608 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4609 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4610 params.use_short_slot_time =
4611 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004612 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4613 params.basic_rates =
4614 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4615 params.basic_rates_len =
4616 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4617 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004618 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4619 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004620 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4621 params.ht_opmode =
4622 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004623
Johannes Berg53cabad2012-11-14 15:17:28 +01004624 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4625 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4626 return -EINVAL;
4627 params.p2p_ctwindow =
4628 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4629 if (params.p2p_ctwindow < 0)
4630 return -EINVAL;
4631 if (params.p2p_ctwindow != 0 &&
4632 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4633 return -EINVAL;
4634 }
4635
4636 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4637 u8 tmp;
4638
4639 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4640 return -EINVAL;
4641 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4642 if (tmp > 1)
4643 return -EINVAL;
4644 params.p2p_opp_ps = tmp;
4645 if (params.p2p_opp_ps &&
4646 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4647 return -EINVAL;
4648 }
4649
Johannes Berg4c476992010-10-04 21:36:35 +02004650 if (!rdev->ops->change_bss)
4651 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004652
Johannes Berg074ac8d2010-09-16 14:58:22 +02004653 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004654 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4655 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004656
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004657 wdev_lock(wdev);
4658 err = rdev_change_bss(rdev, dev, &params);
4659 wdev_unlock(wdev);
4660
4661 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004662}
4663
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004664static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004665 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4666 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4667 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4668 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4669 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4670 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004671 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004672};
4673
4674static int parse_reg_rule(struct nlattr *tb[],
4675 struct ieee80211_reg_rule *reg_rule)
4676{
4677 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4678 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4679
4680 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4681 return -EINVAL;
4682 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4683 return -EINVAL;
4684 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4685 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004686 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4687 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004688 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4689 return -EINVAL;
4690
4691 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4692
4693 freq_range->start_freq_khz =
4694 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4695 freq_range->end_freq_khz =
4696 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004697 freq_range->max_bandwidth_khz =
4698 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004699
4700 power_rule->max_eirp =
4701 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4702
4703 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4704 power_rule->max_antenna_gain =
4705 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4706
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004707 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4708 reg_rule->dfs_cac_ms =
4709 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4710
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004711 return 0;
4712}
4713
4714static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4715{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004716 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004717 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004718
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004719 /*
4720 * You should only get this when cfg80211 hasn't yet initialized
4721 * completely when built-in to the kernel right between the time
4722 * window between nl80211_init() and regulatory_init(), if that is
4723 * even possible.
4724 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004725 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004726 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004727
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004728 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4729 user_reg_hint_type =
4730 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4731 else
4732 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4733
4734 switch (user_reg_hint_type) {
4735 case NL80211_USER_REG_HINT_USER:
4736 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004737 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4738 return -EINVAL;
4739
4740 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4741 return regulatory_hint_user(data, user_reg_hint_type);
4742 case NL80211_USER_REG_HINT_INDOOR:
4743 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004744 default:
4745 return -EINVAL;
4746 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004747}
4748
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004749static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004750 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004751{
Johannes Berg4c476992010-10-04 21:36:35 +02004752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004753 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004754 struct wireless_dev *wdev = dev->ieee80211_ptr;
4755 struct mesh_config cur_params;
4756 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004757 void *hdr;
4758 struct nlattr *pinfoattr;
4759 struct sk_buff *msg;
4760
Johannes Berg29cbe682010-12-03 09:20:44 +01004761 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4762 return -EOPNOTSUPP;
4763
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004764 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004765 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004766
Johannes Berg29cbe682010-12-03 09:20:44 +01004767 wdev_lock(wdev);
4768 /* If not connected, get default parameters */
4769 if (!wdev->mesh_id_len)
4770 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4771 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004772 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004773 wdev_unlock(wdev);
4774
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004775 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004776 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004777
4778 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004779 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004780 if (!msg)
4781 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004782 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004783 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004784 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004785 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004786 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004787 if (!pinfoattr)
4788 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004789 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4790 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4791 cur_params.dot11MeshRetryTimeout) ||
4792 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4793 cur_params.dot11MeshConfirmTimeout) ||
4794 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4795 cur_params.dot11MeshHoldingTimeout) ||
4796 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4797 cur_params.dot11MeshMaxPeerLinks) ||
4798 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4799 cur_params.dot11MeshMaxRetries) ||
4800 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4801 cur_params.dot11MeshTTL) ||
4802 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4803 cur_params.element_ttl) ||
4804 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4805 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004806 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4807 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004808 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4809 cur_params.dot11MeshHWMPmaxPREQretries) ||
4810 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4811 cur_params.path_refresh_time) ||
4812 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4813 cur_params.min_discovery_timeout) ||
4814 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4815 cur_params.dot11MeshHWMPactivePathTimeout) ||
4816 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4817 cur_params.dot11MeshHWMPpreqMinInterval) ||
4818 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4819 cur_params.dot11MeshHWMPperrMinInterval) ||
4820 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4821 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4822 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4823 cur_params.dot11MeshHWMPRootMode) ||
4824 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4825 cur_params.dot11MeshHWMPRannInterval) ||
4826 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4827 cur_params.dot11MeshGateAnnouncementProtocol) ||
4828 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4829 cur_params.dot11MeshForwarding) ||
4830 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004831 cur_params.rssi_threshold) ||
4832 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004833 cur_params.ht_opmode) ||
4834 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4835 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4836 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004837 cur_params.dot11MeshHWMProotInterval) ||
4838 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004839 cur_params.dot11MeshHWMPconfirmationInterval) ||
4840 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4841 cur_params.power_mode) ||
4842 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004843 cur_params.dot11MeshAwakeWindowDuration) ||
4844 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4845 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004846 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004847 nla_nest_end(msg, pinfoattr);
4848 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004849 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004850
Johannes Berg3b858752009-03-12 09:55:09 +01004851 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004852 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004853 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004854 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004855 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004856}
4857
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004858static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004859 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4860 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4861 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4862 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4863 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4864 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004865 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004866 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004867 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004868 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4869 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4870 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4871 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4872 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004873 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004874 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004875 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004876 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004877 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004878 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004879 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4880 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004881 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4882 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004883 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004884 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4885 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004886 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004887};
4888
Javier Cardonac80d5452010-12-16 17:37:49 -08004889static const struct nla_policy
4890 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004891 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004892 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4893 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004894 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004895 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004896 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004897 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004898 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004899 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004900};
4901
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004902static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004903 struct mesh_config *cfg,
4904 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004905{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004906 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004907 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004908
Marco Porschea54fba2013-01-07 16:04:48 +01004909#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4910do { \
4911 if (tb[attr]) { \
4912 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4913 return -EINVAL; \
4914 cfg->param = fn(tb[attr]); \
4915 mask |= (1 << (attr - 1)); \
4916 } \
4917} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004918
4919
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004920 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004921 return -EINVAL;
4922 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004923 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004924 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004925 return -EINVAL;
4926
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004927 /* This makes sure that there aren't more than 32 mesh config
4928 * parameters (otherwise our bitfield scheme would not work.) */
4929 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4930
4931 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004932 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004933 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4934 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004935 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004936 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4937 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004939 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4940 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004941 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004942 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4943 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004944 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004945 mask, NL80211_MESHCONF_MAX_RETRIES,
4946 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004948 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004949 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004950 mask, NL80211_MESHCONF_ELEMENT_TTL,
4951 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004952 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004953 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4954 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004955 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4956 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004957 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4958 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004959 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004960 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4961 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004962 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004963 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4964 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004965 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004966 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4967 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004968 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4969 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004970 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4971 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004972 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004973 1, 65535, mask,
4974 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004975 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004976 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004977 1, 65535, mask,
4978 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004979 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004980 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004981 dot11MeshHWMPnetDiameterTraversalTime,
4982 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004983 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4984 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004985 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4986 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4987 nla_get_u8);
4988 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4989 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004990 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004991 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004992 dot11MeshGateAnnouncementProtocol, 0, 1,
4993 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004994 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004995 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004996 mask, NL80211_MESHCONF_FORWARDING,
4997 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004998 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004999 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005000 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005001 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005002 mask, NL80211_MESHCONF_HT_OPMODE,
5003 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005004 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005005 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005006 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5007 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005008 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005009 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5010 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005011 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005012 dot11MeshHWMPconfirmationInterval,
5013 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005014 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5015 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005016 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5017 NL80211_MESH_POWER_ACTIVE,
5018 NL80211_MESH_POWER_MAX,
5019 mask, NL80211_MESHCONF_POWER_MODE,
5020 nla_get_u32);
5021 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5022 0, 65535, mask,
5023 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005024 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5025 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5026 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005027 if (mask_out)
5028 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005029
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005030 return 0;
5031
5032#undef FILL_IN_MESH_PARAM_IF_SET
5033}
5034
Javier Cardonac80d5452010-12-16 17:37:49 -08005035static int nl80211_parse_mesh_setup(struct genl_info *info,
5036 struct mesh_setup *setup)
5037{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005039 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5040
5041 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5042 return -EINVAL;
5043 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5044 info->attrs[NL80211_ATTR_MESH_SETUP],
5045 nl80211_mesh_setup_params_policy))
5046 return -EINVAL;
5047
Javier Cardonad299a1f2012-03-31 11:31:33 -07005048 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5049 setup->sync_method =
5050 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5051 IEEE80211_SYNC_METHOD_VENDOR :
5052 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5053
Javier Cardonac80d5452010-12-16 17:37:49 -08005054 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5055 setup->path_sel_proto =
5056 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5057 IEEE80211_PATH_PROTOCOL_VENDOR :
5058 IEEE80211_PATH_PROTOCOL_HWMP;
5059
5060 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5061 setup->path_metric =
5062 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5063 IEEE80211_PATH_METRIC_VENDOR :
5064 IEEE80211_PATH_METRIC_AIRTIME;
5065
Javier Cardona581a8b02011-04-07 15:08:27 -07005066
5067 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005068 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005069 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005070 if (!is_valid_ie_attr(ieattr))
5071 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005072 setup->ie = nla_data(ieattr);
5073 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005074 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005075 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5076 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5077 return -EINVAL;
5078 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005079 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5080 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005081 if (setup->is_secure)
5082 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005083
Colleen Twitty6e16d902013-05-08 11:45:59 -07005084 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5085 if (!setup->user_mpm)
5086 return -EINVAL;
5087 setup->auth_id =
5088 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5089 }
5090
Javier Cardonac80d5452010-12-16 17:37:49 -08005091 return 0;
5092}
5093
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005094static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005095 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005096{
5097 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5098 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005099 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005100 struct mesh_config cfg;
5101 u32 mask;
5102 int err;
5103
Johannes Berg29cbe682010-12-03 09:20:44 +01005104 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5105 return -EOPNOTSUPP;
5106
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005107 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005108 return -EOPNOTSUPP;
5109
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005110 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005111 if (err)
5112 return err;
5113
Johannes Berg29cbe682010-12-03 09:20:44 +01005114 wdev_lock(wdev);
5115 if (!wdev->mesh_id_len)
5116 err = -ENOLINK;
5117
5118 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005119 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005120
5121 wdev_unlock(wdev);
5122
5123 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005124}
5125
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005126static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5127{
Johannes Berg458f4f92012-12-06 15:47:38 +01005128 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005129 struct sk_buff *msg;
5130 void *hdr = NULL;
5131 struct nlattr *nl_reg_rules;
5132 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005133
5134 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005135 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005136
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005137 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005138 if (!msg)
5139 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005140
Eric W. Biederman15e47302012-09-07 20:12:54 +00005141 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005142 NL80211_CMD_GET_REG);
5143 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005144 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005145
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005146 if (reg_last_request_cell_base() &&
5147 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5148 NL80211_USER_REG_HINT_CELL_BASE))
5149 goto nla_put_failure;
5150
Johannes Berg458f4f92012-12-06 15:47:38 +01005151 rcu_read_lock();
5152 regdom = rcu_dereference(cfg80211_regdomain);
5153
5154 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5155 (regdom->dfs_region &&
5156 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5157 goto nla_put_failure_rcu;
5158
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005159 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5160 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005161 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005162
Johannes Berg458f4f92012-12-06 15:47:38 +01005163 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005164 struct nlattr *nl_reg_rule;
5165 const struct ieee80211_reg_rule *reg_rule;
5166 const struct ieee80211_freq_range *freq_range;
5167 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005168 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005169
Johannes Berg458f4f92012-12-06 15:47:38 +01005170 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005171 freq_range = &reg_rule->freq_range;
5172 power_rule = &reg_rule->power_rule;
5173
5174 nl_reg_rule = nla_nest_start(msg, i);
5175 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005176 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005177
Janusz Dziedzic97524822014-01-30 09:52:20 +01005178 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5179 if (!max_bandwidth_khz)
5180 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5181 reg_rule);
5182
David S. Miller9360ffd2012-03-29 04:41:26 -04005183 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5184 reg_rule->flags) ||
5185 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5186 freq_range->start_freq_khz) ||
5187 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5188 freq_range->end_freq_khz) ||
5189 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005190 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005191 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5192 power_rule->max_antenna_gain) ||
5193 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005194 power_rule->max_eirp) ||
5195 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5196 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005197 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005198
5199 nla_nest_end(msg, nl_reg_rule);
5200 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005201 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005202
5203 nla_nest_end(msg, nl_reg_rules);
5204
5205 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005206 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005207
Johannes Berg458f4f92012-12-06 15:47:38 +01005208nla_put_failure_rcu:
5209 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005210nla_put_failure:
5211 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005212put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005213 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005214 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005215}
5216
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005217static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5218{
5219 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5220 struct nlattr *nl_reg_rule;
5221 char *alpha2 = NULL;
5222 int rem_reg_rules = 0, r = 0;
5223 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005224 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005225 struct ieee80211_regdomain *rd = NULL;
5226
5227 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5228 return -EINVAL;
5229
5230 if (!info->attrs[NL80211_ATTR_REG_RULES])
5231 return -EINVAL;
5232
5233 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5234
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005235 if (info->attrs[NL80211_ATTR_DFS_REGION])
5236 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5237
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005238 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005239 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005240 num_rules++;
5241 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005242 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005243 }
5244
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005245 if (!reg_is_valid_request(alpha2))
5246 return -EINVAL;
5247
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005248 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005249 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005250
5251 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005252 if (!rd)
5253 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005254
5255 rd->n_reg_rules = num_rules;
5256 rd->alpha2[0] = alpha2[0];
5257 rd->alpha2[1] = alpha2[1];
5258
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005259 /*
5260 * Disable DFS master mode if the DFS region was
5261 * not supported or known on this kernel.
5262 */
5263 if (reg_supported_dfs_region(dfs_region))
5264 rd->dfs_region = dfs_region;
5265
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005266 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005267 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005268 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5269 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5270 reg_rule_policy);
5271 if (r)
5272 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005273 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5274 if (r)
5275 goto bad_reg;
5276
5277 rule_idx++;
5278
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005279 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5280 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005281 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005282 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005283 }
5284
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005285 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005286 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005287 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005288
Johannes Bergd2372b32008-10-24 20:32:20 +02005289 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005290 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005291 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005292}
5293
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005294static int validate_scan_freqs(struct nlattr *freqs)
5295{
5296 struct nlattr *attr1, *attr2;
5297 int n_channels = 0, tmp1, tmp2;
5298
5299 nla_for_each_nested(attr1, freqs, tmp1) {
5300 n_channels++;
5301 /*
5302 * Some hardware has a limited channel list for
5303 * scanning, and it is pretty much nonsensical
5304 * to scan for a channel twice, so disallow that
5305 * and don't require drivers to check that the
5306 * channel list they get isn't longer than what
5307 * they can scan, as long as they can scan all
5308 * the channels they registered at once.
5309 */
5310 nla_for_each_nested(attr2, freqs, tmp2)
5311 if (attr1 != attr2 &&
5312 nla_get_u32(attr1) == nla_get_u32(attr2))
5313 return 0;
5314 }
5315
5316 return n_channels;
5317}
5318
Johannes Berg2a519312009-02-10 21:25:55 +01005319static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5320{
Johannes Berg4c476992010-10-04 21:36:35 +02005321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005322 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005323 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005324 struct nlattr *attr;
5325 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005326 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005327 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005328
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005329 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5330 return -EINVAL;
5331
Johannes Berg79c97e92009-07-07 03:56:12 +02005332 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005333
Johannes Berg4c476992010-10-04 21:36:35 +02005334 if (!rdev->ops->scan)
5335 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005336
Johannes Bergf9d15d12014-01-22 11:14:19 +02005337 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005338 err = -EBUSY;
5339 goto unlock;
5340 }
Johannes Berg2a519312009-02-10 21:25:55 +01005341
5342 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005343 n_channels = validate_scan_freqs(
5344 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005345 if (!n_channels) {
5346 err = -EINVAL;
5347 goto unlock;
5348 }
Johannes Berg2a519312009-02-10 21:25:55 +01005349 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005350 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005351 }
5352
5353 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5354 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5355 n_ssids++;
5356
Johannes Bergf9f47522013-03-19 15:04:07 +01005357 if (n_ssids > wiphy->max_scan_ssids) {
5358 err = -EINVAL;
5359 goto unlock;
5360 }
Johannes Berg2a519312009-02-10 21:25:55 +01005361
Jouni Malinen70692ad2009-02-16 19:39:13 +02005362 if (info->attrs[NL80211_ATTR_IE])
5363 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5364 else
5365 ie_len = 0;
5366
Johannes Bergf9f47522013-03-19 15:04:07 +01005367 if (ie_len > wiphy->max_scan_ie_len) {
5368 err = -EINVAL;
5369 goto unlock;
5370 }
Johannes Berg18a83652009-03-31 12:12:05 +02005371
Johannes Berg2a519312009-02-10 21:25:55 +01005372 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005373 + sizeof(*request->ssids) * n_ssids
5374 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005375 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005376 if (!request) {
5377 err = -ENOMEM;
5378 goto unlock;
5379 }
Johannes Berg2a519312009-02-10 21:25:55 +01005380
Johannes Berg2a519312009-02-10 21:25:55 +01005381 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005382 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005383 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005384 if (ie_len) {
5385 if (request->ssids)
5386 request->ie = (void *)(request->ssids + n_ssids);
5387 else
5388 request->ie = (void *)(request->channels + n_channels);
5389 }
Johannes Berg2a519312009-02-10 21:25:55 +01005390
Johannes Berg584991d2009-11-02 13:32:03 +01005391 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005392 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5393 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005394 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005395 struct ieee80211_channel *chan;
5396
5397 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5398
5399 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005400 err = -EINVAL;
5401 goto out_free;
5402 }
Johannes Berg584991d2009-11-02 13:32:03 +01005403
5404 /* ignore disabled channels */
5405 if (chan->flags & IEEE80211_CHAN_DISABLED)
5406 continue;
5407
5408 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005409 i++;
5410 }
5411 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005412 enum ieee80211_band band;
5413
Johannes Berg2a519312009-02-10 21:25:55 +01005414 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005415 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5416 int j;
5417 if (!wiphy->bands[band])
5418 continue;
5419 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005420 struct ieee80211_channel *chan;
5421
5422 chan = &wiphy->bands[band]->channels[j];
5423
5424 if (chan->flags & IEEE80211_CHAN_DISABLED)
5425 continue;
5426
5427 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005428 i++;
5429 }
5430 }
5431 }
5432
Johannes Berg584991d2009-11-02 13:32:03 +01005433 if (!i) {
5434 err = -EINVAL;
5435 goto out_free;
5436 }
5437
5438 request->n_channels = i;
5439
Johannes Berg2a519312009-02-10 21:25:55 +01005440 i = 0;
5441 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5442 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005443 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005444 err = -EINVAL;
5445 goto out_free;
5446 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005447 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005448 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005449 i++;
5450 }
5451 }
5452
Jouni Malinen70692ad2009-02-16 19:39:13 +02005453 if (info->attrs[NL80211_ATTR_IE]) {
5454 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005455 memcpy((void *)request->ie,
5456 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005457 request->ie_len);
5458 }
5459
Johannes Berg34850ab2011-07-18 18:08:35 +02005460 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005461 if (wiphy->bands[i])
5462 request->rates[i] =
5463 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005464
5465 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5466 nla_for_each_nested(attr,
5467 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5468 tmp) {
5469 enum ieee80211_band band = nla_type(attr);
5470
Dan Carpenter84404622011-07-29 11:52:18 +03005471 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005472 err = -EINVAL;
5473 goto out_free;
5474 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005475
5476 if (!wiphy->bands[band])
5477 continue;
5478
Johannes Berg34850ab2011-07-18 18:08:35 +02005479 err = ieee80211_get_ratemask(wiphy->bands[band],
5480 nla_data(attr),
5481 nla_len(attr),
5482 &request->rates[band]);
5483 if (err)
5484 goto out_free;
5485 }
5486 }
5487
Sam Leffler46856bb2012-10-11 21:03:32 -07005488 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005489 request->flags = nla_get_u32(
5490 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005491 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5492 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005493 err = -EOPNOTSUPP;
5494 goto out_free;
5495 }
5496 }
Sam Lefflered4737712012-10-11 21:03:31 -07005497
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305498 request->no_cck =
5499 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5500
Johannes Bergfd014282012-06-18 19:17:03 +02005501 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005502 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005503 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005504
Johannes Berg79c97e92009-07-07 03:56:12 +02005505 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005506 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005507
Johannes Berg463d0182009-07-14 00:33:35 +02005508 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005509 nl80211_send_scan_start(rdev, wdev);
5510 if (wdev->netdev)
5511 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005512 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005513 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005514 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005515 kfree(request);
5516 }
Johannes Berg3b858752009-03-12 09:55:09 +01005517
Johannes Bergf9f47522013-03-19 15:04:07 +01005518 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005519 return err;
5520}
5521
Luciano Coelho807f8a82011-05-11 17:09:35 +03005522static int nl80211_start_sched_scan(struct sk_buff *skb,
5523 struct genl_info *info)
5524{
5525 struct cfg80211_sched_scan_request *request;
5526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5527 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005528 struct nlattr *attr;
5529 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005530 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005531 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005532 enum ieee80211_band band;
5533 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005534 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005535 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005536
5537 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5538 !rdev->ops->sched_scan_start)
5539 return -EOPNOTSUPP;
5540
5541 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5542 return -EINVAL;
5543
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005544 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5545 return -EINVAL;
5546
5547 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5548 if (interval == 0)
5549 return -EINVAL;
5550
Luciano Coelho807f8a82011-05-11 17:09:35 +03005551 wiphy = &rdev->wiphy;
5552
5553 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5554 n_channels = validate_scan_freqs(
5555 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5556 if (!n_channels)
5557 return -EINVAL;
5558 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005559 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005560 }
5561
5562 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5563 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5564 tmp)
5565 n_ssids++;
5566
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005567 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005568 return -EINVAL;
5569
Johannes Bergea73cbc2014-01-24 10:53:53 +01005570 /*
5571 * First, count the number of 'real' matchsets. Due to an issue with
5572 * the old implementation, matchsets containing only the RSSI attribute
5573 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5574 * RSSI for all matchsets, rather than their own matchset for reporting
5575 * all APs with a strong RSSI. This is needed to be compatible with
5576 * older userspace that treated a matchset with only the RSSI as the
5577 * global RSSI for all other matchsets - if there are other matchsets.
5578 */
5579 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005580 nla_for_each_nested(attr,
5581 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005582 tmp) {
5583 struct nlattr *rssi;
5584
5585 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5586 nla_data(attr), nla_len(attr),
5587 nl80211_match_policy);
5588 if (err)
5589 return err;
5590 /* add other standalone attributes here */
5591 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5592 n_match_sets++;
5593 continue;
5594 }
5595 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5596 if (rssi)
5597 default_match_rssi = nla_get_s32(rssi);
5598 }
5599 }
5600
5601 /* However, if there's no other matchset, add the RSSI one */
5602 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5603 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005604
5605 if (n_match_sets > wiphy->max_match_sets)
5606 return -EINVAL;
5607
Luciano Coelho807f8a82011-05-11 17:09:35 +03005608 if (info->attrs[NL80211_ATTR_IE])
5609 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5610 else
5611 ie_len = 0;
5612
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005613 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005614 return -EINVAL;
5615
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005616 if (rdev->sched_scan_req) {
5617 err = -EINPROGRESS;
5618 goto out;
5619 }
5620
Luciano Coelho807f8a82011-05-11 17:09:35 +03005621 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005622 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005623 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005624 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005625 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005626 if (!request) {
5627 err = -ENOMEM;
5628 goto out;
5629 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005630
5631 if (n_ssids)
5632 request->ssids = (void *)&request->channels[n_channels];
5633 request->n_ssids = n_ssids;
5634 if (ie_len) {
5635 if (request->ssids)
5636 request->ie = (void *)(request->ssids + n_ssids);
5637 else
5638 request->ie = (void *)(request->channels + n_channels);
5639 }
5640
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005641 if (n_match_sets) {
5642 if (request->ie)
5643 request->match_sets = (void *)(request->ie + ie_len);
5644 else if (request->ssids)
5645 request->match_sets =
5646 (void *)(request->ssids + n_ssids);
5647 else
5648 request->match_sets =
5649 (void *)(request->channels + n_channels);
5650 }
5651 request->n_match_sets = n_match_sets;
5652
Luciano Coelho807f8a82011-05-11 17:09:35 +03005653 i = 0;
5654 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5655 /* user specified, bail out if channel not found */
5656 nla_for_each_nested(attr,
5657 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5658 tmp) {
5659 struct ieee80211_channel *chan;
5660
5661 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5662
5663 if (!chan) {
5664 err = -EINVAL;
5665 goto out_free;
5666 }
5667
5668 /* ignore disabled channels */
5669 if (chan->flags & IEEE80211_CHAN_DISABLED)
5670 continue;
5671
5672 request->channels[i] = chan;
5673 i++;
5674 }
5675 } else {
5676 /* all channels */
5677 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5678 int j;
5679 if (!wiphy->bands[band])
5680 continue;
5681 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5682 struct ieee80211_channel *chan;
5683
5684 chan = &wiphy->bands[band]->channels[j];
5685
5686 if (chan->flags & IEEE80211_CHAN_DISABLED)
5687 continue;
5688
5689 request->channels[i] = chan;
5690 i++;
5691 }
5692 }
5693 }
5694
5695 if (!i) {
5696 err = -EINVAL;
5697 goto out_free;
5698 }
5699
5700 request->n_channels = i;
5701
5702 i = 0;
5703 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5704 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5705 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005706 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005707 err = -EINVAL;
5708 goto out_free;
5709 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005710 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005711 memcpy(request->ssids[i].ssid, nla_data(attr),
5712 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005713 i++;
5714 }
5715 }
5716
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005717 i = 0;
5718 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5719 nla_for_each_nested(attr,
5720 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5721 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005722 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005723
Johannes Bergae811e22014-01-24 10:17:47 +01005724 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5725 nla_data(attr), nla_len(attr),
5726 nl80211_match_policy);
5727 if (err)
5728 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005729 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005730 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005731 if (WARN_ON(i >= n_match_sets)) {
5732 /* this indicates a programming error,
5733 * the loop above should have verified
5734 * things properly
5735 */
5736 err = -EINVAL;
5737 goto out_free;
5738 }
5739
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005740 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5741 err = -EINVAL;
5742 goto out_free;
5743 }
5744 memcpy(request->match_sets[i].ssid.ssid,
5745 nla_data(ssid), nla_len(ssid));
5746 request->match_sets[i].ssid.ssid_len =
5747 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005748 /* special attribute - old implemenation w/a */
5749 request->match_sets[i].rssi_thold =
5750 default_match_rssi;
5751 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5752 if (rssi)
5753 request->match_sets[i].rssi_thold =
5754 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005755 }
5756 i++;
5757 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01005758
5759 /* there was no other matchset, so the RSSI one is alone */
5760 if (i == 0)
5761 request->match_sets[0].rssi_thold = default_match_rssi;
5762
5763 request->min_rssi_thold = INT_MAX;
5764 for (i = 0; i < n_match_sets; i++)
5765 request->min_rssi_thold =
5766 min(request->match_sets[i].rssi_thold,
5767 request->min_rssi_thold);
5768 } else {
5769 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005770 }
5771
Johannes Berg9900e482014-02-04 21:01:25 +01005772 if (ie_len) {
5773 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005774 memcpy((void *)request->ie,
5775 nla_data(info->attrs[NL80211_ATTR_IE]),
5776 request->ie_len);
5777 }
5778
Sam Leffler46856bb2012-10-11 21:03:32 -07005779 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005780 request->flags = nla_get_u32(
5781 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005782 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5783 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005784 err = -EOPNOTSUPP;
5785 goto out_free;
5786 }
5787 }
Sam Lefflered4737712012-10-11 21:03:31 -07005788
Luciano Coelho807f8a82011-05-11 17:09:35 +03005789 request->dev = dev;
5790 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005791 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005792 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005793
Hila Gonene35e4d22012-06-27 17:19:42 +03005794 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005795 if (!err) {
5796 rdev->sched_scan_req = request;
5797 nl80211_send_sched_scan(rdev, dev,
5798 NL80211_CMD_START_SCHED_SCAN);
5799 goto out;
5800 }
5801
5802out_free:
5803 kfree(request);
5804out:
5805 return err;
5806}
5807
5808static int nl80211_stop_sched_scan(struct sk_buff *skb,
5809 struct genl_info *info)
5810{
5811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5812
5813 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5814 !rdev->ops->sched_scan_stop)
5815 return -EOPNOTSUPP;
5816
Johannes Berg5fe231e2013-05-08 21:45:15 +02005817 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005818}
5819
Simon Wunderlich04f39042013-02-08 18:16:19 +01005820static int nl80211_start_radar_detection(struct sk_buff *skb,
5821 struct genl_info *info)
5822{
5823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5824 struct net_device *dev = info->user_ptr[1];
5825 struct wireless_dev *wdev = dev->ieee80211_ptr;
5826 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005827 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005828 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005829 int err;
5830
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005831 dfs_region = reg_get_dfs_region(wdev->wiphy);
5832 if (dfs_region == NL80211_DFS_UNSET)
5833 return -EINVAL;
5834
Simon Wunderlich04f39042013-02-08 18:16:19 +01005835 err = nl80211_parse_chandef(rdev, info, &chandef);
5836 if (err)
5837 return err;
5838
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005839 if (netif_carrier_ok(dev))
5840 return -EBUSY;
5841
Simon Wunderlich04f39042013-02-08 18:16:19 +01005842 if (wdev->cac_started)
5843 return -EBUSY;
5844
Luciano Coelho2beb6da2014-02-18 11:40:36 +02005845 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03005846 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005847 if (err < 0)
5848 return err;
5849
5850 if (err == 0)
5851 return -EINVAL;
5852
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005853 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005854 return -EINVAL;
5855
5856 if (!rdev->ops->start_radar_detection)
5857 return -EOPNOTSUPP;
5858
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005859 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
5860 if (WARN_ON(!cac_time_ms))
5861 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
5862
5863 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
5864 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01005865 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01005866 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005867 wdev->cac_started = true;
5868 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01005869 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005870 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005871 return err;
5872}
5873
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005874static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5875{
5876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5877 struct net_device *dev = info->user_ptr[1];
5878 struct wireless_dev *wdev = dev->ieee80211_ptr;
5879 struct cfg80211_csa_settings params;
5880 /* csa_attrs is defined static to avoid waste of stack size - this
5881 * function is called under RTNL lock, so this should not be a problem.
5882 */
5883 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5884 u8 radar_detect_width = 0;
5885 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005886 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005887 int len, i;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005888
5889 if (!rdev->ops->channel_switch ||
5890 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5891 return -EOPNOTSUPP;
5892
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005893 switch (dev->ieee80211_ptr->iftype) {
5894 case NL80211_IFTYPE_AP:
5895 case NL80211_IFTYPE_P2P_GO:
5896 need_new_beacon = true;
5897
5898 /* useless if AP is not running */
5899 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01005900 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005901 break;
5902 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005903 if (!wdev->ssid_len)
5904 return -ENOTCONN;
5905 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005906 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01005907 if (!wdev->mesh_id_len)
5908 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005909 break;
5910 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005911 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005912 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005913
5914 memset(&params, 0, sizeof(params));
5915
5916 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5917 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5918 return -EINVAL;
5919
5920 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005921 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005922 return -EINVAL;
5923
5924 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5925
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005926 if (!need_new_beacon)
5927 goto skip_beacons;
5928
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005929 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5930 if (err)
5931 return err;
5932
5933 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5934 info->attrs[NL80211_ATTR_CSA_IES],
5935 nl80211_policy);
5936 if (err)
5937 return err;
5938
5939 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5940 if (err)
5941 return err;
5942
5943 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5944 return -EINVAL;
5945
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005946 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5947 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005948 return -EINVAL;
5949
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005950 params.n_counter_offsets_beacon = len / sizeof(u16);
5951 if (rdev->wiphy.max_num_csa_counters &&
5952 (params.n_counter_offsets_beacon >
5953 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005954 return -EINVAL;
5955
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005956 params.counter_offsets_beacon =
5957 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5958
5959 /* sanity checks - counters should fit and be the same */
5960 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
5961 u16 offset = params.counter_offsets_beacon[i];
5962
5963 if (offset >= params.beacon_csa.tail_len)
5964 return -EINVAL;
5965
5966 if (params.beacon_csa.tail[offset] != params.count)
5967 return -EINVAL;
5968 }
5969
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005970 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005971 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5972 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005973 return -EINVAL;
5974
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005975 params.n_counter_offsets_presp = len / sizeof(u16);
5976 if (rdev->wiphy.max_num_csa_counters &&
5977 (params.n_counter_offsets_beacon >
5978 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005979 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03005980
5981 params.counter_offsets_presp =
5982 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5983
5984 /* sanity checks - counters should fit and be the same */
5985 for (i = 0; i < params.n_counter_offsets_presp; i++) {
5986 u16 offset = params.counter_offsets_presp[i];
5987
5988 if (offset >= params.beacon_csa.probe_resp_len)
5989 return -EINVAL;
5990
5991 if (params.beacon_csa.probe_resp[offset] !=
5992 params.count)
5993 return -EINVAL;
5994 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005995 }
5996
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005997skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005998 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5999 if (err)
6000 return err;
6001
Ilan Peer174e0cd2014-02-23 09:13:01 +02006002 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6003 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006004 return -EINVAL;
6005
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006006 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6007 &params.chandef,
6008 wdev->iftype);
6009 if (err < 0)
6010 return err;
6011
6012 if (err > 0) {
6013 radar_detect_width = BIT(params.chandef.width);
6014 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006015 }
6016
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006017 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6018 params.block_tx = true;
6019
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006020 wdev_lock(wdev);
6021 err = rdev_channel_switch(rdev, dev, &params);
6022 wdev_unlock(wdev);
6023
6024 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006025}
6026
Johannes Berg9720bb32011-06-21 09:45:33 +02006027static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6028 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006029 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006030 struct wireless_dev *wdev,
6031 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006032{
Johannes Berg48ab9052009-07-10 18:42:31 +02006033 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006034 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006035 void *hdr;
6036 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006037
6038 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006039
Eric W. Biederman15e47302012-09-07 20:12:54 +00006040 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006041 NL80211_CMD_NEW_SCAN_RESULTS);
6042 if (!hdr)
6043 return -1;
6044
Johannes Berg9720bb32011-06-21 09:45:33 +02006045 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6046
Johannes Berg97990a02013-04-19 01:02:55 +02006047 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6048 goto nla_put_failure;
6049 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006050 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6051 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006052 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6053 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006054
6055 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6056 if (!bss)
6057 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006058 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006059 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006060 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006061
6062 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006063 /* indicate whether we have probe response data or not */
6064 if (rcu_access_pointer(res->proberesp_ies) &&
6065 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6066 goto fail_unlock_rcu;
6067
6068 /* this pointer prefers to be pointed to probe response data
6069 * but is always valid
6070 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006071 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006072 if (ies) {
6073 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6074 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006075 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6076 ies->len, ies->data))
6077 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006078 }
Johannes Berg0e227082014-08-12 20:34:30 +02006079
6080 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006081 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006082 if (ies && ies->from_beacon) {
6083 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006084 goto fail_unlock_rcu;
6085 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6086 ies->len, ies->data))
6087 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006088 }
6089 rcu_read_unlock();
6090
David S. Miller9360ffd2012-03-29 04:41:26 -04006091 if (res->beacon_interval &&
6092 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6093 goto nla_put_failure;
6094 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6095 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006096 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006097 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6098 jiffies_to_msecs(jiffies - intbss->ts)))
6099 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006100
Johannes Berg77965c92009-02-18 18:45:06 +01006101 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006102 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006103 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6104 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006105 break;
6106 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006107 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6108 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006109 break;
6110 default:
6111 break;
6112 }
6113
Johannes Berg48ab9052009-07-10 18:42:31 +02006114 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006115 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006116 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006117 if (intbss == wdev->current_bss &&
6118 nla_put_u32(msg, NL80211_BSS_STATUS,
6119 NL80211_BSS_STATUS_ASSOCIATED))
6120 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006121 break;
6122 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006123 if (intbss == wdev->current_bss &&
6124 nla_put_u32(msg, NL80211_BSS_STATUS,
6125 NL80211_BSS_STATUS_IBSS_JOINED))
6126 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006127 break;
6128 default:
6129 break;
6130 }
6131
Johannes Berg2a519312009-02-10 21:25:55 +01006132 nla_nest_end(msg, bss);
6133
6134 return genlmsg_end(msg, hdr);
6135
Johannes Berg8cef2c92013-02-05 16:54:31 +01006136 fail_unlock_rcu:
6137 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006138 nla_put_failure:
6139 genlmsg_cancel(msg, hdr);
6140 return -EMSGSIZE;
6141}
6142
Johannes Berg97990a02013-04-19 01:02:55 +02006143static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006144{
Johannes Berg48ab9052009-07-10 18:42:31 +02006145 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006146 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006147 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006148 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006149 int err;
6150
Johannes Berg97990a02013-04-19 01:02:55 +02006151 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006152 if (err)
6153 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006154
Johannes Berg48ab9052009-07-10 18:42:31 +02006155 wdev_lock(wdev);
6156 spin_lock_bh(&rdev->bss_lock);
6157 cfg80211_bss_expire(rdev);
6158
Johannes Berg9720bb32011-06-21 09:45:33 +02006159 cb->seq = rdev->bss_generation;
6160
Johannes Berg48ab9052009-07-10 18:42:31 +02006161 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006162 if (++idx <= start)
6163 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006164 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006165 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006166 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006167 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006168 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006169 }
6170 }
6171
Johannes Berg48ab9052009-07-10 18:42:31 +02006172 spin_unlock_bh(&rdev->bss_lock);
6173 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006174
Johannes Berg97990a02013-04-19 01:02:55 +02006175 cb->args[2] = idx;
6176 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006177
Johannes Berg67748892010-10-04 21:14:06 +02006178 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006179}
6180
Eric W. Biederman15e47302012-09-07 20:12:54 +00006181static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006182 int flags, struct net_device *dev,
6183 struct survey_info *survey)
6184{
6185 void *hdr;
6186 struct nlattr *infoattr;
6187
Eric W. Biederman15e47302012-09-07 20:12:54 +00006188 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006189 NL80211_CMD_NEW_SURVEY_RESULTS);
6190 if (!hdr)
6191 return -ENOMEM;
6192
David S. Miller9360ffd2012-03-29 04:41:26 -04006193 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6194 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006195
6196 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6197 if (!infoattr)
6198 goto nla_put_failure;
6199
David S. Miller9360ffd2012-03-29 04:41:26 -04006200 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6201 survey->channel->center_freq))
6202 goto nla_put_failure;
6203
6204 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6205 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6206 goto nla_put_failure;
6207 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6208 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6209 goto nla_put_failure;
6210 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6211 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6212 survey->channel_time))
6213 goto nla_put_failure;
6214 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6215 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6216 survey->channel_time_busy))
6217 goto nla_put_failure;
6218 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6219 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6220 survey->channel_time_ext_busy))
6221 goto nla_put_failure;
6222 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6223 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6224 survey->channel_time_rx))
6225 goto nla_put_failure;
6226 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6227 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6228 survey->channel_time_tx))
6229 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006230
6231 nla_nest_end(msg, infoattr);
6232
6233 return genlmsg_end(msg, hdr);
6234
6235 nla_put_failure:
6236 genlmsg_cancel(msg, hdr);
6237 return -EMSGSIZE;
6238}
6239
6240static int nl80211_dump_survey(struct sk_buff *skb,
6241 struct netlink_callback *cb)
6242{
6243 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006244 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006245 struct wireless_dev *wdev;
6246 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006247 int res;
6248
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006249 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006250 if (res)
6251 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006252
Johannes Berg97990a02013-04-19 01:02:55 +02006253 if (!wdev->netdev) {
6254 res = -EINVAL;
6255 goto out_err;
6256 }
6257
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006258 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006259 res = -EOPNOTSUPP;
6260 goto out_err;
6261 }
6262
6263 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006264 struct ieee80211_channel *chan;
6265
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006266 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006267 if (res == -ENOENT)
6268 break;
6269 if (res)
6270 goto out_err;
6271
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006272 /* Survey without a channel doesn't make sense */
6273 if (!survey.channel) {
6274 res = -EINVAL;
6275 goto out;
6276 }
6277
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006278 chan = ieee80211_get_channel(&rdev->wiphy,
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006279 survey.channel->center_freq);
6280 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6281 survey_idx++;
6282 continue;
6283 }
6284
Holger Schurig61fa7132009-11-11 12:25:40 +01006285 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006286 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006287 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006288 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006289 goto out;
6290 survey_idx++;
6291 }
6292
6293 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006294 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006295 res = skb->len;
6296 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006297 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006298 return res;
6299}
6300
Samuel Ortizb23aa672009-07-01 21:26:54 +02006301static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6302{
6303 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6304 NL80211_WPA_VERSION_2));
6305}
6306
Jouni Malinen636a5d32009-03-19 13:39:22 +02006307static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6308{
Johannes Berg4c476992010-10-04 21:36:35 +02006309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6310 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006311 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006312 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6313 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006314 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006315 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006316 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006317
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006318 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6319 return -EINVAL;
6320
6321 if (!info->attrs[NL80211_ATTR_MAC])
6322 return -EINVAL;
6323
Jouni Malinen17780922009-03-27 20:52:47 +02006324 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6325 return -EINVAL;
6326
Johannes Berg19957bb2009-07-02 17:20:43 +02006327 if (!info->attrs[NL80211_ATTR_SSID])
6328 return -EINVAL;
6329
6330 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6331 return -EINVAL;
6332
Johannes Bergfffd0932009-07-08 14:22:54 +02006333 err = nl80211_parse_key(info, &key);
6334 if (err)
6335 return err;
6336
6337 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006338 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6339 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006340 if (!key.p.key || !key.p.key_len)
6341 return -EINVAL;
6342 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6343 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6344 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6345 key.p.key_len != WLAN_KEY_LEN_WEP104))
6346 return -EINVAL;
6347 if (key.idx > 4)
6348 return -EINVAL;
6349 } else {
6350 key.p.key_len = 0;
6351 key.p.key = NULL;
6352 }
6353
Johannes Bergafea0b72010-08-10 09:46:42 +02006354 if (key.idx >= 0) {
6355 int i;
6356 bool ok = false;
6357 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6358 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6359 ok = true;
6360 break;
6361 }
6362 }
Johannes Berg4c476992010-10-04 21:36:35 +02006363 if (!ok)
6364 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006365 }
6366
Johannes Berg4c476992010-10-04 21:36:35 +02006367 if (!rdev->ops->auth)
6368 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006369
Johannes Berg074ac8d2010-09-16 14:58:22 +02006370 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006371 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6372 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006373
Johannes Berg19957bb2009-07-02 17:20:43 +02006374 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006375 chan = nl80211_get_valid_chan(&rdev->wiphy,
6376 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6377 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006378 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006379
Johannes Berg19957bb2009-07-02 17:20:43 +02006380 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6381 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6382
6383 if (info->attrs[NL80211_ATTR_IE]) {
6384 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6385 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6386 }
6387
6388 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006389 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006390 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006391
Jouni Malinene39e5b52012-09-30 19:29:39 +03006392 if (auth_type == NL80211_AUTHTYPE_SAE &&
6393 !info->attrs[NL80211_ATTR_SAE_DATA])
6394 return -EINVAL;
6395
6396 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6397 if (auth_type != NL80211_AUTHTYPE_SAE)
6398 return -EINVAL;
6399 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6400 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6401 /* need to include at least Auth Transaction and Status Code */
6402 if (sae_data_len < 4)
6403 return -EINVAL;
6404 }
6405
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006406 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6407
Johannes Berg95de8172012-01-20 13:55:25 +01006408 /*
6409 * Since we no longer track auth state, ignore
6410 * requests to only change local state.
6411 */
6412 if (local_state_change)
6413 return 0;
6414
Johannes Berg91bf9b22013-05-15 17:44:01 +02006415 wdev_lock(dev->ieee80211_ptr);
6416 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6417 ssid, ssid_len, ie, ie_len,
6418 key.p.key, key.p.key_len, key.idx,
6419 sae_data, sae_data_len);
6420 wdev_unlock(dev->ieee80211_ptr);
6421 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006422}
6423
Johannes Bergc0692b82010-08-27 14:26:53 +03006424static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6425 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006426 struct cfg80211_crypto_settings *settings,
6427 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006428{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006429 memset(settings, 0, sizeof(*settings));
6430
Samuel Ortizb23aa672009-07-01 21:26:54 +02006431 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6432
Johannes Bergc0692b82010-08-27 14:26:53 +03006433 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6434 u16 proto;
6435 proto = nla_get_u16(
6436 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6437 settings->control_port_ethertype = cpu_to_be16(proto);
6438 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6439 proto != ETH_P_PAE)
6440 return -EINVAL;
6441 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6442 settings->control_port_no_encrypt = true;
6443 } else
6444 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6445
Samuel Ortizb23aa672009-07-01 21:26:54 +02006446 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6447 void *data;
6448 int len, i;
6449
6450 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6451 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6452 settings->n_ciphers_pairwise = len / sizeof(u32);
6453
6454 if (len % sizeof(u32))
6455 return -EINVAL;
6456
Johannes Berg3dc27d22009-07-02 21:36:37 +02006457 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006458 return -EINVAL;
6459
6460 memcpy(settings->ciphers_pairwise, data, len);
6461
6462 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006463 if (!cfg80211_supported_cipher_suite(
6464 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006465 settings->ciphers_pairwise[i]))
6466 return -EINVAL;
6467 }
6468
6469 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6470 settings->cipher_group =
6471 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006472 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6473 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006474 return -EINVAL;
6475 }
6476
6477 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6478 settings->wpa_versions =
6479 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6480 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6481 return -EINVAL;
6482 }
6483
6484 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6485 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006486 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006487
6488 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6489 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6490 settings->n_akm_suites = len / sizeof(u32);
6491
6492 if (len % sizeof(u32))
6493 return -EINVAL;
6494
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006495 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6496 return -EINVAL;
6497
Samuel Ortizb23aa672009-07-01 21:26:54 +02006498 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006499 }
6500
6501 return 0;
6502}
6503
Jouni Malinen636a5d32009-03-19 13:39:22 +02006504static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6505{
Johannes Berg4c476992010-10-04 21:36:35 +02006506 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6507 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006508 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006509 struct cfg80211_assoc_request req = {};
6510 const u8 *bssid, *ssid;
6511 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006512
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006513 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6514 return -EINVAL;
6515
6516 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006517 !info->attrs[NL80211_ATTR_SSID] ||
6518 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006519 return -EINVAL;
6520
Johannes Berg4c476992010-10-04 21:36:35 +02006521 if (!rdev->ops->assoc)
6522 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006523
Johannes Berg074ac8d2010-09-16 14:58:22 +02006524 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6526 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006527
Johannes Berg19957bb2009-07-02 17:20:43 +02006528 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006529
Jouni Malinen664834d2014-01-15 00:01:44 +02006530 chan = nl80211_get_valid_chan(&rdev->wiphy,
6531 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6532 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006533 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006534
Johannes Berg19957bb2009-07-02 17:20:43 +02006535 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6536 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006537
6538 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006539 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6540 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006541 }
6542
Jouni Malinendc6382c2009-05-06 22:09:37 +03006543 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006544 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006545 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006546 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006547 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006548 else if (mfp != NL80211_MFP_NO)
6549 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006550 }
6551
Johannes Berg3e5d7642009-07-07 14:37:26 +02006552 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006553 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006554
Ben Greear7e7c8922011-11-18 11:31:59 -08006555 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006556 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006557
6558 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006559 memcpy(&req.ht_capa_mask,
6560 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6561 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006562
6563 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006564 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006565 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006566 memcpy(&req.ht_capa,
6567 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6568 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006569 }
6570
Johannes Bergee2aca32013-02-21 17:36:01 +01006571 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006572 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006573
6574 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006575 memcpy(&req.vht_capa_mask,
6576 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6577 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006578
6579 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006580 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006581 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006582 memcpy(&req.vht_capa,
6583 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6584 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006585 }
6586
Johannes Bergf62fab72013-02-21 20:09:09 +01006587 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006588 if (!err) {
6589 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006590 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6591 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006592 wdev_unlock(dev->ieee80211_ptr);
6593 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006594
Jouni Malinen636a5d32009-03-19 13:39:22 +02006595 return err;
6596}
6597
6598static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6599{
Johannes Berg4c476992010-10-04 21:36:35 +02006600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6601 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006602 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006603 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006604 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006605 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006606
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006607 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6608 return -EINVAL;
6609
6610 if (!info->attrs[NL80211_ATTR_MAC])
6611 return -EINVAL;
6612
6613 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6614 return -EINVAL;
6615
Johannes Berg4c476992010-10-04 21:36:35 +02006616 if (!rdev->ops->deauth)
6617 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006618
Johannes Berg074ac8d2010-09-16 14:58:22 +02006619 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006620 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6621 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006622
Johannes Berg19957bb2009-07-02 17:20:43 +02006623 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006624
Johannes Berg19957bb2009-07-02 17:20:43 +02006625 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6626 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006627 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006628 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006629 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006630
6631 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006632 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6633 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006634 }
6635
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006636 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6637
Johannes Berg91bf9b22013-05-15 17:44:01 +02006638 wdev_lock(dev->ieee80211_ptr);
6639 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6640 local_state_change);
6641 wdev_unlock(dev->ieee80211_ptr);
6642 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006643}
6644
6645static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6646{
Johannes Berg4c476992010-10-04 21:36:35 +02006647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6648 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006649 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006650 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006651 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006652 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006653
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006654 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6655 return -EINVAL;
6656
6657 if (!info->attrs[NL80211_ATTR_MAC])
6658 return -EINVAL;
6659
6660 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6661 return -EINVAL;
6662
Johannes Berg4c476992010-10-04 21:36:35 +02006663 if (!rdev->ops->disassoc)
6664 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006665
Johannes Berg074ac8d2010-09-16 14:58:22 +02006666 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006667 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6668 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006669
Johannes Berg19957bb2009-07-02 17:20:43 +02006670 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006671
Johannes Berg19957bb2009-07-02 17:20:43 +02006672 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6673 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006674 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006675 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006676 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006677
6678 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006679 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6680 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006681 }
6682
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006683 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6684
Johannes Berg91bf9b22013-05-15 17:44:01 +02006685 wdev_lock(dev->ieee80211_ptr);
6686 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6687 local_state_change);
6688 wdev_unlock(dev->ieee80211_ptr);
6689 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006690}
6691
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006692static bool
6693nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6694 int mcast_rate[IEEE80211_NUM_BANDS],
6695 int rateval)
6696{
6697 struct wiphy *wiphy = &rdev->wiphy;
6698 bool found = false;
6699 int band, i;
6700
6701 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6702 struct ieee80211_supported_band *sband;
6703
6704 sband = wiphy->bands[band];
6705 if (!sband)
6706 continue;
6707
6708 for (i = 0; i < sband->n_bitrates; i++) {
6709 if (sband->bitrates[i].bitrate == rateval) {
6710 mcast_rate[band] = i + 1;
6711 found = true;
6712 break;
6713 }
6714 }
6715 }
6716
6717 return found;
6718}
6719
Johannes Berg04a773a2009-04-19 21:24:32 +02006720static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6721{
Johannes Berg4c476992010-10-04 21:36:35 +02006722 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6723 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006724 struct cfg80211_ibss_params ibss;
6725 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006726 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006727 int err;
6728
Johannes Berg8e30bc52009-04-22 17:45:38 +02006729 memset(&ibss, 0, sizeof(ibss));
6730
Johannes Berg04a773a2009-04-19 21:24:32 +02006731 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6732 return -EINVAL;
6733
Johannes Berg683b6d32012-11-08 21:25:48 +01006734 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006735 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6736 return -EINVAL;
6737
Johannes Berg8e30bc52009-04-22 17:45:38 +02006738 ibss.beacon_interval = 100;
6739
6740 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6741 ibss.beacon_interval =
6742 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6743 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6744 return -EINVAL;
6745 }
6746
Johannes Berg4c476992010-10-04 21:36:35 +02006747 if (!rdev->ops->join_ibss)
6748 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006749
Johannes Berg4c476992010-10-04 21:36:35 +02006750 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6751 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006752
Johannes Berg79c97e92009-07-07 03:56:12 +02006753 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006754
Johannes Berg39193492011-09-16 13:45:25 +02006755 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006756 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006757
6758 if (!is_valid_ether_addr(ibss.bssid))
6759 return -EINVAL;
6760 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006761 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6762 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6763
6764 if (info->attrs[NL80211_ATTR_IE]) {
6765 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6766 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6767 }
6768
Johannes Berg683b6d32012-11-08 21:25:48 +01006769 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6770 if (err)
6771 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006772
Ilan Peer174e0cd2014-02-23 09:13:01 +02006773 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
6774 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006775 return -EINVAL;
6776
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006777 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006778 case NL80211_CHAN_WIDTH_5:
6779 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006780 case NL80211_CHAN_WIDTH_20_NOHT:
6781 break;
6782 case NL80211_CHAN_WIDTH_20:
6783 case NL80211_CHAN_WIDTH_40:
6784 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6785 break;
6786 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006787 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006788 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006789
Johannes Berg04a773a2009-04-19 21:24:32 +02006790 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006791 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006792
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006793 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6794 u8 *rates =
6795 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6796 int n_rates =
6797 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6798 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006799 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006800
Johannes Berg34850ab2011-07-18 18:08:35 +02006801 err = ieee80211_get_ratemask(sband, rates, n_rates,
6802 &ibss.basic_rates);
6803 if (err)
6804 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006805 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006806
Simon Wunderlich803768f2013-06-28 10:39:58 +02006807 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6808 memcpy(&ibss.ht_capa_mask,
6809 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6810 sizeof(ibss.ht_capa_mask));
6811
6812 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6813 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6814 return -EINVAL;
6815 memcpy(&ibss.ht_capa,
6816 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6817 sizeof(ibss.ht_capa));
6818 }
6819
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006820 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6821 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6822 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6823 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006824
Johannes Berg4c476992010-10-04 21:36:35 +02006825 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306826 bool no_ht = false;
6827
Johannes Berg4c476992010-10-04 21:36:35 +02006828 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306829 info->attrs[NL80211_ATTR_KEYS],
6830 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006831 if (IS_ERR(connkeys))
6832 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306833
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006834 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6835 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306836 kfree(connkeys);
6837 return -EINVAL;
6838 }
Johannes Berg4c476992010-10-04 21:36:35 +02006839 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006840
Antonio Quartulli267335d2012-01-31 20:25:47 +01006841 ibss.control_port =
6842 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6843
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006844 ibss.userspace_handles_dfs =
6845 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6846
Johannes Berg4c476992010-10-04 21:36:35 +02006847 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006848 if (err)
6849 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006850 return err;
6851}
6852
6853static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6854{
Johannes Berg4c476992010-10-04 21:36:35 +02006855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6856 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006857
Johannes Berg4c476992010-10-04 21:36:35 +02006858 if (!rdev->ops->leave_ibss)
6859 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006860
Johannes Berg4c476992010-10-04 21:36:35 +02006861 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6862 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006863
Johannes Berg4c476992010-10-04 21:36:35 +02006864 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006865}
6866
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006867static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6868{
6869 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6870 struct net_device *dev = info->user_ptr[1];
6871 int mcast_rate[IEEE80211_NUM_BANDS];
6872 u32 nla_rate;
6873 int err;
6874
6875 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6876 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6877 return -EOPNOTSUPP;
6878
6879 if (!rdev->ops->set_mcast_rate)
6880 return -EOPNOTSUPP;
6881
6882 memset(mcast_rate, 0, sizeof(mcast_rate));
6883
6884 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6885 return -EINVAL;
6886
6887 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6888 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6889 return -EINVAL;
6890
6891 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6892
6893 return err;
6894}
6895
Johannes Bergad7e7182013-11-13 13:37:47 +01006896static struct sk_buff *
6897__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6898 int approxlen, u32 portid, u32 seq,
6899 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01006900 enum nl80211_attrs attr,
6901 const struct nl80211_vendor_cmd_info *info,
6902 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01006903{
6904 struct sk_buff *skb;
6905 void *hdr;
6906 struct nlattr *data;
6907
6908 skb = nlmsg_new(approxlen + 100, gfp);
6909 if (!skb)
6910 return NULL;
6911
6912 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6913 if (!hdr) {
6914 kfree_skb(skb);
6915 return NULL;
6916 }
6917
6918 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6919 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01006920
6921 if (info) {
6922 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
6923 info->vendor_id))
6924 goto nla_put_failure;
6925 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
6926 info->subcmd))
6927 goto nla_put_failure;
6928 }
6929
Johannes Bergad7e7182013-11-13 13:37:47 +01006930 data = nla_nest_start(skb, attr);
6931
6932 ((void **)skb->cb)[0] = rdev;
6933 ((void **)skb->cb)[1] = hdr;
6934 ((void **)skb->cb)[2] = data;
6935
6936 return skb;
6937
6938 nla_put_failure:
6939 kfree_skb(skb);
6940 return NULL;
6941}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006942
Johannes Berge03ad6e2014-01-01 17:22:30 +01006943struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
6944 enum nl80211_commands cmd,
6945 enum nl80211_attrs attr,
6946 int vendor_event_idx,
6947 int approxlen, gfp_t gfp)
6948{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08006949 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01006950 const struct nl80211_vendor_cmd_info *info;
6951
6952 switch (cmd) {
6953 case NL80211_CMD_TESTMODE:
6954 if (WARN_ON(vendor_event_idx != -1))
6955 return NULL;
6956 info = NULL;
6957 break;
6958 case NL80211_CMD_VENDOR:
6959 if (WARN_ON(vendor_event_idx < 0 ||
6960 vendor_event_idx >= wiphy->n_vendor_events))
6961 return NULL;
6962 info = &wiphy->vendor_events[vendor_event_idx];
6963 break;
6964 default:
6965 WARN_ON(1);
6966 return NULL;
6967 }
6968
6969 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6970 cmd, attr, info, gfp);
6971}
6972EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
6973
6974void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
6975{
6976 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
6977 void *hdr = ((void **)skb->cb)[1];
6978 struct nlattr *data = ((void **)skb->cb)[2];
6979 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
6980
6981 nla_nest_end(skb, data);
6982 genlmsg_end(skb, hdr);
6983
6984 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
6985 mcgrp = NL80211_MCGRP_VENDOR;
6986
6987 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
6988 mcgrp, gfp);
6989}
6990EXPORT_SYMBOL(__cfg80211_send_event_skb);
6991
Johannes Bergaff89a92009-07-01 21:26:51 +02006992#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006993static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6994{
Johannes Berg4c476992010-10-04 21:36:35 +02006995 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006996 struct wireless_dev *wdev =
6997 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006998 int err;
6999
David Spinadelfc73f112013-07-31 18:04:15 +03007000 if (!rdev->ops->testmode_cmd)
7001 return -EOPNOTSUPP;
7002
7003 if (IS_ERR(wdev)) {
7004 err = PTR_ERR(wdev);
7005 if (err != -EINVAL)
7006 return err;
7007 wdev = NULL;
7008 } else if (wdev->wiphy != &rdev->wiphy) {
7009 return -EINVAL;
7010 }
7011
Johannes Bergaff89a92009-07-01 21:26:51 +02007012 if (!info->attrs[NL80211_ATTR_TESTDATA])
7013 return -EINVAL;
7014
Johannes Bergad7e7182013-11-13 13:37:47 +01007015 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007016 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007017 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7018 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007019 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007020
Johannes Bergaff89a92009-07-01 21:26:51 +02007021 return err;
7022}
7023
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007024static int nl80211_testmode_dump(struct sk_buff *skb,
7025 struct netlink_callback *cb)
7026{
Johannes Berg00918d32011-12-13 17:22:05 +01007027 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007028 int err;
7029 long phy_idx;
7030 void *data = NULL;
7031 int data_len = 0;
7032
Johannes Berg5fe231e2013-05-08 21:45:15 +02007033 rtnl_lock();
7034
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007035 if (cb->args[0]) {
7036 /*
7037 * 0 is a valid index, but not valid for args[0],
7038 * so we need to offset by 1.
7039 */
7040 phy_idx = cb->args[0] - 1;
7041 } else {
7042 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7043 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7044 nl80211_policy);
7045 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007046 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007047
Johannes Berg2bd7e352012-06-15 14:23:16 +02007048 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7049 nl80211_fam.attrbuf);
7050 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007051 err = PTR_ERR(rdev);
7052 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007053 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007054 phy_idx = rdev->wiphy_idx;
7055 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007056
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007057 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7058 cb->args[1] =
7059 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7060 }
7061
7062 if (cb->args[1]) {
7063 data = nla_data((void *)cb->args[1]);
7064 data_len = nla_len((void *)cb->args[1]);
7065 }
7066
Johannes Berg00918d32011-12-13 17:22:05 +01007067 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7068 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007069 err = -ENOENT;
7070 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007071 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007072
Johannes Berg00918d32011-12-13 17:22:05 +01007073 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007074 err = -EOPNOTSUPP;
7075 goto out_err;
7076 }
7077
7078 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007079 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007080 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7081 NL80211_CMD_TESTMODE);
7082 struct nlattr *tmdata;
7083
Dan Carpentercb35fba2013-08-14 14:50:01 +03007084 if (!hdr)
7085 break;
7086
David S. Miller9360ffd2012-03-29 04:41:26 -04007087 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007088 genlmsg_cancel(skb, hdr);
7089 break;
7090 }
7091
7092 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7093 if (!tmdata) {
7094 genlmsg_cancel(skb, hdr);
7095 break;
7096 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007097 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007098 nla_nest_end(skb, tmdata);
7099
7100 if (err == -ENOBUFS || err == -ENOENT) {
7101 genlmsg_cancel(skb, hdr);
7102 break;
7103 } else if (err) {
7104 genlmsg_cancel(skb, hdr);
7105 goto out_err;
7106 }
7107
7108 genlmsg_end(skb, hdr);
7109 }
7110
7111 err = skb->len;
7112 /* see above */
7113 cb->args[0] = phy_idx + 1;
7114 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007115 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007116 return err;
7117}
Johannes Bergaff89a92009-07-01 21:26:51 +02007118#endif
7119
Samuel Ortizb23aa672009-07-01 21:26:54 +02007120static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7121{
Johannes Berg4c476992010-10-04 21:36:35 +02007122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7123 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007124 struct cfg80211_connect_params connect;
7125 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007126 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007127 int err;
7128
7129 memset(&connect, 0, sizeof(connect));
7130
7131 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7132 return -EINVAL;
7133
7134 if (!info->attrs[NL80211_ATTR_SSID] ||
7135 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7136 return -EINVAL;
7137
7138 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7139 connect.auth_type =
7140 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007141 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7142 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007143 return -EINVAL;
7144 } else
7145 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7146
7147 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7148
Johannes Bergc0692b82010-08-27 14:26:53 +03007149 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007150 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007151 if (err)
7152 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007153
Johannes Berg074ac8d2010-09-16 14:58:22 +02007154 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007155 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7156 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007157
Johannes Berg79c97e92009-07-07 03:56:12 +02007158 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007159
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307160 connect.bg_scan_period = -1;
7161 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7162 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7163 connect.bg_scan_period =
7164 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7165 }
7166
Samuel Ortizb23aa672009-07-01 21:26:54 +02007167 if (info->attrs[NL80211_ATTR_MAC])
7168 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007169 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7170 connect.bssid_hint =
7171 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007172 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7173 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7174
7175 if (info->attrs[NL80211_ATTR_IE]) {
7176 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7177 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7178 }
7179
Jouni Malinencee00a92013-01-15 17:15:57 +02007180 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7181 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7182 if (connect.mfp != NL80211_MFP_REQUIRED &&
7183 connect.mfp != NL80211_MFP_NO)
7184 return -EINVAL;
7185 } else {
7186 connect.mfp = NL80211_MFP_NO;
7187 }
7188
Samuel Ortizb23aa672009-07-01 21:26:54 +02007189 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007190 connect.channel = nl80211_get_valid_chan(
7191 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7192 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007193 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007194 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007195 connect.channel_hint = nl80211_get_valid_chan(
7196 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7197 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007198 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007199 }
7200
Johannes Bergfffd0932009-07-08 14:22:54 +02007201 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7202 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307203 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007204 if (IS_ERR(connkeys))
7205 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007206 }
7207
Ben Greear7e7c8922011-11-18 11:31:59 -08007208 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7209 connect.flags |= ASSOC_REQ_DISABLE_HT;
7210
7211 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7212 memcpy(&connect.ht_capa_mask,
7213 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7214 sizeof(connect.ht_capa_mask));
7215
7216 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007217 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7218 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007219 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007220 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007221 memcpy(&connect.ht_capa,
7222 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7223 sizeof(connect.ht_capa));
7224 }
7225
Johannes Bergee2aca32013-02-21 17:36:01 +01007226 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7227 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7228
7229 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7230 memcpy(&connect.vht_capa_mask,
7231 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7232 sizeof(connect.vht_capa_mask));
7233
7234 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7235 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7236 kfree(connkeys);
7237 return -EINVAL;
7238 }
7239 memcpy(&connect.vht_capa,
7240 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7241 sizeof(connect.vht_capa));
7242 }
7243
Johannes Berg83739b02013-05-15 17:44:01 +02007244 wdev_lock(dev->ieee80211_ptr);
7245 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7246 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007247 if (err)
7248 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007249 return err;
7250}
7251
7252static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7253{
Johannes Berg4c476992010-10-04 21:36:35 +02007254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7255 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007256 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007257 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007258
7259 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7260 reason = WLAN_REASON_DEAUTH_LEAVING;
7261 else
7262 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7263
7264 if (reason == 0)
7265 return -EINVAL;
7266
Johannes Berg074ac8d2010-09-16 14:58:22 +02007267 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007268 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7269 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007270
Johannes Berg83739b02013-05-15 17:44:01 +02007271 wdev_lock(dev->ieee80211_ptr);
7272 ret = cfg80211_disconnect(rdev, dev, reason, true);
7273 wdev_unlock(dev->ieee80211_ptr);
7274 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007275}
7276
Johannes Berg463d0182009-07-14 00:33:35 +02007277static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7278{
Johannes Berg4c476992010-10-04 21:36:35 +02007279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007280 struct net *net;
7281 int err;
7282 u32 pid;
7283
7284 if (!info->attrs[NL80211_ATTR_PID])
7285 return -EINVAL;
7286
7287 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7288
Johannes Berg463d0182009-07-14 00:33:35 +02007289 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007290 if (IS_ERR(net))
7291 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007292
7293 err = 0;
7294
7295 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007296 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7297 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007298
Johannes Berg463d0182009-07-14 00:33:35 +02007299 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007300 return err;
7301}
7302
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007303static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7304{
Johannes Berg4c476992010-10-04 21:36:35 +02007305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007306 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7307 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007308 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007309 struct cfg80211_pmksa pmksa;
7310
7311 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7312
7313 if (!info->attrs[NL80211_ATTR_MAC])
7314 return -EINVAL;
7315
7316 if (!info->attrs[NL80211_ATTR_PMKID])
7317 return -EINVAL;
7318
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007319 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7320 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7321
Johannes Berg074ac8d2010-09-16 14:58:22 +02007322 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007323 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7324 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007325
7326 switch (info->genlhdr->cmd) {
7327 case NL80211_CMD_SET_PMKSA:
7328 rdev_ops = rdev->ops->set_pmksa;
7329 break;
7330 case NL80211_CMD_DEL_PMKSA:
7331 rdev_ops = rdev->ops->del_pmksa;
7332 break;
7333 default:
7334 WARN_ON(1);
7335 break;
7336 }
7337
Johannes Berg4c476992010-10-04 21:36:35 +02007338 if (!rdev_ops)
7339 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007340
Johannes Berg4c476992010-10-04 21:36:35 +02007341 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007342}
7343
7344static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7345{
Johannes Berg4c476992010-10-04 21:36:35 +02007346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7347 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007348
Johannes Berg074ac8d2010-09-16 14:58:22 +02007349 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007350 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7351 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007352
Johannes Berg4c476992010-10-04 21:36:35 +02007353 if (!rdev->ops->flush_pmksa)
7354 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007355
Hila Gonene35e4d22012-06-27 17:19:42 +03007356 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007357}
7358
Arik Nemtsov109086c2011-09-28 14:12:50 +03007359static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7360{
7361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7362 struct net_device *dev = info->user_ptr[1];
7363 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307364 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007365 u16 status_code;
7366 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007367 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007368
7369 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7370 !rdev->ops->tdls_mgmt)
7371 return -EOPNOTSUPP;
7372
7373 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7374 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7375 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7376 !info->attrs[NL80211_ATTR_IE] ||
7377 !info->attrs[NL80211_ATTR_MAC])
7378 return -EINVAL;
7379
7380 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7381 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7382 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7383 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007384 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307385 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7386 peer_capability =
7387 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007388
Hila Gonene35e4d22012-06-27 17:19:42 +03007389 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307390 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007391 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007392 nla_data(info->attrs[NL80211_ATTR_IE]),
7393 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007394}
7395
7396static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7397{
7398 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7399 struct net_device *dev = info->user_ptr[1];
7400 enum nl80211_tdls_operation operation;
7401 u8 *peer;
7402
7403 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7404 !rdev->ops->tdls_oper)
7405 return -EOPNOTSUPP;
7406
7407 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7408 !info->attrs[NL80211_ATTR_MAC])
7409 return -EINVAL;
7410
7411 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7412 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7413
Hila Gonene35e4d22012-06-27 17:19:42 +03007414 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007415}
7416
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007417static int nl80211_remain_on_channel(struct sk_buff *skb,
7418 struct genl_info *info)
7419{
Johannes Berg4c476992010-10-04 21:36:35 +02007420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007421 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007422 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007423 struct sk_buff *msg;
7424 void *hdr;
7425 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007426 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007427 int err;
7428
7429 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7430 !info->attrs[NL80211_ATTR_DURATION])
7431 return -EINVAL;
7432
7433 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7434
Johannes Berg7c4ef712011-11-18 15:33:48 +01007435 if (!rdev->ops->remain_on_channel ||
7436 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007437 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007438
Johannes Bergebf348f2012-06-01 12:50:54 +02007439 /*
7440 * We should be on that channel for at least a minimum amount of
7441 * time (10ms) but no longer than the driver supports.
7442 */
7443 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7444 duration > rdev->wiphy.max_remain_on_channel_duration)
7445 return -EINVAL;
7446
Johannes Berg683b6d32012-11-08 21:25:48 +01007447 err = nl80211_parse_chandef(rdev, info, &chandef);
7448 if (err)
7449 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007450
7451 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007452 if (!msg)
7453 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007454
Eric W. Biederman15e47302012-09-07 20:12:54 +00007455 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007456 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007457 if (!hdr) {
7458 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007459 goto free_msg;
7460 }
7461
Johannes Berg683b6d32012-11-08 21:25:48 +01007462 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7463 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007464
7465 if (err)
7466 goto free_msg;
7467
David S. Miller9360ffd2012-03-29 04:41:26 -04007468 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7469 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007470
7471 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007472
7473 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007474
7475 nla_put_failure:
7476 err = -ENOBUFS;
7477 free_msg:
7478 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007479 return err;
7480}
7481
7482static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7483 struct genl_info *info)
7484{
Johannes Berg4c476992010-10-04 21:36:35 +02007485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007486 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007487 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007488
7489 if (!info->attrs[NL80211_ATTR_COOKIE])
7490 return -EINVAL;
7491
Johannes Berg4c476992010-10-04 21:36:35 +02007492 if (!rdev->ops->cancel_remain_on_channel)
7493 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007494
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007495 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7496
Hila Gonene35e4d22012-06-27 17:19:42 +03007497 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007498}
7499
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007500static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7501 u8 *rates, u8 rates_len)
7502{
7503 u8 i;
7504 u32 mask = 0;
7505
7506 for (i = 0; i < rates_len; i++) {
7507 int rate = (rates[i] & 0x7f) * 5;
7508 int ridx;
7509 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7510 struct ieee80211_rate *srate =
7511 &sband->bitrates[ridx];
7512 if (rate == srate->bitrate) {
7513 mask |= 1 << ridx;
7514 break;
7515 }
7516 }
7517 if (ridx == sband->n_bitrates)
7518 return 0; /* rate not found */
7519 }
7520
7521 return mask;
7522}
7523
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007524static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7525 u8 *rates, u8 rates_len,
7526 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7527{
7528 u8 i;
7529
7530 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7531
7532 for (i = 0; i < rates_len; i++) {
7533 int ridx, rbit;
7534
7535 ridx = rates[i] / 8;
7536 rbit = BIT(rates[i] % 8);
7537
7538 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007539 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007540 return false;
7541
7542 /* check availability */
7543 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7544 mcs[ridx] |= rbit;
7545 else
7546 return false;
7547 }
7548
7549 return true;
7550}
7551
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007552static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7553{
7554 u16 mcs_mask = 0;
7555
7556 switch (vht_mcs_map) {
7557 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7558 break;
7559 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7560 mcs_mask = 0x00FF;
7561 break;
7562 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7563 mcs_mask = 0x01FF;
7564 break;
7565 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7566 mcs_mask = 0x03FF;
7567 break;
7568 default:
7569 break;
7570 }
7571
7572 return mcs_mask;
7573}
7574
7575static void vht_build_mcs_mask(u16 vht_mcs_map,
7576 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7577{
7578 u8 nss;
7579
7580 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7581 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7582 vht_mcs_map >>= 2;
7583 }
7584}
7585
7586static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7587 struct nl80211_txrate_vht *txrate,
7588 u16 mcs[NL80211_VHT_NSS_MAX])
7589{
7590 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7591 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7592 u8 i;
7593
7594 if (!sband->vht_cap.vht_supported)
7595 return false;
7596
7597 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7598
7599 /* Build vht_mcs_mask from VHT capabilities */
7600 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7601
7602 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7603 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7604 mcs[i] = txrate->mcs[i];
7605 else
7606 return false;
7607 }
7608
7609 return true;
7610}
7611
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007612static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007613 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7614 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007615 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7616 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007617 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007618 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007619};
7620
7621static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7622 struct genl_info *info)
7623{
7624 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007625 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007626 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007627 int rem, i;
7628 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007629 struct nlattr *tx_rates;
7630 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007631 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007632
Johannes Berg4c476992010-10-04 21:36:35 +02007633 if (!rdev->ops->set_bitrate_mask)
7634 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007635
7636 memset(&mask, 0, sizeof(mask));
7637 /* Default to all rates enabled */
7638 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7639 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007640
7641 if (!sband)
7642 continue;
7643
7644 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007645 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007646 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007647 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007648
7649 if (!sband->vht_cap.vht_supported)
7650 continue;
7651
7652 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7653 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007654 }
7655
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007656 /* if no rates are given set it back to the defaults */
7657 if (!info->attrs[NL80211_ATTR_TX_RATES])
7658 goto out;
7659
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007660 /*
7661 * The nested attribute uses enum nl80211_band as the index. This maps
7662 * directly to the enum ieee80211_band values used in cfg80211.
7663 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007664 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007665 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007666 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007667 int err;
7668
Johannes Berg4c476992010-10-04 21:36:35 +02007669 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7670 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007671 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007672 if (sband == NULL)
7673 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007674 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7675 nla_len(tx_rates), nl80211_txattr_policy);
7676 if (err)
7677 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007678 if (tb[NL80211_TXRATE_LEGACY]) {
7679 mask.control[band].legacy = rateset_to_mask(
7680 sband,
7681 nla_data(tb[NL80211_TXRATE_LEGACY]),
7682 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307683 if ((mask.control[band].legacy == 0) &&
7684 nla_len(tb[NL80211_TXRATE_LEGACY]))
7685 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007686 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007687 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007688 if (!ht_rateset_to_mask(
7689 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007690 nla_data(tb[NL80211_TXRATE_HT]),
7691 nla_len(tb[NL80211_TXRATE_HT]),
7692 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007693 return -EINVAL;
7694 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007695 if (tb[NL80211_TXRATE_VHT]) {
7696 if (!vht_set_mcs_mask(
7697 sband,
7698 nla_data(tb[NL80211_TXRATE_VHT]),
7699 mask.control[band].vht_mcs))
7700 return -EINVAL;
7701 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007702 if (tb[NL80211_TXRATE_GI]) {
7703 mask.control[band].gi =
7704 nla_get_u8(tb[NL80211_TXRATE_GI]);
7705 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
7706 return -EINVAL;
7707 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007708
7709 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007710 /* don't allow empty legacy rates if HT or VHT
7711 * are not even supported.
7712 */
7713 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7714 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007715 return -EINVAL;
7716
7717 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007718 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007719 goto out;
7720
7721 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7722 if (mask.control[band].vht_mcs[i])
7723 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007724
7725 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007726 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007727 }
7728 }
7729
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007730out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007731 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007732}
7733
Johannes Berg2e161f72010-08-12 15:38:38 +02007734static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007735{
Johannes Berg4c476992010-10-04 21:36:35 +02007736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007737 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007738 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007739
7740 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7741 return -EINVAL;
7742
Johannes Berg2e161f72010-08-12 15:38:38 +02007743 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7744 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007745
Johannes Berg71bbc992012-06-15 15:30:18 +02007746 switch (wdev->iftype) {
7747 case NL80211_IFTYPE_STATION:
7748 case NL80211_IFTYPE_ADHOC:
7749 case NL80211_IFTYPE_P2P_CLIENT:
7750 case NL80211_IFTYPE_AP:
7751 case NL80211_IFTYPE_AP_VLAN:
7752 case NL80211_IFTYPE_MESH_POINT:
7753 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007754 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007755 break;
7756 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007757 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007758 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007759
7760 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007761 if (!rdev->ops->mgmt_tx)
7762 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007763
Eric W. Biederman15e47302012-09-07 20:12:54 +00007764 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007765 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7766 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007767}
7768
Johannes Berg2e161f72010-08-12 15:38:38 +02007769static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007770{
Johannes Berg4c476992010-10-04 21:36:35 +02007771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007772 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007773 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007774 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007775 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007776 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007777 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007778 struct cfg80211_mgmt_tx_params params = {
7779 .dont_wait_for_ack =
7780 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7781 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007782
Johannes Berg683b6d32012-11-08 21:25:48 +01007783 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007784 return -EINVAL;
7785
Johannes Berg4c476992010-10-04 21:36:35 +02007786 if (!rdev->ops->mgmt_tx)
7787 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007788
Johannes Berg71bbc992012-06-15 15:30:18 +02007789 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007790 case NL80211_IFTYPE_P2P_DEVICE:
7791 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7792 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007793 case NL80211_IFTYPE_STATION:
7794 case NL80211_IFTYPE_ADHOC:
7795 case NL80211_IFTYPE_P2P_CLIENT:
7796 case NL80211_IFTYPE_AP:
7797 case NL80211_IFTYPE_AP_VLAN:
7798 case NL80211_IFTYPE_MESH_POINT:
7799 case NL80211_IFTYPE_P2P_GO:
7800 break;
7801 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007802 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007803 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007804
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007805 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007806 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007807 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007808 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007809
7810 /*
7811 * We should wait on the channel for at least a minimum amount
7812 * of time (10ms) but no longer than the driver supports.
7813 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007814 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7815 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007816 return -EINVAL;
7817
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007818 }
7819
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007820 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007821
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007822 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007823 return -EINVAL;
7824
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007825 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307826
Antonio Quartulliea141b752013-06-11 14:20:03 +02007827 /* get the channel if any has been specified, otherwise pass NULL to
7828 * the driver. The latter will use the current one
7829 */
7830 chandef.chan = NULL;
7831 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7832 err = nl80211_parse_chandef(rdev, info, &chandef);
7833 if (err)
7834 return err;
7835 }
7836
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007837 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007838 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007839
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03007840 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7841 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7842
7843 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
7844 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7845 int i;
7846
7847 if (len % sizeof(u16))
7848 return -EINVAL;
7849
7850 params.n_csa_offsets = len / sizeof(u16);
7851 params.csa_offsets =
7852 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
7853
7854 /* check that all the offsets fit the frame */
7855 for (i = 0; i < params.n_csa_offsets; i++) {
7856 if (params.csa_offsets[i] >= params.len)
7857 return -EINVAL;
7858 }
7859 }
7860
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007861 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007862 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7863 if (!msg)
7864 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007865
Eric W. Biederman15e47302012-09-07 20:12:54 +00007866 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007867 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007868 if (!hdr) {
7869 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007870 goto free_msg;
7871 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007872 }
Johannes Berge247bd902011-11-04 11:18:21 +01007873
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007874 params.chan = chandef.chan;
7875 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007876 if (err)
7877 goto free_msg;
7878
Johannes Berge247bd902011-11-04 11:18:21 +01007879 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007880 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7881 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007882
Johannes Berge247bd902011-11-04 11:18:21 +01007883 genlmsg_end(msg, hdr);
7884 return genlmsg_reply(msg, info);
7885 }
7886
7887 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007888
7889 nla_put_failure:
7890 err = -ENOBUFS;
7891 free_msg:
7892 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007893 return err;
7894}
7895
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007896static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7897{
7898 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007899 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007900 u64 cookie;
7901
7902 if (!info->attrs[NL80211_ATTR_COOKIE])
7903 return -EINVAL;
7904
7905 if (!rdev->ops->mgmt_tx_cancel_wait)
7906 return -EOPNOTSUPP;
7907
Johannes Berg71bbc992012-06-15 15:30:18 +02007908 switch (wdev->iftype) {
7909 case NL80211_IFTYPE_STATION:
7910 case NL80211_IFTYPE_ADHOC:
7911 case NL80211_IFTYPE_P2P_CLIENT:
7912 case NL80211_IFTYPE_AP:
7913 case NL80211_IFTYPE_AP_VLAN:
7914 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007915 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007916 break;
7917 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007918 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007919 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007920
7921 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7922
Hila Gonene35e4d22012-06-27 17:19:42 +03007923 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007924}
7925
Kalle Valoffb9eb32010-02-17 17:58:10 +02007926static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7927{
Johannes Berg4c476992010-10-04 21:36:35 +02007928 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007929 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007930 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007931 u8 ps_state;
7932 bool state;
7933 int err;
7934
Johannes Berg4c476992010-10-04 21:36:35 +02007935 if (!info->attrs[NL80211_ATTR_PS_STATE])
7936 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007937
7938 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7939
Johannes Berg4c476992010-10-04 21:36:35 +02007940 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7941 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007942
7943 wdev = dev->ieee80211_ptr;
7944
Johannes Berg4c476992010-10-04 21:36:35 +02007945 if (!rdev->ops->set_power_mgmt)
7946 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007947
7948 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7949
7950 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007951 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007952
Hila Gonene35e4d22012-06-27 17:19:42 +03007953 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007954 if (!err)
7955 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007956 return err;
7957}
7958
7959static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7960{
Johannes Berg4c476992010-10-04 21:36:35 +02007961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007962 enum nl80211_ps_state ps_state;
7963 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007964 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007965 struct sk_buff *msg;
7966 void *hdr;
7967 int err;
7968
Kalle Valoffb9eb32010-02-17 17:58:10 +02007969 wdev = dev->ieee80211_ptr;
7970
Johannes Berg4c476992010-10-04 21:36:35 +02007971 if (!rdev->ops->set_power_mgmt)
7972 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007973
7974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007975 if (!msg)
7976 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007977
Eric W. Biederman15e47302012-09-07 20:12:54 +00007978 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007979 NL80211_CMD_GET_POWER_SAVE);
7980 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007981 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007982 goto free_msg;
7983 }
7984
7985 if (wdev->ps)
7986 ps_state = NL80211_PS_ENABLED;
7987 else
7988 ps_state = NL80211_PS_DISABLED;
7989
David S. Miller9360ffd2012-03-29 04:41:26 -04007990 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7991 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007992
7993 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007994 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007995
Johannes Berg4c476992010-10-04 21:36:35 +02007996 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007997 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007998 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007999 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008000 return err;
8001}
8002
Johannes Berg94e860f2014-01-20 23:58:15 +01008003static const struct nla_policy
8004nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008005 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8006 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8007 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008008 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8009 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8010 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008011};
8012
Thomas Pedersen84f10702012-07-12 16:17:33 -07008013static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008014 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008015{
8016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008017 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008018 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008019
Johannes Bergd9d8b012012-11-26 12:51:52 +01008020 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008021 return -EINVAL;
8022
Thomas Pedersen84f10702012-07-12 16:17:33 -07008023 if (!rdev->ops->set_cqm_txe_config)
8024 return -EOPNOTSUPP;
8025
8026 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8027 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8028 return -EOPNOTSUPP;
8029
Hila Gonene35e4d22012-06-27 17:19:42 +03008030 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008031}
8032
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008033static int nl80211_set_cqm_rssi(struct genl_info *info,
8034 s32 threshold, u32 hysteresis)
8035{
Johannes Berg4c476992010-10-04 21:36:35 +02008036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008037 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008038 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008039
8040 if (threshold > 0)
8041 return -EINVAL;
8042
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008043 /* disabling - hysteresis should also be zero then */
8044 if (threshold == 0)
8045 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008046
Johannes Berg4c476992010-10-04 21:36:35 +02008047 if (!rdev->ops->set_cqm_rssi_config)
8048 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008049
Johannes Berg074ac8d2010-09-16 14:58:22 +02008050 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008051 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8052 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008053
Hila Gonene35e4d22012-06-27 17:19:42 +03008054 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008055}
8056
8057static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8058{
8059 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8060 struct nlattr *cqm;
8061 int err;
8062
8063 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008064 if (!cqm)
8065 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008066
8067 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8068 nl80211_attr_cqm_policy);
8069 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008070 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008071
8072 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8073 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008074 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8075 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008076
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008077 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8078 }
8079
8080 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8081 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8082 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8083 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8084 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8085 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8086
8087 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8088 }
8089
8090 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008091}
8092
Johannes Berg29cbe682010-12-03 09:20:44 +01008093static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8094{
8095 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8096 struct net_device *dev = info->user_ptr[1];
8097 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008098 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008099 int err;
8100
8101 /* start with default */
8102 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008103 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008104
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008105 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008106 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008107 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008108 if (err)
8109 return err;
8110 }
8111
8112 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8113 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8114 return -EINVAL;
8115
Javier Cardonac80d5452010-12-16 17:37:49 -08008116 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8117 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8118
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008119 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8120 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8121 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8122 return -EINVAL;
8123
Marco Porsch9bdbf042013-01-07 16:04:51 +01008124 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8125 setup.beacon_interval =
8126 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8127 if (setup.beacon_interval < 10 ||
8128 setup.beacon_interval > 10000)
8129 return -EINVAL;
8130 }
8131
8132 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8133 setup.dtim_period =
8134 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8135 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8136 return -EINVAL;
8137 }
8138
Javier Cardonac80d5452010-12-16 17:37:49 -08008139 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8140 /* parse additional setup parameters if given */
8141 err = nl80211_parse_mesh_setup(info, &setup);
8142 if (err)
8143 return err;
8144 }
8145
Thomas Pedersend37bb182013-03-04 13:06:13 -08008146 if (setup.user_mpm)
8147 cfg.auto_open_plinks = false;
8148
Johannes Bergcc1d2802012-05-16 23:50:20 +02008149 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008150 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8151 if (err)
8152 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008153 } else {
8154 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008155 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008156 }
8157
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008158 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8159 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8160 int n_rates =
8161 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8162 struct ieee80211_supported_band *sband;
8163
8164 if (!setup.chandef.chan)
8165 return -EINVAL;
8166
8167 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8168
8169 err = ieee80211_get_ratemask(sband, rates, n_rates,
8170 &setup.basic_rates);
8171 if (err)
8172 return err;
8173 }
8174
Javier Cardonac80d5452010-12-16 17:37:49 -08008175 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008176}
8177
8178static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8179{
8180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8181 struct net_device *dev = info->user_ptr[1];
8182
8183 return cfg80211_leave_mesh(rdev, dev);
8184}
8185
Johannes Bergdfb89c52012-06-27 09:23:48 +02008186#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008187static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8188 struct cfg80211_registered_device *rdev)
8189{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008190 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008191 struct nlattr *nl_pats, *nl_pat;
8192 int i, pat_len;
8193
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008194 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008195 return 0;
8196
8197 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8198 if (!nl_pats)
8199 return -ENOBUFS;
8200
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008201 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008202 nl_pat = nla_nest_start(msg, i + 1);
8203 if (!nl_pat)
8204 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008205 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008206 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008207 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008208 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8209 wowlan->patterns[i].pattern) ||
8210 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008211 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008212 return -ENOBUFS;
8213 nla_nest_end(msg, nl_pat);
8214 }
8215 nla_nest_end(msg, nl_pats);
8216
8217 return 0;
8218}
8219
Johannes Berg2a0e0472013-01-23 22:57:40 +01008220static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8221 struct cfg80211_wowlan_tcp *tcp)
8222{
8223 struct nlattr *nl_tcp;
8224
8225 if (!tcp)
8226 return 0;
8227
8228 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8229 if (!nl_tcp)
8230 return -ENOBUFS;
8231
8232 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8233 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8234 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8235 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8236 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8237 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8238 tcp->payload_len, tcp->payload) ||
8239 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8240 tcp->data_interval) ||
8241 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8242 tcp->wake_len, tcp->wake_data) ||
8243 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8244 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8245 return -ENOBUFS;
8246
8247 if (tcp->payload_seq.len &&
8248 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8249 sizeof(tcp->payload_seq), &tcp->payload_seq))
8250 return -ENOBUFS;
8251
8252 if (tcp->payload_tok.len &&
8253 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8254 sizeof(tcp->payload_tok) + tcp->tokens_size,
8255 &tcp->payload_tok))
8256 return -ENOBUFS;
8257
Johannes Berge248ad32013-05-16 10:24:28 +02008258 nla_nest_end(msg, nl_tcp);
8259
Johannes Berg2a0e0472013-01-23 22:57:40 +01008260 return 0;
8261}
8262
Johannes Bergff1b6e62011-05-04 15:37:28 +02008263static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8264{
8265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8266 struct sk_buff *msg;
8267 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008268 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008269
Johannes Berg964dc9e2013-06-03 17:25:34 +02008270 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008271 return -EOPNOTSUPP;
8272
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008273 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008274 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008275 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8276 rdev->wiphy.wowlan_config->tcp->payload_len +
8277 rdev->wiphy.wowlan_config->tcp->wake_len +
8278 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008279 }
8280
8281 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008282 if (!msg)
8283 return -ENOMEM;
8284
Eric W. Biederman15e47302012-09-07 20:12:54 +00008285 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008286 NL80211_CMD_GET_WOWLAN);
8287 if (!hdr)
8288 goto nla_put_failure;
8289
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008290 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008291 struct nlattr *nl_wowlan;
8292
8293 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8294 if (!nl_wowlan)
8295 goto nla_put_failure;
8296
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008297 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008298 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008299 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008300 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008301 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008302 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008303 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008304 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008305 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008306 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008307 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008308 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008309 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008310 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8311 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008312
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008313 if (nl80211_send_wowlan_patterns(msg, rdev))
8314 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008315
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008316 if (nl80211_send_wowlan_tcp(msg,
8317 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008318 goto nla_put_failure;
8319
Johannes Bergff1b6e62011-05-04 15:37:28 +02008320 nla_nest_end(msg, nl_wowlan);
8321 }
8322
8323 genlmsg_end(msg, hdr);
8324 return genlmsg_reply(msg, info);
8325
8326nla_put_failure:
8327 nlmsg_free(msg);
8328 return -ENOBUFS;
8329}
8330
Johannes Berg2a0e0472013-01-23 22:57:40 +01008331static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8332 struct nlattr *attr,
8333 struct cfg80211_wowlan *trig)
8334{
8335 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8336 struct cfg80211_wowlan_tcp *cfg;
8337 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8338 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8339 u32 size;
8340 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8341 int err, port;
8342
Johannes Berg964dc9e2013-06-03 17:25:34 +02008343 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008344 return -EINVAL;
8345
8346 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8347 nla_data(attr), nla_len(attr),
8348 nl80211_wowlan_tcp_policy);
8349 if (err)
8350 return err;
8351
8352 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8353 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8354 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8355 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8356 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8357 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8358 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8359 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8360 return -EINVAL;
8361
8362 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008363 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008364 return -EINVAL;
8365
8366 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008367 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008368 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008369 return -EINVAL;
8370
8371 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008372 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008373 return -EINVAL;
8374
8375 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8376 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8377 return -EINVAL;
8378
8379 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8380 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8381
8382 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8383 tokens_size = tokln - sizeof(*tok);
8384
8385 if (!tok->len || tokens_size % tok->len)
8386 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008387 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008388 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008389 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008390 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008391 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008392 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008393 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008394 return -EINVAL;
8395 if (tok->offset + tok->len > data_size)
8396 return -EINVAL;
8397 }
8398
8399 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8400 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008401 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008402 return -EINVAL;
8403 if (seq->len == 0 || seq->len > 4)
8404 return -EINVAL;
8405 if (seq->len + seq->offset > data_size)
8406 return -EINVAL;
8407 }
8408
8409 size = sizeof(*cfg);
8410 size += data_size;
8411 size += wake_size + wake_mask_size;
8412 size += tokens_size;
8413
8414 cfg = kzalloc(size, GFP_KERNEL);
8415 if (!cfg)
8416 return -ENOMEM;
8417 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8418 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8419 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8420 ETH_ALEN);
8421 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8422 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8423 else
8424 port = 0;
8425#ifdef CONFIG_INET
8426 /* allocate a socket and port for it and use it */
8427 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8428 IPPROTO_TCP, &cfg->sock, 1);
8429 if (err) {
8430 kfree(cfg);
8431 return err;
8432 }
8433 if (inet_csk_get_port(cfg->sock->sk, port)) {
8434 sock_release(cfg->sock);
8435 kfree(cfg);
8436 return -EADDRINUSE;
8437 }
8438 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8439#else
8440 if (!port) {
8441 kfree(cfg);
8442 return -EINVAL;
8443 }
8444 cfg->src_port = port;
8445#endif
8446
8447 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8448 cfg->payload_len = data_size;
8449 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8450 memcpy((void *)cfg->payload,
8451 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8452 data_size);
8453 if (seq)
8454 cfg->payload_seq = *seq;
8455 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8456 cfg->wake_len = wake_size;
8457 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8458 memcpy((void *)cfg->wake_data,
8459 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8460 wake_size);
8461 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8462 data_size + wake_size;
8463 memcpy((void *)cfg->wake_mask,
8464 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8465 wake_mask_size);
8466 if (tok) {
8467 cfg->tokens_size = tokens_size;
8468 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8469 }
8470
8471 trig->tcp = cfg;
8472
8473 return 0;
8474}
8475
Johannes Bergff1b6e62011-05-04 15:37:28 +02008476static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8477{
8478 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8479 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008480 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008481 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008482 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008483 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008484 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008485
Johannes Berg964dc9e2013-06-03 17:25:34 +02008486 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008487 return -EOPNOTSUPP;
8488
Johannes Bergae33bd82012-07-12 16:25:02 +02008489 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8490 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008491 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008492 goto set_wakeup;
8493 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008494
8495 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8496 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8497 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8498 nl80211_wowlan_policy);
8499 if (err)
8500 return err;
8501
8502 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8503 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8504 return -EINVAL;
8505 new_triggers.any = true;
8506 }
8507
8508 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8509 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8510 return -EINVAL;
8511 new_triggers.disconnect = true;
8512 }
8513
8514 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8515 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8516 return -EINVAL;
8517 new_triggers.magic_pkt = true;
8518 }
8519
Johannes Berg77dbbb12011-07-13 10:48:55 +02008520 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8521 return -EINVAL;
8522
8523 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8524 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8525 return -EINVAL;
8526 new_triggers.gtk_rekey_failure = true;
8527 }
8528
8529 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8530 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8531 return -EINVAL;
8532 new_triggers.eap_identity_req = true;
8533 }
8534
8535 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8536 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8537 return -EINVAL;
8538 new_triggers.four_way_handshake = true;
8539 }
8540
8541 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8542 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8543 return -EINVAL;
8544 new_triggers.rfkill_release = true;
8545 }
8546
Johannes Bergff1b6e62011-05-04 15:37:28 +02008547 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8548 struct nlattr *pat;
8549 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008550 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008551 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008552
8553 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8554 rem)
8555 n_patterns++;
8556 if (n_patterns > wowlan->n_patterns)
8557 return -EINVAL;
8558
8559 new_triggers.patterns = kcalloc(n_patterns,
8560 sizeof(new_triggers.patterns[0]),
8561 GFP_KERNEL);
8562 if (!new_triggers.patterns)
8563 return -ENOMEM;
8564
8565 new_triggers.n_patterns = n_patterns;
8566 i = 0;
8567
8568 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8569 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008570 u8 *mask_pat;
8571
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008572 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8573 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008574 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008575 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8576 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008577 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008578 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008579 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008580 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008581 goto error;
8582 if (pat_len > wowlan->pattern_max_len ||
8583 pat_len < wowlan->pattern_min_len)
8584 goto error;
8585
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008586 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008587 pkt_offset = 0;
8588 else
8589 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008590 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008591 if (pkt_offset > wowlan->max_pkt_offset)
8592 goto error;
8593 new_triggers.patterns[i].pkt_offset = pkt_offset;
8594
Johannes Berg922bd802014-05-19 17:59:50 +02008595 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8596 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008597 err = -ENOMEM;
8598 goto error;
8599 }
Johannes Berg922bd802014-05-19 17:59:50 +02008600 new_triggers.patterns[i].mask = mask_pat;
8601 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008602 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008603 mask_pat += mask_len;
8604 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008605 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008606 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008607 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008608 pat_len);
8609 i++;
8610 }
8611 }
8612
Johannes Berg2a0e0472013-01-23 22:57:40 +01008613 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8614 err = nl80211_parse_wowlan_tcp(
8615 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8616 &new_triggers);
8617 if (err)
8618 goto error;
8619 }
8620
Johannes Bergae33bd82012-07-12 16:25:02 +02008621 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8622 if (!ntrig) {
8623 err = -ENOMEM;
8624 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008625 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008626 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008627 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008628
Johannes Bergae33bd82012-07-12 16:25:02 +02008629 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008630 if (rdev->ops->set_wakeup &&
8631 prev_enabled != !!rdev->wiphy.wowlan_config)
8632 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008633
Johannes Bergff1b6e62011-05-04 15:37:28 +02008634 return 0;
8635 error:
8636 for (i = 0; i < new_triggers.n_patterns; i++)
8637 kfree(new_triggers.patterns[i].mask);
8638 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008639 if (new_triggers.tcp && new_triggers.tcp->sock)
8640 sock_release(new_triggers.tcp->sock);
8641 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008642 return err;
8643}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008644#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008645
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008646static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8647 struct cfg80211_registered_device *rdev)
8648{
8649 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8650 int i, j, pat_len;
8651 struct cfg80211_coalesce_rules *rule;
8652
8653 if (!rdev->coalesce->n_rules)
8654 return 0;
8655
8656 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8657 if (!nl_rules)
8658 return -ENOBUFS;
8659
8660 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8661 nl_rule = nla_nest_start(msg, i + 1);
8662 if (!nl_rule)
8663 return -ENOBUFS;
8664
8665 rule = &rdev->coalesce->rules[i];
8666 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8667 rule->delay))
8668 return -ENOBUFS;
8669
8670 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8671 rule->condition))
8672 return -ENOBUFS;
8673
8674 nl_pats = nla_nest_start(msg,
8675 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8676 if (!nl_pats)
8677 return -ENOBUFS;
8678
8679 for (j = 0; j < rule->n_patterns; j++) {
8680 nl_pat = nla_nest_start(msg, j + 1);
8681 if (!nl_pat)
8682 return -ENOBUFS;
8683 pat_len = rule->patterns[j].pattern_len;
8684 if (nla_put(msg, NL80211_PKTPAT_MASK,
8685 DIV_ROUND_UP(pat_len, 8),
8686 rule->patterns[j].mask) ||
8687 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8688 rule->patterns[j].pattern) ||
8689 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8690 rule->patterns[j].pkt_offset))
8691 return -ENOBUFS;
8692 nla_nest_end(msg, nl_pat);
8693 }
8694 nla_nest_end(msg, nl_pats);
8695 nla_nest_end(msg, nl_rule);
8696 }
8697 nla_nest_end(msg, nl_rules);
8698
8699 return 0;
8700}
8701
8702static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8703{
8704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8705 struct sk_buff *msg;
8706 void *hdr;
8707
8708 if (!rdev->wiphy.coalesce)
8709 return -EOPNOTSUPP;
8710
8711 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8712 if (!msg)
8713 return -ENOMEM;
8714
8715 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8716 NL80211_CMD_GET_COALESCE);
8717 if (!hdr)
8718 goto nla_put_failure;
8719
8720 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8721 goto nla_put_failure;
8722
8723 genlmsg_end(msg, hdr);
8724 return genlmsg_reply(msg, info);
8725
8726nla_put_failure:
8727 nlmsg_free(msg);
8728 return -ENOBUFS;
8729}
8730
8731void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8732{
8733 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8734 int i, j;
8735 struct cfg80211_coalesce_rules *rule;
8736
8737 if (!coalesce)
8738 return;
8739
8740 for (i = 0; i < coalesce->n_rules; i++) {
8741 rule = &coalesce->rules[i];
8742 for (j = 0; j < rule->n_patterns; j++)
8743 kfree(rule->patterns[j].mask);
8744 kfree(rule->patterns);
8745 }
8746 kfree(coalesce->rules);
8747 kfree(coalesce);
8748 rdev->coalesce = NULL;
8749}
8750
8751static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8752 struct nlattr *rule,
8753 struct cfg80211_coalesce_rules *new_rule)
8754{
8755 int err, i;
8756 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8757 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8758 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8759 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8760
8761 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8762 nla_len(rule), nl80211_coalesce_policy);
8763 if (err)
8764 return err;
8765
8766 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8767 new_rule->delay =
8768 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8769 if (new_rule->delay > coalesce->max_delay)
8770 return -EINVAL;
8771
8772 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8773 new_rule->condition =
8774 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8775 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8776 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8777 return -EINVAL;
8778
8779 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8780 return -EINVAL;
8781
8782 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8783 rem)
8784 n_patterns++;
8785 if (n_patterns > coalesce->n_patterns)
8786 return -EINVAL;
8787
8788 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8789 GFP_KERNEL);
8790 if (!new_rule->patterns)
8791 return -ENOMEM;
8792
8793 new_rule->n_patterns = n_patterns;
8794 i = 0;
8795
8796 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8797 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008798 u8 *mask_pat;
8799
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008800 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8801 nla_len(pat), NULL);
8802 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8803 !pat_tb[NL80211_PKTPAT_PATTERN])
8804 return -EINVAL;
8805 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8806 mask_len = DIV_ROUND_UP(pat_len, 8);
8807 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8808 return -EINVAL;
8809 if (pat_len > coalesce->pattern_max_len ||
8810 pat_len < coalesce->pattern_min_len)
8811 return -EINVAL;
8812
8813 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8814 pkt_offset = 0;
8815 else
8816 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8817 if (pkt_offset > coalesce->max_pkt_offset)
8818 return -EINVAL;
8819 new_rule->patterns[i].pkt_offset = pkt_offset;
8820
Johannes Berg922bd802014-05-19 17:59:50 +02008821 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8822 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008823 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02008824
8825 new_rule->patterns[i].mask = mask_pat;
8826 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
8827 mask_len);
8828
8829 mask_pat += mask_len;
8830 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008831 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008832 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
8833 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008834 i++;
8835 }
8836
8837 return 0;
8838}
8839
8840static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8841{
8842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8843 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8844 struct cfg80211_coalesce new_coalesce = {};
8845 struct cfg80211_coalesce *n_coalesce;
8846 int err, rem_rule, n_rules = 0, i, j;
8847 struct nlattr *rule;
8848 struct cfg80211_coalesce_rules *tmp_rule;
8849
8850 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8851 return -EOPNOTSUPP;
8852
8853 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8854 cfg80211_rdev_free_coalesce(rdev);
8855 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8856 return 0;
8857 }
8858
8859 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8860 rem_rule)
8861 n_rules++;
8862 if (n_rules > coalesce->n_rules)
8863 return -EINVAL;
8864
8865 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8866 GFP_KERNEL);
8867 if (!new_coalesce.rules)
8868 return -ENOMEM;
8869
8870 new_coalesce.n_rules = n_rules;
8871 i = 0;
8872
8873 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8874 rem_rule) {
8875 err = nl80211_parse_coalesce_rule(rdev, rule,
8876 &new_coalesce.rules[i]);
8877 if (err)
8878 goto error;
8879
8880 i++;
8881 }
8882
8883 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8884 if (err)
8885 goto error;
8886
8887 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8888 if (!n_coalesce) {
8889 err = -ENOMEM;
8890 goto error;
8891 }
8892 cfg80211_rdev_free_coalesce(rdev);
8893 rdev->coalesce = n_coalesce;
8894
8895 return 0;
8896error:
8897 for (i = 0; i < new_coalesce.n_rules; i++) {
8898 tmp_rule = &new_coalesce.rules[i];
8899 for (j = 0; j < tmp_rule->n_patterns; j++)
8900 kfree(tmp_rule->patterns[j].mask);
8901 kfree(tmp_rule->patterns);
8902 }
8903 kfree(new_coalesce.rules);
8904
8905 return err;
8906}
8907
Johannes Berge5497d72011-07-05 16:35:40 +02008908static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8909{
8910 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8911 struct net_device *dev = info->user_ptr[1];
8912 struct wireless_dev *wdev = dev->ieee80211_ptr;
8913 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8914 struct cfg80211_gtk_rekey_data rekey_data;
8915 int err;
8916
8917 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8918 return -EINVAL;
8919
8920 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8921 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8922 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8923 nl80211_rekey_policy);
8924 if (err)
8925 return err;
8926
8927 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8928 return -ERANGE;
8929 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8930 return -ERANGE;
8931 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8932 return -ERANGE;
8933
8934 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8935 NL80211_KEK_LEN);
8936 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8937 NL80211_KCK_LEN);
8938 memcpy(rekey_data.replay_ctr,
8939 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8940 NL80211_REPLAY_CTR_LEN);
8941
8942 wdev_lock(wdev);
8943 if (!wdev->current_bss) {
8944 err = -ENOTCONN;
8945 goto out;
8946 }
8947
8948 if (!rdev->ops->set_rekey_data) {
8949 err = -EOPNOTSUPP;
8950 goto out;
8951 }
8952
Hila Gonene35e4d22012-06-27 17:19:42 +03008953 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008954 out:
8955 wdev_unlock(wdev);
8956 return err;
8957}
8958
Johannes Berg28946da2011-11-04 11:18:12 +01008959static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8960 struct genl_info *info)
8961{
8962 struct net_device *dev = info->user_ptr[1];
8963 struct wireless_dev *wdev = dev->ieee80211_ptr;
8964
8965 if (wdev->iftype != NL80211_IFTYPE_AP &&
8966 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8967 return -EINVAL;
8968
Eric W. Biederman15e47302012-09-07 20:12:54 +00008969 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008970 return -EBUSY;
8971
Eric W. Biederman15e47302012-09-07 20:12:54 +00008972 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008973 return 0;
8974}
8975
Johannes Berg7f6cf312011-11-04 11:18:15 +01008976static int nl80211_probe_client(struct sk_buff *skb,
8977 struct genl_info *info)
8978{
8979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8980 struct net_device *dev = info->user_ptr[1];
8981 struct wireless_dev *wdev = dev->ieee80211_ptr;
8982 struct sk_buff *msg;
8983 void *hdr;
8984 const u8 *addr;
8985 u64 cookie;
8986 int err;
8987
8988 if (wdev->iftype != NL80211_IFTYPE_AP &&
8989 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8990 return -EOPNOTSUPP;
8991
8992 if (!info->attrs[NL80211_ATTR_MAC])
8993 return -EINVAL;
8994
8995 if (!rdev->ops->probe_client)
8996 return -EOPNOTSUPP;
8997
8998 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8999 if (!msg)
9000 return -ENOMEM;
9001
Eric W. Biederman15e47302012-09-07 20:12:54 +00009002 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009003 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009004 if (!hdr) {
9005 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009006 goto free_msg;
9007 }
9008
9009 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9010
Hila Gonene35e4d22012-06-27 17:19:42 +03009011 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009012 if (err)
9013 goto free_msg;
9014
David S. Miller9360ffd2012-03-29 04:41:26 -04009015 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9016 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009017
9018 genlmsg_end(msg, hdr);
9019
9020 return genlmsg_reply(msg, info);
9021
9022 nla_put_failure:
9023 err = -ENOBUFS;
9024 free_msg:
9025 nlmsg_free(msg);
9026 return err;
9027}
9028
Johannes Berg5e760232011-11-04 11:18:17 +01009029static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9030{
9031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009032 struct cfg80211_beacon_registration *reg, *nreg;
9033 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009034
9035 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9036 return -EOPNOTSUPP;
9037
Ben Greear37c73b52012-10-26 14:49:25 -07009038 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9039 if (!nreg)
9040 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009041
Ben Greear37c73b52012-10-26 14:49:25 -07009042 /* First, check if already registered. */
9043 spin_lock_bh(&rdev->beacon_registrations_lock);
9044 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9045 if (reg->nlportid == info->snd_portid) {
9046 rv = -EALREADY;
9047 goto out_err;
9048 }
9049 }
9050 /* Add it to the list */
9051 nreg->nlportid = info->snd_portid;
9052 list_add(&nreg->list, &rdev->beacon_registrations);
9053
9054 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009055
9056 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009057out_err:
9058 spin_unlock_bh(&rdev->beacon_registrations_lock);
9059 kfree(nreg);
9060 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009061}
9062
Johannes Berg98104fde2012-06-16 00:19:54 +02009063static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9064{
9065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9066 struct wireless_dev *wdev = info->user_ptr[1];
9067 int err;
9068
9069 if (!rdev->ops->start_p2p_device)
9070 return -EOPNOTSUPP;
9071
9072 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9073 return -EOPNOTSUPP;
9074
9075 if (wdev->p2p_started)
9076 return 0;
9077
Luciano Coelhob6a55012014-02-27 11:07:21 +02009078 if (rfkill_blocked(rdev->rfkill))
9079 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009080
Johannes Bergeeb126e2012-10-23 15:16:50 +02009081 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009082 if (err)
9083 return err;
9084
9085 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009086 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009087
9088 return 0;
9089}
9090
9091static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9092{
9093 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9094 struct wireless_dev *wdev = info->user_ptr[1];
9095
9096 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9097 return -EOPNOTSUPP;
9098
9099 if (!rdev->ops->stop_p2p_device)
9100 return -EOPNOTSUPP;
9101
Johannes Bergf9f47522013-03-19 15:04:07 +01009102 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009103
9104 return 0;
9105}
9106
Johannes Berg3713b4e2013-02-14 16:19:38 +01009107static int nl80211_get_protocol_features(struct sk_buff *skb,
9108 struct genl_info *info)
9109{
9110 void *hdr;
9111 struct sk_buff *msg;
9112
9113 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9114 if (!msg)
9115 return -ENOMEM;
9116
9117 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9118 NL80211_CMD_GET_PROTOCOL_FEATURES);
9119 if (!hdr)
9120 goto nla_put_failure;
9121
9122 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9123 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9124 goto nla_put_failure;
9125
9126 genlmsg_end(msg, hdr);
9127 return genlmsg_reply(msg, info);
9128
9129 nla_put_failure:
9130 kfree_skb(msg);
9131 return -ENOBUFS;
9132}
9133
Jouni Malinen355199e2013-02-27 17:14:27 +02009134static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9135{
9136 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9137 struct cfg80211_update_ft_ies_params ft_params;
9138 struct net_device *dev = info->user_ptr[1];
9139
9140 if (!rdev->ops->update_ft_ies)
9141 return -EOPNOTSUPP;
9142
9143 if (!info->attrs[NL80211_ATTR_MDID] ||
9144 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9145 return -EINVAL;
9146
9147 memset(&ft_params, 0, sizeof(ft_params));
9148 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9149 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9150 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9151
9152 return rdev_update_ft_ies(rdev, dev, &ft_params);
9153}
9154
Arend van Spriel5de17982013-04-18 15:49:00 +02009155static int nl80211_crit_protocol_start(struct sk_buff *skb,
9156 struct genl_info *info)
9157{
9158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9159 struct wireless_dev *wdev = info->user_ptr[1];
9160 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9161 u16 duration;
9162 int ret;
9163
9164 if (!rdev->ops->crit_proto_start)
9165 return -EOPNOTSUPP;
9166
9167 if (WARN_ON(!rdev->ops->crit_proto_stop))
9168 return -EINVAL;
9169
9170 if (rdev->crit_proto_nlportid)
9171 return -EBUSY;
9172
9173 /* determine protocol if provided */
9174 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9175 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9176
9177 if (proto >= NUM_NL80211_CRIT_PROTO)
9178 return -EINVAL;
9179
9180 /* timeout must be provided */
9181 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9182 return -EINVAL;
9183
9184 duration =
9185 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9186
9187 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9188 return -ERANGE;
9189
9190 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9191 if (!ret)
9192 rdev->crit_proto_nlportid = info->snd_portid;
9193
9194 return ret;
9195}
9196
9197static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9198 struct genl_info *info)
9199{
9200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9201 struct wireless_dev *wdev = info->user_ptr[1];
9202
9203 if (!rdev->ops->crit_proto_stop)
9204 return -EOPNOTSUPP;
9205
9206 if (rdev->crit_proto_nlportid) {
9207 rdev->crit_proto_nlportid = 0;
9208 rdev_crit_proto_stop(rdev, wdev);
9209 }
9210 return 0;
9211}
9212
Johannes Bergad7e7182013-11-13 13:37:47 +01009213static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9214{
9215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9216 struct wireless_dev *wdev =
9217 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9218 int i, err;
9219 u32 vid, subcmd;
9220
9221 if (!rdev->wiphy.vendor_commands)
9222 return -EOPNOTSUPP;
9223
9224 if (IS_ERR(wdev)) {
9225 err = PTR_ERR(wdev);
9226 if (err != -EINVAL)
9227 return err;
9228 wdev = NULL;
9229 } else if (wdev->wiphy != &rdev->wiphy) {
9230 return -EINVAL;
9231 }
9232
9233 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9234 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9235 return -EINVAL;
9236
9237 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9238 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9239 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9240 const struct wiphy_vendor_command *vcmd;
9241 void *data = NULL;
9242 int len = 0;
9243
9244 vcmd = &rdev->wiphy.vendor_commands[i];
9245
9246 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9247 continue;
9248
9249 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9250 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9251 if (!wdev)
9252 return -EINVAL;
9253 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9254 !wdev->netdev)
9255 return -EINVAL;
9256
9257 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9258 if (wdev->netdev &&
9259 !netif_running(wdev->netdev))
9260 return -ENETDOWN;
9261 if (!wdev->netdev && !wdev->p2p_started)
9262 return -ENETDOWN;
9263 }
9264 } else {
9265 wdev = NULL;
9266 }
9267
9268 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9269 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9270 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9271 }
9272
9273 rdev->cur_cmd_info = info;
9274 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9275 data, len);
9276 rdev->cur_cmd_info = NULL;
9277 return err;
9278 }
9279
9280 return -EOPNOTSUPP;
9281}
9282
9283struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9284 enum nl80211_commands cmd,
9285 enum nl80211_attrs attr,
9286 int approxlen)
9287{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009288 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009289
9290 if (WARN_ON(!rdev->cur_cmd_info))
9291 return NULL;
9292
9293 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9294 rdev->cur_cmd_info->snd_portid,
9295 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009296 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009297}
9298EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9299
9300int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9301{
9302 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9303 void *hdr = ((void **)skb->cb)[1];
9304 struct nlattr *data = ((void **)skb->cb)[2];
9305
9306 if (WARN_ON(!rdev->cur_cmd_info)) {
9307 kfree_skb(skb);
9308 return -EINVAL;
9309 }
9310
9311 nla_nest_end(skb, data);
9312 genlmsg_end(skb, hdr);
9313 return genlmsg_reply(skb, rdev->cur_cmd_info);
9314}
9315EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9316
9317
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009318static int nl80211_set_qos_map(struct sk_buff *skb,
9319 struct genl_info *info)
9320{
9321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9322 struct cfg80211_qos_map *qos_map = NULL;
9323 struct net_device *dev = info->user_ptr[1];
9324 u8 *pos, len, num_des, des_len, des;
9325 int ret;
9326
9327 if (!rdev->ops->set_qos_map)
9328 return -EOPNOTSUPP;
9329
9330 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9331 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9332 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9333
9334 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9335 len > IEEE80211_QOS_MAP_LEN_MAX)
9336 return -EINVAL;
9337
9338 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9339 if (!qos_map)
9340 return -ENOMEM;
9341
9342 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9343 if (num_des) {
9344 des_len = num_des *
9345 sizeof(struct cfg80211_dscp_exception);
9346 memcpy(qos_map->dscp_exception, pos, des_len);
9347 qos_map->num_des = num_des;
9348 for (des = 0; des < num_des; des++) {
9349 if (qos_map->dscp_exception[des].up > 7) {
9350 kfree(qos_map);
9351 return -EINVAL;
9352 }
9353 }
9354 pos += des_len;
9355 }
9356 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9357 }
9358
9359 wdev_lock(dev->ieee80211_ptr);
9360 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9361 if (!ret)
9362 ret = rdev_set_qos_map(rdev, dev, qos_map);
9363 wdev_unlock(dev->ieee80211_ptr);
9364
9365 kfree(qos_map);
9366 return ret;
9367}
9368
Johannes Berg4c476992010-10-04 21:36:35 +02009369#define NL80211_FLAG_NEED_WIPHY 0x01
9370#define NL80211_FLAG_NEED_NETDEV 0x02
9371#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009372#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9373#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9374 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009375#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009376/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009377#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9378 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009379
Johannes Bergf84f7712013-11-14 17:14:45 +01009380static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009381 struct genl_info *info)
9382{
9383 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009384 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009385 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009386 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9387
9388 if (rtnl)
9389 rtnl_lock();
9390
9391 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009392 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009393 if (IS_ERR(rdev)) {
9394 if (rtnl)
9395 rtnl_unlock();
9396 return PTR_ERR(rdev);
9397 }
9398 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009399 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9400 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009401 ASSERT_RTNL();
9402
Johannes Berg89a54e42012-06-15 14:33:17 +02009403 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9404 info->attrs);
9405 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009406 if (rtnl)
9407 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009408 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009409 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009410
Johannes Berg89a54e42012-06-15 14:33:17 +02009411 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009412 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009413
Johannes Berg1bf614e2012-06-15 15:23:36 +02009414 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9415 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009416 if (rtnl)
9417 rtnl_unlock();
9418 return -EINVAL;
9419 }
9420
9421 info->user_ptr[1] = dev;
9422 } else {
9423 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009424 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009425
Johannes Berg1bf614e2012-06-15 15:23:36 +02009426 if (dev) {
9427 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9428 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009429 if (rtnl)
9430 rtnl_unlock();
9431 return -ENETDOWN;
9432 }
9433
9434 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009435 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9436 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009437 if (rtnl)
9438 rtnl_unlock();
9439 return -ENETDOWN;
9440 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009441 }
9442
Johannes Berg4c476992010-10-04 21:36:35 +02009443 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009444 }
9445
9446 return 0;
9447}
9448
Johannes Bergf84f7712013-11-14 17:14:45 +01009449static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009450 struct genl_info *info)
9451{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009452 if (info->user_ptr[1]) {
9453 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9454 struct wireless_dev *wdev = info->user_ptr[1];
9455
9456 if (wdev->netdev)
9457 dev_put(wdev->netdev);
9458 } else {
9459 dev_put(info->user_ptr[1]);
9460 }
9461 }
Johannes Berg4c476992010-10-04 21:36:35 +02009462 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9463 rtnl_unlock();
9464}
9465
Johannes Berg4534de82013-11-14 17:14:46 +01009466static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009467 {
9468 .cmd = NL80211_CMD_GET_WIPHY,
9469 .doit = nl80211_get_wiphy,
9470 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009471 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009472 .policy = nl80211_policy,
9473 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009474 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9475 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009476 },
9477 {
9478 .cmd = NL80211_CMD_SET_WIPHY,
9479 .doit = nl80211_set_wiphy,
9480 .policy = nl80211_policy,
9481 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009482 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009483 },
9484 {
9485 .cmd = NL80211_CMD_GET_INTERFACE,
9486 .doit = nl80211_get_interface,
9487 .dumpit = nl80211_dump_interface,
9488 .policy = nl80211_policy,
9489 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009490 .internal_flags = NL80211_FLAG_NEED_WDEV |
9491 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009492 },
9493 {
9494 .cmd = NL80211_CMD_SET_INTERFACE,
9495 .doit = nl80211_set_interface,
9496 .policy = nl80211_policy,
9497 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009498 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9499 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009500 },
9501 {
9502 .cmd = NL80211_CMD_NEW_INTERFACE,
9503 .doit = nl80211_new_interface,
9504 .policy = nl80211_policy,
9505 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009506 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9507 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009508 },
9509 {
9510 .cmd = NL80211_CMD_DEL_INTERFACE,
9511 .doit = nl80211_del_interface,
9512 .policy = nl80211_policy,
9513 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009514 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009515 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009516 },
Johannes Berg41ade002007-12-19 02:03:29 +01009517 {
9518 .cmd = NL80211_CMD_GET_KEY,
9519 .doit = nl80211_get_key,
9520 .policy = nl80211_policy,
9521 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009522 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009523 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009524 },
9525 {
9526 .cmd = NL80211_CMD_SET_KEY,
9527 .doit = nl80211_set_key,
9528 .policy = nl80211_policy,
9529 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009531 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009532 },
9533 {
9534 .cmd = NL80211_CMD_NEW_KEY,
9535 .doit = nl80211_new_key,
9536 .policy = nl80211_policy,
9537 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009539 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009540 },
9541 {
9542 .cmd = NL80211_CMD_DEL_KEY,
9543 .doit = nl80211_del_key,
9544 .policy = nl80211_policy,
9545 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009547 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009548 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009549 {
9550 .cmd = NL80211_CMD_SET_BEACON,
9551 .policy = nl80211_policy,
9552 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009553 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009555 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009556 },
9557 {
Johannes Berg88600202012-02-13 15:17:18 +01009558 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009559 .policy = nl80211_policy,
9560 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009561 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009562 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009563 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009564 },
9565 {
Johannes Berg88600202012-02-13 15:17:18 +01009566 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009567 .policy = nl80211_policy,
9568 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009569 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009570 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009571 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009572 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009573 {
9574 .cmd = NL80211_CMD_GET_STATION,
9575 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009576 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009577 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009578 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9579 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009580 },
9581 {
9582 .cmd = NL80211_CMD_SET_STATION,
9583 .doit = nl80211_set_station,
9584 .policy = nl80211_policy,
9585 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009586 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009587 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009588 },
9589 {
9590 .cmd = NL80211_CMD_NEW_STATION,
9591 .doit = nl80211_new_station,
9592 .policy = nl80211_policy,
9593 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009594 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009595 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009596 },
9597 {
9598 .cmd = NL80211_CMD_DEL_STATION,
9599 .doit = nl80211_del_station,
9600 .policy = nl80211_policy,
9601 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009603 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009604 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009605 {
9606 .cmd = NL80211_CMD_GET_MPATH,
9607 .doit = nl80211_get_mpath,
9608 .dumpit = nl80211_dump_mpath,
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,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009613 },
9614 {
9615 .cmd = NL80211_CMD_SET_MPATH,
9616 .doit = nl80211_set_mpath,
9617 .policy = nl80211_policy,
9618 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009620 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009621 },
9622 {
9623 .cmd = NL80211_CMD_NEW_MPATH,
9624 .doit = nl80211_new_mpath,
9625 .policy = nl80211_policy,
9626 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009627 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009628 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009629 },
9630 {
9631 .cmd = NL80211_CMD_DEL_MPATH,
9632 .doit = nl80211_del_mpath,
9633 .policy = nl80211_policy,
9634 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009635 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009636 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009637 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009638 {
9639 .cmd = NL80211_CMD_SET_BSS,
9640 .doit = nl80211_set_bss,
9641 .policy = nl80211_policy,
9642 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009644 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009645 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009646 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009647 .cmd = NL80211_CMD_GET_REG,
9648 .doit = nl80211_get_reg,
9649 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009650 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009651 /* can be retrieved by unprivileged users */
9652 },
9653 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009654 .cmd = NL80211_CMD_SET_REG,
9655 .doit = nl80211_set_reg,
9656 .policy = nl80211_policy,
9657 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009658 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009659 },
9660 {
9661 .cmd = NL80211_CMD_REQ_SET_REG,
9662 .doit = nl80211_req_set_reg,
9663 .policy = nl80211_policy,
9664 .flags = GENL_ADMIN_PERM,
9665 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009666 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009667 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9668 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009669 .policy = nl80211_policy,
9670 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009672 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009673 },
9674 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009675 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9676 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009677 .policy = nl80211_policy,
9678 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009680 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009681 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009682 {
Johannes Berg2a519312009-02-10 21:25:55 +01009683 .cmd = NL80211_CMD_TRIGGER_SCAN,
9684 .doit = nl80211_trigger_scan,
9685 .policy = nl80211_policy,
9686 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009687 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009688 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009689 },
9690 {
9691 .cmd = NL80211_CMD_GET_SCAN,
9692 .policy = nl80211_policy,
9693 .dumpit = nl80211_dump_scan,
9694 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009695 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009696 .cmd = NL80211_CMD_START_SCHED_SCAN,
9697 .doit = nl80211_start_sched_scan,
9698 .policy = nl80211_policy,
9699 .flags = GENL_ADMIN_PERM,
9700 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9701 NL80211_FLAG_NEED_RTNL,
9702 },
9703 {
9704 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9705 .doit = nl80211_stop_sched_scan,
9706 .policy = nl80211_policy,
9707 .flags = GENL_ADMIN_PERM,
9708 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9709 NL80211_FLAG_NEED_RTNL,
9710 },
9711 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009712 .cmd = NL80211_CMD_AUTHENTICATE,
9713 .doit = nl80211_authenticate,
9714 .policy = nl80211_policy,
9715 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009716 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009717 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009718 },
9719 {
9720 .cmd = NL80211_CMD_ASSOCIATE,
9721 .doit = nl80211_associate,
9722 .policy = nl80211_policy,
9723 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009724 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009725 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009726 },
9727 {
9728 .cmd = NL80211_CMD_DEAUTHENTICATE,
9729 .doit = nl80211_deauthenticate,
9730 .policy = nl80211_policy,
9731 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009732 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009733 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009734 },
9735 {
9736 .cmd = NL80211_CMD_DISASSOCIATE,
9737 .doit = nl80211_disassociate,
9738 .policy = nl80211_policy,
9739 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009740 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009741 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009742 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009743 {
9744 .cmd = NL80211_CMD_JOIN_IBSS,
9745 .doit = nl80211_join_ibss,
9746 .policy = nl80211_policy,
9747 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009748 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009749 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009750 },
9751 {
9752 .cmd = NL80211_CMD_LEAVE_IBSS,
9753 .doit = nl80211_leave_ibss,
9754 .policy = nl80211_policy,
9755 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009756 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009757 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009758 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009759#ifdef CONFIG_NL80211_TESTMODE
9760 {
9761 .cmd = NL80211_CMD_TESTMODE,
9762 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009763 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009764 .policy = nl80211_policy,
9765 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009766 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9767 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009768 },
9769#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009770 {
9771 .cmd = NL80211_CMD_CONNECT,
9772 .doit = nl80211_connect,
9773 .policy = nl80211_policy,
9774 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009775 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009776 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009777 },
9778 {
9779 .cmd = NL80211_CMD_DISCONNECT,
9780 .doit = nl80211_disconnect,
9781 .policy = nl80211_policy,
9782 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009783 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009784 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009785 },
Johannes Berg463d0182009-07-14 00:33:35 +02009786 {
9787 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9788 .doit = nl80211_wiphy_netns,
9789 .policy = nl80211_policy,
9790 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009791 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9792 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009793 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009794 {
9795 .cmd = NL80211_CMD_GET_SURVEY,
9796 .policy = nl80211_policy,
9797 .dumpit = nl80211_dump_survey,
9798 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009799 {
9800 .cmd = NL80211_CMD_SET_PMKSA,
9801 .doit = nl80211_setdel_pmksa,
9802 .policy = nl80211_policy,
9803 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009804 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009805 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009806 },
9807 {
9808 .cmd = NL80211_CMD_DEL_PMKSA,
9809 .doit = nl80211_setdel_pmksa,
9810 .policy = nl80211_policy,
9811 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009813 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009814 },
9815 {
9816 .cmd = NL80211_CMD_FLUSH_PMKSA,
9817 .doit = nl80211_flush_pmksa,
9818 .policy = nl80211_policy,
9819 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009821 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009822 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009823 {
9824 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9825 .doit = nl80211_remain_on_channel,
9826 .policy = nl80211_policy,
9827 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009828 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009829 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009830 },
9831 {
9832 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9833 .doit = nl80211_cancel_remain_on_channel,
9834 .policy = nl80211_policy,
9835 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009836 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009837 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009838 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009839 {
9840 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9841 .doit = nl80211_set_tx_bitrate_mask,
9842 .policy = nl80211_policy,
9843 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009844 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9845 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009846 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009847 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009848 .cmd = NL80211_CMD_REGISTER_FRAME,
9849 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009850 .policy = nl80211_policy,
9851 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009852 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009853 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009854 },
9855 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009856 .cmd = NL80211_CMD_FRAME,
9857 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009858 .policy = nl80211_policy,
9859 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009860 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009861 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009862 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009863 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009864 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9865 .doit = nl80211_tx_mgmt_cancel_wait,
9866 .policy = nl80211_policy,
9867 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009868 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009869 NL80211_FLAG_NEED_RTNL,
9870 },
9871 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009872 .cmd = NL80211_CMD_SET_POWER_SAVE,
9873 .doit = nl80211_set_power_save,
9874 .policy = nl80211_policy,
9875 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009876 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9877 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009878 },
9879 {
9880 .cmd = NL80211_CMD_GET_POWER_SAVE,
9881 .doit = nl80211_get_power_save,
9882 .policy = nl80211_policy,
9883 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009884 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9885 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009886 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009887 {
9888 .cmd = NL80211_CMD_SET_CQM,
9889 .doit = nl80211_set_cqm,
9890 .policy = nl80211_policy,
9891 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009892 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9893 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009894 },
Johannes Bergf444de02010-05-05 15:25:02 +02009895 {
9896 .cmd = NL80211_CMD_SET_CHANNEL,
9897 .doit = nl80211_set_channel,
9898 .policy = nl80211_policy,
9899 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009900 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9901 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009902 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009903 {
9904 .cmd = NL80211_CMD_SET_WDS_PEER,
9905 .doit = nl80211_set_wds_peer,
9906 .policy = nl80211_policy,
9907 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009908 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9909 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009910 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009911 {
9912 .cmd = NL80211_CMD_JOIN_MESH,
9913 .doit = nl80211_join_mesh,
9914 .policy = nl80211_policy,
9915 .flags = GENL_ADMIN_PERM,
9916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9917 NL80211_FLAG_NEED_RTNL,
9918 },
9919 {
9920 .cmd = NL80211_CMD_LEAVE_MESH,
9921 .doit = nl80211_leave_mesh,
9922 .policy = nl80211_policy,
9923 .flags = GENL_ADMIN_PERM,
9924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9925 NL80211_FLAG_NEED_RTNL,
9926 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009927#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009928 {
9929 .cmd = NL80211_CMD_GET_WOWLAN,
9930 .doit = nl80211_get_wowlan,
9931 .policy = nl80211_policy,
9932 /* can be retrieved by unprivileged users */
9933 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9934 NL80211_FLAG_NEED_RTNL,
9935 },
9936 {
9937 .cmd = NL80211_CMD_SET_WOWLAN,
9938 .doit = nl80211_set_wowlan,
9939 .policy = nl80211_policy,
9940 .flags = GENL_ADMIN_PERM,
9941 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9942 NL80211_FLAG_NEED_RTNL,
9943 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009944#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009945 {
9946 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9947 .doit = nl80211_set_rekey_data,
9948 .policy = nl80211_policy,
9949 .flags = GENL_ADMIN_PERM,
9950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9951 NL80211_FLAG_NEED_RTNL,
9952 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009953 {
9954 .cmd = NL80211_CMD_TDLS_MGMT,
9955 .doit = nl80211_tdls_mgmt,
9956 .policy = nl80211_policy,
9957 .flags = GENL_ADMIN_PERM,
9958 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9959 NL80211_FLAG_NEED_RTNL,
9960 },
9961 {
9962 .cmd = NL80211_CMD_TDLS_OPER,
9963 .doit = nl80211_tdls_oper,
9964 .policy = nl80211_policy,
9965 .flags = GENL_ADMIN_PERM,
9966 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9967 NL80211_FLAG_NEED_RTNL,
9968 },
Johannes Berg28946da2011-11-04 11:18:12 +01009969 {
9970 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9971 .doit = nl80211_register_unexpected_frame,
9972 .policy = nl80211_policy,
9973 .flags = GENL_ADMIN_PERM,
9974 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9975 NL80211_FLAG_NEED_RTNL,
9976 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009977 {
9978 .cmd = NL80211_CMD_PROBE_CLIENT,
9979 .doit = nl80211_probe_client,
9980 .policy = nl80211_policy,
9981 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009982 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009983 NL80211_FLAG_NEED_RTNL,
9984 },
Johannes Berg5e760232011-11-04 11:18:17 +01009985 {
9986 .cmd = NL80211_CMD_REGISTER_BEACONS,
9987 .doit = nl80211_register_beacons,
9988 .policy = nl80211_policy,
9989 .flags = GENL_ADMIN_PERM,
9990 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9991 NL80211_FLAG_NEED_RTNL,
9992 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009993 {
9994 .cmd = NL80211_CMD_SET_NOACK_MAP,
9995 .doit = nl80211_set_noack_map,
9996 .policy = nl80211_policy,
9997 .flags = GENL_ADMIN_PERM,
9998 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9999 NL80211_FLAG_NEED_RTNL,
10000 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010001 {
10002 .cmd = NL80211_CMD_START_P2P_DEVICE,
10003 .doit = nl80211_start_p2p_device,
10004 .policy = nl80211_policy,
10005 .flags = GENL_ADMIN_PERM,
10006 .internal_flags = NL80211_FLAG_NEED_WDEV |
10007 NL80211_FLAG_NEED_RTNL,
10008 },
10009 {
10010 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10011 .doit = nl80211_stop_p2p_device,
10012 .policy = nl80211_policy,
10013 .flags = GENL_ADMIN_PERM,
10014 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10015 NL80211_FLAG_NEED_RTNL,
10016 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010017 {
10018 .cmd = NL80211_CMD_SET_MCAST_RATE,
10019 .doit = nl80211_set_mcast_rate,
10020 .policy = nl80211_policy,
10021 .flags = GENL_ADMIN_PERM,
10022 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10023 NL80211_FLAG_NEED_RTNL,
10024 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010025 {
10026 .cmd = NL80211_CMD_SET_MAC_ACL,
10027 .doit = nl80211_set_mac_acl,
10028 .policy = nl80211_policy,
10029 .flags = GENL_ADMIN_PERM,
10030 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10031 NL80211_FLAG_NEED_RTNL,
10032 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010033 {
10034 .cmd = NL80211_CMD_RADAR_DETECT,
10035 .doit = nl80211_start_radar_detection,
10036 .policy = nl80211_policy,
10037 .flags = GENL_ADMIN_PERM,
10038 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10039 NL80211_FLAG_NEED_RTNL,
10040 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010041 {
10042 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10043 .doit = nl80211_get_protocol_features,
10044 .policy = nl80211_policy,
10045 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010046 {
10047 .cmd = NL80211_CMD_UPDATE_FT_IES,
10048 .doit = nl80211_update_ft_ies,
10049 .policy = nl80211_policy,
10050 .flags = GENL_ADMIN_PERM,
10051 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10052 NL80211_FLAG_NEED_RTNL,
10053 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010054 {
10055 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10056 .doit = nl80211_crit_protocol_start,
10057 .policy = nl80211_policy,
10058 .flags = GENL_ADMIN_PERM,
10059 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10060 NL80211_FLAG_NEED_RTNL,
10061 },
10062 {
10063 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10064 .doit = nl80211_crit_protocol_stop,
10065 .policy = nl80211_policy,
10066 .flags = GENL_ADMIN_PERM,
10067 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10068 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010069 },
10070 {
10071 .cmd = NL80211_CMD_GET_COALESCE,
10072 .doit = nl80211_get_coalesce,
10073 .policy = nl80211_policy,
10074 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10075 NL80211_FLAG_NEED_RTNL,
10076 },
10077 {
10078 .cmd = NL80211_CMD_SET_COALESCE,
10079 .doit = nl80211_set_coalesce,
10080 .policy = nl80211_policy,
10081 .flags = GENL_ADMIN_PERM,
10082 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10083 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010084 },
10085 {
10086 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10087 .doit = nl80211_channel_switch,
10088 .policy = nl80211_policy,
10089 .flags = GENL_ADMIN_PERM,
10090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10091 NL80211_FLAG_NEED_RTNL,
10092 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010093 {
10094 .cmd = NL80211_CMD_VENDOR,
10095 .doit = nl80211_vendor_cmd,
10096 .policy = nl80211_policy,
10097 .flags = GENL_ADMIN_PERM,
10098 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10099 NL80211_FLAG_NEED_RTNL,
10100 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010101 {
10102 .cmd = NL80211_CMD_SET_QOS_MAP,
10103 .doit = nl80211_set_qos_map,
10104 .policy = nl80211_policy,
10105 .flags = GENL_ADMIN_PERM,
10106 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10107 NL80211_FLAG_NEED_RTNL,
10108 },
Johannes Berg55682962007-09-20 13:09:35 -040010109};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010110
Johannes Berg55682962007-09-20 13:09:35 -040010111/* notification functions */
10112
Johannes Berg3bb20552014-05-26 13:52:25 +020010113void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10114 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010115{
10116 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010117 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010118
Johannes Berg3bb20552014-05-26 13:52:25 +020010119 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10120 cmd != NL80211_CMD_DEL_WIPHY);
10121
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010122 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010123 if (!msg)
10124 return;
10125
Johannes Berg3bb20552014-05-26 13:52:25 +020010126 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010127 nlmsg_free(msg);
10128 return;
10129 }
10130
Johannes Berg68eb5502013-11-19 15:19:38 +010010131 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010132 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010133}
10134
Johannes Berg362a4152009-05-24 16:43:15 +020010135static int nl80211_add_scan_req(struct sk_buff *msg,
10136 struct cfg80211_registered_device *rdev)
10137{
10138 struct cfg80211_scan_request *req = rdev->scan_req;
10139 struct nlattr *nest;
10140 int i;
10141
10142 if (WARN_ON(!req))
10143 return 0;
10144
10145 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10146 if (!nest)
10147 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010148 for (i = 0; i < req->n_ssids; i++) {
10149 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10150 goto nla_put_failure;
10151 }
Johannes Berg362a4152009-05-24 16:43:15 +020010152 nla_nest_end(msg, nest);
10153
10154 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10155 if (!nest)
10156 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010157 for (i = 0; i < req->n_channels; i++) {
10158 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10159 goto nla_put_failure;
10160 }
Johannes Berg362a4152009-05-24 16:43:15 +020010161 nla_nest_end(msg, nest);
10162
David S. Miller9360ffd2012-03-29 04:41:26 -040010163 if (req->ie &&
10164 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10165 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010166
Johannes Bergae917c92013-10-25 11:05:22 +020010167 if (req->flags &&
10168 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10169 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010170
Johannes Berg362a4152009-05-24 16:43:15 +020010171 return 0;
10172 nla_put_failure:
10173 return -ENOBUFS;
10174}
10175
Johannes Berga538e2d2009-06-16 19:56:42 +020010176static int nl80211_send_scan_msg(struct sk_buff *msg,
10177 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010178 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010179 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010180 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010181{
10182 void *hdr;
10183
Eric W. Biederman15e47302012-09-07 20:12:54 +000010184 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010185 if (!hdr)
10186 return -1;
10187
David S. Miller9360ffd2012-03-29 04:41:26 -040010188 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010189 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10190 wdev->netdev->ifindex)) ||
10191 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010192 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010193
Johannes Berg362a4152009-05-24 16:43:15 +020010194 /* ignore errors and send incomplete event anyway */
10195 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010196
10197 return genlmsg_end(msg, hdr);
10198
10199 nla_put_failure:
10200 genlmsg_cancel(msg, hdr);
10201 return -EMSGSIZE;
10202}
10203
Luciano Coelho807f8a82011-05-11 17:09:35 +030010204static int
10205nl80211_send_sched_scan_msg(struct sk_buff *msg,
10206 struct cfg80211_registered_device *rdev,
10207 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010208 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010209{
10210 void *hdr;
10211
Eric W. Biederman15e47302012-09-07 20:12:54 +000010212 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010213 if (!hdr)
10214 return -1;
10215
David S. Miller9360ffd2012-03-29 04:41:26 -040010216 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10217 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10218 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010219
10220 return genlmsg_end(msg, hdr);
10221
10222 nla_put_failure:
10223 genlmsg_cancel(msg, hdr);
10224 return -EMSGSIZE;
10225}
10226
Johannes Berga538e2d2009-06-16 19:56:42 +020010227void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010228 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010229{
10230 struct sk_buff *msg;
10231
Thomas Graf58050fc2012-06-28 03:57:45 +000010232 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010233 if (!msg)
10234 return;
10235
Johannes Bergfd014282012-06-18 19:17:03 +020010236 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010237 NL80211_CMD_TRIGGER_SCAN) < 0) {
10238 nlmsg_free(msg);
10239 return;
10240 }
10241
Johannes Berg68eb5502013-11-19 15:19:38 +010010242 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010243 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010244}
10245
Johannes Bergf9d15d12014-01-22 11:14:19 +020010246struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10247 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010248{
10249 struct sk_buff *msg;
10250
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010251 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010252 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010253 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010254
Johannes Bergfd014282012-06-18 19:17:03 +020010255 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010256 aborted ? NL80211_CMD_SCAN_ABORTED :
10257 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010258 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010259 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010260 }
10261
Johannes Bergf9d15d12014-01-22 11:14:19 +020010262 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010263}
10264
Johannes Bergf9d15d12014-01-22 11:14:19 +020010265void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10266 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010267{
Johannes Berg2a519312009-02-10 21:25:55 +010010268 if (!msg)
10269 return;
10270
Johannes Berg68eb5502013-11-19 15:19:38 +010010271 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010272 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010273}
10274
Luciano Coelho807f8a82011-05-11 17:09:35 +030010275void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10276 struct net_device *netdev)
10277{
10278 struct sk_buff *msg;
10279
10280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10281 if (!msg)
10282 return;
10283
10284 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10285 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10286 nlmsg_free(msg);
10287 return;
10288 }
10289
Johannes Berg68eb5502013-11-19 15:19:38 +010010290 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010291 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010292}
10293
10294void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10295 struct net_device *netdev, u32 cmd)
10296{
10297 struct sk_buff *msg;
10298
Thomas Graf58050fc2012-06-28 03:57:45 +000010299 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010300 if (!msg)
10301 return;
10302
10303 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10304 nlmsg_free(msg);
10305 return;
10306 }
10307
Johannes Berg68eb5502013-11-19 15:19:38 +010010308 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010309 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010310}
10311
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010312/*
10313 * This can happen on global regulatory changes or device specific settings
10314 * based on custom world regulatory domains.
10315 */
10316void nl80211_send_reg_change_event(struct regulatory_request *request)
10317{
10318 struct sk_buff *msg;
10319 void *hdr;
10320
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010321 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010322 if (!msg)
10323 return;
10324
10325 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10326 if (!hdr) {
10327 nlmsg_free(msg);
10328 return;
10329 }
10330
10331 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010332 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10333 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010334
David S. Miller9360ffd2012-03-29 04:41:26 -040010335 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10336 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10337 NL80211_REGDOM_TYPE_WORLD))
10338 goto nla_put_failure;
10339 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10340 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10341 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10342 goto nla_put_failure;
10343 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10344 request->intersect) {
10345 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10346 NL80211_REGDOM_TYPE_INTERSECTION))
10347 goto nla_put_failure;
10348 } else {
10349 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10350 NL80211_REGDOM_TYPE_COUNTRY) ||
10351 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10352 request->alpha2))
10353 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010354 }
10355
Johannes Bergf4173762012-12-03 18:23:37 +010010356 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010357 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10358 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010359
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010360 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010361
Johannes Bergbc43b282009-07-25 10:54:13 +020010362 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010363 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010364 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010365 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010366
10367 return;
10368
10369nla_put_failure:
10370 genlmsg_cancel(msg, hdr);
10371 nlmsg_free(msg);
10372}
10373
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010374static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10375 struct net_device *netdev,
10376 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010377 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010378{
10379 struct sk_buff *msg;
10380 void *hdr;
10381
Johannes Berge6d6e342009-07-01 21:26:47 +020010382 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010383 if (!msg)
10384 return;
10385
10386 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10387 if (!hdr) {
10388 nlmsg_free(msg);
10389 return;
10390 }
10391
David S. Miller9360ffd2012-03-29 04:41:26 -040010392 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10393 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10394 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10395 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010396
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010397 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010398
Johannes Berg68eb5502013-11-19 15:19:38 +010010399 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010400 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010401 return;
10402
10403 nla_put_failure:
10404 genlmsg_cancel(msg, hdr);
10405 nlmsg_free(msg);
10406}
10407
10408void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010409 struct net_device *netdev, const u8 *buf,
10410 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010411{
10412 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010413 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010414}
10415
10416void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10417 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010418 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010419{
Johannes Berge6d6e342009-07-01 21:26:47 +020010420 nl80211_send_mlme_event(rdev, netdev, buf, len,
10421 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010422}
10423
Jouni Malinen53b46b82009-03-27 20:53:56 +020010424void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010425 struct net_device *netdev, const u8 *buf,
10426 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010427{
10428 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010429 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010430}
10431
Jouni Malinen53b46b82009-03-27 20:53:56 +020010432void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10433 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010434 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010435{
10436 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010437 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010438}
10439
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010440void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10441 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010442{
Johannes Berg947add32013-02-22 22:05:20 +010010443 struct wireless_dev *wdev = dev->ieee80211_ptr;
10444 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010445 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010446 const struct ieee80211_mgmt *mgmt = (void *)buf;
10447 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010448
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010449 if (WARN_ON(len < 2))
10450 return;
10451
10452 if (ieee80211_is_deauth(mgmt->frame_control))
10453 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10454 else
10455 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10456
10457 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10458 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010459}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010460EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010461
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010462static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10463 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010464 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010465{
10466 struct sk_buff *msg;
10467 void *hdr;
10468
Johannes Berge6d6e342009-07-01 21:26:47 +020010469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010470 if (!msg)
10471 return;
10472
10473 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10474 if (!hdr) {
10475 nlmsg_free(msg);
10476 return;
10477 }
10478
David S. Miller9360ffd2012-03-29 04:41:26 -040010479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10480 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10481 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10482 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10483 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010484
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010485 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010486
Johannes Berg68eb5502013-11-19 15:19:38 +010010487 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010488 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010489 return;
10490
10491 nla_put_failure:
10492 genlmsg_cancel(msg, hdr);
10493 nlmsg_free(msg);
10494}
10495
10496void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010497 struct net_device *netdev, const u8 *addr,
10498 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010499{
10500 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010501 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010502}
10503
10504void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010505 struct net_device *netdev, const u8 *addr,
10506 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010507{
Johannes Berge6d6e342009-07-01 21:26:47 +020010508 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10509 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010510}
10511
Samuel Ortizb23aa672009-07-01 21:26:54 +020010512void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10513 struct net_device *netdev, const u8 *bssid,
10514 const u8 *req_ie, size_t req_ie_len,
10515 const u8 *resp_ie, size_t resp_ie_len,
10516 u16 status, gfp_t gfp)
10517{
10518 struct sk_buff *msg;
10519 void *hdr;
10520
Thomas Graf58050fc2012-06-28 03:57:45 +000010521 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010522 if (!msg)
10523 return;
10524
10525 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10526 if (!hdr) {
10527 nlmsg_free(msg);
10528 return;
10529 }
10530
David S. Miller9360ffd2012-03-29 04:41:26 -040010531 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10532 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10533 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10534 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10535 (req_ie &&
10536 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10537 (resp_ie &&
10538 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10539 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010540
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010541 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010542
Johannes Berg68eb5502013-11-19 15:19:38 +010010543 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010544 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010545 return;
10546
10547 nla_put_failure:
10548 genlmsg_cancel(msg, hdr);
10549 nlmsg_free(msg);
10550
10551}
10552
10553void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10554 struct net_device *netdev, const u8 *bssid,
10555 const u8 *req_ie, size_t req_ie_len,
10556 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10557{
10558 struct sk_buff *msg;
10559 void *hdr;
10560
Thomas Graf58050fc2012-06-28 03:57:45 +000010561 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010562 if (!msg)
10563 return;
10564
10565 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10566 if (!hdr) {
10567 nlmsg_free(msg);
10568 return;
10569 }
10570
David S. Miller9360ffd2012-03-29 04:41:26 -040010571 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10572 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10573 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10574 (req_ie &&
10575 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10576 (resp_ie &&
10577 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10578 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010579
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010580 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010581
Johannes Berg68eb5502013-11-19 15:19:38 +010010582 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010583 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010584 return;
10585
10586 nla_put_failure:
10587 genlmsg_cancel(msg, hdr);
10588 nlmsg_free(msg);
10589
10590}
10591
10592void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10593 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010594 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010595{
10596 struct sk_buff *msg;
10597 void *hdr;
10598
Thomas Graf58050fc2012-06-28 03:57:45 +000010599 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010600 if (!msg)
10601 return;
10602
10603 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10604 if (!hdr) {
10605 nlmsg_free(msg);
10606 return;
10607 }
10608
David S. Miller9360ffd2012-03-29 04:41:26 -040010609 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10610 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10611 (from_ap && reason &&
10612 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10613 (from_ap &&
10614 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10615 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10616 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010617
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010618 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010619
Johannes Berg68eb5502013-11-19 15:19:38 +010010620 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010621 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010622 return;
10623
10624 nla_put_failure:
10625 genlmsg_cancel(msg, hdr);
10626 nlmsg_free(msg);
10627
10628}
10629
Johannes Berg04a773a2009-04-19 21:24:32 +020010630void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10631 struct net_device *netdev, const u8 *bssid,
10632 gfp_t gfp)
10633{
10634 struct sk_buff *msg;
10635 void *hdr;
10636
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010637 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010638 if (!msg)
10639 return;
10640
10641 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10642 if (!hdr) {
10643 nlmsg_free(msg);
10644 return;
10645 }
10646
David S. Miller9360ffd2012-03-29 04:41:26 -040010647 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10648 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10649 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10650 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010651
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010652 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010653
Johannes Berg68eb5502013-11-19 15:19:38 +010010654 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010655 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010656 return;
10657
10658 nla_put_failure:
10659 genlmsg_cancel(msg, hdr);
10660 nlmsg_free(msg);
10661}
10662
Johannes Berg947add32013-02-22 22:05:20 +010010663void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10664 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010665{
Johannes Berg947add32013-02-22 22:05:20 +010010666 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010667 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010668 struct sk_buff *msg;
10669 void *hdr;
10670
Johannes Berg947add32013-02-22 22:05:20 +010010671 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10672 return;
10673
10674 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10675
Javier Cardonac93b5e72011-04-07 15:08:34 -070010676 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10677 if (!msg)
10678 return;
10679
10680 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10681 if (!hdr) {
10682 nlmsg_free(msg);
10683 return;
10684 }
10685
David S. Miller9360ffd2012-03-29 04:41:26 -040010686 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010687 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10688 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010689 (ie_len && ie &&
10690 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10691 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010692
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010693 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010694
Johannes Berg68eb5502013-11-19 15:19:38 +010010695 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010696 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010697 return;
10698
10699 nla_put_failure:
10700 genlmsg_cancel(msg, hdr);
10701 nlmsg_free(msg);
10702}
Johannes Berg947add32013-02-22 22:05:20 +010010703EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010704
Jouni Malinena3b8b052009-03-27 21:59:49 +020010705void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10706 struct net_device *netdev, const u8 *addr,
10707 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010708 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010709{
10710 struct sk_buff *msg;
10711 void *hdr;
10712
Johannes Berge6d6e342009-07-01 21:26:47 +020010713 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010714 if (!msg)
10715 return;
10716
10717 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10718 if (!hdr) {
10719 nlmsg_free(msg);
10720 return;
10721 }
10722
David S. Miller9360ffd2012-03-29 04:41:26 -040010723 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10724 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10725 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10726 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10727 (key_id != -1 &&
10728 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10729 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10730 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010731
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010732 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010733
Johannes Berg68eb5502013-11-19 15:19:38 +010010734 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010735 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010736 return;
10737
10738 nla_put_failure:
10739 genlmsg_cancel(msg, hdr);
10740 nlmsg_free(msg);
10741}
10742
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010743void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10744 struct ieee80211_channel *channel_before,
10745 struct ieee80211_channel *channel_after)
10746{
10747 struct sk_buff *msg;
10748 void *hdr;
10749 struct nlattr *nl_freq;
10750
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010752 if (!msg)
10753 return;
10754
10755 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10756 if (!hdr) {
10757 nlmsg_free(msg);
10758 return;
10759 }
10760
10761 /*
10762 * Since we are applying the beacon hint to a wiphy we know its
10763 * wiphy_idx is valid
10764 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010765 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10766 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010767
10768 /* Before */
10769 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10770 if (!nl_freq)
10771 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010772 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010773 goto nla_put_failure;
10774 nla_nest_end(msg, nl_freq);
10775
10776 /* After */
10777 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10778 if (!nl_freq)
10779 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010780 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010781 goto nla_put_failure;
10782 nla_nest_end(msg, nl_freq);
10783
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010784 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010785
Johannes Berg463d0182009-07-14 00:33:35 +020010786 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010787 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010788 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010789 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010790
10791 return;
10792
10793nla_put_failure:
10794 genlmsg_cancel(msg, hdr);
10795 nlmsg_free(msg);
10796}
10797
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010798static void nl80211_send_remain_on_chan_event(
10799 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010800 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010801 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010802 unsigned int duration, gfp_t gfp)
10803{
10804 struct sk_buff *msg;
10805 void *hdr;
10806
10807 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10808 if (!msg)
10809 return;
10810
10811 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10812 if (!hdr) {
10813 nlmsg_free(msg);
10814 return;
10815 }
10816
David S. Miller9360ffd2012-03-29 04:41:26 -040010817 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010818 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10819 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010820 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010821 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010822 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10823 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010824 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10825 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010826
David S. Miller9360ffd2012-03-29 04:41:26 -040010827 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10828 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10829 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010830
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010831 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010832
Johannes Berg68eb5502013-11-19 15:19:38 +010010833 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010834 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010835 return;
10836
10837 nla_put_failure:
10838 genlmsg_cancel(msg, hdr);
10839 nlmsg_free(msg);
10840}
10841
Johannes Berg947add32013-02-22 22:05:20 +010010842void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10843 struct ieee80211_channel *chan,
10844 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010845{
Johannes Berg947add32013-02-22 22:05:20 +010010846 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010847 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010848
10849 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010850 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010851 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010852 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010853}
Johannes Berg947add32013-02-22 22:05:20 +010010854EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010855
Johannes Berg947add32013-02-22 22:05:20 +010010856void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10857 struct ieee80211_channel *chan,
10858 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010859{
Johannes Berg947add32013-02-22 22:05:20 +010010860 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010861 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010010862
10863 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010864 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010865 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010866}
Johannes Berg947add32013-02-22 22:05:20 +010010867EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010868
Johannes Berg947add32013-02-22 22:05:20 +010010869void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10870 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010871{
Johannes Berg947add32013-02-22 22:05:20 +010010872 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010873 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010874 struct sk_buff *msg;
10875
Johannes Berg947add32013-02-22 22:05:20 +010010876 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10877
Thomas Graf58050fc2012-06-28 03:57:45 +000010878 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010879 if (!msg)
10880 return;
10881
John W. Linville66266b32012-03-15 13:25:41 -040010882 if (nl80211_send_station(msg, 0, 0, 0,
10883 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010884 nlmsg_free(msg);
10885 return;
10886 }
10887
Johannes Berg68eb5502013-11-19 15:19:38 +010010888 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010889 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010890}
Johannes Berg947add32013-02-22 22:05:20 +010010891EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010892
Johannes Berg947add32013-02-22 22:05:20 +010010893void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010894{
Johannes Berg947add32013-02-22 22:05:20 +010010895 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010896 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010897 struct sk_buff *msg;
10898 void *hdr;
10899
Johannes Berg947add32013-02-22 22:05:20 +010010900 trace_cfg80211_del_sta(dev, mac_addr);
10901
Thomas Graf58050fc2012-06-28 03:57:45 +000010902 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010903 if (!msg)
10904 return;
10905
10906 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10907 if (!hdr) {
10908 nlmsg_free(msg);
10909 return;
10910 }
10911
David S. Miller9360ffd2012-03-29 04:41:26 -040010912 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10913 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10914 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010915
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010916 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010917
Johannes Berg68eb5502013-11-19 15:19:38 +010010918 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010919 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010920 return;
10921
10922 nla_put_failure:
10923 genlmsg_cancel(msg, hdr);
10924 nlmsg_free(msg);
10925}
Johannes Berg947add32013-02-22 22:05:20 +010010926EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010927
Johannes Berg947add32013-02-22 22:05:20 +010010928void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10929 enum nl80211_connect_failed_reason reason,
10930 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010931{
Johannes Berg947add32013-02-22 22:05:20 +010010932 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010933 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010934 struct sk_buff *msg;
10935 void *hdr;
10936
10937 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10938 if (!msg)
10939 return;
10940
10941 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10942 if (!hdr) {
10943 nlmsg_free(msg);
10944 return;
10945 }
10946
10947 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10948 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10949 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10950 goto nla_put_failure;
10951
10952 genlmsg_end(msg, hdr);
10953
Johannes Berg68eb5502013-11-19 15:19:38 +010010954 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010955 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010956 return;
10957
10958 nla_put_failure:
10959 genlmsg_cancel(msg, hdr);
10960 nlmsg_free(msg);
10961}
Johannes Berg947add32013-02-22 22:05:20 +010010962EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010963
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010964static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10965 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010966{
10967 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010968 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010010969 struct sk_buff *msg;
10970 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010971 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010972
Eric W. Biederman15e47302012-09-07 20:12:54 +000010973 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010974 return false;
10975
10976 msg = nlmsg_new(100, gfp);
10977 if (!msg)
10978 return true;
10979
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010980 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010981 if (!hdr) {
10982 nlmsg_free(msg);
10983 return true;
10984 }
10985
David S. Miller9360ffd2012-03-29 04:41:26 -040010986 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10987 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10988 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10989 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010990
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010991 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010992 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010993 return true;
10994
10995 nla_put_failure:
10996 genlmsg_cancel(msg, hdr);
10997 nlmsg_free(msg);
10998 return true;
10999}
11000
Johannes Berg947add32013-02-22 22:05:20 +010011001bool cfg80211_rx_spurious_frame(struct net_device *dev,
11002 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011003{
Johannes Berg947add32013-02-22 22:05:20 +010011004 struct wireless_dev *wdev = dev->ieee80211_ptr;
11005 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011006
Johannes Berg947add32013-02-22 22:05:20 +010011007 trace_cfg80211_rx_spurious_frame(dev, addr);
11008
11009 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11010 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11011 trace_cfg80211_return_bool(false);
11012 return false;
11013 }
11014 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11015 addr, gfp);
11016 trace_cfg80211_return_bool(ret);
11017 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011018}
Johannes Berg947add32013-02-22 22:05:20 +010011019EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11020
11021bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11022 const u8 *addr, gfp_t gfp)
11023{
11024 struct wireless_dev *wdev = dev->ieee80211_ptr;
11025 bool ret;
11026
11027 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11028
11029 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11030 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11031 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11032 trace_cfg80211_return_bool(false);
11033 return false;
11034 }
11035 ret = __nl80211_unexpected_frame(dev,
11036 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11037 addr, gfp);
11038 trace_cfg80211_return_bool(ret);
11039 return ret;
11040}
11041EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011042
Johannes Berg2e161f72010-08-12 15:38:38 +020011043int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011044 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011045 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011046 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011047{
Johannes Berg71bbc992012-06-15 15:30:18 +020011048 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011049 struct sk_buff *msg;
11050 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011051
11052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11053 if (!msg)
11054 return -ENOMEM;
11055
Johannes Berg2e161f72010-08-12 15:38:38 +020011056 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011057 if (!hdr) {
11058 nlmsg_free(msg);
11059 return -ENOMEM;
11060 }
11061
David S. Miller9360ffd2012-03-29 04:41:26 -040011062 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011063 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11064 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011065 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011066 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11067 (sig_dbm &&
11068 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011069 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11070 (flags &&
11071 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011072 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011073
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011074 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011075
Eric W. Biederman15e47302012-09-07 20:12:54 +000011076 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011077
11078 nla_put_failure:
11079 genlmsg_cancel(msg, hdr);
11080 nlmsg_free(msg);
11081 return -ENOBUFS;
11082}
11083
Johannes Berg947add32013-02-22 22:05:20 +010011084void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11085 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011086{
Johannes Berg947add32013-02-22 22:05:20 +010011087 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011088 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011089 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011090 struct sk_buff *msg;
11091 void *hdr;
11092
Johannes Berg947add32013-02-22 22:05:20 +010011093 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11094
Jouni Malinen026331c2010-02-15 12:53:10 +020011095 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11096 if (!msg)
11097 return;
11098
Johannes Berg2e161f72010-08-12 15:38:38 +020011099 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011100 if (!hdr) {
11101 nlmsg_free(msg);
11102 return;
11103 }
11104
David S. Miller9360ffd2012-03-29 04:41:26 -040011105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011106 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11107 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011108 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011109 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11110 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11111 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11112 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011113
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011114 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011115
Johannes Berg68eb5502013-11-19 15:19:38 +010011116 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011117 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011118 return;
11119
11120 nla_put_failure:
11121 genlmsg_cancel(msg, hdr);
11122 nlmsg_free(msg);
11123}
Johannes Berg947add32013-02-22 22:05:20 +010011124EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011125
Johannes Berg947add32013-02-22 22:05:20 +010011126void cfg80211_cqm_rssi_notify(struct net_device *dev,
11127 enum nl80211_cqm_rssi_threshold_event rssi_event,
11128 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011129{
Johannes Berg947add32013-02-22 22:05:20 +010011130 struct wireless_dev *wdev = dev->ieee80211_ptr;
11131 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011132 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011133 struct sk_buff *msg;
11134 struct nlattr *pinfoattr;
11135 void *hdr;
11136
Johannes Berg947add32013-02-22 22:05:20 +010011137 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11138
Thomas Graf58050fc2012-06-28 03:57:45 +000011139 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011140 if (!msg)
11141 return;
11142
11143 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11144 if (!hdr) {
11145 nlmsg_free(msg);
11146 return;
11147 }
11148
David S. Miller9360ffd2012-03-29 04:41:26 -040011149 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011150 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011151 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011152
11153 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11154 if (!pinfoattr)
11155 goto nla_put_failure;
11156
David S. Miller9360ffd2012-03-29 04:41:26 -040011157 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11158 rssi_event))
11159 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011160
11161 nla_nest_end(msg, pinfoattr);
11162
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011163 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011164
Johannes Berg68eb5502013-11-19 15:19:38 +010011165 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011166 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011167 return;
11168
11169 nla_put_failure:
11170 genlmsg_cancel(msg, hdr);
11171 nlmsg_free(msg);
11172}
Johannes Berg947add32013-02-22 22:05:20 +010011173EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011174
Johannes Berg947add32013-02-22 22:05:20 +010011175static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11176 struct net_device *netdev, const u8 *bssid,
11177 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011178{
11179 struct sk_buff *msg;
11180 struct nlattr *rekey_attr;
11181 void *hdr;
11182
Thomas Graf58050fc2012-06-28 03:57:45 +000011183 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011184 if (!msg)
11185 return;
11186
11187 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11188 if (!hdr) {
11189 nlmsg_free(msg);
11190 return;
11191 }
11192
David S. Miller9360ffd2012-03-29 04:41:26 -040011193 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11194 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11195 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11196 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011197
11198 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11199 if (!rekey_attr)
11200 goto nla_put_failure;
11201
David S. Miller9360ffd2012-03-29 04:41:26 -040011202 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11203 NL80211_REPLAY_CTR_LEN, replay_ctr))
11204 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011205
11206 nla_nest_end(msg, rekey_attr);
11207
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011208 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011209
Johannes Berg68eb5502013-11-19 15:19:38 +010011210 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011211 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011212 return;
11213
11214 nla_put_failure:
11215 genlmsg_cancel(msg, hdr);
11216 nlmsg_free(msg);
11217}
11218
Johannes Berg947add32013-02-22 22:05:20 +010011219void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11220 const u8 *replay_ctr, gfp_t gfp)
11221{
11222 struct wireless_dev *wdev = dev->ieee80211_ptr;
11223 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011224 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011225
11226 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11227 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11228}
11229EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11230
11231static void
11232nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11233 struct net_device *netdev, int index,
11234 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011235{
11236 struct sk_buff *msg;
11237 struct nlattr *attr;
11238 void *hdr;
11239
Thomas Graf58050fc2012-06-28 03:57:45 +000011240 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011241 if (!msg)
11242 return;
11243
11244 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11245 if (!hdr) {
11246 nlmsg_free(msg);
11247 return;
11248 }
11249
David S. Miller9360ffd2012-03-29 04:41:26 -040011250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11251 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11252 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011253
11254 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11255 if (!attr)
11256 goto nla_put_failure;
11257
David S. Miller9360ffd2012-03-29 04:41:26 -040011258 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11259 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11260 (preauth &&
11261 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11262 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011263
11264 nla_nest_end(msg, attr);
11265
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011266 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011267
Johannes Berg68eb5502013-11-19 15:19:38 +010011268 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011269 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011270 return;
11271
11272 nla_put_failure:
11273 genlmsg_cancel(msg, hdr);
11274 nlmsg_free(msg);
11275}
11276
Johannes Berg947add32013-02-22 22:05:20 +010011277void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11278 const u8 *bssid, bool preauth, gfp_t gfp)
11279{
11280 struct wireless_dev *wdev = dev->ieee80211_ptr;
11281 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011282 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011283
11284 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
11285 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
11286}
11287EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
11288
11289static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
11290 struct net_device *netdev,
11291 struct cfg80211_chan_def *chandef,
11292 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070011293{
11294 struct sk_buff *msg;
11295 void *hdr;
11296
Thomas Graf58050fc2012-06-28 03:57:45 +000011297 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011298 if (!msg)
11299 return;
11300
11301 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
11302 if (!hdr) {
11303 nlmsg_free(msg);
11304 return;
11305 }
11306
Johannes Berg683b6d32012-11-08 21:25:48 +010011307 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11308 goto nla_put_failure;
11309
11310 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011311 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011312
11313 genlmsg_end(msg, hdr);
11314
Johannes Berg68eb5502013-11-19 15:19:38 +010011315 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011316 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011317 return;
11318
11319 nla_put_failure:
11320 genlmsg_cancel(msg, hdr);
11321 nlmsg_free(msg);
11322}
11323
Johannes Berg947add32013-02-22 22:05:20 +010011324void cfg80211_ch_switch_notify(struct net_device *dev,
11325 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011326{
Johannes Berg947add32013-02-22 22:05:20 +010011327 struct wireless_dev *wdev = dev->ieee80211_ptr;
11328 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011329 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011330
Simon Wunderliche487eae2013-11-21 18:19:51 +010011331 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011332
Simon Wunderliche487eae2013-11-21 18:19:51 +010011333 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011334
11335 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011336 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011337 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11338 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011339 return;
Johannes Berg947add32013-02-22 22:05:20 +010011340
Michal Kazior9e0e2962014-01-29 14:22:27 +010011341 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010011342 wdev->preset_chandef = *chandef;
Johannes Berg947add32013-02-22 22:05:20 +010011343 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011344}
11345EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11346
11347void cfg80211_cqm_txe_notify(struct net_device *dev,
11348 const u8 *peer, u32 num_packets,
11349 u32 rate, u32 intvl, gfp_t gfp)
11350{
11351 struct wireless_dev *wdev = dev->ieee80211_ptr;
11352 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011353 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011354 struct sk_buff *msg;
11355 struct nlattr *pinfoattr;
11356 void *hdr;
11357
11358 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11359 if (!msg)
11360 return;
11361
11362 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11363 if (!hdr) {
11364 nlmsg_free(msg);
11365 return;
11366 }
11367
11368 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011369 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011370 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11371 goto nla_put_failure;
11372
11373 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11374 if (!pinfoattr)
11375 goto nla_put_failure;
11376
11377 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11378 goto nla_put_failure;
11379
11380 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11381 goto nla_put_failure;
11382
11383 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11384 goto nla_put_failure;
11385
11386 nla_nest_end(msg, pinfoattr);
11387
11388 genlmsg_end(msg, hdr);
11389
Johannes Berg68eb5502013-11-19 15:19:38 +010011390 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011391 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011392 return;
11393
11394 nla_put_failure:
11395 genlmsg_cancel(msg, hdr);
11396 nlmsg_free(msg);
11397}
Johannes Berg947add32013-02-22 22:05:20 +010011398EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011399
11400void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011401nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011402 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011403 enum nl80211_radar_event event,
11404 struct net_device *netdev, gfp_t gfp)
11405{
11406 struct sk_buff *msg;
11407 void *hdr;
11408
11409 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11410 if (!msg)
11411 return;
11412
11413 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11414 if (!hdr) {
11415 nlmsg_free(msg);
11416 return;
11417 }
11418
11419 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11420 goto nla_put_failure;
11421
11422 /* NOP and radar events don't need a netdev parameter */
11423 if (netdev) {
11424 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11425
11426 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11427 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11428 goto nla_put_failure;
11429 }
11430
11431 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11432 goto nla_put_failure;
11433
11434 if (nl80211_send_chandef(msg, chandef))
11435 goto nla_put_failure;
11436
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011437 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011438
Johannes Berg68eb5502013-11-19 15:19:38 +010011439 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011440 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011441 return;
11442
11443 nla_put_failure:
11444 genlmsg_cancel(msg, hdr);
11445 nlmsg_free(msg);
11446}
11447
Johannes Berg947add32013-02-22 22:05:20 +010011448void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11449 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011450{
Johannes Berg947add32013-02-22 22:05:20 +010011451 struct wireless_dev *wdev = dev->ieee80211_ptr;
11452 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011453 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011454 struct sk_buff *msg;
11455 struct nlattr *pinfoattr;
11456 void *hdr;
11457
Johannes Berg947add32013-02-22 22:05:20 +010011458 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11459
Thomas Graf58050fc2012-06-28 03:57:45 +000011460 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011461 if (!msg)
11462 return;
11463
11464 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11465 if (!hdr) {
11466 nlmsg_free(msg);
11467 return;
11468 }
11469
David S. Miller9360ffd2012-03-29 04:41:26 -040011470 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011471 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011472 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11473 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011474
11475 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11476 if (!pinfoattr)
11477 goto nla_put_failure;
11478
David S. Miller9360ffd2012-03-29 04:41:26 -040011479 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11480 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011481
11482 nla_nest_end(msg, pinfoattr);
11483
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011484 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011485
Johannes Berg68eb5502013-11-19 15:19:38 +010011486 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011487 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011488 return;
11489
11490 nla_put_failure:
11491 genlmsg_cancel(msg, hdr);
11492 nlmsg_free(msg);
11493}
Johannes Berg947add32013-02-22 22:05:20 +010011494EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011495
Johannes Berg7f6cf312011-11-04 11:18:15 +010011496void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11497 u64 cookie, bool acked, gfp_t gfp)
11498{
11499 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011500 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011501 struct sk_buff *msg;
11502 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011503
Beni Lev4ee3e062012-08-27 12:49:39 +030011504 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11505
Thomas Graf58050fc2012-06-28 03:57:45 +000011506 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011507
Johannes Berg7f6cf312011-11-04 11:18:15 +010011508 if (!msg)
11509 return;
11510
11511 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11512 if (!hdr) {
11513 nlmsg_free(msg);
11514 return;
11515 }
11516
David S. Miller9360ffd2012-03-29 04:41:26 -040011517 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11518 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11519 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11520 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11521 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11522 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011523
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011524 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011525
Johannes Berg68eb5502013-11-19 15:19:38 +010011526 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011527 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011528 return;
11529
11530 nla_put_failure:
11531 genlmsg_cancel(msg, hdr);
11532 nlmsg_free(msg);
11533}
11534EXPORT_SYMBOL(cfg80211_probe_status);
11535
Johannes Berg5e760232011-11-04 11:18:17 +010011536void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11537 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011538 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011539{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011540 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010011541 struct sk_buff *msg;
11542 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011543 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011544
Beni Lev4ee3e062012-08-27 12:49:39 +030011545 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11546
Ben Greear37c73b52012-10-26 14:49:25 -070011547 spin_lock_bh(&rdev->beacon_registrations_lock);
11548 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11549 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11550 if (!msg) {
11551 spin_unlock_bh(&rdev->beacon_registrations_lock);
11552 return;
11553 }
Johannes Berg5e760232011-11-04 11:18:17 +010011554
Ben Greear37c73b52012-10-26 14:49:25 -070011555 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11556 if (!hdr)
11557 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011558
Ben Greear37c73b52012-10-26 14:49:25 -070011559 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11560 (freq &&
11561 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11562 (sig_dbm &&
11563 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11564 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11565 goto nla_put_failure;
11566
11567 genlmsg_end(msg, hdr);
11568
11569 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011570 }
Ben Greear37c73b52012-10-26 14:49:25 -070011571 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011572 return;
11573
11574 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011575 spin_unlock_bh(&rdev->beacon_registrations_lock);
11576 if (hdr)
11577 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011578 nlmsg_free(msg);
11579}
11580EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11581
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011582#ifdef CONFIG_PM
11583void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11584 struct cfg80211_wowlan_wakeup *wakeup,
11585 gfp_t gfp)
11586{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011587 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011588 struct sk_buff *msg;
11589 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011590 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011591
11592 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11593
11594 if (wakeup)
11595 size += wakeup->packet_present_len;
11596
11597 msg = nlmsg_new(size, gfp);
11598 if (!msg)
11599 return;
11600
11601 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11602 if (!hdr)
11603 goto free_msg;
11604
11605 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11606 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11607 goto free_msg;
11608
11609 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11610 wdev->netdev->ifindex))
11611 goto free_msg;
11612
11613 if (wakeup) {
11614 struct nlattr *reasons;
11615
11616 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011617 if (!reasons)
11618 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011619
11620 if (wakeup->disconnect &&
11621 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11622 goto free_msg;
11623 if (wakeup->magic_pkt &&
11624 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11625 goto free_msg;
11626 if (wakeup->gtk_rekey_failure &&
11627 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11628 goto free_msg;
11629 if (wakeup->eap_identity_req &&
11630 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11631 goto free_msg;
11632 if (wakeup->four_way_handshake &&
11633 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11634 goto free_msg;
11635 if (wakeup->rfkill_release &&
11636 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11637 goto free_msg;
11638
11639 if (wakeup->pattern_idx >= 0 &&
11640 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11641 wakeup->pattern_idx))
11642 goto free_msg;
11643
Johannes Bergae917c92013-10-25 11:05:22 +020011644 if (wakeup->tcp_match &&
11645 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11646 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011647
Johannes Bergae917c92013-10-25 11:05:22 +020011648 if (wakeup->tcp_connlost &&
11649 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11650 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011651
Johannes Bergae917c92013-10-25 11:05:22 +020011652 if (wakeup->tcp_nomoretokens &&
11653 nla_put_flag(msg,
11654 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11655 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011656
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011657 if (wakeup->packet) {
11658 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11659 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11660
11661 if (!wakeup->packet_80211) {
11662 pkt_attr =
11663 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11664 len_attr =
11665 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11666 }
11667
11668 if (wakeup->packet_len &&
11669 nla_put_u32(msg, len_attr, wakeup->packet_len))
11670 goto free_msg;
11671
11672 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11673 wakeup->packet))
11674 goto free_msg;
11675 }
11676
11677 nla_nest_end(msg, reasons);
11678 }
11679
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011680 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011681
Johannes Berg68eb5502013-11-19 15:19:38 +010011682 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011683 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011684 return;
11685
11686 free_msg:
11687 nlmsg_free(msg);
11688}
11689EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11690#endif
11691
Jouni Malinen3475b092012-11-16 22:49:57 +020011692void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11693 enum nl80211_tdls_operation oper,
11694 u16 reason_code, gfp_t gfp)
11695{
11696 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011697 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020011698 struct sk_buff *msg;
11699 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011700
11701 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11702 reason_code);
11703
11704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11705 if (!msg)
11706 return;
11707
11708 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11709 if (!hdr) {
11710 nlmsg_free(msg);
11711 return;
11712 }
11713
11714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11716 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11717 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11718 (reason_code > 0 &&
11719 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11720 goto nla_put_failure;
11721
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011722 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011723
Johannes Berg68eb5502013-11-19 15:19:38 +010011724 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011725 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011726 return;
11727
11728 nla_put_failure:
11729 genlmsg_cancel(msg, hdr);
11730 nlmsg_free(msg);
11731}
11732EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11733
Jouni Malinen026331c2010-02-15 12:53:10 +020011734static int nl80211_netlink_notify(struct notifier_block * nb,
11735 unsigned long state,
11736 void *_notify)
11737{
11738 struct netlink_notify *notify = _notify;
11739 struct cfg80211_registered_device *rdev;
11740 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011741 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011742
11743 if (state != NETLINK_URELEASE)
11744 return NOTIFY_DONE;
11745
11746 rcu_read_lock();
11747
Johannes Berg5e760232011-11-04 11:18:17 +010011748 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010011749 bool schedule_destroy_work = false;
11750
11751 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000011752 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011753
Johannes Berg78f22b62014-03-24 17:57:27 +010011754 if (wdev->owner_nlportid == notify->portid)
11755 schedule_destroy_work = true;
11756 }
11757
Ben Greear37c73b52012-10-26 14:49:25 -070011758 spin_lock_bh(&rdev->beacon_registrations_lock);
11759 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11760 list) {
11761 if (reg->nlportid == notify->portid) {
11762 list_del(&reg->list);
11763 kfree(reg);
11764 break;
11765 }
11766 }
11767 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010011768
11769 if (schedule_destroy_work) {
11770 struct cfg80211_iface_destroy *destroy;
11771
11772 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
11773 if (destroy) {
11774 destroy->nlportid = notify->portid;
11775 spin_lock(&rdev->destroy_list_lock);
11776 list_add(&destroy->list, &rdev->destroy_list);
11777 spin_unlock(&rdev->destroy_list_lock);
11778 schedule_work(&rdev->destroy_work);
11779 }
11780 }
Johannes Berg5e760232011-11-04 11:18:17 +010011781 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011782
11783 rcu_read_unlock();
11784
Zhao, Gang6784c7d2014-04-21 12:53:04 +080011785 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020011786}
11787
11788static struct notifier_block nl80211_netlink_notifier = {
11789 .notifier_call = nl80211_netlink_notify,
11790};
11791
Jouni Malinen355199e2013-02-27 17:14:27 +020011792void cfg80211_ft_event(struct net_device *netdev,
11793 struct cfg80211_ft_event_params *ft_event)
11794{
11795 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011796 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020011797 struct sk_buff *msg;
11798 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011799
11800 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11801
11802 if (!ft_event->target_ap)
11803 return;
11804
11805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11806 if (!msg)
11807 return;
11808
11809 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011810 if (!hdr)
11811 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011812
Johannes Bergae917c92013-10-25 11:05:22 +020011813 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11814 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11815 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11816 goto out;
11817
11818 if (ft_event->ies &&
11819 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11820 goto out;
11821 if (ft_event->ric_ies &&
11822 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11823 ft_event->ric_ies))
11824 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011825
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011826 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011827
Johannes Berg68eb5502013-11-19 15:19:38 +010011828 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011829 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011830 return;
11831 out:
11832 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011833}
11834EXPORT_SYMBOL(cfg80211_ft_event);
11835
Arend van Spriel5de17982013-04-18 15:49:00 +020011836void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11837{
11838 struct cfg80211_registered_device *rdev;
11839 struct sk_buff *msg;
11840 void *hdr;
11841 u32 nlportid;
11842
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011843 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020011844 if (!rdev->crit_proto_nlportid)
11845 return;
11846
11847 nlportid = rdev->crit_proto_nlportid;
11848 rdev->crit_proto_nlportid = 0;
11849
11850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11851 if (!msg)
11852 return;
11853
11854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11855 if (!hdr)
11856 goto nla_put_failure;
11857
11858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11859 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11860 goto nla_put_failure;
11861
11862 genlmsg_end(msg, hdr);
11863
11864 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11865 return;
11866
11867 nla_put_failure:
11868 if (hdr)
11869 genlmsg_cancel(msg, hdr);
11870 nlmsg_free(msg);
11871
11872}
11873EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11874
Johannes Berg348baf02014-01-24 14:06:29 +010011875void nl80211_send_ap_stopped(struct wireless_dev *wdev)
11876{
11877 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011878 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010011879 struct sk_buff *msg;
11880 void *hdr;
11881
11882 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11883 if (!msg)
11884 return;
11885
11886 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
11887 if (!hdr)
11888 goto out;
11889
11890 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11891 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
11892 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11893 goto out;
11894
11895 genlmsg_end(msg, hdr);
11896
11897 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
11898 NL80211_MCGRP_MLME, GFP_KERNEL);
11899 return;
11900 out:
11901 nlmsg_free(msg);
11902}
11903
Johannes Berg55682962007-09-20 13:09:35 -040011904/* initialisation/exit functions */
11905
11906int nl80211_init(void)
11907{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011908 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011909
Johannes Berg2a94fe42013-11-19 15:19:39 +010011910 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11911 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011912 if (err)
11913 return err;
11914
Jouni Malinen026331c2010-02-15 12:53:10 +020011915 err = netlink_register_notifier(&nl80211_netlink_notifier);
11916 if (err)
11917 goto err_out;
11918
Johannes Berg55682962007-09-20 13:09:35 -040011919 return 0;
11920 err_out:
11921 genl_unregister_family(&nl80211_fam);
11922 return err;
11923}
11924
11925void nl80211_exit(void)
11926{
Jouni Malinen026331c2010-02-15 12:53:10 +020011927 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011928 genl_unregister_family(&nl80211_fam);
11929}