blob: 04681a46eda8fc974997041e52b2709882755720 [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 Berg55682962007-09-20 13:09:35 -04005 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040011#include <linux/list.h>
12#include <linux/if_ether.h>
13#include <linux/ieee80211.h>
14#include <linux/nl80211.h>
15#include <linux/rtnetlink.h>
16#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010017#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020018#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040019#include <net/genetlink.h>
20#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020021#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010022#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040023#include "core.h"
24#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070025#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030026#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040027
Jouni Malinen5fb628e2011-08-10 23:54:35 +030028static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
29 struct genl_info *info,
30 struct cfg80211_crypto_settings *settings,
31 int cipher_limit);
32
Johannes Bergf84f7712013-11-14 17:14:45 +010033static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020034 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010035static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
39static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070040 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
41 .name = NL80211_GENL_NAME, /* have users key off the name instead */
42 .hdrsize = 0, /* no private header */
43 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040044 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020045 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020046 .pre_doit = nl80211_pre_doit,
47 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040048};
49
Johannes Berg2a94fe42013-11-19 15:19:39 +010050/* multicast groups */
51enum nl80211_multicast_groups {
52 NL80211_MCGRP_CONFIG,
53 NL80211_MCGRP_SCAN,
54 NL80211_MCGRP_REGULATORY,
55 NL80211_MCGRP_MLME,
56 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
57};
58
59static const struct genl_multicast_group nl80211_mcgrps[] = {
60 [NL80211_MCGRP_CONFIG] = { .name = "config", },
61 [NL80211_MCGRP_SCAN] = { .name = "scan", },
62 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
63 [NL80211_MCGRP_MLME] = { .name = "mlme", },
64#ifdef CONFIG_NL80211_TESTMODE
65 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
66#endif
67};
68
Johannes Berg89a54e42012-06-15 14:33:17 +020069/* returns ERR_PTR values */
70static struct wireless_dev *
71__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040072{
Johannes Berg89a54e42012-06-15 14:33:17 +020073 struct cfg80211_registered_device *rdev;
74 struct wireless_dev *result = NULL;
75 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
76 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
77 u64 wdev_id;
78 int wiphy_idx = -1;
79 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040080
Johannes Berg5fe231e2013-05-08 21:45:15 +020081 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040082
Johannes Berg89a54e42012-06-15 14:33:17 +020083 if (!have_ifidx && !have_wdev_id)
84 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (have_ifidx)
87 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
88 if (have_wdev_id) {
89 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
90 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040091 }
92
Johannes Berg89a54e42012-06-15 14:33:17 +020093 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
94 struct wireless_dev *wdev;
95
96 if (wiphy_net(&rdev->wiphy) != netns)
97 continue;
98
99 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
100 continue;
101
Johannes Berg89a54e42012-06-15 14:33:17 +0200102 list_for_each_entry(wdev, &rdev->wdev_list, list) {
103 if (have_ifidx && wdev->netdev &&
104 wdev->netdev->ifindex == ifidx) {
105 result = wdev;
106 break;
107 }
108 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
109 result = wdev;
110 break;
111 }
112 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200113
114 if (result)
115 break;
116 }
117
118 if (result)
119 return result;
120 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400121}
122
Johannes Berga9455402012-06-15 13:32:49 +0200123static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200124__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200125{
Johannes Berg7fee4772012-06-15 14:09:58 +0200126 struct cfg80211_registered_device *rdev = NULL, *tmp;
127 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200128
Johannes Berg5fe231e2013-05-08 21:45:15 +0200129 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200130
Johannes Berg878d9ec2012-06-15 14:18:32 +0200131 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200132 !attrs[NL80211_ATTR_IFINDEX] &&
133 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200134 return ERR_PTR(-EINVAL);
135
Johannes Berg878d9ec2012-06-15 14:18:32 +0200136 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200138 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200139
Johannes Berg89a54e42012-06-15 14:33:17 +0200140 if (attrs[NL80211_ATTR_WDEV]) {
141 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
142 struct wireless_dev *wdev;
143 bool found = false;
144
145 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
146 if (tmp) {
147 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200148 list_for_each_entry(wdev, &tmp->wdev_list, list) {
149 if (wdev->identifier != (u32)wdev_id)
150 continue;
151 found = true;
152 break;
153 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200154
155 if (!found)
156 tmp = NULL;
157
158 if (rdev && tmp != rdev)
159 return ERR_PTR(-EINVAL);
160 rdev = tmp;
161 }
162 }
163
Johannes Berg878d9ec2012-06-15 14:18:32 +0200164 if (attrs[NL80211_ATTR_IFINDEX]) {
165 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg4f7eff12012-06-15 14:14:22 +0200166 netdev = dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200167 if (netdev) {
168 if (netdev->ieee80211_ptr)
169 tmp = wiphy_to_dev(
170 netdev->ieee80211_ptr->wiphy);
171 else
172 tmp = NULL;
173
174 dev_put(netdev);
175
176 /* not wireless device -- return error */
177 if (!tmp)
178 return ERR_PTR(-EINVAL);
179
180 /* mismatch -- return error */
181 if (rdev && tmp != rdev)
182 return ERR_PTR(-EINVAL);
183
184 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200185 }
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
187
Johannes Berg4f7eff12012-06-15 14:14:22 +0200188 if (!rdev)
189 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200190
Johannes Berg4f7eff12012-06-15 14:14:22 +0200191 if (netns != wiphy_net(&rdev->wiphy))
192 return ERR_PTR(-ENODEV);
193
194 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200195}
196
197/*
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200200 *
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
203 */
204static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200205cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200206{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200207 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200208}
209
Johannes Berg55682962007-09-20 13:09:35 -0400210/* policy for the attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000211static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
Johannes Berg55682962007-09-20 13:09:35 -0400212 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
213 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700214 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200215 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100216
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200217 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100219 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
220 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200223 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
224 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Johannes Berg55682962007-09-20 13:09:35 -0400228
229 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
230 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
231 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100232
Eliad Pellere007b852011-11-24 18:13:56 +0200233 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
234 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Johannes Bergb9454e82009-07-08 13:29:08 +0200236 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100237 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
238 .len = WLAN_MAX_KEY_LEN },
239 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
240 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
241 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200242 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200243 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100244
245 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
246 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
247 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
248 .len = IEEE80211_MAX_DATA_LEN },
249 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100251 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
252 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
253 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
255 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100256 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100257 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200258 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800260 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300262
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700263 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
264 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
265
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300266 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200269 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
270 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100271 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300272
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800273 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700274 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700275
Johannes Berg6c739412011-11-03 09:27:01 +0100276 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200277
278 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
279 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
280 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100281 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
282 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200283
284 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
285 .len = IEEE80211_MAX_SSID_LEN },
286 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
287 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200288 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300289 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300290 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300291 [NL80211_ATTR_STA_FLAGS2] = {
292 .len = sizeof(struct nl80211_sta_flag_update),
293 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300294 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200297 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
298 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
299 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200300 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100301 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100302 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
303 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100304 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
305 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200306 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200307 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
308 .len = IEEE80211_MAX_DATA_LEN },
309 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200310 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200311 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200313 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200316 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900317 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100319 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100320 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100321 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200322 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700323 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300324 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200325 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200326 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300327 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300328 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
329 .len = IEEE80211_MAX_DATA_LEN },
330 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530332 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300333 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530334 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300335 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
337 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100340 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200341 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
342 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700343 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800344 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
345 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
346 .len = NL80211_HT_CAPABILITY_LEN
347 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100348 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530349 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530350 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200351 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700352 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300353 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000354 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700355 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100356 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
357 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530358 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
359 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200360 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
361 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100362 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100363 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
364 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
365 .len = NL80211_VHT_CAPABILITY_LEN,
366 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200367 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
368 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
369 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300370 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200371 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
373 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
374 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
375 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530376 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
377 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200378 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100379 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100380 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
381 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
382 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Johannes Berg55682962007-09-20 13:09:35 -0400383};
384
Johannes Berge31b8212010-10-05 19:39:30 +0200385/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000386static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200387 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200388 [NL80211_KEY_IDX] = { .type = NLA_U8 },
389 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200390 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200391 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
392 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200393 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100394 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
395};
396
397/* policy for the key default flags */
398static const struct nla_policy
399nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
400 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
401 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200402};
403
Johannes Bergff1b6e62011-05-04 15:37:28 +0200404/* policy for WoWLAN attributes */
405static const struct nla_policy
406nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
407 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
408 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
409 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
410 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200411 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
412 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
413 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
414 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100415 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
416};
417
418static const struct nla_policy
419nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
420 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
421 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
422 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
423 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
424 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
425 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
426 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
427 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
428 },
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
430 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
431 },
432 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
433 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
434 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200435};
436
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700437/* policy for coalesce rule attributes */
438static const struct nla_policy
439nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
440 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
441 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
442 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
443};
444
Johannes Berge5497d72011-07-05 16:35:40 +0200445/* policy for GTK rekey offload attributes */
446static const struct nla_policy
447nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
448 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
449 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
450 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
451};
452
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300453static const struct nla_policy
454nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200455 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300456 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700457 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300458};
459
Johannes Berg97990a02013-04-19 01:02:55 +0200460static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
461 struct netlink_callback *cb,
462 struct cfg80211_registered_device **rdev,
463 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100464{
Johannes Berg67748892010-10-04 21:14:06 +0200465 int err;
466
Johannes Berg67748892010-10-04 21:14:06 +0200467 rtnl_lock();
468
Johannes Berg97990a02013-04-19 01:02:55 +0200469 if (!cb->args[0]) {
470 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
471 nl80211_fam.attrbuf, nl80211_fam.maxattr,
472 nl80211_policy);
473 if (err)
474 goto out_unlock;
475
476 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
477 nl80211_fam.attrbuf);
478 if (IS_ERR(*wdev)) {
479 err = PTR_ERR(*wdev);
480 goto out_unlock;
481 }
482 *rdev = wiphy_to_dev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200483 /* 0 is the first index - add 1 to parse only once */
484 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200485 cb->args[1] = (*wdev)->identifier;
486 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200487 /* subtract the 1 again here */
488 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200489 struct wireless_dev *tmp;
490
491 if (!wiphy) {
492 err = -ENODEV;
493 goto out_unlock;
494 }
495 *rdev = wiphy_to_dev(wiphy);
496 *wdev = NULL;
497
Johannes Berg97990a02013-04-19 01:02:55 +0200498 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
499 if (tmp->identifier == cb->args[1]) {
500 *wdev = tmp;
501 break;
502 }
503 }
Johannes Berg97990a02013-04-19 01:02:55 +0200504
505 if (!*wdev) {
506 err = -ENODEV;
507 goto out_unlock;
508 }
Johannes Berg67748892010-10-04 21:14:06 +0200509 }
510
Johannes Berg67748892010-10-04 21:14:06 +0200511 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200512 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200513 rtnl_unlock();
514 return err;
515}
516
Johannes Berg97990a02013-04-19 01:02:55 +0200517static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200518{
Johannes Berg67748892010-10-04 21:14:06 +0200519 rtnl_unlock();
520}
521
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100522/* IE validation */
523static bool is_valid_ie_attr(const struct nlattr *attr)
524{
525 const u8 *pos;
526 int len;
527
528 if (!attr)
529 return true;
530
531 pos = nla_data(attr);
532 len = nla_len(attr);
533
534 while (len) {
535 u8 elemlen;
536
537 if (len < 2)
538 return false;
539 len -= 2;
540
541 elemlen = pos[1];
542 if (elemlen > len)
543 return false;
544
545 len -= elemlen;
546 pos += 2 + elemlen;
547 }
548
549 return true;
550}
551
Johannes Berg55682962007-09-20 13:09:35 -0400552/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000553static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400554 int flags, u8 cmd)
555{
556 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000557 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400558}
559
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400560static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100561 struct ieee80211_channel *chan,
562 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400563{
David S. Miller9360ffd2012-03-29 04:41:26 -0400564 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
565 chan->center_freq))
566 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400567
David S. Miller9360ffd2012-03-29 04:41:26 -0400568 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
569 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
570 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200571 if (chan->flags & IEEE80211_CHAN_NO_IR) {
572 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
573 goto nla_put_failure;
574 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
575 goto nla_put_failure;
576 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100577 if (chan->flags & IEEE80211_CHAN_RADAR) {
578 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
579 goto nla_put_failure;
580 if (large) {
581 u32 time;
582
583 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
584
585 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
586 chan->dfs_state))
587 goto nla_put_failure;
588 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
589 time))
590 goto nla_put_failure;
591 }
592 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400593
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100594 if (large) {
595 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
596 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
597 goto nla_put_failure;
598 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
599 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
600 goto nla_put_failure;
601 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
602 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
603 goto nla_put_failure;
604 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
605 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
606 goto nla_put_failure;
607 }
608
David S. Miller9360ffd2012-03-29 04:41:26 -0400609 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
610 DBM_TO_MBM(chan->max_power)))
611 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400612
613 return 0;
614
615 nla_put_failure:
616 return -ENOBUFS;
617}
618
Johannes Berg55682962007-09-20 13:09:35 -0400619/* netlink command implementations */
620
Johannes Bergb9454e82009-07-08 13:29:08 +0200621struct key_parse {
622 struct key_params p;
623 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200624 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200625 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100626 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200627};
628
629static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
630{
631 struct nlattr *tb[NL80211_KEY_MAX + 1];
632 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
633 nl80211_key_policy);
634 if (err)
635 return err;
636
637 k->def = !!tb[NL80211_KEY_DEFAULT];
638 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
639
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100640 if (k->def) {
641 k->def_uni = true;
642 k->def_multi = true;
643 }
644 if (k->defmgmt)
645 k->def_multi = true;
646
Johannes Bergb9454e82009-07-08 13:29:08 +0200647 if (tb[NL80211_KEY_IDX])
648 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
649
650 if (tb[NL80211_KEY_DATA]) {
651 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
652 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
653 }
654
655 if (tb[NL80211_KEY_SEQ]) {
656 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
657 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
658 }
659
660 if (tb[NL80211_KEY_CIPHER])
661 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
662
Johannes Berge31b8212010-10-05 19:39:30 +0200663 if (tb[NL80211_KEY_TYPE]) {
664 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
665 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
666 return -EINVAL;
667 }
668
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100669 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
670 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100671 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
672 tb[NL80211_KEY_DEFAULT_TYPES],
673 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100674 if (err)
675 return err;
676
677 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
678 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
679 }
680
Johannes Bergb9454e82009-07-08 13:29:08 +0200681 return 0;
682}
683
684static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
685{
686 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
687 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
688 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
689 }
690
691 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
692 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
693 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
694 }
695
696 if (info->attrs[NL80211_ATTR_KEY_IDX])
697 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
698
699 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
700 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
701
702 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
703 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
704
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100705 if (k->def) {
706 k->def_uni = true;
707 k->def_multi = true;
708 }
709 if (k->defmgmt)
710 k->def_multi = true;
711
Johannes Berge31b8212010-10-05 19:39:30 +0200712 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
713 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
714 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
715 return -EINVAL;
716 }
717
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100718 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
719 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
720 int err = nla_parse_nested(
721 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
722 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
723 nl80211_key_default_policy);
724 if (err)
725 return err;
726
727 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
728 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
729 }
730
Johannes Bergb9454e82009-07-08 13:29:08 +0200731 return 0;
732}
733
734static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
735{
736 int err;
737
738 memset(k, 0, sizeof(*k));
739 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200740 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200741
742 if (info->attrs[NL80211_ATTR_KEY])
743 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
744 else
745 err = nl80211_parse_key_old(info, k);
746
747 if (err)
748 return err;
749
750 if (k->def && k->defmgmt)
751 return -EINVAL;
752
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100753 if (k->defmgmt) {
754 if (k->def_uni || !k->def_multi)
755 return -EINVAL;
756 }
757
Johannes Bergb9454e82009-07-08 13:29:08 +0200758 if (k->idx != -1) {
759 if (k->defmgmt) {
760 if (k->idx < 4 || k->idx > 5)
761 return -EINVAL;
762 } else if (k->def) {
763 if (k->idx < 0 || k->idx > 3)
764 return -EINVAL;
765 } else {
766 if (k->idx < 0 || k->idx > 5)
767 return -EINVAL;
768 }
769 }
770
771 return 0;
772}
773
Johannes Bergfffd0932009-07-08 14:22:54 +0200774static struct cfg80211_cached_keys *
775nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530776 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200777{
778 struct key_parse parse;
779 struct nlattr *key;
780 struct cfg80211_cached_keys *result;
781 int rem, err, def = 0;
782
783 result = kzalloc(sizeof(*result), GFP_KERNEL);
784 if (!result)
785 return ERR_PTR(-ENOMEM);
786
787 result->def = -1;
788 result->defmgmt = -1;
789
790 nla_for_each_nested(key, keys, rem) {
791 memset(&parse, 0, sizeof(parse));
792 parse.idx = -1;
793
794 err = nl80211_parse_key_new(key, &parse);
795 if (err)
796 goto error;
797 err = -EINVAL;
798 if (!parse.p.key)
799 goto error;
800 if (parse.idx < 0 || parse.idx > 4)
801 goto error;
802 if (parse.def) {
803 if (def)
804 goto error;
805 def = 1;
806 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100807 if (!parse.def_uni || !parse.def_multi)
808 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200809 } else if (parse.defmgmt)
810 goto error;
811 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200812 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200813 if (err)
814 goto error;
815 result->params[parse.idx].cipher = parse.p.cipher;
816 result->params[parse.idx].key_len = parse.p.key_len;
817 result->params[parse.idx].key = result->data[parse.idx];
818 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530819
820 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
821 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
822 if (no_ht)
823 *no_ht = true;
824 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200825 }
826
827 return result;
828 error:
829 kfree(result);
830 return ERR_PTR(err);
831}
832
833static int nl80211_key_allowed(struct wireless_dev *wdev)
834{
835 ASSERT_WDEV_LOCK(wdev);
836
Johannes Bergfffd0932009-07-08 14:22:54 +0200837 switch (wdev->iftype) {
838 case NL80211_IFTYPE_AP:
839 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200840 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700841 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200842 break;
843 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200844 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200845 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200846 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200847 return -ENOLINK;
848 break;
849 default:
850 return -EINVAL;
851 }
852
853 return 0;
854}
855
Johannes Berg7527a782011-05-13 10:58:57 +0200856static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
857{
858 struct nlattr *nl_modes = nla_nest_start(msg, attr);
859 int i;
860
861 if (!nl_modes)
862 goto nla_put_failure;
863
864 i = 0;
865 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400866 if ((ifmodes & 1) && nla_put_flag(msg, i))
867 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200868 ifmodes >>= 1;
869 i++;
870 }
871
872 nla_nest_end(msg, nl_modes);
873 return 0;
874
875nla_put_failure:
876 return -ENOBUFS;
877}
878
879static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100880 struct sk_buff *msg,
881 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200882{
883 struct nlattr *nl_combis;
884 int i, j;
885
886 nl_combis = nla_nest_start(msg,
887 NL80211_ATTR_INTERFACE_COMBINATIONS);
888 if (!nl_combis)
889 goto nla_put_failure;
890
891 for (i = 0; i < wiphy->n_iface_combinations; i++) {
892 const struct ieee80211_iface_combination *c;
893 struct nlattr *nl_combi, *nl_limits;
894
895 c = &wiphy->iface_combinations[i];
896
897 nl_combi = nla_nest_start(msg, i + 1);
898 if (!nl_combi)
899 goto nla_put_failure;
900
901 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
902 if (!nl_limits)
903 goto nla_put_failure;
904
905 for (j = 0; j < c->n_limits; j++) {
906 struct nlattr *nl_limit;
907
908 nl_limit = nla_nest_start(msg, j + 1);
909 if (!nl_limit)
910 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400911 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
912 c->limits[j].max))
913 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200914 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
915 c->limits[j].types))
916 goto nla_put_failure;
917 nla_nest_end(msg, nl_limit);
918 }
919
920 nla_nest_end(msg, nl_limits);
921
David S. Miller9360ffd2012-03-29 04:41:26 -0400922 if (c->beacon_int_infra_match &&
923 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
924 goto nla_put_failure;
925 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
926 c->num_different_channels) ||
927 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
928 c->max_interfaces))
929 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100930 if (large &&
931 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
932 c->radar_detect_widths))
933 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200934
935 nla_nest_end(msg, nl_combi);
936 }
937
938 nla_nest_end(msg, nl_combis);
939
940 return 0;
941nla_put_failure:
942 return -ENOBUFS;
943}
944
Johannes Berg3713b4e2013-02-14 16:19:38 +0100945#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +0100946static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
947 struct sk_buff *msg)
948{
Johannes Berg964dc9e2013-06-03 17:25:34 +0200949 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +0100950 struct nlattr *nl_tcp;
951
952 if (!tcp)
953 return 0;
954
955 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
956 if (!nl_tcp)
957 return -ENOBUFS;
958
959 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
960 tcp->data_payload_max))
961 return -ENOBUFS;
962
963 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
964 tcp->data_payload_max))
965 return -ENOBUFS;
966
967 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
968 return -ENOBUFS;
969
970 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
971 sizeof(*tcp->tok), tcp->tok))
972 return -ENOBUFS;
973
974 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
975 tcp->data_interval_max))
976 return -ENOBUFS;
977
978 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
979 tcp->wake_payload_max))
980 return -ENOBUFS;
981
982 nla_nest_end(msg, nl_tcp);
983 return 0;
984}
985
Johannes Berg3713b4e2013-02-14 16:19:38 +0100986static int nl80211_send_wowlan(struct sk_buff *msg,
Johannes Bergb56cf722013-02-20 01:02:38 +0100987 struct cfg80211_registered_device *dev,
988 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100989{
990 struct nlattr *nl_wowlan;
991
Johannes Berg964dc9e2013-06-03 17:25:34 +0200992 if (!dev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +0100993 return 0;
994
995 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
996 if (!nl_wowlan)
997 return -ENOBUFS;
998
Johannes Berg964dc9e2013-06-03 17:25:34 +0200999 if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001000 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001001 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001002 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001003 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001004 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001005 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001006 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001007 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001008 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001011 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001012 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001014 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1015 return -ENOBUFS;
1016
Johannes Berg964dc9e2013-06-03 17:25:34 +02001017 if (dev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001018 struct nl80211_pattern_support pat = {
Johannes Berg964dc9e2013-06-03 17:25:34 +02001019 .max_patterns = dev->wiphy.wowlan->n_patterns,
1020 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1021 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1022 .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001023 };
1024
1025 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1026 sizeof(pat), &pat))
1027 return -ENOBUFS;
1028 }
1029
Johannes Bergb56cf722013-02-20 01:02:38 +01001030 if (large && nl80211_send_wowlan_tcp_caps(dev, msg))
1031 return -ENOBUFS;
1032
Johannes Berg3713b4e2013-02-14 16:19:38 +01001033 nla_nest_end(msg, nl_wowlan);
1034
1035 return 0;
1036}
1037#endif
1038
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001039static int nl80211_send_coalesce(struct sk_buff *msg,
1040 struct cfg80211_registered_device *dev)
1041{
1042 struct nl80211_coalesce_rule_support rule;
1043
1044 if (!dev->wiphy.coalesce)
1045 return 0;
1046
1047 rule.max_rules = dev->wiphy.coalesce->n_rules;
1048 rule.max_delay = dev->wiphy.coalesce->max_delay;
1049 rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns;
1050 rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len;
1051 rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len;
1052 rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset;
1053
1054 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1055 return -ENOBUFS;
1056
1057 return 0;
1058}
1059
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1061 struct ieee80211_supported_band *sband)
1062{
1063 struct nlattr *nl_rates, *nl_rate;
1064 struct ieee80211_rate *rate;
1065 int i;
1066
1067 /* add HT info */
1068 if (sband->ht_cap.ht_supported &&
1069 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1070 sizeof(sband->ht_cap.mcs),
1071 &sband->ht_cap.mcs) ||
1072 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1073 sband->ht_cap.cap) ||
1074 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1075 sband->ht_cap.ampdu_factor) ||
1076 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1077 sband->ht_cap.ampdu_density)))
1078 return -ENOBUFS;
1079
1080 /* add VHT info */
1081 if (sband->vht_cap.vht_supported &&
1082 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1083 sizeof(sband->vht_cap.vht_mcs),
1084 &sband->vht_cap.vht_mcs) ||
1085 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1086 sband->vht_cap.cap)))
1087 return -ENOBUFS;
1088
1089 /* add bitrates */
1090 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1091 if (!nl_rates)
1092 return -ENOBUFS;
1093
1094 for (i = 0; i < sband->n_bitrates; i++) {
1095 nl_rate = nla_nest_start(msg, i);
1096 if (!nl_rate)
1097 return -ENOBUFS;
1098
1099 rate = &sband->bitrates[i];
1100 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1101 rate->bitrate))
1102 return -ENOBUFS;
1103 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1104 nla_put_flag(msg,
1105 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1106 return -ENOBUFS;
1107
1108 nla_nest_end(msg, nl_rate);
1109 }
1110
1111 nla_nest_end(msg, nl_rates);
1112
1113 return 0;
1114}
1115
1116static int
1117nl80211_send_mgmt_stypes(struct sk_buff *msg,
1118 const struct ieee80211_txrx_stypes *mgmt_stypes)
1119{
1120 u16 stypes;
1121 struct nlattr *nl_ftypes, *nl_ifs;
1122 enum nl80211_iftype ift;
1123 int i;
1124
1125 if (!mgmt_stypes)
1126 return 0;
1127
1128 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1129 if (!nl_ifs)
1130 return -ENOBUFS;
1131
1132 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1133 nl_ftypes = nla_nest_start(msg, ift);
1134 if (!nl_ftypes)
1135 return -ENOBUFS;
1136 i = 0;
1137 stypes = mgmt_stypes[ift].tx;
1138 while (stypes) {
1139 if ((stypes & 1) &&
1140 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1141 (i << 4) | IEEE80211_FTYPE_MGMT))
1142 return -ENOBUFS;
1143 stypes >>= 1;
1144 i++;
1145 }
1146 nla_nest_end(msg, nl_ftypes);
1147 }
1148
1149 nla_nest_end(msg, nl_ifs);
1150
1151 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1152 if (!nl_ifs)
1153 return -ENOBUFS;
1154
1155 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1156 nl_ftypes = nla_nest_start(msg, ift);
1157 if (!nl_ftypes)
1158 return -ENOBUFS;
1159 i = 0;
1160 stypes = mgmt_stypes[ift].rx;
1161 while (stypes) {
1162 if ((stypes & 1) &&
1163 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1164 (i << 4) | IEEE80211_FTYPE_MGMT))
1165 return -ENOBUFS;
1166 stypes >>= 1;
1167 i++;
1168 }
1169 nla_nest_end(msg, nl_ftypes);
1170 }
1171 nla_nest_end(msg, nl_ifs);
1172
1173 return 0;
1174}
1175
Johannes Berg86e8cf92013-06-19 10:57:22 +02001176struct nl80211_dump_wiphy_state {
1177 s64 filter_wiphy;
1178 long start;
1179 long split_start, band_start, chan_start;
1180 bool split;
1181};
1182
Johannes Berg3713b4e2013-02-14 16:19:38 +01001183static int nl80211_send_wiphy(struct cfg80211_registered_device *dev,
1184 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001185 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001186{
1187 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001188 struct nlattr *nl_bands, *nl_band;
1189 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001190 struct nlattr *nl_cmds;
Johannes Bergad7e7182013-11-13 13:37:47 +01001191 struct nlattr *nl_vendor_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001192 enum ieee80211_band band;
1193 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001194 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001195 const struct ieee80211_txrx_stypes *mgmt_stypes =
1196 dev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001197 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001198
Eric W. Biederman15e47302012-09-07 20:12:54 +00001199 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
Johannes Berg55682962007-09-20 13:09:35 -04001200 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001201 return -ENOBUFS;
1202
Johannes Berg86e8cf92013-06-19 10:57:22 +02001203 if (WARN_ON(!state))
1204 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001205
David S. Miller9360ffd2012-03-29 04:41:26 -04001206 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001207 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
1208 wiphy_name(&dev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001209 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001210 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001211 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001212
Johannes Berg86e8cf92013-06-19 10:57:22 +02001213 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001214 case 0:
1215 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
1216 dev->wiphy.retry_short) ||
1217 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
1218 dev->wiphy.retry_long) ||
1219 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
1220 dev->wiphy.frag_threshold) ||
1221 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
1222 dev->wiphy.rts_threshold) ||
1223 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
1224 dev->wiphy.coverage_class) ||
1225 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
1226 dev->wiphy.max_scan_ssids) ||
1227 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
1228 dev->wiphy.max_sched_scan_ssids) ||
1229 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
1230 dev->wiphy.max_scan_ie_len) ||
1231 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
1232 dev->wiphy.max_sched_scan_ie_len) ||
1233 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
1234 dev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001235 goto nla_put_failure;
1236
Johannes Berg3713b4e2013-02-14 16:19:38 +01001237 if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
1238 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1239 goto nla_put_failure;
1240 if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
1241 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1242 goto nla_put_failure;
1243 if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
1244 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1245 goto nla_put_failure;
1246 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
1247 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1248 goto nla_put_failure;
1249 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
1250 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1251 goto nla_put_failure;
1252 if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
1253 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001254 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001255 state->split_start++;
1256 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001257 break;
1258 case 1:
1259 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
1260 sizeof(u32) * dev->wiphy.n_cipher_suites,
1261 dev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001262 goto nla_put_failure;
1263
Johannes Berg3713b4e2013-02-14 16:19:38 +01001264 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
1265 dev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001266 goto nla_put_failure;
1267
Johannes Berg3713b4e2013-02-14 16:19:38 +01001268 if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
1269 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1270 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001271
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
1273 dev->wiphy.available_antennas_tx) ||
1274 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
1275 dev->wiphy.available_antennas_rx))
1276 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001277
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
1279 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
1280 dev->wiphy.probe_resp_offload))
1281 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001282
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 if ((dev->wiphy.available_antennas_tx ||
1284 dev->wiphy.available_antennas_rx) &&
1285 dev->ops->get_antenna) {
1286 u32 tx_ant = 0, rx_ant = 0;
1287 int res;
1288 res = rdev_get_antenna(dev, &tx_ant, &rx_ant);
1289 if (!res) {
1290 if (nla_put_u32(msg,
1291 NL80211_ATTR_WIPHY_ANTENNA_TX,
1292 tx_ant) ||
1293 nla_put_u32(msg,
1294 NL80211_ATTR_WIPHY_ANTENNA_RX,
1295 rx_ant))
1296 goto nla_put_failure;
1297 }
Johannes Bergee688b002008-01-24 19:38:39 +01001298 }
1299
Johannes Berg86e8cf92013-06-19 10:57:22 +02001300 state->split_start++;
1301 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 break;
1303 case 2:
1304 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
1305 dev->wiphy.interface_modes))
1306 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001307 state->split_start++;
1308 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 break;
1310 case 3:
1311 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1312 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001313 goto nla_put_failure;
1314
Johannes Berg86e8cf92013-06-19 10:57:22 +02001315 for (band = state->band_start;
1316 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 struct ieee80211_supported_band *sband;
1318
1319 sband = dev->wiphy.bands[band];
1320
1321 if (!sband)
1322 continue;
1323
1324 nl_band = nla_nest_start(msg, band);
1325 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001326 goto nla_put_failure;
1327
Johannes Berg86e8cf92013-06-19 10:57:22 +02001328 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 case 0:
1330 if (nl80211_send_band_rateinfo(msg, sband))
1331 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001332 state->chan_start++;
1333 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 break;
1335 default:
1336 /* add frequencies */
1337 nl_freqs = nla_nest_start(
1338 msg, NL80211_BAND_ATTR_FREQS);
1339 if (!nl_freqs)
1340 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001341
Johannes Berg86e8cf92013-06-19 10:57:22 +02001342 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 i < sband->n_channels;
1344 i++) {
1345 nl_freq = nla_nest_start(msg, i);
1346 if (!nl_freq)
1347 goto nla_put_failure;
1348
1349 chan = &sband->channels[i];
1350
Johannes Berg86e8cf92013-06-19 10:57:22 +02001351 if (nl80211_msg_put_channel(
1352 msg, chan,
1353 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 goto nla_put_failure;
1355
1356 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001357 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 break;
1359 }
1360 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001361 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001363 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001364 nla_nest_end(msg, nl_freqs);
1365 }
1366
1367 nla_nest_end(msg, nl_band);
1368
Johannes Berg86e8cf92013-06-19 10:57:22 +02001369 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001370 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001371 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 band--;
1373 break;
1374 }
Johannes Bergee688b002008-01-24 19:38:39 +01001375 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001377
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001380 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001381 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001382
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001384 if (state->band_start == 0 && state->chan_start == 0)
1385 state->split_start++;
1386 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001387 break;
1388 case 4:
1389 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1390 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001391 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392
1393 i = 0;
1394#define CMD(op, n) \
1395 do { \
1396 if (dev->ops->op) { \
1397 i++; \
1398 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1399 goto nla_put_failure; \
1400 } \
1401 } while (0)
1402
1403 CMD(add_virtual_intf, NEW_INTERFACE);
1404 CMD(change_virtual_intf, SET_INTERFACE);
1405 CMD(add_key, NEW_KEY);
1406 CMD(start_ap, START_AP);
1407 CMD(add_station, NEW_STATION);
1408 CMD(add_mpath, NEW_MPATH);
1409 CMD(update_mesh_config, SET_MESH_CONFIG);
1410 CMD(change_bss, SET_BSS);
1411 CMD(auth, AUTHENTICATE);
1412 CMD(assoc, ASSOCIATE);
1413 CMD(deauth, DEAUTHENTICATE);
1414 CMD(disassoc, DISASSOCIATE);
1415 CMD(join_ibss, JOIN_IBSS);
1416 CMD(join_mesh, JOIN_MESH);
1417 CMD(set_pmksa, SET_PMKSA);
1418 CMD(del_pmksa, DEL_PMKSA);
1419 CMD(flush_pmksa, FLUSH_PMKSA);
1420 if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1421 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1422 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1423 CMD(mgmt_tx, FRAME);
1424 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1425 if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1426 i++;
1427 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1428 goto nla_put_failure;
1429 }
1430 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
1431 dev->ops->join_mesh) {
1432 i++;
1433 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1434 goto nla_put_failure;
1435 }
1436 CMD(set_wds_peer, SET_WDS_PEER);
1437 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1438 CMD(tdls_mgmt, TDLS_MGMT);
1439 CMD(tdls_oper, TDLS_OPER);
1440 }
1441 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
1442 CMD(sched_scan_start, START_SCHED_SCAN);
1443 CMD(probe_client, PROBE_CLIENT);
1444 CMD(set_noack_map, SET_NOACK_MAP);
1445 if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1446 i++;
1447 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1448 goto nla_put_failure;
1449 }
1450 CMD(start_p2p_device, START_P2P_DEVICE);
1451 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001452 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001453 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1454 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001455 if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1456 CMD(channel_switch, CHANNEL_SWITCH);
Arend van Spriel5de17982013-04-18 15:49:00 +02001457 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01001458
Kalle Valo4745fc02011-11-17 19:06:10 +02001459#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg3713b4e2013-02-14 16:19:38 +01001460 CMD(testmode_cmd, TESTMODE);
Kalle Valo4745fc02011-11-17 19:06:10 +02001461#endif
1462
Johannes Berg8fdc6212009-03-14 09:34:01 +01001463#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001464
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 if (dev->ops->connect || dev->ops->auth) {
1466 i++;
1467 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001468 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001469 }
1470
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 if (dev->ops->disconnect || dev->ops->deauth) {
1472 i++;
1473 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1474 goto nla_put_failure;
1475 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001476
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001478 state->split_start++;
1479 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001480 break;
1481 case 5:
1482 if (dev->ops->remain_on_channel &&
1483 (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
1484 nla_put_u32(msg,
1485 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
1486 dev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001487 goto nla_put_failure;
1488
Johannes Berg3713b4e2013-02-14 16:19:38 +01001489 if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
1490 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1491 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001492
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1494 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001495 state->split_start++;
1496 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 break;
1498 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001499#ifdef CONFIG_PM
Johannes Berg86e8cf92013-06-19 10:57:22 +02001500 if (nl80211_send_wowlan(msg, dev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001502 state->split_start++;
1503 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 break;
1505#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001506 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507#endif
1508 case 7:
1509 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
1510 dev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001511 goto nla_put_failure;
1512
Johannes Berg86e8cf92013-06-19 10:57:22 +02001513 if (nl80211_put_iface_combinations(&dev->wiphy, msg,
1514 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001516
Johannes Berg86e8cf92013-06-19 10:57:22 +02001517 state->split_start++;
1518 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 break;
1520 case 8:
1521 if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
1522 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
1523 dev->wiphy.ap_sme_capa))
1524 goto nla_put_failure;
1525
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001526 features = dev->wiphy.features;
1527 /*
1528 * We can only add the per-channel limit information if the
1529 * dump is split, otherwise it makes it too big. Therefore
1530 * only advertise it in that case.
1531 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001532 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001533 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1534 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001535 goto nla_put_failure;
1536
1537 if (dev->wiphy.ht_capa_mod_mask &&
1538 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
1539 sizeof(*dev->wiphy.ht_capa_mod_mask),
1540 dev->wiphy.ht_capa_mod_mask))
1541 goto nla_put_failure;
1542
1543 if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1544 dev->wiphy.max_acl_mac_addrs &&
1545 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
1546 dev->wiphy.max_acl_mac_addrs))
1547 goto nla_put_failure;
1548
1549 /*
1550 * Any information below this point is only available to
1551 * applications that can deal with it being split. This
1552 * helps ensure that newly added capabilities don't break
1553 * older tools by overrunning their buffers.
1554 *
1555 * We still increment split_start so that in the split
1556 * case we'll continue with more data in the next round,
1557 * but break unconditionally so unsplit data stops here.
1558 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001559 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 break;
1561 case 9:
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001562 if (dev->wiphy.extended_capabilities &&
1563 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
1564 dev->wiphy.extended_capabilities_len,
1565 dev->wiphy.extended_capabilities) ||
1566 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
1567 dev->wiphy.extended_capabilities_len,
1568 dev->wiphy.extended_capabilities_mask)))
1569 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570
Johannes Bergee2aca32013-02-21 17:36:01 +01001571 if (dev->wiphy.vht_capa_mod_mask &&
1572 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
1573 sizeof(*dev->wiphy.vht_capa_mod_mask),
1574 dev->wiphy.vht_capa_mod_mask))
1575 goto nla_put_failure;
1576
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001577 state->split_start++;
1578 break;
1579 case 10:
1580 if (nl80211_send_coalesce(msg, dev))
1581 goto nla_put_failure;
1582
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001583 if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
1584 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1585 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1586 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01001587 state->split_start++;
1588 break;
1589 case 11:
1590 nl_vendor_cmds = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1591 if (!nl_vendor_cmds)
1592 goto nla_put_failure;
1593
1594 for (i = 0; i < dev->wiphy.n_vendor_commands; i++)
1595 if (nla_put(msg, i + 1,
1596 sizeof(struct nl80211_vendor_cmd_info),
1597 &dev->wiphy.vendor_commands[i].info))
1598 goto nla_put_failure;
1599 nla_nest_end(msg, nl_vendor_cmds);
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001600
Johannes Berg3713b4e2013-02-14 16:19:38 +01001601 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001604 }
Johannes Berg55682962007-09-20 13:09:35 -04001605 return genlmsg_end(msg, hdr);
1606
1607 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001608 genlmsg_cancel(msg, hdr);
1609 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001610}
1611
Johannes Berg86e8cf92013-06-19 10:57:22 +02001612static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1613 struct netlink_callback *cb,
1614 struct nl80211_dump_wiphy_state *state)
1615{
1616 struct nlattr **tb = nl80211_fam.attrbuf;
1617 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1618 tb, nl80211_fam.maxattr, nl80211_policy);
1619 /* ignore parse errors for backward compatibility */
1620 if (ret)
1621 return 0;
1622
1623 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1624 if (tb[NL80211_ATTR_WIPHY])
1625 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1626 if (tb[NL80211_ATTR_WDEV])
1627 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1628 if (tb[NL80211_ATTR_IFINDEX]) {
1629 struct net_device *netdev;
1630 struct cfg80211_registered_device *rdev;
1631 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1632
1633 netdev = dev_get_by_index(sock_net(skb->sk), ifidx);
1634 if (!netdev)
1635 return -ENODEV;
1636 if (netdev->ieee80211_ptr) {
1637 rdev = wiphy_to_dev(
1638 netdev->ieee80211_ptr->wiphy);
1639 state->filter_wiphy = rdev->wiphy_idx;
1640 }
1641 dev_put(netdev);
1642 }
1643
1644 return 0;
1645}
1646
Johannes Berg55682962007-09-20 13:09:35 -04001647static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1648{
Johannes Berg645e77d2013-03-01 14:03:49 +01001649 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001650 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Johannes Berg55682962007-09-20 13:09:35 -04001651 struct cfg80211_registered_device *dev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001652
Johannes Berg5fe231e2013-05-08 21:45:15 +02001653 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001654 if (!state) {
1655 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001656 if (!state) {
1657 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001658 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001660 state->filter_wiphy = -1;
1661 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1662 if (ret) {
1663 kfree(state);
1664 rtnl_unlock();
1665 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001666 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001667 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 }
1669
Johannes Berg79c97e92009-07-07 03:56:12 +02001670 list_for_each_entry(dev, &cfg80211_rdev_list, list) {
Johannes Berg463d0182009-07-14 00:33:35 +02001671 if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk)))
1672 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001673 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001674 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001675 if (state->filter_wiphy != -1 &&
1676 state->filter_wiphy != dev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001677 continue;
1678 /* attempt to fit multiple wiphy data chunks into the skb */
1679 do {
1680 ret = nl80211_send_wiphy(dev, skb,
1681 NETLINK_CB(cb->skb).portid,
1682 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001683 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001684 if (ret < 0) {
1685 /*
1686 * If sending the wiphy data didn't fit (ENOBUFS
1687 * or EMSGSIZE returned), this SKB is still
1688 * empty (so it's not too big because another
1689 * wiphy dataset is already in the skb) and
1690 * we've not tried to adjust the dump allocation
1691 * yet ... then adjust the alloc size to be
1692 * bigger, and return 1 but with the empty skb.
1693 * This results in an empty message being RX'ed
1694 * in userspace, but that is ignored.
1695 *
1696 * We can then retry with the larger buffer.
1697 */
1698 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
1699 !skb->len &&
1700 cb->min_dump_alloc < 4096) {
1701 cb->min_dump_alloc = 4096;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001702 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001703 return 1;
1704 }
1705 idx--;
1706 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001707 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001708 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001709 break;
Johannes Berg55682962007-09-20 13:09:35 -04001710 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001711 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001712
Johannes Berg86e8cf92013-06-19 10:57:22 +02001713 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001714
1715 return skb->len;
1716}
1717
Johannes Berg86e8cf92013-06-19 10:57:22 +02001718static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1719{
1720 kfree((void *)cb->args[0]);
1721 return 0;
1722}
1723
Johannes Berg55682962007-09-20 13:09:35 -04001724static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1725{
1726 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02001727 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001728 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001729
Johannes Berg645e77d2013-03-01 14:03:49 +01001730 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001731 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001732 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001733
Johannes Berg3713b4e2013-02-14 16:19:38 +01001734 if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001735 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001736 nlmsg_free(msg);
1737 return -ENOBUFS;
1738 }
Johannes Berg55682962007-09-20 13:09:35 -04001739
Johannes Berg134e6372009-07-10 09:51:34 +00001740 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001741}
1742
Jouni Malinen31888482008-10-30 16:59:24 +02001743static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1744 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1745 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1746 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1747 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1748 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1749};
1750
1751static int parse_txq_params(struct nlattr *tb[],
1752 struct ieee80211_txq_params *txq_params)
1753{
Johannes Berga3304b02012-03-28 11:04:24 +02001754 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001755 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1756 !tb[NL80211_TXQ_ATTR_AIFS])
1757 return -EINVAL;
1758
Johannes Berga3304b02012-03-28 11:04:24 +02001759 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001760 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1761 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1762 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1763 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1764
Johannes Berga3304b02012-03-28 11:04:24 +02001765 if (txq_params->ac >= NL80211_NUM_ACS)
1766 return -EINVAL;
1767
Jouni Malinen31888482008-10-30 16:59:24 +02001768 return 0;
1769}
1770
Johannes Bergf444de02010-05-05 15:25:02 +02001771static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1772{
1773 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001774 * You can only set the channel explicitly for WDS interfaces,
1775 * all others have their channel managed via their respective
1776 * "establish a connection" command (connect, join, ...)
1777 *
1778 * For AP/GO and mesh mode, the channel can be set with the
1779 * channel userspace API, but is only stored and passed to the
1780 * low-level driver when the AP starts or the mesh is joined.
1781 * This is for backward compatibility, userspace can also give
1782 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001783 *
1784 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001785 * whatever else is going on, so they have their own special
1786 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001787 */
1788 return !wdev ||
1789 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001790 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001791 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1792 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001793}
1794
Johannes Berg683b6d32012-11-08 21:25:48 +01001795static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1796 struct genl_info *info,
1797 struct cfg80211_chan_def *chandef)
1798{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301799 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001800
1801 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1802 return -EINVAL;
1803
1804 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1805
1806 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001807 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1808 chandef->center_freq1 = control_freq;
1809 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001810
1811 /* Primary channel not allowed */
1812 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1813 return -EINVAL;
1814
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001815 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1816 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001817
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001818 chantype = nla_get_u32(
1819 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1820
1821 switch (chantype) {
1822 case NL80211_CHAN_NO_HT:
1823 case NL80211_CHAN_HT20:
1824 case NL80211_CHAN_HT40PLUS:
1825 case NL80211_CHAN_HT40MINUS:
1826 cfg80211_chandef_create(chandef, chandef->chan,
1827 chantype);
1828 break;
1829 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001830 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001831 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001832 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1833 chandef->width =
1834 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1835 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1836 chandef->center_freq1 =
1837 nla_get_u32(
1838 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1839 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1840 chandef->center_freq2 =
1841 nla_get_u32(
1842 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1843 }
1844
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001845 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001846 return -EINVAL;
1847
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001848 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1849 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001850 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001851
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001852 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1853 chandef->width == NL80211_CHAN_WIDTH_10) &&
1854 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1855 return -EINVAL;
1856
Johannes Berg683b6d32012-11-08 21:25:48 +01001857 return 0;
1858}
1859
Johannes Bergf444de02010-05-05 15:25:02 +02001860static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1861 struct wireless_dev *wdev,
1862 struct genl_info *info)
1863{
Johannes Berg683b6d32012-11-08 21:25:48 +01001864 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001865 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001866 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1867
1868 if (wdev)
1869 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001870
Johannes Bergf444de02010-05-05 15:25:02 +02001871 if (!nl80211_can_set_dev_channel(wdev))
1872 return -EOPNOTSUPP;
1873
Johannes Berg683b6d32012-11-08 21:25:48 +01001874 result = nl80211_parse_chandef(rdev, info, &chandef);
1875 if (result)
1876 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001877
Johannes Berge8c9bd52012-06-06 08:18:22 +02001878 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001879 case NL80211_IFTYPE_AP:
1880 case NL80211_IFTYPE_P2P_GO:
1881 if (wdev->beacon_interval) {
1882 result = -EBUSY;
1883 break;
1884 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001885 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001886 result = -EINVAL;
1887 break;
1888 }
Johannes Berg683b6d32012-11-08 21:25:48 +01001889 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02001890 result = 0;
1891 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001892 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01001893 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001894 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001895 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01001896 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02001897 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02001898 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02001899 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02001900 }
Johannes Bergf444de02010-05-05 15:25:02 +02001901
1902 return result;
1903}
1904
1905static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
1906{
Johannes Berg4c476992010-10-04 21:36:35 +02001907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1908 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02001909
Johannes Berg4c476992010-10-04 21:36:35 +02001910 return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info);
Johannes Bergf444de02010-05-05 15:25:02 +02001911}
1912
Bill Jordane8347eb2010-10-01 13:54:28 -04001913static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
1914{
Johannes Berg43b19952010-10-07 13:10:30 +02001915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1916 struct net_device *dev = info->user_ptr[1];
1917 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02001918 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04001919
1920 if (!info->attrs[NL80211_ATTR_MAC])
1921 return -EINVAL;
1922
Johannes Berg43b19952010-10-07 13:10:30 +02001923 if (netif_running(dev))
1924 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04001925
Johannes Berg43b19952010-10-07 13:10:30 +02001926 if (!rdev->ops->set_wds_peer)
1927 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001928
Johannes Berg43b19952010-10-07 13:10:30 +02001929 if (wdev->iftype != NL80211_IFTYPE_WDS)
1930 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04001931
1932 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03001933 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04001934}
1935
1936
Johannes Berg55682962007-09-20 13:09:35 -04001937static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1938{
1939 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02001940 struct net_device *netdev = NULL;
1941 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04001942 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02001943 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001944 u32 changed;
1945 u8 retry_short = 0, retry_long = 0;
1946 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01001947 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04001948
Johannes Berg5fe231e2013-05-08 21:45:15 +02001949 ASSERT_RTNL();
1950
Johannes Bergf444de02010-05-05 15:25:02 +02001951 /*
1952 * Try to find the wiphy and netdev. Normally this
1953 * function shouldn't need the netdev, but this is
1954 * done for backward compatibility -- previously
1955 * setting the channel was done per wiphy, but now
1956 * it is per netdev. Previous userland like hostapd
1957 * also passed a netdev to set_wiphy, so that it is
1958 * possible to let that go to the right netdev!
1959 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001960
Johannes Bergf444de02010-05-05 15:25:02 +02001961 if (info->attrs[NL80211_ATTR_IFINDEX]) {
1962 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
1963
1964 netdev = dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001965 if (netdev && netdev->ieee80211_ptr)
Johannes Bergf444de02010-05-05 15:25:02 +02001966 rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001967 else
Johannes Bergf444de02010-05-05 15:25:02 +02001968 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001969 }
1970
Johannes Bergf444de02010-05-05 15:25:02 +02001971 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02001972 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
1973 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02001974 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02001975 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02001976 wdev = NULL;
1977 netdev = NULL;
1978 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02001979 } else
Johannes Bergf444de02010-05-05 15:25:02 +02001980 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001981
1982 /*
1983 * end workaround code, by now the rdev is available
1984 * and locked, and wdev may or may not be NULL.
1985 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001986
1987 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02001988 result = cfg80211_dev_rename(
1989 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001990
Johannes Berg4bbf4d52009-03-24 09:35:46 +01001991 if (result)
1992 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -04001993
Jouni Malinen31888482008-10-30 16:59:24 +02001994 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
1995 struct ieee80211_txq_params txq_params;
1996 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
1997
1998 if (!rdev->ops->set_txq_params) {
1999 result = -EOPNOTSUPP;
2000 goto bad_res;
2001 }
2002
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002003 if (!netdev) {
2004 result = -EINVAL;
2005 goto bad_res;
2006 }
2007
Johannes Berg133a3ff2011-11-03 14:50:13 +01002008 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2009 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
2010 result = -EINVAL;
2011 goto bad_res;
2012 }
2013
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002014 if (!netif_running(netdev)) {
2015 result = -ENETDOWN;
2016 goto bad_res;
2017 }
2018
Jouni Malinen31888482008-10-30 16:59:24 +02002019 nla_for_each_nested(nl_txq_params,
2020 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2021 rem_txq_params) {
2022 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2023 nla_data(nl_txq_params),
2024 nla_len(nl_txq_params),
2025 txq_params_policy);
2026 result = parse_txq_params(tb, &txq_params);
2027 if (result)
2028 goto bad_res;
2029
Hila Gonene35e4d22012-06-27 17:19:42 +03002030 result = rdev_set_txq_params(rdev, netdev,
2031 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002032 if (result)
2033 goto bad_res;
2034 }
2035 }
2036
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002037 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg71fe96b2012-10-24 10:04:58 +02002038 result = __nl80211_set_channel(rdev,
2039 nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
2040 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002041 if (result)
2042 goto bad_res;
2043 }
2044
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002045 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002046 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002047 enum nl80211_tx_power_setting type;
2048 int idx, mbm = 0;
2049
Johannes Bergc8442112012-10-24 10:17:18 +02002050 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2051 txp_wdev = NULL;
2052
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002053 if (!rdev->ops->set_tx_power) {
Jiri Slaby60ea3852010-07-07 15:02:46 +02002054 result = -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002055 goto bad_res;
2056 }
2057
2058 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2059 type = nla_get_u32(info->attrs[idx]);
2060
2061 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
2062 (type != NL80211_TX_POWER_AUTOMATIC)) {
2063 result = -EINVAL;
2064 goto bad_res;
2065 }
2066
2067 if (type != NL80211_TX_POWER_AUTOMATIC) {
2068 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2069 mbm = nla_get_u32(info->attrs[idx]);
2070 }
2071
Johannes Bergc8442112012-10-24 10:17:18 +02002072 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002073 if (result)
2074 goto bad_res;
2075 }
2076
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002077 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2078 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2079 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002080 if ((!rdev->wiphy.available_antennas_tx &&
2081 !rdev->wiphy.available_antennas_rx) ||
2082 !rdev->ops->set_antenna) {
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002083 result = -EOPNOTSUPP;
2084 goto bad_res;
2085 }
2086
2087 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2088 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2089
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002090 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002091 * available antenna masks, except for the "all" mask */
2092 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
2093 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) {
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002094 result = -EINVAL;
2095 goto bad_res;
2096 }
2097
Bruno Randolf7f531e02010-12-16 11:30:22 +09002098 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2099 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002100
Hila Gonene35e4d22012-06-27 17:19:42 +03002101 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002102 if (result)
2103 goto bad_res;
2104 }
2105
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002106 changed = 0;
2107
2108 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2109 retry_short = nla_get_u8(
2110 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
2111 if (retry_short == 0) {
2112 result = -EINVAL;
2113 goto bad_res;
2114 }
2115 changed |= WIPHY_PARAM_RETRY_SHORT;
2116 }
2117
2118 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2119 retry_long = nla_get_u8(
2120 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
2121 if (retry_long == 0) {
2122 result = -EINVAL;
2123 goto bad_res;
2124 }
2125 changed |= WIPHY_PARAM_RETRY_LONG;
2126 }
2127
2128 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2129 frag_threshold = nla_get_u32(
2130 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
2131 if (frag_threshold < 256) {
2132 result = -EINVAL;
2133 goto bad_res;
2134 }
2135 if (frag_threshold != (u32) -1) {
2136 /*
2137 * Fragments (apart from the last one) are required to
2138 * have even length. Make the fragmentation code
2139 * simpler by stripping LSB should someone try to use
2140 * odd threshold value.
2141 */
2142 frag_threshold &= ~0x1;
2143 }
2144 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2145 }
2146
2147 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2148 rts_threshold = nla_get_u32(
2149 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2150 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2151 }
2152
Lukáš Turek81077e82009-12-21 22:50:47 +01002153 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
2154 coverage_class = nla_get_u8(
2155 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2156 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2157 }
2158
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002159 if (changed) {
2160 u8 old_retry_short, old_retry_long;
2161 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002162 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002163
2164 if (!rdev->ops->set_wiphy_params) {
2165 result = -EOPNOTSUPP;
2166 goto bad_res;
2167 }
2168
2169 old_retry_short = rdev->wiphy.retry_short;
2170 old_retry_long = rdev->wiphy.retry_long;
2171 old_frag_threshold = rdev->wiphy.frag_threshold;
2172 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002173 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002174
2175 if (changed & WIPHY_PARAM_RETRY_SHORT)
2176 rdev->wiphy.retry_short = retry_short;
2177 if (changed & WIPHY_PARAM_RETRY_LONG)
2178 rdev->wiphy.retry_long = retry_long;
2179 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2180 rdev->wiphy.frag_threshold = frag_threshold;
2181 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2182 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002183 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2184 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002185
Hila Gonene35e4d22012-06-27 17:19:42 +03002186 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002187 if (result) {
2188 rdev->wiphy.retry_short = old_retry_short;
2189 rdev->wiphy.retry_long = old_retry_long;
2190 rdev->wiphy.frag_threshold = old_frag_threshold;
2191 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002192 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002193 }
2194 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002195
Johannes Berg306d6112008-12-08 12:39:04 +01002196 bad_res:
Johannes Bergf444de02010-05-05 15:25:02 +02002197 if (netdev)
2198 dev_put(netdev);
Johannes Berg55682962007-09-20 13:09:35 -04002199 return result;
2200}
2201
Johannes Berg71bbc992012-06-15 15:30:18 +02002202static inline u64 wdev_id(struct wireless_dev *wdev)
2203{
2204 return (u64)wdev->identifier |
2205 ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32);
2206}
Johannes Berg55682962007-09-20 13:09:35 -04002207
Johannes Berg683b6d32012-11-08 21:25:48 +01002208static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002209 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002210{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002211 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002212
Johannes Berg683b6d32012-11-08 21:25:48 +01002213 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2214 chandef->chan->center_freq))
2215 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002216 switch (chandef->width) {
2217 case NL80211_CHAN_WIDTH_20_NOHT:
2218 case NL80211_CHAN_WIDTH_20:
2219 case NL80211_CHAN_WIDTH_40:
2220 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2221 cfg80211_get_chandef_type(chandef)))
2222 return -ENOBUFS;
2223 break;
2224 default:
2225 break;
2226 }
2227 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2228 return -ENOBUFS;
2229 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2230 return -ENOBUFS;
2231 if (chandef->center_freq2 &&
2232 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002233 return -ENOBUFS;
2234 return 0;
2235}
2236
Eric W. Biederman15e47302012-09-07 20:12:54 +00002237static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002238 struct cfg80211_registered_device *rdev,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002239 struct wireless_dev *wdev)
Johannes Berg55682962007-09-20 13:09:35 -04002240{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002241 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04002242 void *hdr;
2243
Eric W. Biederman15e47302012-09-07 20:12:54 +00002244 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE);
Johannes Berg55682962007-09-20 13:09:35 -04002245 if (!hdr)
2246 return -1;
2247
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002248 if (dev &&
2249 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002250 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002251 goto nla_put_failure;
2252
2253 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2254 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002255 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002256 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002257 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2258 rdev->devlist_generation ^
2259 (cfg80211_rdev_list_generation << 2)))
2260 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002261
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002262 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002263 int ret;
2264 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002265
Johannes Berg683b6d32012-11-08 21:25:48 +01002266 ret = rdev_get_channel(rdev, wdev, &chandef);
2267 if (ret == 0) {
2268 if (nl80211_send_chandef(msg, &chandef))
2269 goto nla_put_failure;
2270 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002271 }
2272
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002273 if (wdev->ssid_len) {
2274 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2275 goto nla_put_failure;
2276 }
2277
Johannes Berg55682962007-09-20 13:09:35 -04002278 return genlmsg_end(msg, hdr);
2279
2280 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002281 genlmsg_cancel(msg, hdr);
2282 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002283}
2284
2285static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2286{
2287 int wp_idx = 0;
2288 int if_idx = 0;
2289 int wp_start = cb->args[0];
2290 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002291 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002292 struct wireless_dev *wdev;
2293
Johannes Berg5fe231e2013-05-08 21:45:15 +02002294 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002295 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2296 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002297 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002298 if (wp_idx < wp_start) {
2299 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002300 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002301 }
Johannes Berg55682962007-09-20 13:09:35 -04002302 if_idx = 0;
2303
Johannes Berg89a54e42012-06-15 14:33:17 +02002304 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002305 if (if_idx < if_start) {
2306 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002307 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002308 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002309 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002310 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002311 rdev, wdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002312 goto out;
2313 }
2314 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002315 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002316
2317 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002318 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002319 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002320 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002321
2322 cb->args[0] = wp_idx;
2323 cb->args[1] = if_idx;
2324
2325 return skb->len;
2326}
2327
2328static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2329{
2330 struct sk_buff *msg;
Johannes Berg4c476992010-10-04 21:36:35 +02002331 struct cfg80211_registered_device *dev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002332 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002333
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002334 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002335 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002336 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002337
Eric W. Biederman15e47302012-09-07 20:12:54 +00002338 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002339 dev, wdev) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002340 nlmsg_free(msg);
2341 return -ENOBUFS;
2342 }
Johannes Berg55682962007-09-20 13:09:35 -04002343
Johannes Berg134e6372009-07-10 09:51:34 +00002344 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002345}
2346
Michael Wu66f7ac52008-01-31 19:48:22 +01002347static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2348 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2349 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2350 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2351 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2352 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002353 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002354};
2355
2356static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2357{
2358 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2359 int flag;
2360
2361 *mntrflags = 0;
2362
2363 if (!nla)
2364 return -EINVAL;
2365
2366 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2367 nla, mntr_flags_policy))
2368 return -EINVAL;
2369
2370 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2371 if (flags[flag])
2372 *mntrflags |= (1<<flag);
2373
2374 return 0;
2375}
2376
Johannes Berg9bc383d2009-11-19 11:55:19 +01002377static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002378 struct net_device *netdev, u8 use_4addr,
2379 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002380{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002381 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002382 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002383 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002384 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002385 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002386
2387 switch (iftype) {
2388 case NL80211_IFTYPE_AP_VLAN:
2389 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2390 return 0;
2391 break;
2392 case NL80211_IFTYPE_STATION:
2393 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2394 return 0;
2395 break;
2396 default:
2397 break;
2398 }
2399
2400 return -EOPNOTSUPP;
2401}
2402
Johannes Berg55682962007-09-20 13:09:35 -04002403static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2404{
Johannes Berg4c476992010-10-04 21:36:35 +02002405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002406 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002407 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002408 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002409 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002410 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002411 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002412
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002413 memset(&params, 0, sizeof(params));
2414
Johannes Berg04a773a2009-04-19 21:24:32 +02002415 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002416
Johannes Berg723b0382008-09-16 20:22:09 +02002417 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002418 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002419 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002420 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002421 if (ntype > NL80211_IFTYPE_MAX)
2422 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002423 }
2424
Johannes Berg92ffe052008-09-16 20:39:36 +02002425 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002426 struct wireless_dev *wdev = dev->ieee80211_ptr;
2427
Johannes Berg4c476992010-10-04 21:36:35 +02002428 if (ntype != NL80211_IFTYPE_MESH_POINT)
2429 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002430 if (netif_running(dev))
2431 return -EBUSY;
2432
2433 wdev_lock(wdev);
2434 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2435 IEEE80211_MAX_MESH_ID_LEN);
2436 wdev->mesh_id_up_len =
2437 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2438 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2439 wdev->mesh_id_up_len);
2440 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002441 }
2442
Felix Fietkau8b787642009-11-10 18:53:10 +01002443 if (info->attrs[NL80211_ATTR_4ADDR]) {
2444 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2445 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002446 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002447 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002448 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002449 } else {
2450 params.use_4addr = -1;
2451 }
2452
Johannes Berg92ffe052008-09-16 20:39:36 +02002453 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002454 if (ntype != NL80211_IFTYPE_MONITOR)
2455 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002456 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2457 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002458 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002459 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002460
2461 flags = &_flags;
2462 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002463 }
Johannes Berg3b858752009-03-12 09:55:09 +01002464
Luciano Coelho18003292013-08-29 13:26:57 +03002465 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002466 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2467 return -EOPNOTSUPP;
2468
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002469 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002470 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002471 else
2472 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002473
Johannes Berg9bc383d2009-11-19 11:55:19 +01002474 if (!err && params.use_4addr != -1)
2475 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2476
Johannes Berg55682962007-09-20 13:09:35 -04002477 return err;
2478}
2479
2480static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2481{
Johannes Berg4c476992010-10-04 21:36:35 +02002482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002483 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002484 struct wireless_dev *wdev;
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002485 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04002486 int err;
2487 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002488 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002489
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002490 memset(&params, 0, sizeof(params));
2491
Johannes Berg55682962007-09-20 13:09:35 -04002492 if (!info->attrs[NL80211_ATTR_IFNAME])
2493 return -EINVAL;
2494
2495 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2496 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2497 if (type > NL80211_IFTYPE_MAX)
2498 return -EINVAL;
2499 }
2500
Johannes Berg79c97e92009-07-07 03:56:12 +02002501 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002502 !(rdev->wiphy.interface_modes & (1 << type)))
2503 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002504
Arend van Spriel1c18f142013-01-08 10:17:27 +01002505 if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) {
2506 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2507 ETH_ALEN);
2508 if (!is_valid_ether_addr(params.macaddr))
2509 return -EADDRNOTAVAIL;
2510 }
2511
Johannes Berg9bc383d2009-11-19 11:55:19 +01002512 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002513 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002514 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002515 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002516 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002517 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002518
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002519 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2520 if (!msg)
2521 return -ENOMEM;
2522
Michael Wu66f7ac52008-01-31 19:48:22 +01002523 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2524 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2525 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002526
Luciano Coelho18003292013-08-29 13:26:57 +03002527 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002528 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2529 return -EOPNOTSUPP;
2530
Hila Gonene35e4d22012-06-27 17:19:42 +03002531 wdev = rdev_add_virtual_intf(rdev,
2532 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2533 type, err ? NULL : &flags, &params);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002534 if (IS_ERR(wdev)) {
2535 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002536 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002537 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002538
Johannes Berg98104fde2012-06-16 00:19:54 +02002539 switch (type) {
2540 case NL80211_IFTYPE_MESH_POINT:
2541 if (!info->attrs[NL80211_ATTR_MESH_ID])
2542 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002543 wdev_lock(wdev);
2544 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2545 IEEE80211_MAX_MESH_ID_LEN);
2546 wdev->mesh_id_up_len =
2547 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2548 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2549 wdev->mesh_id_up_len);
2550 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002551 break;
2552 case NL80211_IFTYPE_P2P_DEVICE:
2553 /*
2554 * P2P Device doesn't have a netdev, so doesn't go
2555 * through the netdev notifier and must be added here
2556 */
2557 mutex_init(&wdev->mtx);
2558 INIT_LIST_HEAD(&wdev->event_list);
2559 spin_lock_init(&wdev->event_lock);
2560 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2561 spin_lock_init(&wdev->mgmt_registrations_lock);
2562
Johannes Berg98104fde2012-06-16 00:19:54 +02002563 wdev->identifier = ++rdev->wdev_id;
2564 list_add_rcu(&wdev->list, &rdev->wdev_list);
2565 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002566 break;
2567 default:
2568 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002569 }
2570
Eric W. Biederman15e47302012-09-07 20:12:54 +00002571 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002572 rdev, wdev) < 0) {
2573 nlmsg_free(msg);
2574 return -ENOBUFS;
2575 }
2576
2577 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002578}
2579
2580static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2581{
Johannes Berg4c476992010-10-04 21:36:35 +02002582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002583 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002584
Johannes Berg4c476992010-10-04 21:36:35 +02002585 if (!rdev->ops->del_virtual_intf)
2586 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002587
Johannes Berg84efbb82012-06-16 00:00:26 +02002588 /*
2589 * If we remove a wireless device without a netdev then clear
2590 * user_ptr[1] so that nl80211_post_doit won't dereference it
2591 * to check if it needs to do dev_put(). Otherwise it crashes
2592 * since the wdev has been freed, unlike with a netdev where
2593 * we need the dev_put() for the netdev to really be freed.
2594 */
2595 if (!wdev->netdev)
2596 info->user_ptr[1] = NULL;
2597
Hila Gonene35e4d22012-06-27 17:19:42 +03002598 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04002599}
2600
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002601static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2602{
2603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2604 struct net_device *dev = info->user_ptr[1];
2605 u16 noack_map;
2606
2607 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2608 return -EINVAL;
2609
2610 if (!rdev->ops->set_noack_map)
2611 return -EOPNOTSUPP;
2612
2613 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2614
Hila Gonene35e4d22012-06-27 17:19:42 +03002615 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002616}
2617
Johannes Berg41ade002007-12-19 02:03:29 +01002618struct get_key_cookie {
2619 struct sk_buff *msg;
2620 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002621 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002622};
2623
2624static void get_key_callback(void *c, struct key_params *params)
2625{
Johannes Bergb9454e82009-07-08 13:29:08 +02002626 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002627 struct get_key_cookie *cookie = c;
2628
David S. Miller9360ffd2012-03-29 04:41:26 -04002629 if ((params->key &&
2630 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2631 params->key_len, params->key)) ||
2632 (params->seq &&
2633 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2634 params->seq_len, params->seq)) ||
2635 (params->cipher &&
2636 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2637 params->cipher)))
2638 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002639
Johannes Bergb9454e82009-07-08 13:29:08 +02002640 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2641 if (!key)
2642 goto nla_put_failure;
2643
David S. Miller9360ffd2012-03-29 04:41:26 -04002644 if ((params->key &&
2645 nla_put(cookie->msg, NL80211_KEY_DATA,
2646 params->key_len, params->key)) ||
2647 (params->seq &&
2648 nla_put(cookie->msg, NL80211_KEY_SEQ,
2649 params->seq_len, params->seq)) ||
2650 (params->cipher &&
2651 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2652 params->cipher)))
2653 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002654
David S. Miller9360ffd2012-03-29 04:41:26 -04002655 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2656 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002657
2658 nla_nest_end(cookie->msg, key);
2659
Johannes Berg41ade002007-12-19 02:03:29 +01002660 return;
2661 nla_put_failure:
2662 cookie->error = 1;
2663}
2664
2665static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2666{
Johannes Berg4c476992010-10-04 21:36:35 +02002667 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002668 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002669 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002670 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002671 const u8 *mac_addr = NULL;
2672 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002673 struct get_key_cookie cookie = {
2674 .error = 0,
2675 };
2676 void *hdr;
2677 struct sk_buff *msg;
2678
2679 if (info->attrs[NL80211_ATTR_KEY_IDX])
2680 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2681
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002682 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002683 return -EINVAL;
2684
2685 if (info->attrs[NL80211_ATTR_MAC])
2686 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2687
Johannes Berge31b8212010-10-05 19:39:30 +02002688 pairwise = !!mac_addr;
2689 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2690 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2691 if (kt >= NUM_NL80211_KEYTYPES)
2692 return -EINVAL;
2693 if (kt != NL80211_KEYTYPE_GROUP &&
2694 kt != NL80211_KEYTYPE_PAIRWISE)
2695 return -EINVAL;
2696 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2697 }
2698
Johannes Berg4c476992010-10-04 21:36:35 +02002699 if (!rdev->ops->get_key)
2700 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002701
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002703 if (!msg)
2704 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002705
Eric W. Biederman15e47302012-09-07 20:12:54 +00002706 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002707 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002708 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002709 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002710
2711 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002712 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002713
David S. Miller9360ffd2012-03-29 04:41:26 -04002714 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2715 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2716 goto nla_put_failure;
2717 if (mac_addr &&
2718 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2719 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002720
Johannes Berge31b8212010-10-05 19:39:30 +02002721 if (pairwise && mac_addr &&
2722 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2723 return -ENOENT;
2724
Hila Gonene35e4d22012-06-27 17:19:42 +03002725 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2726 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002727
2728 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002729 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002730
2731 if (cookie.error)
2732 goto nla_put_failure;
2733
2734 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002735 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002736
2737 nla_put_failure:
2738 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002739 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002740 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002741 return err;
2742}
2743
2744static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2745{
Johannes Berg4c476992010-10-04 21:36:35 +02002746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002747 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002748 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002749 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002750
Johannes Bergb9454e82009-07-08 13:29:08 +02002751 err = nl80211_parse_key(info, &key);
2752 if (err)
2753 return err;
2754
2755 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002756 return -EINVAL;
2757
Johannes Bergb9454e82009-07-08 13:29:08 +02002758 /* only support setting default key */
2759 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002760 return -EINVAL;
2761
Johannes Bergfffd0932009-07-08 14:22:54 +02002762 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002763
2764 if (key.def) {
2765 if (!rdev->ops->set_default_key) {
2766 err = -EOPNOTSUPP;
2767 goto out;
2768 }
2769
2770 err = nl80211_key_allowed(dev->ieee80211_ptr);
2771 if (err)
2772 goto out;
2773
Hila Gonene35e4d22012-06-27 17:19:42 +03002774 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002775 key.def_uni, key.def_multi);
2776
2777 if (err)
2778 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002779
Johannes Berg3d23e342009-09-29 23:27:28 +02002780#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002781 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002782#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002783 } else {
2784 if (key.def_uni || !key.def_multi) {
2785 err = -EINVAL;
2786 goto out;
2787 }
2788
2789 if (!rdev->ops->set_default_mgmt_key) {
2790 err = -EOPNOTSUPP;
2791 goto out;
2792 }
2793
2794 err = nl80211_key_allowed(dev->ieee80211_ptr);
2795 if (err)
2796 goto out;
2797
Hila Gonene35e4d22012-06-27 17:19:42 +03002798 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002799 if (err)
2800 goto out;
2801
2802#ifdef CONFIG_CFG80211_WEXT
2803 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2804#endif
2805 }
2806
2807 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002808 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002809
Johannes Berg41ade002007-12-19 02:03:29 +01002810 return err;
2811}
2812
2813static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2814{
Johannes Berg4c476992010-10-04 21:36:35 +02002815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002816 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002817 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002818 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002819 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002820
Johannes Bergb9454e82009-07-08 13:29:08 +02002821 err = nl80211_parse_key(info, &key);
2822 if (err)
2823 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002824
Johannes Bergb9454e82009-07-08 13:29:08 +02002825 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002826 return -EINVAL;
2827
Johannes Berg41ade002007-12-19 02:03:29 +01002828 if (info->attrs[NL80211_ATTR_MAC])
2829 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2830
Johannes Berge31b8212010-10-05 19:39:30 +02002831 if (key.type == -1) {
2832 if (mac_addr)
2833 key.type = NL80211_KEYTYPE_PAIRWISE;
2834 else
2835 key.type = NL80211_KEYTYPE_GROUP;
2836 }
2837
2838 /* for now */
2839 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2840 key.type != NL80211_KEYTYPE_GROUP)
2841 return -EINVAL;
2842
Johannes Berg4c476992010-10-04 21:36:35 +02002843 if (!rdev->ops->add_key)
2844 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002845
Johannes Berge31b8212010-10-05 19:39:30 +02002846 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
2847 key.type == NL80211_KEYTYPE_PAIRWISE,
2848 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02002849 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02002850
2851 wdev_lock(dev->ieee80211_ptr);
2852 err = nl80211_key_allowed(dev->ieee80211_ptr);
2853 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002854 err = rdev_add_key(rdev, dev, key.idx,
2855 key.type == NL80211_KEYTYPE_PAIRWISE,
2856 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02002857 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002858
Johannes Berg41ade002007-12-19 02:03:29 +01002859 return err;
2860}
2861
2862static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
2863{
Johannes Berg4c476992010-10-04 21:36:35 +02002864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002865 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002866 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002867 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02002868 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002869
Johannes Bergb9454e82009-07-08 13:29:08 +02002870 err = nl80211_parse_key(info, &key);
2871 if (err)
2872 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002873
2874 if (info->attrs[NL80211_ATTR_MAC])
2875 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2876
Johannes Berge31b8212010-10-05 19:39:30 +02002877 if (key.type == -1) {
2878 if (mac_addr)
2879 key.type = NL80211_KEYTYPE_PAIRWISE;
2880 else
2881 key.type = NL80211_KEYTYPE_GROUP;
2882 }
2883
2884 /* for now */
2885 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2886 key.type != NL80211_KEYTYPE_GROUP)
2887 return -EINVAL;
2888
Johannes Berg4c476992010-10-04 21:36:35 +02002889 if (!rdev->ops->del_key)
2890 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002891
Johannes Bergfffd0932009-07-08 14:22:54 +02002892 wdev_lock(dev->ieee80211_ptr);
2893 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02002894
2895 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
2896 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2897 err = -ENOENT;
2898
Johannes Bergfffd0932009-07-08 14:22:54 +02002899 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03002900 err = rdev_del_key(rdev, dev, key.idx,
2901 key.type == NL80211_KEYTYPE_PAIRWISE,
2902 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01002903
Johannes Berg3d23e342009-09-29 23:27:28 +02002904#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02002905 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02002906 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02002907 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02002908 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02002909 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
2910 }
2911#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02002912 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02002913
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return err;
2915}
2916
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05302917/* This function returns an error or the number of nested attributes */
2918static int validate_acl_mac_addrs(struct nlattr *nl_attr)
2919{
2920 struct nlattr *attr;
2921 int n_entries = 0, tmp;
2922
2923 nla_for_each_nested(attr, nl_attr, tmp) {
2924 if (nla_len(attr) != ETH_ALEN)
2925 return -EINVAL;
2926
2927 n_entries++;
2928 }
2929
2930 return n_entries;
2931}
2932
2933/*
2934 * This function parses ACL information and allocates memory for ACL data.
2935 * On successful return, the calling function is responsible to free the
2936 * ACL buffer returned by this function.
2937 */
2938static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
2939 struct genl_info *info)
2940{
2941 enum nl80211_acl_policy acl_policy;
2942 struct nlattr *attr;
2943 struct cfg80211_acl_data *acl;
2944 int i = 0, n_entries, tmp;
2945
2946 if (!wiphy->max_acl_mac_addrs)
2947 return ERR_PTR(-EOPNOTSUPP);
2948
2949 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
2950 return ERR_PTR(-EINVAL);
2951
2952 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
2953 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
2954 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
2955 return ERR_PTR(-EINVAL);
2956
2957 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
2958 return ERR_PTR(-EINVAL);
2959
2960 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
2961 if (n_entries < 0)
2962 return ERR_PTR(n_entries);
2963
2964 if (n_entries > wiphy->max_acl_mac_addrs)
2965 return ERR_PTR(-ENOTSUPP);
2966
2967 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
2968 GFP_KERNEL);
2969 if (!acl)
2970 return ERR_PTR(-ENOMEM);
2971
2972 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
2973 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
2974 i++;
2975 }
2976
2977 acl->n_acl_entries = n_entries;
2978 acl->acl_policy = acl_policy;
2979
2980 return acl;
2981}
2982
2983static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
2984{
2985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2986 struct net_device *dev = info->user_ptr[1];
2987 struct cfg80211_acl_data *acl;
2988 int err;
2989
2990 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2991 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2992 return -EOPNOTSUPP;
2993
2994 if (!dev->ieee80211_ptr->beacon_interval)
2995 return -EINVAL;
2996
2997 acl = parse_acl_data(&rdev->wiphy, info);
2998 if (IS_ERR(acl))
2999 return PTR_ERR(acl);
3000
3001 err = rdev_set_mac_acl(rdev, dev, acl);
3002
3003 kfree(acl);
3004
3005 return err;
3006}
3007
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003008static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003009 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003010{
Johannes Berg88600202012-02-13 15:17:18 +01003011 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003012
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003013 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3014 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3015 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3016 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003017 return -EINVAL;
3018
Johannes Berg88600202012-02-13 15:17:18 +01003019 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003020
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003021 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3022 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3023 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003024 if (!bcn->head_len)
3025 return -EINVAL;
3026 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003027 }
3028
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003029 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3030 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3031 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003032 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003033 }
3034
Johannes Berg4c476992010-10-04 21:36:35 +02003035 if (!haveinfo)
3036 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003037
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003038 if (attrs[NL80211_ATTR_IE]) {
3039 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3040 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003041 }
3042
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003043 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003044 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003045 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003046 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003047 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003048 }
3049
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003050 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003051 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003052 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003053 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003054 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003055 }
3056
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003057 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3058 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3059 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003060 }
3061
Johannes Berg88600202012-02-13 15:17:18 +01003062 return 0;
3063}
3064
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003065static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3066 struct cfg80211_ap_settings *params)
3067{
3068 struct wireless_dev *wdev;
3069 bool ret = false;
3070
Johannes Berg89a54e42012-06-15 14:33:17 +02003071 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003072 if (wdev->iftype != NL80211_IFTYPE_AP &&
3073 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3074 continue;
3075
Johannes Berg683b6d32012-11-08 21:25:48 +01003076 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003077 continue;
3078
Johannes Berg683b6d32012-11-08 21:25:48 +01003079 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003080 ret = true;
3081 break;
3082 }
3083
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003084 return ret;
3085}
3086
Jouni Malinene39e5b52012-09-30 19:29:39 +03003087static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3088 enum nl80211_auth_type auth_type,
3089 enum nl80211_commands cmd)
3090{
3091 if (auth_type > NL80211_AUTHTYPE_MAX)
3092 return false;
3093
3094 switch (cmd) {
3095 case NL80211_CMD_AUTHENTICATE:
3096 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3097 auth_type == NL80211_AUTHTYPE_SAE)
3098 return false;
3099 return true;
3100 case NL80211_CMD_CONNECT:
3101 case NL80211_CMD_START_AP:
3102 /* SAE not supported yet */
3103 if (auth_type == NL80211_AUTHTYPE_SAE)
3104 return false;
3105 return true;
3106 default:
3107 return false;
3108 }
3109}
3110
Johannes Berg88600202012-02-13 15:17:18 +01003111static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3112{
3113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3114 struct net_device *dev = info->user_ptr[1];
3115 struct wireless_dev *wdev = dev->ieee80211_ptr;
3116 struct cfg80211_ap_settings params;
3117 int err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01003118 u8 radar_detect_width = 0;
Johannes Berg88600202012-02-13 15:17:18 +01003119
3120 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3121 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3122 return -EOPNOTSUPP;
3123
3124 if (!rdev->ops->start_ap)
3125 return -EOPNOTSUPP;
3126
3127 if (wdev->beacon_interval)
3128 return -EALREADY;
3129
3130 memset(&params, 0, sizeof(params));
3131
3132 /* these are required for START_AP */
3133 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3134 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3135 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3136 return -EINVAL;
3137
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003138 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003139 if (err)
3140 return err;
3141
3142 params.beacon_interval =
3143 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3144 params.dtim_period =
3145 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3146
3147 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3148 if (err)
3149 return err;
3150
3151 /*
3152 * In theory, some of these attributes should be required here
3153 * but since they were not used when the command was originally
3154 * added, keep them optional for old user space programs to let
3155 * them continue to work with drivers that do not need the
3156 * additional information -- drivers must check!
3157 */
3158 if (info->attrs[NL80211_ATTR_SSID]) {
3159 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3160 params.ssid_len =
3161 nla_len(info->attrs[NL80211_ATTR_SSID]);
3162 if (params.ssid_len == 0 ||
3163 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3164 return -EINVAL;
3165 }
3166
3167 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3168 params.hidden_ssid = nla_get_u32(
3169 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3170 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3171 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3172 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3173 return -EINVAL;
3174 }
3175
3176 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3177
3178 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3179 params.auth_type = nla_get_u32(
3180 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003181 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3182 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003183 return -EINVAL;
3184 } else
3185 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3186
3187 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3188 NL80211_MAX_NR_CIPHER_SUITES);
3189 if (err)
3190 return err;
3191
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303192 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3193 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3194 return -EOPNOTSUPP;
3195 params.inactivity_timeout = nla_get_u16(
3196 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3197 }
3198
Johannes Berg53cabad2012-11-14 15:17:28 +01003199 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3201 return -EINVAL;
3202 params.p2p_ctwindow =
3203 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3204 if (params.p2p_ctwindow > 127)
3205 return -EINVAL;
3206 if (params.p2p_ctwindow != 0 &&
3207 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3208 return -EINVAL;
3209 }
3210
3211 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3212 u8 tmp;
3213
3214 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3215 return -EINVAL;
3216 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3217 if (tmp > 1)
3218 return -EINVAL;
3219 params.p2p_opp_ps = tmp;
3220 if (params.p2p_opp_ps != 0 &&
3221 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3222 return -EINVAL;
3223 }
3224
Johannes Bergaa430da2012-05-16 23:50:18 +02003225 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003226 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3227 if (err)
3228 return err;
3229 } else if (wdev->preset_chandef.chan) {
3230 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003231 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003232 return -EINVAL;
3233
Johannes Berg683b6d32012-11-08 21:25:48 +01003234 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
Johannes Bergaa430da2012-05-16 23:50:18 +02003235 return -EINVAL;
3236
Simon Wunderlich04f39042013-02-08 18:16:19 +01003237 err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
3238 if (err < 0)
3239 return err;
3240 if (err) {
3241 radar_detect_width = BIT(params.chandef.width);
3242 params.radar_required = true;
3243 }
3244
Simon Wunderlich04f39042013-02-08 18:16:19 +01003245 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
3246 params.chandef.chan,
3247 CHAN_MODE_SHARED,
3248 radar_detect_width);
Michal Kaziore4e32452012-06-29 12:47:08 +02003249 if (err)
3250 return err;
3251
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303252 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3253 params.acl = parse_acl_data(&rdev->wiphy, info);
3254 if (IS_ERR(params.acl))
3255 return PTR_ERR(params.acl);
3256 }
3257
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003258 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003259 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003260 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003261 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003262 wdev->beacon_interval = params.beacon_interval;
Johannes Berg683b6d32012-11-08 21:25:48 +01003263 wdev->channel = params.chandef.chan;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003264 wdev->ssid_len = params.ssid_len;
3265 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003266 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003267 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303268
3269 kfree(params.acl);
3270
Johannes Berg56d18932011-05-09 18:41:15 +02003271 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003272}
3273
Johannes Berg88600202012-02-13 15:17:18 +01003274static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3275{
3276 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3277 struct net_device *dev = info->user_ptr[1];
3278 struct wireless_dev *wdev = dev->ieee80211_ptr;
3279 struct cfg80211_beacon_data params;
3280 int err;
3281
3282 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3283 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3284 return -EOPNOTSUPP;
3285
3286 if (!rdev->ops->change_beacon)
3287 return -EOPNOTSUPP;
3288
3289 if (!wdev->beacon_interval)
3290 return -EINVAL;
3291
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003292 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003293 if (err)
3294 return err;
3295
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003296 wdev_lock(wdev);
3297 err = rdev_change_beacon(rdev, dev, &params);
3298 wdev_unlock(wdev);
3299
3300 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003301}
3302
3303static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003304{
Johannes Berg4c476992010-10-04 21:36:35 +02003305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3306 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003307
Michal Kazior60771782012-06-29 12:46:56 +02003308 return cfg80211_stop_ap(rdev, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003309}
3310
Johannes Berg5727ef12007-12-19 02:03:34 +01003311static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3312 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3313 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3314 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003315 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003316 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003317 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003318};
3319
Johannes Bergeccb8e82009-05-11 21:57:56 +03003320static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003321 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003322 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003323{
3324 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003325 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003326 int flag;
3327
Johannes Bergeccb8e82009-05-11 21:57:56 +03003328 /*
3329 * Try parsing the new attribute first so userspace
3330 * can specify both for older kernels.
3331 */
3332 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3333 if (nla) {
3334 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003335
Johannes Bergeccb8e82009-05-11 21:57:56 +03003336 sta_flags = nla_data(nla);
3337 params->sta_flags_mask = sta_flags->mask;
3338 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003339 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003340 if ((params->sta_flags_mask |
3341 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3342 return -EINVAL;
3343 return 0;
3344 }
3345
3346 /* if present, parse the old attribute */
3347
3348 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003349 if (!nla)
3350 return 0;
3351
3352 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3353 nla, sta_flags_policy))
3354 return -EINVAL;
3355
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003356 /*
3357 * Only allow certain flags for interface types so that
3358 * other attributes are silently ignored. Remember that
3359 * this is backward compatibility code with old userspace
3360 * and shouldn't be hit in other cases anyway.
3361 */
3362 switch (iftype) {
3363 case NL80211_IFTYPE_AP:
3364 case NL80211_IFTYPE_AP_VLAN:
3365 case NL80211_IFTYPE_P2P_GO:
3366 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3367 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3368 BIT(NL80211_STA_FLAG_WME) |
3369 BIT(NL80211_STA_FLAG_MFP);
3370 break;
3371 case NL80211_IFTYPE_P2P_CLIENT:
3372 case NL80211_IFTYPE_STATION:
3373 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3374 BIT(NL80211_STA_FLAG_TDLS_PEER);
3375 break;
3376 case NL80211_IFTYPE_MESH_POINT:
3377 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3378 BIT(NL80211_STA_FLAG_MFP) |
3379 BIT(NL80211_STA_FLAG_AUTHORIZED);
3380 default:
3381 return -EINVAL;
3382 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003383
Johannes Berg3383b5a2012-05-10 20:14:43 +02003384 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3385 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003386 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003387
Johannes Berg3383b5a2012-05-10 20:14:43 +02003388 /* no longer support new API additions in old API */
3389 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3390 return -EINVAL;
3391 }
3392 }
3393
Johannes Berg5727ef12007-12-19 02:03:34 +01003394 return 0;
3395}
3396
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003397static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3398 int attr)
3399{
3400 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003401 u32 bitrate;
3402 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003403
3404 rate = nla_nest_start(msg, attr);
3405 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003406 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003407
3408 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3409 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003410 /* report 16-bit bitrate only if we can */
3411 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003412 if (bitrate > 0 &&
3413 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3414 return false;
3415 if (bitrate_compat > 0 &&
3416 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3417 return false;
3418
3419 if (info->flags & RATE_INFO_FLAGS_MCS) {
3420 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3421 return false;
3422 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3423 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3424 return false;
3425 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3426 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3427 return false;
3428 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3429 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3430 return false;
3431 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3432 return false;
3433 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3434 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3435 return false;
3436 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3437 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3438 return false;
3439 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3440 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3441 return false;
3442 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3443 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3444 return false;
3445 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3446 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3447 return false;
3448 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003449
3450 nla_nest_end(msg, rate);
3451 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003452}
3453
Felix Fietkau119363c2013-04-22 16:29:30 +02003454static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3455 int id)
3456{
3457 void *attr;
3458 int i = 0;
3459
3460 if (!mask)
3461 return true;
3462
3463 attr = nla_nest_start(msg, id);
3464 if (!attr)
3465 return false;
3466
3467 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3468 if (!(mask & BIT(i)))
3469 continue;
3470
3471 if (nla_put_u8(msg, i, signal[i]))
3472 return false;
3473 }
3474
3475 nla_nest_end(msg, attr);
3476
3477 return true;
3478}
3479
Eric W. Biederman15e47302012-09-07 20:12:54 +00003480static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003481 int flags,
3482 struct cfg80211_registered_device *rdev,
3483 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003484 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003485{
3486 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003487 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003488
Eric W. Biederman15e47302012-09-07 20:12:54 +00003489 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003490 if (!hdr)
3491 return -1;
3492
David S. Miller9360ffd2012-03-29 04:41:26 -04003493 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3494 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3495 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3496 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003497
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003498 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3499 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003500 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003501 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3502 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3503 sinfo->connected_time))
3504 goto nla_put_failure;
3505 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3506 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3507 sinfo->inactive_time))
3508 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003509 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3510 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003511 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003512 (u32)sinfo->rx_bytes))
3513 goto nla_put_failure;
3514 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003515 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003516 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3517 (u32)sinfo->tx_bytes))
3518 goto nla_put_failure;
3519 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3520 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003521 sinfo->rx_bytes))
3522 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003523 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3524 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003525 sinfo->tx_bytes))
3526 goto nla_put_failure;
3527 if ((sinfo->filled & STATION_INFO_LLID) &&
3528 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3529 goto nla_put_failure;
3530 if ((sinfo->filled & STATION_INFO_PLID) &&
3531 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3532 goto nla_put_failure;
3533 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3534 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3535 sinfo->plink_state))
3536 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003537 switch (rdev->wiphy.signal_type) {
3538 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003539 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3540 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3541 sinfo->signal))
3542 goto nla_put_failure;
3543 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3544 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3545 sinfo->signal_avg))
3546 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003547 break;
3548 default:
3549 break;
3550 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003551 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3552 if (!nl80211_put_signal(msg, sinfo->chains,
3553 sinfo->chain_signal,
3554 NL80211_STA_INFO_CHAIN_SIGNAL))
3555 goto nla_put_failure;
3556 }
3557 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3558 if (!nl80211_put_signal(msg, sinfo->chains,
3559 sinfo->chain_signal_avg,
3560 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3561 goto nla_put_failure;
3562 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003563 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003564 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3565 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003566 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003567 }
3568 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3569 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3570 NL80211_STA_INFO_RX_BITRATE))
3571 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003572 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003573 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3574 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3575 sinfo->rx_packets))
3576 goto nla_put_failure;
3577 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3578 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3579 sinfo->tx_packets))
3580 goto nla_put_failure;
3581 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3582 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3583 sinfo->tx_retries))
3584 goto nla_put_failure;
3585 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3586 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3587 sinfo->tx_failed))
3588 goto nla_put_failure;
3589 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3590 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3591 sinfo->beacon_loss_count))
3592 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003593 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3594 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3595 sinfo->local_pm))
3596 goto nla_put_failure;
3597 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3598 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3599 sinfo->peer_pm))
3600 goto nla_put_failure;
3601 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3602 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3603 sinfo->nonpeer_pm))
3604 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003605 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3606 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3607 if (!bss_param)
3608 goto nla_put_failure;
3609
David S. Miller9360ffd2012-03-29 04:41:26 -04003610 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3611 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3612 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3613 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3614 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3615 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3616 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3617 sinfo->bss_param.dtim_period) ||
3618 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3619 sinfo->bss_param.beacon_interval))
3620 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003621
3622 nla_nest_end(msg, bss_param);
3623 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003624 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3625 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3626 sizeof(struct nl80211_sta_flag_update),
3627 &sinfo->sta_flags))
3628 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003629 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3630 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3631 sinfo->t_offset))
3632 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003633 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003634
David S. Miller9360ffd2012-03-29 04:41:26 -04003635 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3636 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3637 sinfo->assoc_req_ies))
3638 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003639
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003640 return genlmsg_end(msg, hdr);
3641
3642 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003643 genlmsg_cancel(msg, hdr);
3644 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003645}
3646
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003647static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003648 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003649{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003650 struct station_info sinfo;
3651 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02003652 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003653 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003654 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003655 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003656
Johannes Berg97990a02013-04-19 01:02:55 +02003657 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003658 if (err)
3659 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003660
Johannes Berg97990a02013-04-19 01:02:55 +02003661 if (!wdev->netdev) {
3662 err = -EINVAL;
3663 goto out_err;
3664 }
3665
Johannes Bergbba95fe2008-07-29 13:22:51 +02003666 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003667 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003668 goto out_err;
3669 }
3670
Johannes Bergbba95fe2008-07-29 13:22:51 +02003671 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003672 memset(&sinfo, 0, sizeof(sinfo));
Johannes Berg97990a02013-04-19 01:02:55 +02003673 err = rdev_dump_station(dev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003674 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003675 if (err == -ENOENT)
3676 break;
3677 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003678 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003679
3680 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003681 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003682 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02003683 dev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003684 &sinfo) < 0)
3685 goto out;
3686
3687 sta_idx++;
3688 }
3689
3690
3691 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003692 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003693 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003694 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02003695 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003696
3697 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003698}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003699
Johannes Berg5727ef12007-12-19 02:03:34 +01003700static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3701{
Johannes Berg4c476992010-10-04 21:36:35 +02003702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3703 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003704 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003705 struct sk_buff *msg;
3706 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003707 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003708
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003709 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003710
3711 if (!info->attrs[NL80211_ATTR_MAC])
3712 return -EINVAL;
3713
3714 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3715
Johannes Berg4c476992010-10-04 21:36:35 +02003716 if (!rdev->ops->get_station)
3717 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003718
Hila Gonene35e4d22012-06-27 17:19:42 +03003719 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003720 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003721 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003722
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003723 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003724 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003725 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003726
Eric W. Biederman15e47302012-09-07 20:12:54 +00003727 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003728 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003729 nlmsg_free(msg);
3730 return -ENOBUFS;
3731 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003732
Johannes Berg4c476992010-10-04 21:36:35 +02003733 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003734}
3735
Johannes Berg77ee7c82013-02-15 00:48:33 +01003736int cfg80211_check_station_change(struct wiphy *wiphy,
3737 struct station_parameters *params,
3738 enum cfg80211_station_type statype)
3739{
3740 if (params->listen_interval != -1)
3741 return -EINVAL;
3742 if (params->aid)
3743 return -EINVAL;
3744
3745 /* When you run into this, adjust the code below for the new flag */
3746 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3747
3748 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003749 case CFG80211_STA_MESH_PEER_KERNEL:
3750 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003751 /*
3752 * No ignoring the TDLS flag here -- the userspace mesh
3753 * code doesn't have the bug of including TDLS in the
3754 * mask everywhere.
3755 */
3756 if (params->sta_flags_mask &
3757 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3758 BIT(NL80211_STA_FLAG_MFP) |
3759 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3760 return -EINVAL;
3761 break;
3762 case CFG80211_STA_TDLS_PEER_SETUP:
3763 case CFG80211_STA_TDLS_PEER_ACTIVE:
3764 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3765 return -EINVAL;
3766 /* ignore since it can't change */
3767 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3768 break;
3769 default:
3770 /* disallow mesh-specific things */
3771 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3772 return -EINVAL;
3773 if (params->local_pm)
3774 return -EINVAL;
3775 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3776 return -EINVAL;
3777 }
3778
3779 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3780 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3781 /* TDLS can't be set, ... */
3782 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3783 return -EINVAL;
3784 /*
3785 * ... but don't bother the driver with it. This works around
3786 * a hostapd/wpa_supplicant issue -- it always includes the
3787 * TLDS_PEER flag in the mask even for AP mode.
3788 */
3789 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3790 }
3791
3792 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3793 /* reject other things that can't change */
3794 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3795 return -EINVAL;
3796 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3797 return -EINVAL;
3798 if (params->supported_rates)
3799 return -EINVAL;
3800 if (params->ext_capab || params->ht_capa || params->vht_capa)
3801 return -EINVAL;
3802 }
3803
3804 if (statype != CFG80211_STA_AP_CLIENT) {
3805 if (params->vlan)
3806 return -EINVAL;
3807 }
3808
3809 switch (statype) {
3810 case CFG80211_STA_AP_MLME_CLIENT:
3811 /* Use this only for authorizing/unauthorizing a station */
3812 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3813 return -EOPNOTSUPP;
3814 break;
3815 case CFG80211_STA_AP_CLIENT:
3816 /* accept only the listed bits */
3817 if (params->sta_flags_mask &
3818 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3819 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3820 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3821 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3822 BIT(NL80211_STA_FLAG_WME) |
3823 BIT(NL80211_STA_FLAG_MFP)))
3824 return -EINVAL;
3825
3826 /* but authenticated/associated only if driver handles it */
3827 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3828 params->sta_flags_mask &
3829 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3830 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3831 return -EINVAL;
3832 break;
3833 case CFG80211_STA_IBSS:
3834 case CFG80211_STA_AP_STA:
3835 /* reject any changes other than AUTHORIZED */
3836 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
3837 return -EINVAL;
3838 break;
3839 case CFG80211_STA_TDLS_PEER_SETUP:
3840 /* reject any changes other than AUTHORIZED or WME */
3841 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3842 BIT(NL80211_STA_FLAG_WME)))
3843 return -EINVAL;
3844 /* force (at least) rates when authorizing */
3845 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
3846 !params->supported_rates)
3847 return -EINVAL;
3848 break;
3849 case CFG80211_STA_TDLS_PEER_ACTIVE:
3850 /* reject any changes */
3851 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003852 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003853 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3854 return -EINVAL;
3855 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08003856 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003857 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3858 return -EINVAL;
3859 break;
3860 }
3861
3862 return 0;
3863}
3864EXPORT_SYMBOL(cfg80211_check_station_change);
3865
Johannes Berg5727ef12007-12-19 02:03:34 +01003866/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01003867 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01003868 */
Johannes Berg80b99892011-11-18 16:23:01 +01003869static struct net_device *get_vlan(struct genl_info *info,
3870 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01003871{
Johannes Berg463d0182009-07-14 00:33:35 +02003872 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01003873 struct net_device *v;
3874 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01003875
Johannes Berg80b99892011-11-18 16:23:01 +01003876 if (!vlanattr)
3877 return NULL;
3878
3879 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
3880 if (!v)
3881 return ERR_PTR(-ENODEV);
3882
3883 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
3884 ret = -EINVAL;
3885 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01003886 }
Johannes Berg80b99892011-11-18 16:23:01 +01003887
Johannes Berg77ee7c82013-02-15 00:48:33 +01003888 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
3889 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3890 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
3891 ret = -EINVAL;
3892 goto error;
3893 }
3894
Johannes Berg80b99892011-11-18 16:23:01 +01003895 if (!netif_running(v)) {
3896 ret = -ENETDOWN;
3897 goto error;
3898 }
3899
3900 return v;
3901 error:
3902 dev_put(v);
3903 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01003904}
3905
Jouni Malinendf881292013-02-14 21:10:54 +02003906static struct nla_policy
3907nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = {
3908 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
3909 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
3910};
3911
Johannes Bergff276692013-02-15 00:09:01 +01003912static int nl80211_parse_sta_wme(struct genl_info *info,
3913 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02003914{
Jouni Malinendf881292013-02-14 21:10:54 +02003915 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
3916 struct nlattr *nla;
3917 int err;
3918
Jouni Malinendf881292013-02-14 21:10:54 +02003919 /* parse WME attributes if present */
3920 if (!info->attrs[NL80211_ATTR_STA_WME])
3921 return 0;
3922
3923 nla = info->attrs[NL80211_ATTR_STA_WME];
3924 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
3925 nl80211_sta_wme_policy);
3926 if (err)
3927 return err;
3928
3929 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
3930 params->uapsd_queues = nla_get_u8(
3931 tb[NL80211_STA_WME_UAPSD_QUEUES]);
3932 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
3933 return -EINVAL;
3934
3935 if (tb[NL80211_STA_WME_MAX_SP])
3936 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
3937
3938 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
3939 return -EINVAL;
3940
3941 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
3942
3943 return 0;
3944}
3945
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303946static int nl80211_parse_sta_channel_info(struct genl_info *info,
3947 struct station_parameters *params)
3948{
3949 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
3950 params->supported_channels =
3951 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3952 params->supported_channels_len =
3953 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
3954 /*
3955 * Need to include at least one (first channel, number of
3956 * channels) tuple for each subband, and must have proper
3957 * tuples for the rest of the data as well.
3958 */
3959 if (params->supported_channels_len < 2)
3960 return -EINVAL;
3961 if (params->supported_channels_len % 2)
3962 return -EINVAL;
3963 }
3964
3965 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
3966 params->supported_oper_classes =
3967 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3968 params->supported_oper_classes_len =
3969 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
3970 /*
3971 * The value of the Length field of the Supported Operating
3972 * Classes element is between 2 and 253.
3973 */
3974 if (params->supported_oper_classes_len < 2 ||
3975 params->supported_oper_classes_len > 253)
3976 return -EINVAL;
3977 }
3978 return 0;
3979}
3980
Johannes Bergff276692013-02-15 00:09:01 +01003981static int nl80211_set_station_tdls(struct genl_info *info,
3982 struct station_parameters *params)
3983{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303984 int err;
Johannes Bergff276692013-02-15 00:09:01 +01003985 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03003986 if (info->attrs[NL80211_ATTR_PEER_AID])
3987 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01003988 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
3989 params->ht_capa =
3990 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
3991 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
3992 params->vht_capa =
3993 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
3994
Sunil Duttc01fc9a2013-10-09 20:45:21 +05303995 err = nl80211_parse_sta_channel_info(info, params);
3996 if (err)
3997 return err;
3998
Johannes Bergff276692013-02-15 00:09:01 +01003999 return nl80211_parse_sta_wme(info, params);
4000}
4001
Johannes Berg5727ef12007-12-19 02:03:34 +01004002static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4003{
Johannes Berg4c476992010-10-04 21:36:35 +02004004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004005 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004006 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004007 u8 *mac_addr;
4008 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004009
4010 memset(&params, 0, sizeof(params));
4011
4012 params.listen_interval = -1;
4013
Johannes Berg77ee7c82013-02-15 00:48:33 +01004014 if (!rdev->ops->change_station)
4015 return -EOPNOTSUPP;
4016
Johannes Berg5727ef12007-12-19 02:03:34 +01004017 if (info->attrs[NL80211_ATTR_STA_AID])
4018 return -EINVAL;
4019
4020 if (!info->attrs[NL80211_ATTR_MAC])
4021 return -EINVAL;
4022
4023 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4024
4025 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4026 params.supported_rates =
4027 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4028 params.supported_rates_len =
4029 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4030 }
4031
Jouni Malinen9d62a982013-02-14 21:10:13 +02004032 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4033 params.capability =
4034 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4035 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4036 }
4037
4038 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4039 params.ext_capab =
4040 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4041 params.ext_capab_len =
4042 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4043 }
4044
Jouni Malinendf881292013-02-14 21:10:54 +02004045 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004046 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004047
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004048 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004049 return -EINVAL;
4050
Johannes Bergf8bacc22013-02-14 23:27:01 +01004051 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004052 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004053 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4054 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4055 return -EINVAL;
4056 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004057
Johannes Bergf8bacc22013-02-14 23:27:01 +01004058 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004059 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004060 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4061 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4062 return -EINVAL;
4063 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4064 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004065
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004066 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4067 enum nl80211_mesh_power_mode pm = nla_get_u32(
4068 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4069
4070 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4071 pm > NL80211_MESH_POWER_MAX)
4072 return -EINVAL;
4073
4074 params.local_pm = pm;
4075 }
4076
Johannes Berg77ee7c82013-02-15 00:48:33 +01004077 /* Include parameters for TDLS peer (will check later) */
4078 err = nl80211_set_station_tdls(info, &params);
4079 if (err)
4080 return err;
4081
4082 params.vlan = get_vlan(info, rdev);
4083 if (IS_ERR(params.vlan))
4084 return PTR_ERR(params.vlan);
4085
Johannes Berga97f4422009-06-18 17:23:43 +02004086 switch (dev->ieee80211_ptr->iftype) {
4087 case NL80211_IFTYPE_AP:
4088 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004089 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004090 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004091 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004092 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004093 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004094 break;
4095 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004096 err = -EOPNOTSUPP;
4097 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004098 }
4099
Johannes Berg77ee7c82013-02-15 00:48:33 +01004100 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004101 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004102
Johannes Berg77ee7c82013-02-15 00:48:33 +01004103 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004104 if (params.vlan)
4105 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004106
Johannes Berg5727ef12007-12-19 02:03:34 +01004107 return err;
4108}
4109
4110static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4111{
Johannes Berg4c476992010-10-04 21:36:35 +02004112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004113 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004114 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004115 struct station_parameters params;
4116 u8 *mac_addr = NULL;
4117
4118 memset(&params, 0, sizeof(params));
4119
Johannes Berg984c3112013-02-14 23:43:25 +01004120 if (!rdev->ops->add_station)
4121 return -EOPNOTSUPP;
4122
Johannes Berg5727ef12007-12-19 02:03:34 +01004123 if (!info->attrs[NL80211_ATTR_MAC])
4124 return -EINVAL;
4125
Johannes Berg5727ef12007-12-19 02:03:34 +01004126 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4127 return -EINVAL;
4128
4129 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4130 return -EINVAL;
4131
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004132 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4133 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004134 return -EINVAL;
4135
Johannes Berg5727ef12007-12-19 02:03:34 +01004136 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4137 params.supported_rates =
4138 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4139 params.supported_rates_len =
4140 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4141 params.listen_interval =
4142 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004143
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004144 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004145 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004146 else
4147 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004148 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4149 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004150
Jouni Malinen9d62a982013-02-14 21:10:13 +02004151 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4152 params.capability =
4153 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4154 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4155 }
4156
4157 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4158 params.ext_capab =
4159 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4160 params.ext_capab_len =
4161 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4162 }
4163
Jouni Malinen36aedc92008-08-25 11:58:58 +03004164 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4165 params.ht_capa =
4166 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004167
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004168 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4169 params.vht_capa =
4170 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4171
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004172 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4173 params.opmode_notif_used = true;
4174 params.opmode_notif =
4175 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4176 }
4177
Johannes Bergf8bacc22013-02-14 23:27:01 +01004178 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004179 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004180 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4181 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4182 return -EINVAL;
4183 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004184
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304185 err = nl80211_parse_sta_channel_info(info, &params);
4186 if (err)
4187 return err;
4188
Johannes Bergff276692013-02-15 00:09:01 +01004189 err = nl80211_parse_sta_wme(info, &params);
4190 if (err)
4191 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004192
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004193 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004194 return -EINVAL;
4195
Johannes Berg77ee7c82013-02-15 00:48:33 +01004196 /* When you run into this, adjust the code below for the new flag */
4197 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4198
Johannes Bergbdd90d52011-12-14 12:20:27 +01004199 switch (dev->ieee80211_ptr->iftype) {
4200 case NL80211_IFTYPE_AP:
4201 case NL80211_IFTYPE_AP_VLAN:
4202 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004203 /* ignore WME attributes if iface/sta is not capable */
4204 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4205 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4206 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004207
Johannes Bergbdd90d52011-12-14 12:20:27 +01004208 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004209 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4210 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004211 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004212 /* but don't bother the driver with it */
4213 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004214
Johannes Bergd582cff2012-10-26 17:53:44 +02004215 /* allow authenticated/associated only if driver handles it */
4216 if (!(rdev->wiphy.features &
4217 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4218 params.sta_flags_mask &
4219 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4220 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4221 return -EINVAL;
4222
Johannes Bergbdd90d52011-12-14 12:20:27 +01004223 /* must be last in here for error handling */
4224 params.vlan = get_vlan(info, rdev);
4225 if (IS_ERR(params.vlan))
4226 return PTR_ERR(params.vlan);
4227 break;
4228 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004229 /* ignore uAPSD data */
4230 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4231
Johannes Bergd582cff2012-10-26 17:53:44 +02004232 /* associated is disallowed */
4233 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4234 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004235 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004236 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4237 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004238 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004239 break;
4240 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004241 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004242 /* ignore uAPSD data */
4243 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4244
Johannes Berg77ee7c82013-02-15 00:48:33 +01004245 /* these are disallowed */
4246 if (params.sta_flags_mask &
4247 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4248 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004249 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004250 /* Only TDLS peers can be added */
4251 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4252 return -EINVAL;
4253 /* Can only add if TDLS ... */
4254 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4255 return -EOPNOTSUPP;
4256 /* ... with external setup is supported */
4257 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4258 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004259 /*
4260 * Older wpa_supplicant versions always mark the TDLS peer
4261 * as authorized, but it shouldn't yet be.
4262 */
4263 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004264 break;
4265 default:
4266 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004267 }
4268
Johannes Bergbdd90d52011-12-14 12:20:27 +01004269 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004270
Hila Gonene35e4d22012-06-27 17:19:42 +03004271 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004272
Johannes Berg5727ef12007-12-19 02:03:34 +01004273 if (params.vlan)
4274 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004275 return err;
4276}
4277
4278static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4279{
Johannes Berg4c476992010-10-04 21:36:35 +02004280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4281 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004282 u8 *mac_addr = NULL;
4283
4284 if (info->attrs[NL80211_ATTR_MAC])
4285 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4286
Johannes Berge80cf852009-05-11 14:43:13 +02004287 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004288 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004289 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004290 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4291 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004292
Johannes Berg4c476992010-10-04 21:36:35 +02004293 if (!rdev->ops->del_station)
4294 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004295
Hila Gonene35e4d22012-06-27 17:19:42 +03004296 return rdev_del_station(rdev, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01004297}
4298
Eric W. Biederman15e47302012-09-07 20:12:54 +00004299static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004300 int flags, struct net_device *dev,
4301 u8 *dst, u8 *next_hop,
4302 struct mpath_info *pinfo)
4303{
4304 void *hdr;
4305 struct nlattr *pinfoattr;
4306
Eric W. Biederman15e47302012-09-07 20:12:54 +00004307 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004308 if (!hdr)
4309 return -1;
4310
David S. Miller9360ffd2012-03-29 04:41:26 -04004311 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4312 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4313 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4314 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4315 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004316
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004317 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4318 if (!pinfoattr)
4319 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004320 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4321 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4322 pinfo->frame_qlen))
4323 goto nla_put_failure;
4324 if (((pinfo->filled & MPATH_INFO_SN) &&
4325 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4326 ((pinfo->filled & MPATH_INFO_METRIC) &&
4327 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4328 pinfo->metric)) ||
4329 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4330 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4331 pinfo->exptime)) ||
4332 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4333 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4334 pinfo->flags)) ||
4335 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4336 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4337 pinfo->discovery_timeout)) ||
4338 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4339 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4340 pinfo->discovery_retries)))
4341 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004342
4343 nla_nest_end(msg, pinfoattr);
4344
4345 return genlmsg_end(msg, hdr);
4346
4347 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004348 genlmsg_cancel(msg, hdr);
4349 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004350}
4351
4352static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004353 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004354{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004355 struct mpath_info pinfo;
4356 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02004357 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004358 u8 dst[ETH_ALEN];
4359 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004360 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004361 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004362
Johannes Berg97990a02013-04-19 01:02:55 +02004363 err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004364 if (err)
4365 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004366
4367 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004368 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004369 goto out_err;
4370 }
4371
Johannes Berg97990a02013-04-19 01:02:55 +02004372 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004373 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004374 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004375 }
4376
Johannes Bergbba95fe2008-07-29 13:22:51 +02004377 while (1) {
Johannes Berg97990a02013-04-19 01:02:55 +02004378 err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst,
4379 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004380 if (err == -ENOENT)
4381 break;
4382 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004383 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004384
Eric W. Biederman15e47302012-09-07 20:12:54 +00004385 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004386 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004387 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004388 &pinfo) < 0)
4389 goto out;
4390
4391 path_idx++;
4392 }
4393
4394
4395 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004396 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004397 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004398 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02004399 nl80211_finish_wdev_dump(dev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004400 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004401}
4402
4403static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4404{
Johannes Berg4c476992010-10-04 21:36:35 +02004405 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004406 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004407 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004408 struct mpath_info pinfo;
4409 struct sk_buff *msg;
4410 u8 *dst = NULL;
4411 u8 next_hop[ETH_ALEN];
4412
4413 memset(&pinfo, 0, sizeof(pinfo));
4414
4415 if (!info->attrs[NL80211_ATTR_MAC])
4416 return -EINVAL;
4417
4418 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4419
Johannes Berg4c476992010-10-04 21:36:35 +02004420 if (!rdev->ops->get_mpath)
4421 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004422
Johannes Berg4c476992010-10-04 21:36:35 +02004423 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4424 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004425
Hila Gonene35e4d22012-06-27 17:19:42 +03004426 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004427 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004428 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004429
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004430 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004431 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004432 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004433
Eric W. Biederman15e47302012-09-07 20:12:54 +00004434 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004435 dev, dst, next_hop, &pinfo) < 0) {
4436 nlmsg_free(msg);
4437 return -ENOBUFS;
4438 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004439
Johannes Berg4c476992010-10-04 21:36:35 +02004440 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004441}
4442
4443static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4444{
Johannes Berg4c476992010-10-04 21:36:35 +02004445 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4446 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004447 u8 *dst = NULL;
4448 u8 *next_hop = NULL;
4449
4450 if (!info->attrs[NL80211_ATTR_MAC])
4451 return -EINVAL;
4452
4453 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4454 return -EINVAL;
4455
4456 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4457 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4458
Johannes Berg4c476992010-10-04 21:36:35 +02004459 if (!rdev->ops->change_mpath)
4460 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004461
Johannes Berg4c476992010-10-04 21:36:35 +02004462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4463 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004464
Hila Gonene35e4d22012-06-27 17:19:42 +03004465 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004466}
Johannes Berg4c476992010-10-04 21:36:35 +02004467
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004468static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4469{
Johannes Berg4c476992010-10-04 21:36:35 +02004470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4471 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004472 u8 *dst = NULL;
4473 u8 *next_hop = NULL;
4474
4475 if (!info->attrs[NL80211_ATTR_MAC])
4476 return -EINVAL;
4477
4478 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4479 return -EINVAL;
4480
4481 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4482 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4483
Johannes Berg4c476992010-10-04 21:36:35 +02004484 if (!rdev->ops->add_mpath)
4485 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004486
Johannes Berg4c476992010-10-04 21:36:35 +02004487 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4488 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004489
Hila Gonene35e4d22012-06-27 17:19:42 +03004490 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004491}
4492
4493static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4494{
Johannes Berg4c476992010-10-04 21:36:35 +02004495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4496 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004497 u8 *dst = NULL;
4498
4499 if (info->attrs[NL80211_ATTR_MAC])
4500 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4501
Johannes Berg4c476992010-10-04 21:36:35 +02004502 if (!rdev->ops->del_mpath)
4503 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004504
Hila Gonene35e4d22012-06-27 17:19:42 +03004505 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004506}
4507
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004508static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4509{
Johannes Berg4c476992010-10-04 21:36:35 +02004510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4511 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004512 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004513 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004514 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004515
4516 memset(&params, 0, sizeof(params));
4517 /* default to not changing parameters */
4518 params.use_cts_prot = -1;
4519 params.use_short_preamble = -1;
4520 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004521 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004522 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004523 params.p2p_ctwindow = -1;
4524 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004525
4526 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4527 params.use_cts_prot =
4528 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4529 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4530 params.use_short_preamble =
4531 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4532 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4533 params.use_short_slot_time =
4534 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004535 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4536 params.basic_rates =
4537 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4538 params.basic_rates_len =
4539 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4540 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004541 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4542 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004543 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4544 params.ht_opmode =
4545 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004546
Johannes Berg53cabad2012-11-14 15:17:28 +01004547 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4548 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4549 return -EINVAL;
4550 params.p2p_ctwindow =
4551 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4552 if (params.p2p_ctwindow < 0)
4553 return -EINVAL;
4554 if (params.p2p_ctwindow != 0 &&
4555 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4556 return -EINVAL;
4557 }
4558
4559 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4560 u8 tmp;
4561
4562 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4563 return -EINVAL;
4564 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4565 if (tmp > 1)
4566 return -EINVAL;
4567 params.p2p_opp_ps = tmp;
4568 if (params.p2p_opp_ps &&
4569 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4570 return -EINVAL;
4571 }
4572
Johannes Berg4c476992010-10-04 21:36:35 +02004573 if (!rdev->ops->change_bss)
4574 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004575
Johannes Berg074ac8d2010-09-16 14:58:22 +02004576 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004577 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4578 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004579
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004580 wdev_lock(wdev);
4581 err = rdev_change_bss(rdev, dev, &params);
4582 wdev_unlock(wdev);
4583
4584 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004585}
4586
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004587static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004588 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4589 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4590 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4591 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4592 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4593 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
4594};
4595
4596static int parse_reg_rule(struct nlattr *tb[],
4597 struct ieee80211_reg_rule *reg_rule)
4598{
4599 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4600 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4601
4602 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4603 return -EINVAL;
4604 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4605 return -EINVAL;
4606 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4607 return -EINVAL;
4608 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4609 return -EINVAL;
4610 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4611 return -EINVAL;
4612
4613 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4614
4615 freq_range->start_freq_khz =
4616 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4617 freq_range->end_freq_khz =
4618 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
4619 freq_range->max_bandwidth_khz =
4620 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
4621
4622 power_rule->max_eirp =
4623 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4624
4625 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4626 power_rule->max_antenna_gain =
4627 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4628
4629 return 0;
4630}
4631
4632static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4633{
4634 int r;
4635 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004636 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004637
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004638 /*
4639 * You should only get this when cfg80211 hasn't yet initialized
4640 * completely when built-in to the kernel right between the time
4641 * window between nl80211_init() and regulatory_init(), if that is
4642 * even possible.
4643 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004644 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004645 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004646
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004647 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4648 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004649
4650 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4651
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004652 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4653 user_reg_hint_type =
4654 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4655 else
4656 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4657
4658 switch (user_reg_hint_type) {
4659 case NL80211_USER_REG_HINT_USER:
4660 case NL80211_USER_REG_HINT_CELL_BASE:
4661 break;
4662 default:
4663 return -EINVAL;
4664 }
4665
4666 r = regulatory_hint_user(data, user_reg_hint_type);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004667
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004668 return r;
4669}
4670
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004671static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004672 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004673{
Johannes Berg4c476992010-10-04 21:36:35 +02004674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004675 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004676 struct wireless_dev *wdev = dev->ieee80211_ptr;
4677 struct mesh_config cur_params;
4678 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004679 void *hdr;
4680 struct nlattr *pinfoattr;
4681 struct sk_buff *msg;
4682
Johannes Berg29cbe682010-12-03 09:20:44 +01004683 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4684 return -EOPNOTSUPP;
4685
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004686 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004687 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004688
Johannes Berg29cbe682010-12-03 09:20:44 +01004689 wdev_lock(wdev);
4690 /* If not connected, get default parameters */
4691 if (!wdev->mesh_id_len)
4692 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4693 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004694 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004695 wdev_unlock(wdev);
4696
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004697 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004698 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004699
4700 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004701 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004702 if (!msg)
4703 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004704 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004705 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004706 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004707 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004708 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004709 if (!pinfoattr)
4710 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004711 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4712 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4713 cur_params.dot11MeshRetryTimeout) ||
4714 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4715 cur_params.dot11MeshConfirmTimeout) ||
4716 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4717 cur_params.dot11MeshHoldingTimeout) ||
4718 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
4719 cur_params.dot11MeshMaxPeerLinks) ||
4720 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
4721 cur_params.dot11MeshMaxRetries) ||
4722 nla_put_u8(msg, NL80211_MESHCONF_TTL,
4723 cur_params.dot11MeshTTL) ||
4724 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
4725 cur_params.element_ttl) ||
4726 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4727 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04004728 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4729 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04004730 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4731 cur_params.dot11MeshHWMPmaxPREQretries) ||
4732 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
4733 cur_params.path_refresh_time) ||
4734 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4735 cur_params.min_discovery_timeout) ||
4736 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4737 cur_params.dot11MeshHWMPactivePathTimeout) ||
4738 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
4739 cur_params.dot11MeshHWMPpreqMinInterval) ||
4740 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
4741 cur_params.dot11MeshHWMPperrMinInterval) ||
4742 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4743 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
4744 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
4745 cur_params.dot11MeshHWMPRootMode) ||
4746 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
4747 cur_params.dot11MeshHWMPRannInterval) ||
4748 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
4749 cur_params.dot11MeshGateAnnouncementProtocol) ||
4750 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
4751 cur_params.dot11MeshForwarding) ||
4752 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07004753 cur_params.rssi_threshold) ||
4754 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004755 cur_params.ht_opmode) ||
4756 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4757 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
4758 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004759 cur_params.dot11MeshHWMProotInterval) ||
4760 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004761 cur_params.dot11MeshHWMPconfirmationInterval) ||
4762 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
4763 cur_params.power_mode) ||
4764 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004765 cur_params.dot11MeshAwakeWindowDuration) ||
4766 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
4767 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04004768 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004769 nla_nest_end(msg, pinfoattr);
4770 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004771 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004772
Johannes Berg3b858752009-03-12 09:55:09 +01004773 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004774 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01004775 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04004776 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02004777 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004778}
4779
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004780static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004781 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
4782 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
4783 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
4784 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
4785 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
4786 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01004787 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004788 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07004789 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004790 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
4791 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
4792 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
4793 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
4794 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08004795 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004796 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07004797 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07004798 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07004799 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08004800 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004801 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
4802 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004803 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
4804 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004805 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004806 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
4807 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004808 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004809};
4810
Javier Cardonac80d5452010-12-16 17:37:49 -08004811static const struct nla_policy
4812 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07004813 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08004814 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
4815 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07004816 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07004817 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004818 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07004819 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004820 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07004821 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08004822};
4823
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004824static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004825 struct mesh_config *cfg,
4826 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004827{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004828 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004829 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004830
Marco Porschea54fba2013-01-07 16:04:48 +01004831#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4832do { \
4833 if (tb[attr]) { \
4834 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4835 return -EINVAL; \
4836 cfg->param = fn(tb[attr]); \
4837 mask |= (1 << (attr - 1)); \
4838 } \
4839} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004840
4841
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004842 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004843 return -EINVAL;
4844 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004845 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004846 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004847 return -EINVAL;
4848
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004849 /* This makes sure that there aren't more than 32 mesh config
4850 * parameters (otherwise our bitfield scheme would not work.) */
4851 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
4852
4853 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01004854 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004855 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
4856 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004857 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004858 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4859 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004860 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004861 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
4862 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004863 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004864 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
4865 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004866 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004867 mask, NL80211_MESHCONF_MAX_RETRIES,
4868 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004869 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004870 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004871 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004872 mask, NL80211_MESHCONF_ELEMENT_TTL,
4873 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004874 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004875 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
4876 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004877 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
4878 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004879 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
4880 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004881 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004882 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
4883 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004884 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004885 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
4886 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004887 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004888 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
4889 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004890 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
4891 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004892 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
4893 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004894 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004895 1, 65535, mask,
4896 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004897 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08004898 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01004899 1, 65535, mask,
4900 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004901 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004902 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004903 dot11MeshHWMPnetDiameterTraversalTime,
4904 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004905 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
4906 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01004907 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
4908 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
4909 nla_get_u8);
4910 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
4911 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004912 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00004913 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004914 dot11MeshGateAnnouncementProtocol, 0, 1,
4915 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004916 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01004917 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004918 mask, NL80211_MESHCONF_FORWARDING,
4919 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004921 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08004922 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01004923 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08004924 mask, NL80211_MESHCONF_HT_OPMODE,
4925 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004926 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01004927 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004928 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
4929 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01004930 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08004931 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
4932 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01004934 dot11MeshHWMPconfirmationInterval,
4935 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08004936 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
4937 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004938 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
4939 NL80211_MESH_POWER_ACTIVE,
4940 NL80211_MESH_POWER_MAX,
4941 mask, NL80211_MESHCONF_POWER_MODE,
4942 nla_get_u32);
4943 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
4944 0, 65535, mask,
4945 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07004946 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
4947 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
4948 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004949 if (mask_out)
4950 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08004951
Johannes Bergbd90fdc2010-12-03 09:20:43 +01004952 return 0;
4953
4954#undef FILL_IN_MESH_PARAM_IF_SET
4955}
4956
Javier Cardonac80d5452010-12-16 17:37:49 -08004957static int nl80211_parse_mesh_setup(struct genl_info *info,
4958 struct mesh_setup *setup)
4959{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004960 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08004961 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
4962
4963 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
4964 return -EINVAL;
4965 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
4966 info->attrs[NL80211_ATTR_MESH_SETUP],
4967 nl80211_mesh_setup_params_policy))
4968 return -EINVAL;
4969
Javier Cardonad299a1f2012-03-31 11:31:33 -07004970 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
4971 setup->sync_method =
4972 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
4973 IEEE80211_SYNC_METHOD_VENDOR :
4974 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
4975
Javier Cardonac80d5452010-12-16 17:37:49 -08004976 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
4977 setup->path_sel_proto =
4978 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
4979 IEEE80211_PATH_PROTOCOL_VENDOR :
4980 IEEE80211_PATH_PROTOCOL_HWMP;
4981
4982 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
4983 setup->path_metric =
4984 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
4985 IEEE80211_PATH_METRIC_VENDOR :
4986 IEEE80211_PATH_METRIC_AIRTIME;
4987
Javier Cardona581a8b02011-04-07 15:08:27 -07004988
4989 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08004990 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07004991 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08004992 if (!is_valid_ie_attr(ieattr))
4993 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07004994 setup->ie = nla_data(ieattr);
4995 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08004996 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08004997 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
4998 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
4999 return -EINVAL;
5000 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005001 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5002 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005003 if (setup->is_secure)
5004 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005005
Colleen Twitty6e16d902013-05-08 11:45:59 -07005006 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5007 if (!setup->user_mpm)
5008 return -EINVAL;
5009 setup->auth_id =
5010 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5011 }
5012
Javier Cardonac80d5452010-12-16 17:37:49 -08005013 return 0;
5014}
5015
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005016static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005017 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005018{
5019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5020 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005021 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005022 struct mesh_config cfg;
5023 u32 mask;
5024 int err;
5025
Johannes Berg29cbe682010-12-03 09:20:44 +01005026 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5027 return -EOPNOTSUPP;
5028
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005029 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005030 return -EOPNOTSUPP;
5031
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005032 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005033 if (err)
5034 return err;
5035
Johannes Berg29cbe682010-12-03 09:20:44 +01005036 wdev_lock(wdev);
5037 if (!wdev->mesh_id_len)
5038 err = -ENOLINK;
5039
5040 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005041 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005042
5043 wdev_unlock(wdev);
5044
5045 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005046}
5047
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005048static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5049{
Johannes Berg458f4f92012-12-06 15:47:38 +01005050 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005051 struct sk_buff *msg;
5052 void *hdr = NULL;
5053 struct nlattr *nl_reg_rules;
5054 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005055
5056 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005057 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005058
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005060 if (!msg)
5061 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005062
Eric W. Biederman15e47302012-09-07 20:12:54 +00005063 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005064 NL80211_CMD_GET_REG);
5065 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005066 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005067
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005068 if (reg_last_request_cell_base() &&
5069 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5070 NL80211_USER_REG_HINT_CELL_BASE))
5071 goto nla_put_failure;
5072
Johannes Berg458f4f92012-12-06 15:47:38 +01005073 rcu_read_lock();
5074 regdom = rcu_dereference(cfg80211_regdomain);
5075
5076 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5077 (regdom->dfs_region &&
5078 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5079 goto nla_put_failure_rcu;
5080
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005081 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5082 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005083 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005084
Johannes Berg458f4f92012-12-06 15:47:38 +01005085 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005086 struct nlattr *nl_reg_rule;
5087 const struct ieee80211_reg_rule *reg_rule;
5088 const struct ieee80211_freq_range *freq_range;
5089 const struct ieee80211_power_rule *power_rule;
5090
Johannes Berg458f4f92012-12-06 15:47:38 +01005091 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005092 freq_range = &reg_rule->freq_range;
5093 power_rule = &reg_rule->power_rule;
5094
5095 nl_reg_rule = nla_nest_start(msg, i);
5096 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005097 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005098
David S. Miller9360ffd2012-03-29 04:41:26 -04005099 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5100 reg_rule->flags) ||
5101 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5102 freq_range->start_freq_khz) ||
5103 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5104 freq_range->end_freq_khz) ||
5105 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
5106 freq_range->max_bandwidth_khz) ||
5107 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5108 power_rule->max_antenna_gain) ||
5109 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
5110 power_rule->max_eirp))
Johannes Berg458f4f92012-12-06 15:47:38 +01005111 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005112
5113 nla_nest_end(msg, nl_reg_rule);
5114 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005115 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005116
5117 nla_nest_end(msg, nl_reg_rules);
5118
5119 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005120 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005121
Johannes Berg458f4f92012-12-06 15:47:38 +01005122nla_put_failure_rcu:
5123 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005124nla_put_failure:
5125 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005126put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005127 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005128 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005129}
5130
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005131static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5132{
5133 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5134 struct nlattr *nl_reg_rule;
5135 char *alpha2 = NULL;
5136 int rem_reg_rules = 0, r = 0;
5137 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005138 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005139 struct ieee80211_regdomain *rd = NULL;
5140
5141 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5142 return -EINVAL;
5143
5144 if (!info->attrs[NL80211_ATTR_REG_RULES])
5145 return -EINVAL;
5146
5147 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5148
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005149 if (info->attrs[NL80211_ATTR_DFS_REGION])
5150 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5151
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005152 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005153 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005154 num_rules++;
5155 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005156 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005157 }
5158
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005159 if (!reg_is_valid_request(alpha2))
5160 return -EINVAL;
5161
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005162 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005163 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005164
5165 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005166 if (!rd)
5167 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005168
5169 rd->n_reg_rules = num_rules;
5170 rd->alpha2[0] = alpha2[0];
5171 rd->alpha2[1] = alpha2[1];
5172
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005173 /*
5174 * Disable DFS master mode if the DFS region was
5175 * not supported or known on this kernel.
5176 */
5177 if (reg_supported_dfs_region(dfs_region))
5178 rd->dfs_region = dfs_region;
5179
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005180 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005181 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005182 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
Johannes Berg1a919312012-12-03 17:21:11 +01005183 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5184 reg_rule_policy);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005185 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5186 if (r)
5187 goto bad_reg;
5188
5189 rule_idx++;
5190
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005191 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5192 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005193 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005194 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005195 }
5196
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005197 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005198 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005199 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005200
Johannes Bergd2372b32008-10-24 20:32:20 +02005201 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005202 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005203 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005204}
5205
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005206static int validate_scan_freqs(struct nlattr *freqs)
5207{
5208 struct nlattr *attr1, *attr2;
5209 int n_channels = 0, tmp1, tmp2;
5210
5211 nla_for_each_nested(attr1, freqs, tmp1) {
5212 n_channels++;
5213 /*
5214 * Some hardware has a limited channel list for
5215 * scanning, and it is pretty much nonsensical
5216 * to scan for a channel twice, so disallow that
5217 * and don't require drivers to check that the
5218 * channel list they get isn't longer than what
5219 * they can scan, as long as they can scan all
5220 * the channels they registered at once.
5221 */
5222 nla_for_each_nested(attr2, freqs, tmp2)
5223 if (attr1 != attr2 &&
5224 nla_get_u32(attr1) == nla_get_u32(attr2))
5225 return 0;
5226 }
5227
5228 return n_channels;
5229}
5230
Johannes Berg2a519312009-02-10 21:25:55 +01005231static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5232{
Johannes Berg4c476992010-10-04 21:36:35 +02005233 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005234 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005235 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005236 struct nlattr *attr;
5237 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005238 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005239 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005240
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005241 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5242 return -EINVAL;
5243
Johannes Berg79c97e92009-07-07 03:56:12 +02005244 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005245
Johannes Berg4c476992010-10-04 21:36:35 +02005246 if (!rdev->ops->scan)
5247 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005248
Johannes Bergf9f47522013-03-19 15:04:07 +01005249 if (rdev->scan_req) {
5250 err = -EBUSY;
5251 goto unlock;
5252 }
Johannes Berg2a519312009-02-10 21:25:55 +01005253
5254 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005255 n_channels = validate_scan_freqs(
5256 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005257 if (!n_channels) {
5258 err = -EINVAL;
5259 goto unlock;
5260 }
Johannes Berg2a519312009-02-10 21:25:55 +01005261 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005262 enum ieee80211_band band;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005263 n_channels = 0;
5264
Johannes Berg2a519312009-02-10 21:25:55 +01005265 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5266 if (wiphy->bands[band])
5267 n_channels += wiphy->bands[band]->n_channels;
5268 }
5269
5270 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5271 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5272 n_ssids++;
5273
Johannes Bergf9f47522013-03-19 15:04:07 +01005274 if (n_ssids > wiphy->max_scan_ssids) {
5275 err = -EINVAL;
5276 goto unlock;
5277 }
Johannes Berg2a519312009-02-10 21:25:55 +01005278
Jouni Malinen70692ad2009-02-16 19:39:13 +02005279 if (info->attrs[NL80211_ATTR_IE])
5280 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5281 else
5282 ie_len = 0;
5283
Johannes Bergf9f47522013-03-19 15:04:07 +01005284 if (ie_len > wiphy->max_scan_ie_len) {
5285 err = -EINVAL;
5286 goto unlock;
5287 }
Johannes Berg18a83652009-03-31 12:12:05 +02005288
Johannes Berg2a519312009-02-10 21:25:55 +01005289 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005290 + sizeof(*request->ssids) * n_ssids
5291 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005292 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005293 if (!request) {
5294 err = -ENOMEM;
5295 goto unlock;
5296 }
Johannes Berg2a519312009-02-10 21:25:55 +01005297
Johannes Berg2a519312009-02-10 21:25:55 +01005298 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005299 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005300 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005301 if (ie_len) {
5302 if (request->ssids)
5303 request->ie = (void *)(request->ssids + n_ssids);
5304 else
5305 request->ie = (void *)(request->channels + n_channels);
5306 }
Johannes Berg2a519312009-02-10 21:25:55 +01005307
Johannes Berg584991d2009-11-02 13:32:03 +01005308 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005309 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5310 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005311 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005312 struct ieee80211_channel *chan;
5313
5314 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5315
5316 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005317 err = -EINVAL;
5318 goto out_free;
5319 }
Johannes Berg584991d2009-11-02 13:32:03 +01005320
5321 /* ignore disabled channels */
5322 if (chan->flags & IEEE80211_CHAN_DISABLED)
5323 continue;
5324
5325 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005326 i++;
5327 }
5328 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005329 enum ieee80211_band band;
5330
Johannes Berg2a519312009-02-10 21:25:55 +01005331 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005332 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5333 int j;
5334 if (!wiphy->bands[band])
5335 continue;
5336 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005337 struct ieee80211_channel *chan;
5338
5339 chan = &wiphy->bands[band]->channels[j];
5340
5341 if (chan->flags & IEEE80211_CHAN_DISABLED)
5342 continue;
5343
5344 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005345 i++;
5346 }
5347 }
5348 }
5349
Johannes Berg584991d2009-11-02 13:32:03 +01005350 if (!i) {
5351 err = -EINVAL;
5352 goto out_free;
5353 }
5354
5355 request->n_channels = i;
5356
Johannes Berg2a519312009-02-10 21:25:55 +01005357 i = 0;
5358 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5359 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005360 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005361 err = -EINVAL;
5362 goto out_free;
5363 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005364 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005365 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005366 i++;
5367 }
5368 }
5369
Jouni Malinen70692ad2009-02-16 19:39:13 +02005370 if (info->attrs[NL80211_ATTR_IE]) {
5371 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005372 memcpy((void *)request->ie,
5373 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005374 request->ie_len);
5375 }
5376
Johannes Berg34850ab2011-07-18 18:08:35 +02005377 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005378 if (wiphy->bands[i])
5379 request->rates[i] =
5380 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005381
5382 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5383 nla_for_each_nested(attr,
5384 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5385 tmp) {
5386 enum ieee80211_band band = nla_type(attr);
5387
Dan Carpenter84404622011-07-29 11:52:18 +03005388 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005389 err = -EINVAL;
5390 goto out_free;
5391 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005392
5393 if (!wiphy->bands[band])
5394 continue;
5395
Johannes Berg34850ab2011-07-18 18:08:35 +02005396 err = ieee80211_get_ratemask(wiphy->bands[band],
5397 nla_data(attr),
5398 nla_len(attr),
5399 &request->rates[band]);
5400 if (err)
5401 goto out_free;
5402 }
5403 }
5404
Sam Leffler46856bb2012-10-11 21:03:32 -07005405 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005406 request->flags = nla_get_u32(
5407 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005408 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5409 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005410 err = -EOPNOTSUPP;
5411 goto out_free;
5412 }
5413 }
Sam Lefflered4737712012-10-11 21:03:31 -07005414
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305415 request->no_cck =
5416 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5417
Johannes Bergfd014282012-06-18 19:17:03 +02005418 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005419 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005420 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005421
Johannes Berg79c97e92009-07-07 03:56:12 +02005422 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005423 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005424
Johannes Berg463d0182009-07-14 00:33:35 +02005425 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005426 nl80211_send_scan_start(rdev, wdev);
5427 if (wdev->netdev)
5428 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005429 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005430 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005431 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005432 kfree(request);
5433 }
Johannes Berg3b858752009-03-12 09:55:09 +01005434
Johannes Bergf9f47522013-03-19 15:04:07 +01005435 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005436 return err;
5437}
5438
Luciano Coelho807f8a82011-05-11 17:09:35 +03005439static int nl80211_start_sched_scan(struct sk_buff *skb,
5440 struct genl_info *info)
5441{
5442 struct cfg80211_sched_scan_request *request;
5443 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5444 struct net_device *dev = info->user_ptr[1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005445 struct nlattr *attr;
5446 struct wiphy *wiphy;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005447 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005448 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005449 enum ieee80211_band band;
5450 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005451 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Luciano Coelho807f8a82011-05-11 17:09:35 +03005452
5453 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5454 !rdev->ops->sched_scan_start)
5455 return -EOPNOTSUPP;
5456
5457 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5458 return -EINVAL;
5459
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005460 if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5461 return -EINVAL;
5462
5463 interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
5464 if (interval == 0)
5465 return -EINVAL;
5466
Luciano Coelho807f8a82011-05-11 17:09:35 +03005467 wiphy = &rdev->wiphy;
5468
5469 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5470 n_channels = validate_scan_freqs(
5471 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
5472 if (!n_channels)
5473 return -EINVAL;
5474 } else {
5475 n_channels = 0;
5476
5477 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
5478 if (wiphy->bands[band])
5479 n_channels += wiphy->bands[band]->n_channels;
5480 }
5481
5482 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5483 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5484 tmp)
5485 n_ssids++;
5486
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005487 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005488 return -EINVAL;
5489
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005490 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH])
5491 nla_for_each_nested(attr,
5492 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5493 tmp)
5494 n_match_sets++;
5495
5496 if (n_match_sets > wiphy->max_match_sets)
5497 return -EINVAL;
5498
Luciano Coelho807f8a82011-05-11 17:09:35 +03005499 if (info->attrs[NL80211_ATTR_IE])
5500 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5501 else
5502 ie_len = 0;
5503
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005504 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005505 return -EINVAL;
5506
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005507 if (rdev->sched_scan_req) {
5508 err = -EINPROGRESS;
5509 goto out;
5510 }
5511
Luciano Coelho807f8a82011-05-11 17:09:35 +03005512 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005513 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005514 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005515 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005516 + ie_len, GFP_KERNEL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005517 if (!request) {
5518 err = -ENOMEM;
5519 goto out;
5520 }
Luciano Coelho807f8a82011-05-11 17:09:35 +03005521
5522 if (n_ssids)
5523 request->ssids = (void *)&request->channels[n_channels];
5524 request->n_ssids = n_ssids;
5525 if (ie_len) {
5526 if (request->ssids)
5527 request->ie = (void *)(request->ssids + n_ssids);
5528 else
5529 request->ie = (void *)(request->channels + n_channels);
5530 }
5531
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005532 if (n_match_sets) {
5533 if (request->ie)
5534 request->match_sets = (void *)(request->ie + ie_len);
5535 else if (request->ssids)
5536 request->match_sets =
5537 (void *)(request->ssids + n_ssids);
5538 else
5539 request->match_sets =
5540 (void *)(request->channels + n_channels);
5541 }
5542 request->n_match_sets = n_match_sets;
5543
Luciano Coelho807f8a82011-05-11 17:09:35 +03005544 i = 0;
5545 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5546 /* user specified, bail out if channel not found */
5547 nla_for_each_nested(attr,
5548 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES],
5549 tmp) {
5550 struct ieee80211_channel *chan;
5551
5552 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5553
5554 if (!chan) {
5555 err = -EINVAL;
5556 goto out_free;
5557 }
5558
5559 /* ignore disabled channels */
5560 if (chan->flags & IEEE80211_CHAN_DISABLED)
5561 continue;
5562
5563 request->channels[i] = chan;
5564 i++;
5565 }
5566 } else {
5567 /* all channels */
5568 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5569 int j;
5570 if (!wiphy->bands[band])
5571 continue;
5572 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5573 struct ieee80211_channel *chan;
5574
5575 chan = &wiphy->bands[band]->channels[j];
5576
5577 if (chan->flags & IEEE80211_CHAN_DISABLED)
5578 continue;
5579
5580 request->channels[i] = chan;
5581 i++;
5582 }
5583 }
5584 }
5585
5586 if (!i) {
5587 err = -EINVAL;
5588 goto out_free;
5589 }
5590
5591 request->n_channels = i;
5592
5593 i = 0;
5594 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5595 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS],
5596 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005597 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005598 err = -EINVAL;
5599 goto out_free;
5600 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005601 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005602 memcpy(request->ssids[i].ssid, nla_data(attr),
5603 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005604 i++;
5605 }
5606 }
5607
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005608 i = 0;
5609 if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
5610 nla_for_each_nested(attr,
5611 info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
5612 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005613 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005614
5615 nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5616 nla_data(attr), nla_len(attr),
5617 nl80211_match_policy);
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005618 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005619 if (ssid) {
5620 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5621 err = -EINVAL;
5622 goto out_free;
5623 }
5624 memcpy(request->match_sets[i].ssid.ssid,
5625 nla_data(ssid), nla_len(ssid));
5626 request->match_sets[i].ssid.ssid_len =
5627 nla_len(ssid);
5628 }
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005629 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5630 if (rssi)
5631 request->rssi_thold = nla_get_u32(rssi);
5632 else
5633 request->rssi_thold =
5634 NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005635 i++;
5636 }
5637 }
5638
Luciano Coelho807f8a82011-05-11 17:09:35 +03005639 if (info->attrs[NL80211_ATTR_IE]) {
5640 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5641 memcpy((void *)request->ie,
5642 nla_data(info->attrs[NL80211_ATTR_IE]),
5643 request->ie_len);
5644 }
5645
Sam Leffler46856bb2012-10-11 21:03:32 -07005646 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005647 request->flags = nla_get_u32(
5648 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005649 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5650 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005651 err = -EOPNOTSUPP;
5652 goto out_free;
5653 }
5654 }
Sam Lefflered4737712012-10-11 21:03:31 -07005655
Luciano Coelho807f8a82011-05-11 17:09:35 +03005656 request->dev = dev;
5657 request->wiphy = &rdev->wiphy;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005658 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07005659 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005660
Hila Gonene35e4d22012-06-27 17:19:42 +03005661 err = rdev_sched_scan_start(rdev, dev, request);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005662 if (!err) {
5663 rdev->sched_scan_req = request;
5664 nl80211_send_sched_scan(rdev, dev,
5665 NL80211_CMD_START_SCHED_SCAN);
5666 goto out;
5667 }
5668
5669out_free:
5670 kfree(request);
5671out:
5672 return err;
5673}
5674
5675static int nl80211_stop_sched_scan(struct sk_buff *skb,
5676 struct genl_info *info)
5677{
5678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5679
5680 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
5681 !rdev->ops->sched_scan_stop)
5682 return -EOPNOTSUPP;
5683
Johannes Berg5fe231e2013-05-08 21:45:15 +02005684 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005685}
5686
Simon Wunderlich04f39042013-02-08 18:16:19 +01005687static int nl80211_start_radar_detection(struct sk_buff *skb,
5688 struct genl_info *info)
5689{
5690 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5691 struct net_device *dev = info->user_ptr[1];
5692 struct wireless_dev *wdev = dev->ieee80211_ptr;
5693 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005694 enum nl80211_dfs_regions dfs_region;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005695 int err;
5696
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01005697 dfs_region = reg_get_dfs_region(wdev->wiphy);
5698 if (dfs_region == NL80211_DFS_UNSET)
5699 return -EINVAL;
5700
Simon Wunderlich04f39042013-02-08 18:16:19 +01005701 err = nl80211_parse_chandef(rdev, info, &chandef);
5702 if (err)
5703 return err;
5704
Simon Wunderlichff311bc2013-09-03 19:43:18 +02005705 if (netif_carrier_ok(dev))
5706 return -EBUSY;
5707
Simon Wunderlich04f39042013-02-08 18:16:19 +01005708 if (wdev->cac_started)
5709 return -EBUSY;
5710
5711 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef);
5712 if (err < 0)
5713 return err;
5714
5715 if (err == 0)
5716 return -EINVAL;
5717
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01005718 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01005719 return -EINVAL;
5720
5721 if (!rdev->ops->start_radar_detection)
5722 return -EOPNOTSUPP;
5723
Simon Wunderlich04f39042013-02-08 18:16:19 +01005724 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5725 chandef.chan, CHAN_MODE_SHARED,
5726 BIT(chandef.width));
5727 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005728 return err;
Simon Wunderlich04f39042013-02-08 18:16:19 +01005729
5730 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef);
5731 if (!err) {
5732 wdev->channel = chandef.chan;
5733 wdev->cac_started = true;
5734 wdev->cac_start_time = jiffies;
5735 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01005736 return err;
5737}
5738
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005739static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
5740{
5741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5742 struct net_device *dev = info->user_ptr[1];
5743 struct wireless_dev *wdev = dev->ieee80211_ptr;
5744 struct cfg80211_csa_settings params;
5745 /* csa_attrs is defined static to avoid waste of stack size - this
5746 * function is called under RTNL lock, so this should not be a problem.
5747 */
5748 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
5749 u8 radar_detect_width = 0;
5750 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005751 bool need_new_beacon = false;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005752
5753 if (!rdev->ops->channel_switch ||
5754 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
5755 return -EOPNOTSUPP;
5756
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005757 switch (dev->ieee80211_ptr->iftype) {
5758 case NL80211_IFTYPE_AP:
5759 case NL80211_IFTYPE_P2P_GO:
5760 need_new_beacon = true;
5761
5762 /* useless if AP is not running */
5763 if (!wdev->beacon_interval)
5764 return -EINVAL;
5765 break;
5766 case NL80211_IFTYPE_ADHOC:
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07005767 case NL80211_IFTYPE_MESH_POINT:
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005768 break;
5769 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005770 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005771 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005772
5773 memset(&params, 0, sizeof(params));
5774
5775 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
5776 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
5777 return -EINVAL;
5778
5779 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02005780 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005781 return -EINVAL;
5782
5783 params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
5784
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005785 if (!need_new_beacon)
5786 goto skip_beacons;
5787
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005788 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
5789 if (err)
5790 return err;
5791
5792 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
5793 info->attrs[NL80211_ATTR_CSA_IES],
5794 nl80211_policy);
5795 if (err)
5796 return err;
5797
5798 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
5799 if (err)
5800 return err;
5801
5802 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
5803 return -EINVAL;
5804
5805 params.counter_offset_beacon =
5806 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
5807 if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
5808 return -EINVAL;
5809
5810 /* sanity check - counters should be the same */
5811 if (params.beacon_csa.tail[params.counter_offset_beacon] !=
5812 params.count)
5813 return -EINVAL;
5814
5815 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
5816 params.counter_offset_presp =
5817 nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
5818 if (params.counter_offset_presp >=
5819 params.beacon_csa.probe_resp_len)
5820 return -EINVAL;
5821
5822 if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
5823 params.count)
5824 return -EINVAL;
5825 }
5826
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005827skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005828 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5829 if (err)
5830 return err;
5831
5832 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
5833 return -EINVAL;
5834
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005835 if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP ||
Simon Wunderlich5336fa82013-10-07 18:41:05 +02005836 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO ||
5837 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) {
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02005838 err = cfg80211_chandef_dfs_required(wdev->wiphy,
5839 &params.chandef);
5840 if (err < 0) {
5841 return err;
5842 } else if (err) {
5843 radar_detect_width = BIT(params.chandef.width);
5844 params.radar_required = true;
5845 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005846 }
5847
5848 err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
5849 params.chandef.chan,
5850 CHAN_MODE_SHARED,
5851 radar_detect_width);
5852 if (err)
5853 return err;
5854
5855 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
5856 params.block_tx = true;
5857
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005858 wdev_lock(wdev);
5859 err = rdev_channel_switch(rdev, dev, &params);
5860 wdev_unlock(wdev);
5861
5862 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02005863}
5864
Johannes Berg9720bb32011-06-21 09:45:33 +02005865static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
5866 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005867 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02005868 struct wireless_dev *wdev,
5869 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01005870{
Johannes Berg48ab9052009-07-10 18:42:31 +02005871 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01005872 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01005873 void *hdr;
5874 struct nlattr *bss;
Johannes Berg8cef2c92013-02-05 16:54:31 +01005875 bool tsf = false;
Johannes Berg48ab9052009-07-10 18:42:31 +02005876
5877 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01005878
Eric W. Biederman15e47302012-09-07 20:12:54 +00005879 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01005880 NL80211_CMD_NEW_SCAN_RESULTS);
5881 if (!hdr)
5882 return -1;
5883
Johannes Berg9720bb32011-06-21 09:45:33 +02005884 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5885
Johannes Berg97990a02013-04-19 01:02:55 +02005886 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
5887 goto nla_put_failure;
5888 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005889 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
5890 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02005891 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
5892 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005893
5894 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
5895 if (!bss)
5896 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005897 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01005898 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04005899 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01005900
5901 rcu_read_lock();
5902 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005903 if (ies) {
5904 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5905 goto fail_unlock_rcu;
5906 tsf = true;
5907 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
5908 ies->len, ies->data))
5909 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005910 }
5911 ies = rcu_dereference(res->beacon_ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01005912 if (ies) {
5913 if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
5914 goto fail_unlock_rcu;
5915 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
5916 ies->len, ies->data))
5917 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01005918 }
5919 rcu_read_unlock();
5920
David S. Miller9360ffd2012-03-29 04:41:26 -04005921 if (res->beacon_interval &&
5922 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
5923 goto nla_put_failure;
5924 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
5925 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02005926 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005927 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
5928 jiffies_to_msecs(jiffies - intbss->ts)))
5929 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005930
Johannes Berg77965c92009-02-18 18:45:06 +01005931 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01005932 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04005933 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
5934 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005935 break;
5936 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005937 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
5938 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01005939 break;
5940 default:
5941 break;
5942 }
5943
Johannes Berg48ab9052009-07-10 18:42:31 +02005944 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02005945 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02005946 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04005947 if (intbss == wdev->current_bss &&
5948 nla_put_u32(msg, NL80211_BSS_STATUS,
5949 NL80211_BSS_STATUS_ASSOCIATED))
5950 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005951 break;
5952 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04005953 if (intbss == wdev->current_bss &&
5954 nla_put_u32(msg, NL80211_BSS_STATUS,
5955 NL80211_BSS_STATUS_IBSS_JOINED))
5956 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02005957 break;
5958 default:
5959 break;
5960 }
5961
Johannes Berg2a519312009-02-10 21:25:55 +01005962 nla_nest_end(msg, bss);
5963
5964 return genlmsg_end(msg, hdr);
5965
Johannes Berg8cef2c92013-02-05 16:54:31 +01005966 fail_unlock_rcu:
5967 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01005968 nla_put_failure:
5969 genlmsg_cancel(msg, hdr);
5970 return -EMSGSIZE;
5971}
5972
Johannes Berg97990a02013-04-19 01:02:55 +02005973static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01005974{
Johannes Berg48ab9052009-07-10 18:42:31 +02005975 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01005976 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02005977 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005978 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005979 int err;
5980
Johannes Berg97990a02013-04-19 01:02:55 +02005981 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005982 if (err)
5983 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01005984
Johannes Berg48ab9052009-07-10 18:42:31 +02005985 wdev_lock(wdev);
5986 spin_lock_bh(&rdev->bss_lock);
5987 cfg80211_bss_expire(rdev);
5988
Johannes Berg9720bb32011-06-21 09:45:33 +02005989 cb->seq = rdev->bss_generation;
5990
Johannes Berg48ab9052009-07-10 18:42:31 +02005991 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01005992 if (++idx <= start)
5993 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02005994 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01005995 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02005996 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01005997 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02005998 break;
Johannes Berg2a519312009-02-10 21:25:55 +01005999 }
6000 }
6001
Johannes Berg48ab9052009-07-10 18:42:31 +02006002 spin_unlock_bh(&rdev->bss_lock);
6003 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006004
Johannes Berg97990a02013-04-19 01:02:55 +02006005 cb->args[2] = idx;
6006 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006007
Johannes Berg67748892010-10-04 21:14:06 +02006008 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006009}
6010
Eric W. Biederman15e47302012-09-07 20:12:54 +00006011static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006012 int flags, struct net_device *dev,
6013 struct survey_info *survey)
6014{
6015 void *hdr;
6016 struct nlattr *infoattr;
6017
Eric W. Biederman15e47302012-09-07 20:12:54 +00006018 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006019 NL80211_CMD_NEW_SURVEY_RESULTS);
6020 if (!hdr)
6021 return -ENOMEM;
6022
David S. Miller9360ffd2012-03-29 04:41:26 -04006023 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6024 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006025
6026 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6027 if (!infoattr)
6028 goto nla_put_failure;
6029
David S. Miller9360ffd2012-03-29 04:41:26 -04006030 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6031 survey->channel->center_freq))
6032 goto nla_put_failure;
6033
6034 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6035 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6036 goto nla_put_failure;
6037 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6038 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6039 goto nla_put_failure;
6040 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6041 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6042 survey->channel_time))
6043 goto nla_put_failure;
6044 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6045 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6046 survey->channel_time_busy))
6047 goto nla_put_failure;
6048 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6049 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6050 survey->channel_time_ext_busy))
6051 goto nla_put_failure;
6052 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6053 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6054 survey->channel_time_rx))
6055 goto nla_put_failure;
6056 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6057 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6058 survey->channel_time_tx))
6059 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006060
6061 nla_nest_end(msg, infoattr);
6062
6063 return genlmsg_end(msg, hdr);
6064
6065 nla_put_failure:
6066 genlmsg_cancel(msg, hdr);
6067 return -EMSGSIZE;
6068}
6069
6070static int nl80211_dump_survey(struct sk_buff *skb,
6071 struct netlink_callback *cb)
6072{
6073 struct survey_info survey;
6074 struct cfg80211_registered_device *dev;
Johannes Berg97990a02013-04-19 01:02:55 +02006075 struct wireless_dev *wdev;
6076 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006077 int res;
6078
Johannes Berg97990a02013-04-19 01:02:55 +02006079 res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006080 if (res)
6081 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006082
Johannes Berg97990a02013-04-19 01:02:55 +02006083 if (!wdev->netdev) {
6084 res = -EINVAL;
6085 goto out_err;
6086 }
6087
Holger Schurig61fa7132009-11-11 12:25:40 +01006088 if (!dev->ops->dump_survey) {
6089 res = -EOPNOTSUPP;
6090 goto out_err;
6091 }
6092
6093 while (1) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006094 struct ieee80211_channel *chan;
6095
Johannes Berg97990a02013-04-19 01:02:55 +02006096 res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006097 if (res == -ENOENT)
6098 break;
6099 if (res)
6100 goto out_err;
6101
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006102 /* Survey without a channel doesn't make sense */
6103 if (!survey.channel) {
6104 res = -EINVAL;
6105 goto out;
6106 }
6107
6108 chan = ieee80211_get_channel(&dev->wiphy,
6109 survey.channel->center_freq);
6110 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) {
6111 survey_idx++;
6112 continue;
6113 }
6114
Holger Schurig61fa7132009-11-11 12:25:40 +01006115 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006116 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006117 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006118 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006119 goto out;
6120 survey_idx++;
6121 }
6122
6123 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006124 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006125 res = skb->len;
6126 out_err:
Johannes Berg97990a02013-04-19 01:02:55 +02006127 nl80211_finish_wdev_dump(dev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006128 return res;
6129}
6130
Samuel Ortizb23aa672009-07-01 21:26:54 +02006131static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6132{
6133 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6134 NL80211_WPA_VERSION_2));
6135}
6136
Jouni Malinen636a5d32009-03-19 13:39:22 +02006137static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6138{
Johannes Berg4c476992010-10-04 21:36:35 +02006139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6140 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006141 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006142 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6143 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006144 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006145 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006146 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006147
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006148 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6149 return -EINVAL;
6150
6151 if (!info->attrs[NL80211_ATTR_MAC])
6152 return -EINVAL;
6153
Jouni Malinen17780922009-03-27 20:52:47 +02006154 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6155 return -EINVAL;
6156
Johannes Berg19957bb2009-07-02 17:20:43 +02006157 if (!info->attrs[NL80211_ATTR_SSID])
6158 return -EINVAL;
6159
6160 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6161 return -EINVAL;
6162
Johannes Bergfffd0932009-07-08 14:22:54 +02006163 err = nl80211_parse_key(info, &key);
6164 if (err)
6165 return err;
6166
6167 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006168 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6169 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006170 if (!key.p.key || !key.p.key_len)
6171 return -EINVAL;
6172 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6173 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6174 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6175 key.p.key_len != WLAN_KEY_LEN_WEP104))
6176 return -EINVAL;
6177 if (key.idx > 4)
6178 return -EINVAL;
6179 } else {
6180 key.p.key_len = 0;
6181 key.p.key = NULL;
6182 }
6183
Johannes Bergafea0b72010-08-10 09:46:42 +02006184 if (key.idx >= 0) {
6185 int i;
6186 bool ok = false;
6187 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6188 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6189 ok = true;
6190 break;
6191 }
6192 }
Johannes Berg4c476992010-10-04 21:36:35 +02006193 if (!ok)
6194 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006195 }
6196
Johannes Berg4c476992010-10-04 21:36:35 +02006197 if (!rdev->ops->auth)
6198 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006199
Johannes Berg074ac8d2010-09-16 14:58:22 +02006200 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006201 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6202 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006203
Johannes Berg19957bb2009-07-02 17:20:43 +02006204 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg79c97e92009-07-07 03:56:12 +02006205 chan = ieee80211_get_channel(&rdev->wiphy,
Johannes Berg19957bb2009-07-02 17:20:43 +02006206 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006207 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6208 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006209
Johannes Berg19957bb2009-07-02 17:20:43 +02006210 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6211 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6212
6213 if (info->attrs[NL80211_ATTR_IE]) {
6214 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6215 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6216 }
6217
6218 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006219 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006220 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006221
Jouni Malinene39e5b52012-09-30 19:29:39 +03006222 if (auth_type == NL80211_AUTHTYPE_SAE &&
6223 !info->attrs[NL80211_ATTR_SAE_DATA])
6224 return -EINVAL;
6225
6226 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6227 if (auth_type != NL80211_AUTHTYPE_SAE)
6228 return -EINVAL;
6229 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6230 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6231 /* need to include at least Auth Transaction and Status Code */
6232 if (sae_data_len < 4)
6233 return -EINVAL;
6234 }
6235
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006236 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6237
Johannes Berg95de8172012-01-20 13:55:25 +01006238 /*
6239 * Since we no longer track auth state, ignore
6240 * requests to only change local state.
6241 */
6242 if (local_state_change)
6243 return 0;
6244
Johannes Berg91bf9b22013-05-15 17:44:01 +02006245 wdev_lock(dev->ieee80211_ptr);
6246 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6247 ssid, ssid_len, ie, ie_len,
6248 key.p.key, key.p.key_len, key.idx,
6249 sae_data, sae_data_len);
6250 wdev_unlock(dev->ieee80211_ptr);
6251 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006252}
6253
Johannes Bergc0692b82010-08-27 14:26:53 +03006254static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6255 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006256 struct cfg80211_crypto_settings *settings,
6257 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006258{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006259 memset(settings, 0, sizeof(*settings));
6260
Samuel Ortizb23aa672009-07-01 21:26:54 +02006261 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6262
Johannes Bergc0692b82010-08-27 14:26:53 +03006263 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6264 u16 proto;
6265 proto = nla_get_u16(
6266 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6267 settings->control_port_ethertype = cpu_to_be16(proto);
6268 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6269 proto != ETH_P_PAE)
6270 return -EINVAL;
6271 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6272 settings->control_port_no_encrypt = true;
6273 } else
6274 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6275
Samuel Ortizb23aa672009-07-01 21:26:54 +02006276 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6277 void *data;
6278 int len, i;
6279
6280 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6281 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6282 settings->n_ciphers_pairwise = len / sizeof(u32);
6283
6284 if (len % sizeof(u32))
6285 return -EINVAL;
6286
Johannes Berg3dc27d22009-07-02 21:36:37 +02006287 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006288 return -EINVAL;
6289
6290 memcpy(settings->ciphers_pairwise, data, len);
6291
6292 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006293 if (!cfg80211_supported_cipher_suite(
6294 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006295 settings->ciphers_pairwise[i]))
6296 return -EINVAL;
6297 }
6298
6299 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6300 settings->cipher_group =
6301 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006302 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6303 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006304 return -EINVAL;
6305 }
6306
6307 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6308 settings->wpa_versions =
6309 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6310 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6311 return -EINVAL;
6312 }
6313
6314 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6315 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006316 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006317
6318 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6319 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6320 settings->n_akm_suites = len / sizeof(u32);
6321
6322 if (len % sizeof(u32))
6323 return -EINVAL;
6324
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006325 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6326 return -EINVAL;
6327
Samuel Ortizb23aa672009-07-01 21:26:54 +02006328 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006329 }
6330
6331 return 0;
6332}
6333
Jouni Malinen636a5d32009-03-19 13:39:22 +02006334static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6335{
Johannes Berg4c476992010-10-04 21:36:35 +02006336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6337 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006338 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006339 struct cfg80211_assoc_request req = {};
6340 const u8 *bssid, *ssid;
6341 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006342
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006343 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6344 return -EINVAL;
6345
6346 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006347 !info->attrs[NL80211_ATTR_SSID] ||
6348 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006349 return -EINVAL;
6350
Johannes Berg4c476992010-10-04 21:36:35 +02006351 if (!rdev->ops->assoc)
6352 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006353
Johannes Berg074ac8d2010-09-16 14:58:22 +02006354 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006355 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6356 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006357
Johannes Berg19957bb2009-07-02 17:20:43 +02006358 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006359
Johannes Berg19957bb2009-07-02 17:20:43 +02006360 chan = ieee80211_get_channel(&rdev->wiphy,
6361 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
Johannes Berg4c476992010-10-04 21:36:35 +02006362 if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED))
6363 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006364
Johannes Berg19957bb2009-07-02 17:20:43 +02006365 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6366 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006367
6368 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006369 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6370 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006371 }
6372
Jouni Malinendc6382c2009-05-06 22:09:37 +03006373 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006374 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006375 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006376 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006377 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006378 else if (mfp != NL80211_MFP_NO)
6379 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006380 }
6381
Johannes Berg3e5d7642009-07-07 14:37:26 +02006382 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006383 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006384
Ben Greear7e7c8922011-11-18 11:31:59 -08006385 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006386 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006387
6388 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006389 memcpy(&req.ht_capa_mask,
6390 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6391 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006392
6393 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006394 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006395 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006396 memcpy(&req.ht_capa,
6397 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6398 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006399 }
6400
Johannes Bergee2aca32013-02-21 17:36:01 +01006401 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006402 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006403
6404 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006405 memcpy(&req.vht_capa_mask,
6406 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6407 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006408
6409 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006410 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006411 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006412 memcpy(&req.vht_capa,
6413 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6414 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006415 }
6416
Johannes Bergf62fab72013-02-21 20:09:09 +01006417 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006418 if (!err) {
6419 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006420 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6421 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006422 wdev_unlock(dev->ieee80211_ptr);
6423 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006424
Jouni Malinen636a5d32009-03-19 13:39:22 +02006425 return err;
6426}
6427
6428static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6429{
Johannes Berg4c476992010-10-04 21:36:35 +02006430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6431 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006432 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006433 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006434 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006435 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006436
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006437 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6438 return -EINVAL;
6439
6440 if (!info->attrs[NL80211_ATTR_MAC])
6441 return -EINVAL;
6442
6443 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6444 return -EINVAL;
6445
Johannes Berg4c476992010-10-04 21:36:35 +02006446 if (!rdev->ops->deauth)
6447 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006448
Johannes Berg074ac8d2010-09-16 14:58:22 +02006449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006450 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6451 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006452
Johannes Berg19957bb2009-07-02 17:20:43 +02006453 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006454
Johannes Berg19957bb2009-07-02 17:20:43 +02006455 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6456 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006457 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006458 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006459 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006460
6461 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006462 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6463 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006464 }
6465
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006466 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6467
Johannes Berg91bf9b22013-05-15 17:44:01 +02006468 wdev_lock(dev->ieee80211_ptr);
6469 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6470 local_state_change);
6471 wdev_unlock(dev->ieee80211_ptr);
6472 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006473}
6474
6475static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6476{
Johannes Berg4c476992010-10-04 21:36:35 +02006477 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6478 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006479 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006480 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006481 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006482 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006483
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006484 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6485 return -EINVAL;
6486
6487 if (!info->attrs[NL80211_ATTR_MAC])
6488 return -EINVAL;
6489
6490 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6491 return -EINVAL;
6492
Johannes Berg4c476992010-10-04 21:36:35 +02006493 if (!rdev->ops->disassoc)
6494 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006495
Johannes Berg074ac8d2010-09-16 14:58:22 +02006496 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006497 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6498 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006499
Johannes Berg19957bb2009-07-02 17:20:43 +02006500 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006501
Johannes Berg19957bb2009-07-02 17:20:43 +02006502 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6503 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006504 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006505 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006506 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006507
6508 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006509 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6510 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006511 }
6512
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006513 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6514
Johannes Berg91bf9b22013-05-15 17:44:01 +02006515 wdev_lock(dev->ieee80211_ptr);
6516 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6517 local_state_change);
6518 wdev_unlock(dev->ieee80211_ptr);
6519 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006520}
6521
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006522static bool
6523nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6524 int mcast_rate[IEEE80211_NUM_BANDS],
6525 int rateval)
6526{
6527 struct wiphy *wiphy = &rdev->wiphy;
6528 bool found = false;
6529 int band, i;
6530
6531 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6532 struct ieee80211_supported_band *sband;
6533
6534 sband = wiphy->bands[band];
6535 if (!sband)
6536 continue;
6537
6538 for (i = 0; i < sband->n_bitrates; i++) {
6539 if (sband->bitrates[i].bitrate == rateval) {
6540 mcast_rate[band] = i + 1;
6541 found = true;
6542 break;
6543 }
6544 }
6545 }
6546
6547 return found;
6548}
6549
Johannes Berg04a773a2009-04-19 21:24:32 +02006550static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
6551{
Johannes Berg4c476992010-10-04 21:36:35 +02006552 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6553 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006554 struct cfg80211_ibss_params ibss;
6555 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006556 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02006557 int err;
6558
Johannes Berg8e30bc52009-04-22 17:45:38 +02006559 memset(&ibss, 0, sizeof(ibss));
6560
Johannes Berg04a773a2009-04-19 21:24:32 +02006561 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6562 return -EINVAL;
6563
Johannes Berg683b6d32012-11-08 21:25:48 +01006564 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02006565 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6566 return -EINVAL;
6567
Johannes Berg8e30bc52009-04-22 17:45:38 +02006568 ibss.beacon_interval = 100;
6569
6570 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
6571 ibss.beacon_interval =
6572 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
6573 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
6574 return -EINVAL;
6575 }
6576
Johannes Berg4c476992010-10-04 21:36:35 +02006577 if (!rdev->ops->join_ibss)
6578 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006579
Johannes Berg4c476992010-10-04 21:36:35 +02006580 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6581 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006582
Johannes Berg79c97e92009-07-07 03:56:12 +02006583 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02006584
Johannes Berg39193492011-09-16 13:45:25 +02006585 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02006586 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02006587
6588 if (!is_valid_ether_addr(ibss.bssid))
6589 return -EINVAL;
6590 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006591 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6592 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6593
6594 if (info->attrs[NL80211_ATTR_IE]) {
6595 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6596 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6597 }
6598
Johannes Berg683b6d32012-11-08 21:25:48 +01006599 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
6600 if (err)
6601 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006602
Johannes Berg683b6d32012-11-08 21:25:48 +01006603 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01006604 return -EINVAL;
6605
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006606 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02006607 case NL80211_CHAN_WIDTH_5:
6608 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006609 case NL80211_CHAN_WIDTH_20_NOHT:
6610 break;
6611 case NL80211_CHAN_WIDTH_20:
6612 case NL80211_CHAN_WIDTH_40:
6613 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
6614 break;
6615 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006616 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02006617 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01006618
Johannes Berg04a773a2009-04-19 21:24:32 +02006619 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02006620 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02006621
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006622 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6623 u8 *rates =
6624 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6625 int n_rates =
6626 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6627 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01006628 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006629
Johannes Berg34850ab2011-07-18 18:08:35 +02006630 err = ieee80211_get_ratemask(sband, rates, n_rates,
6631 &ibss.basic_rates);
6632 if (err)
6633 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006634 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006635
Simon Wunderlich803768f2013-06-28 10:39:58 +02006636 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6637 memcpy(&ibss.ht_capa_mask,
6638 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6639 sizeof(ibss.ht_capa_mask));
6640
6641 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
6642 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6643 return -EINVAL;
6644 memcpy(&ibss.ht_capa,
6645 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6646 sizeof(ibss.ht_capa));
6647 }
6648
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006649 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
6650 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
6651 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
6652 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03006653
Johannes Berg4c476992010-10-04 21:36:35 +02006654 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306655 bool no_ht = false;
6656
Johannes Berg4c476992010-10-04 21:36:35 +02006657 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306658 info->attrs[NL80211_ATTR_KEYS],
6659 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02006660 if (IS_ERR(connkeys))
6661 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05306662
Johannes Berg3d9d1d62012-11-08 23:14:50 +01006663 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
6664 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05306665 kfree(connkeys);
6666 return -EINVAL;
6667 }
Johannes Berg4c476992010-10-04 21:36:35 +02006668 }
Johannes Berg04a773a2009-04-19 21:24:32 +02006669
Antonio Quartulli267335d2012-01-31 20:25:47 +01006670 ibss.control_port =
6671 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
6672
Simon Wunderlich5336fa82013-10-07 18:41:05 +02006673 ibss.userspace_handles_dfs =
6674 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
6675
Johannes Berg4c476992010-10-04 21:36:35 +02006676 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006677 if (err)
6678 kfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02006679 return err;
6680}
6681
6682static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
6683{
Johannes Berg4c476992010-10-04 21:36:35 +02006684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6685 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02006686
Johannes Berg4c476992010-10-04 21:36:35 +02006687 if (!rdev->ops->leave_ibss)
6688 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006689
Johannes Berg4c476992010-10-04 21:36:35 +02006690 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
6691 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02006692
Johannes Berg4c476992010-10-04 21:36:35 +02006693 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02006694}
6695
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006696static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
6697{
6698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6699 struct net_device *dev = info->user_ptr[1];
6700 int mcast_rate[IEEE80211_NUM_BANDS];
6701 u32 nla_rate;
6702 int err;
6703
6704 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
6705 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6706 return -EOPNOTSUPP;
6707
6708 if (!rdev->ops->set_mcast_rate)
6709 return -EOPNOTSUPP;
6710
6711 memset(mcast_rate, 0, sizeof(mcast_rate));
6712
6713 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
6714 return -EINVAL;
6715
6716 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
6717 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
6718 return -EINVAL;
6719
6720 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
6721
6722 return err;
6723}
6724
Johannes Bergad7e7182013-11-13 13:37:47 +01006725static struct sk_buff *
6726__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
6727 int approxlen, u32 portid, u32 seq,
6728 enum nl80211_commands cmd,
6729 enum nl80211_attrs attr, gfp_t gfp)
6730{
6731 struct sk_buff *skb;
6732 void *hdr;
6733 struct nlattr *data;
6734
6735 skb = nlmsg_new(approxlen + 100, gfp);
6736 if (!skb)
6737 return NULL;
6738
6739 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
6740 if (!hdr) {
6741 kfree_skb(skb);
6742 return NULL;
6743 }
6744
6745 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
6746 goto nla_put_failure;
6747 data = nla_nest_start(skb, attr);
6748
6749 ((void **)skb->cb)[0] = rdev;
6750 ((void **)skb->cb)[1] = hdr;
6751 ((void **)skb->cb)[2] = data;
6752
6753 return skb;
6754
6755 nla_put_failure:
6756 kfree_skb(skb);
6757 return NULL;
6758}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01006759
Johannes Bergaff89a92009-07-01 21:26:51 +02006760#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02006761static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
6762{
Johannes Berg4c476992010-10-04 21:36:35 +02006763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03006764 struct wireless_dev *wdev =
6765 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02006766 int err;
6767
David Spinadelfc73f112013-07-31 18:04:15 +03006768 if (!rdev->ops->testmode_cmd)
6769 return -EOPNOTSUPP;
6770
6771 if (IS_ERR(wdev)) {
6772 err = PTR_ERR(wdev);
6773 if (err != -EINVAL)
6774 return err;
6775 wdev = NULL;
6776 } else if (wdev->wiphy != &rdev->wiphy) {
6777 return -EINVAL;
6778 }
6779
Johannes Bergaff89a92009-07-01 21:26:51 +02006780 if (!info->attrs[NL80211_ATTR_TESTDATA])
6781 return -EINVAL;
6782
Johannes Bergad7e7182013-11-13 13:37:47 +01006783 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03006784 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02006785 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
6786 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01006787 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02006788
Johannes Bergaff89a92009-07-01 21:26:51 +02006789 return err;
6790}
6791
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006792static int nl80211_testmode_dump(struct sk_buff *skb,
6793 struct netlink_callback *cb)
6794{
Johannes Berg00918d32011-12-13 17:22:05 +01006795 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006796 int err;
6797 long phy_idx;
6798 void *data = NULL;
6799 int data_len = 0;
6800
Johannes Berg5fe231e2013-05-08 21:45:15 +02006801 rtnl_lock();
6802
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006803 if (cb->args[0]) {
6804 /*
6805 * 0 is a valid index, but not valid for args[0],
6806 * so we need to offset by 1.
6807 */
6808 phy_idx = cb->args[0] - 1;
6809 } else {
6810 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
6811 nl80211_fam.attrbuf, nl80211_fam.maxattr,
6812 nl80211_policy);
6813 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02006814 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006815
Johannes Berg2bd7e352012-06-15 14:23:16 +02006816 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
6817 nl80211_fam.attrbuf);
6818 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006819 err = PTR_ERR(rdev);
6820 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01006821 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02006822 phy_idx = rdev->wiphy_idx;
6823 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02006824
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006825 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
6826 cb->args[1] =
6827 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
6828 }
6829
6830 if (cb->args[1]) {
6831 data = nla_data((void *)cb->args[1]);
6832 data_len = nla_len((void *)cb->args[1]);
6833 }
6834
Johannes Berg00918d32011-12-13 17:22:05 +01006835 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
6836 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02006837 err = -ENOENT;
6838 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006839 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006840
Johannes Berg00918d32011-12-13 17:22:05 +01006841 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006842 err = -EOPNOTSUPP;
6843 goto out_err;
6844 }
6845
6846 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00006847 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006848 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6849 NL80211_CMD_TESTMODE);
6850 struct nlattr *tmdata;
6851
Dan Carpentercb35fba2013-08-14 14:50:01 +03006852 if (!hdr)
6853 break;
6854
David S. Miller9360ffd2012-03-29 04:41:26 -04006855 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006856 genlmsg_cancel(skb, hdr);
6857 break;
6858 }
6859
6860 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
6861 if (!tmdata) {
6862 genlmsg_cancel(skb, hdr);
6863 break;
6864 }
Hila Gonene35e4d22012-06-27 17:19:42 +03006865 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006866 nla_nest_end(skb, tmdata);
6867
6868 if (err == -ENOBUFS || err == -ENOENT) {
6869 genlmsg_cancel(skb, hdr);
6870 break;
6871 } else if (err) {
6872 genlmsg_cancel(skb, hdr);
6873 goto out_err;
6874 }
6875
6876 genlmsg_end(skb, hdr);
6877 }
6878
6879 err = skb->len;
6880 /* see above */
6881 cb->args[0] = phy_idx + 1;
6882 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02006883 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07006884 return err;
6885}
6886
Johannes Bergaff89a92009-07-01 21:26:51 +02006887struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy,
6888 int approxlen, gfp_t gfp)
6889{
6890 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
6891
Johannes Bergad7e7182013-11-13 13:37:47 +01006892 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
6893 NL80211_CMD_TESTMODE,
6894 NL80211_ATTR_TESTDATA, gfp);
Johannes Bergaff89a92009-07-01 21:26:51 +02006895}
6896EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb);
6897
6898void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
6899{
Michal Kaziora0ec5702013-06-25 09:17:17 +02006900 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
Johannes Bergaff89a92009-07-01 21:26:51 +02006901 void *hdr = ((void **)skb->cb)[1];
6902 struct nlattr *data = ((void **)skb->cb)[2];
6903
6904 nla_nest_end(skb, data);
6905 genlmsg_end(skb, hdr);
Johannes Berg68eb5502013-11-19 15:19:38 +01006906 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01006907 NL80211_MCGRP_TESTMODE, gfp);
Johannes Bergaff89a92009-07-01 21:26:51 +02006908}
6909EXPORT_SYMBOL(cfg80211_testmode_event);
6910#endif
6911
Samuel Ortizb23aa672009-07-01 21:26:54 +02006912static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
6913{
Johannes Berg4c476992010-10-04 21:36:35 +02006914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6915 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02006916 struct cfg80211_connect_params connect;
6917 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02006918 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006919 int err;
6920
6921 memset(&connect, 0, sizeof(connect));
6922
6923 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6924 return -EINVAL;
6925
6926 if (!info->attrs[NL80211_ATTR_SSID] ||
6927 !nla_len(info->attrs[NL80211_ATTR_SSID]))
6928 return -EINVAL;
6929
6930 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
6931 connect.auth_type =
6932 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006933 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
6934 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006935 return -EINVAL;
6936 } else
6937 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
6938
6939 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
6940
Johannes Bergc0692b82010-08-27 14:26:53 +03006941 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006942 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006943 if (err)
6944 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006945
Johannes Berg074ac8d2010-09-16 14:58:22 +02006946 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006947 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6948 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006949
Johannes Berg79c97e92009-07-07 03:56:12 +02006950 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006951
Bala Shanmugam4486ea92012-03-07 17:27:12 +05306952 connect.bg_scan_period = -1;
6953 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
6954 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
6955 connect.bg_scan_period =
6956 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
6957 }
6958
Samuel Ortizb23aa672009-07-01 21:26:54 +02006959 if (info->attrs[NL80211_ATTR_MAC])
6960 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
6961 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6962 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6963
6964 if (info->attrs[NL80211_ATTR_IE]) {
6965 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6966 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6967 }
6968
Jouni Malinencee00a92013-01-15 17:15:57 +02006969 if (info->attrs[NL80211_ATTR_USE_MFP]) {
6970 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
6971 if (connect.mfp != NL80211_MFP_REQUIRED &&
6972 connect.mfp != NL80211_MFP_NO)
6973 return -EINVAL;
6974 } else {
6975 connect.mfp = NL80211_MFP_NO;
6976 }
6977
Samuel Ortizb23aa672009-07-01 21:26:54 +02006978 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6979 connect.channel =
6980 ieee80211_get_channel(wiphy,
6981 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
6982 if (!connect.channel ||
Johannes Berg4c476992010-10-04 21:36:35 +02006983 connect.channel->flags & IEEE80211_CHAN_DISABLED)
6984 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006985 }
6986
Johannes Bergfffd0932009-07-08 14:22:54 +02006987 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
6988 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05306989 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02006990 if (IS_ERR(connkeys))
6991 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02006992 }
6993
Ben Greear7e7c8922011-11-18 11:31:59 -08006994 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
6995 connect.flags |= ASSOC_REQ_DISABLE_HT;
6996
6997 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
6998 memcpy(&connect.ht_capa_mask,
6999 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7000 sizeof(connect.ht_capa_mask));
7001
7002 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007003 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
7004 kfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007005 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007006 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007007 memcpy(&connect.ht_capa,
7008 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7009 sizeof(connect.ht_capa));
7010 }
7011
Johannes Bergee2aca32013-02-21 17:36:01 +01007012 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7013 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7014
7015 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7016 memcpy(&connect.vht_capa_mask,
7017 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7018 sizeof(connect.vht_capa_mask));
7019
7020 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7021 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
7022 kfree(connkeys);
7023 return -EINVAL;
7024 }
7025 memcpy(&connect.vht_capa,
7026 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7027 sizeof(connect.vht_capa));
7028 }
7029
Johannes Berg83739b02013-05-15 17:44:01 +02007030 wdev_lock(dev->ieee80211_ptr);
7031 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7032 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007033 if (err)
7034 kfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007035 return err;
7036}
7037
7038static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7039{
Johannes Berg4c476992010-10-04 21:36:35 +02007040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7041 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007042 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007043 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007044
7045 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7046 reason = WLAN_REASON_DEAUTH_LEAVING;
7047 else
7048 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7049
7050 if (reason == 0)
7051 return -EINVAL;
7052
Johannes Berg074ac8d2010-09-16 14:58:22 +02007053 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007054 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7055 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007056
Johannes Berg83739b02013-05-15 17:44:01 +02007057 wdev_lock(dev->ieee80211_ptr);
7058 ret = cfg80211_disconnect(rdev, dev, reason, true);
7059 wdev_unlock(dev->ieee80211_ptr);
7060 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007061}
7062
Johannes Berg463d0182009-07-14 00:33:35 +02007063static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7064{
Johannes Berg4c476992010-10-04 21:36:35 +02007065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007066 struct net *net;
7067 int err;
7068 u32 pid;
7069
7070 if (!info->attrs[NL80211_ATTR_PID])
7071 return -EINVAL;
7072
7073 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7074
Johannes Berg463d0182009-07-14 00:33:35 +02007075 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007076 if (IS_ERR(net))
7077 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007078
7079 err = 0;
7080
7081 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007082 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7083 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007084
Johannes Berg463d0182009-07-14 00:33:35 +02007085 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007086 return err;
7087}
7088
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007089static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7090{
Johannes Berg4c476992010-10-04 21:36:35 +02007091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007092 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7093 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007094 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007095 struct cfg80211_pmksa pmksa;
7096
7097 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7098
7099 if (!info->attrs[NL80211_ATTR_MAC])
7100 return -EINVAL;
7101
7102 if (!info->attrs[NL80211_ATTR_PMKID])
7103 return -EINVAL;
7104
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007105 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7106 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7107
Johannes Berg074ac8d2010-09-16 14:58:22 +02007108 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007109 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7110 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007111
7112 switch (info->genlhdr->cmd) {
7113 case NL80211_CMD_SET_PMKSA:
7114 rdev_ops = rdev->ops->set_pmksa;
7115 break;
7116 case NL80211_CMD_DEL_PMKSA:
7117 rdev_ops = rdev->ops->del_pmksa;
7118 break;
7119 default:
7120 WARN_ON(1);
7121 break;
7122 }
7123
Johannes Berg4c476992010-10-04 21:36:35 +02007124 if (!rdev_ops)
7125 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007126
Johannes Berg4c476992010-10-04 21:36:35 +02007127 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007128}
7129
7130static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7131{
Johannes Berg4c476992010-10-04 21:36:35 +02007132 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7133 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007134
Johannes Berg074ac8d2010-09-16 14:58:22 +02007135 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007136 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7137 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007138
Johannes Berg4c476992010-10-04 21:36:35 +02007139 if (!rdev->ops->flush_pmksa)
7140 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007141
Hila Gonene35e4d22012-06-27 17:19:42 +03007142 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007143}
7144
Arik Nemtsov109086c2011-09-28 14:12:50 +03007145static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7146{
7147 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7148 struct net_device *dev = info->user_ptr[1];
7149 u8 action_code, dialog_token;
7150 u16 status_code;
7151 u8 *peer;
7152
7153 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7154 !rdev->ops->tdls_mgmt)
7155 return -EOPNOTSUPP;
7156
7157 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7158 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7159 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7160 !info->attrs[NL80211_ATTR_IE] ||
7161 !info->attrs[NL80211_ATTR_MAC])
7162 return -EINVAL;
7163
7164 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7165 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7166 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7167 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
7168
Hila Gonene35e4d22012-06-27 17:19:42 +03007169 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
7170 dialog_token, status_code,
7171 nla_data(info->attrs[NL80211_ATTR_IE]),
7172 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007173}
7174
7175static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7176{
7177 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7178 struct net_device *dev = info->user_ptr[1];
7179 enum nl80211_tdls_operation operation;
7180 u8 *peer;
7181
7182 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7183 !rdev->ops->tdls_oper)
7184 return -EOPNOTSUPP;
7185
7186 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7187 !info->attrs[NL80211_ATTR_MAC])
7188 return -EINVAL;
7189
7190 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7191 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7192
Hila Gonene35e4d22012-06-27 17:19:42 +03007193 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007194}
7195
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007196static int nl80211_remain_on_channel(struct sk_buff *skb,
7197 struct genl_info *info)
7198{
Johannes Berg4c476992010-10-04 21:36:35 +02007199 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007200 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007201 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007202 struct sk_buff *msg;
7203 void *hdr;
7204 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007205 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007206 int err;
7207
7208 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7209 !info->attrs[NL80211_ATTR_DURATION])
7210 return -EINVAL;
7211
7212 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7213
Johannes Berg7c4ef712011-11-18 15:33:48 +01007214 if (!rdev->ops->remain_on_channel ||
7215 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007216 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007217
Johannes Bergebf348f2012-06-01 12:50:54 +02007218 /*
7219 * We should be on that channel for at least a minimum amount of
7220 * time (10ms) but no longer than the driver supports.
7221 */
7222 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7223 duration > rdev->wiphy.max_remain_on_channel_duration)
7224 return -EINVAL;
7225
Johannes Berg683b6d32012-11-08 21:25:48 +01007226 err = nl80211_parse_chandef(rdev, info, &chandef);
7227 if (err)
7228 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007229
7230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007231 if (!msg)
7232 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007233
Eric W. Biederman15e47302012-09-07 20:12:54 +00007234 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007235 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007236 if (!hdr) {
7237 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007238 goto free_msg;
7239 }
7240
Johannes Berg683b6d32012-11-08 21:25:48 +01007241 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7242 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007243
7244 if (err)
7245 goto free_msg;
7246
David S. Miller9360ffd2012-03-29 04:41:26 -04007247 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7248 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007249
7250 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007251
7252 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007253
7254 nla_put_failure:
7255 err = -ENOBUFS;
7256 free_msg:
7257 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007258 return err;
7259}
7260
7261static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7262 struct genl_info *info)
7263{
Johannes Berg4c476992010-10-04 21:36:35 +02007264 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007265 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007266 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007267
7268 if (!info->attrs[NL80211_ATTR_COOKIE])
7269 return -EINVAL;
7270
Johannes Berg4c476992010-10-04 21:36:35 +02007271 if (!rdev->ops->cancel_remain_on_channel)
7272 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007273
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007274 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7275
Hila Gonene35e4d22012-06-27 17:19:42 +03007276 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007277}
7278
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007279static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7280 u8 *rates, u8 rates_len)
7281{
7282 u8 i;
7283 u32 mask = 0;
7284
7285 for (i = 0; i < rates_len; i++) {
7286 int rate = (rates[i] & 0x7f) * 5;
7287 int ridx;
7288 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7289 struct ieee80211_rate *srate =
7290 &sband->bitrates[ridx];
7291 if (rate == srate->bitrate) {
7292 mask |= 1 << ridx;
7293 break;
7294 }
7295 }
7296 if (ridx == sband->n_bitrates)
7297 return 0; /* rate not found */
7298 }
7299
7300 return mask;
7301}
7302
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007303static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7304 u8 *rates, u8 rates_len,
7305 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7306{
7307 u8 i;
7308
7309 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7310
7311 for (i = 0; i < rates_len; i++) {
7312 int ridx, rbit;
7313
7314 ridx = rates[i] / 8;
7315 rbit = BIT(rates[i] % 8);
7316
7317 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007318 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007319 return false;
7320
7321 /* check availability */
7322 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7323 mcs[ridx] |= rbit;
7324 else
7325 return false;
7326 }
7327
7328 return true;
7329}
7330
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007331static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7332{
7333 u16 mcs_mask = 0;
7334
7335 switch (vht_mcs_map) {
7336 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7337 break;
7338 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7339 mcs_mask = 0x00FF;
7340 break;
7341 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7342 mcs_mask = 0x01FF;
7343 break;
7344 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7345 mcs_mask = 0x03FF;
7346 break;
7347 default:
7348 break;
7349 }
7350
7351 return mcs_mask;
7352}
7353
7354static void vht_build_mcs_mask(u16 vht_mcs_map,
7355 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7356{
7357 u8 nss;
7358
7359 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7360 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7361 vht_mcs_map >>= 2;
7362 }
7363}
7364
7365static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7366 struct nl80211_txrate_vht *txrate,
7367 u16 mcs[NL80211_VHT_NSS_MAX])
7368{
7369 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7370 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7371 u8 i;
7372
7373 if (!sband->vht_cap.vht_supported)
7374 return false;
7375
7376 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7377
7378 /* Build vht_mcs_mask from VHT capabilities */
7379 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7380
7381 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7382 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7383 mcs[i] = txrate->mcs[i];
7384 else
7385 return false;
7386 }
7387
7388 return true;
7389}
7390
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007391static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007392 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7393 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007394 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7395 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007396 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007397};
7398
7399static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7400 struct genl_info *info)
7401{
7402 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007403 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007404 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007405 int rem, i;
7406 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007407 struct nlattr *tx_rates;
7408 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007409 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007410
Johannes Berg4c476992010-10-04 21:36:35 +02007411 if (!rdev->ops->set_bitrate_mask)
7412 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007413
7414 memset(&mask, 0, sizeof(mask));
7415 /* Default to all rates enabled */
7416 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7417 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007418
7419 if (!sband)
7420 continue;
7421
7422 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007423 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007424 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007425 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007426
7427 if (!sband->vht_cap.vht_supported)
7428 continue;
7429
7430 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7431 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007432 }
7433
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007434 /* if no rates are given set it back to the defaults */
7435 if (!info->attrs[NL80211_ATTR_TX_RATES])
7436 goto out;
7437
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007438 /*
7439 * The nested attribute uses enum nl80211_band as the index. This maps
7440 * directly to the enum ieee80211_band values used in cfg80211.
7441 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007442 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007443 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7444 {
7445 enum ieee80211_band band = nla_type(tx_rates);
Johannes Berg4c476992010-10-04 21:36:35 +02007446 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7447 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007448 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007449 if (sband == NULL)
7450 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007451 nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7452 nla_len(tx_rates), nl80211_txattr_policy);
7453 if (tb[NL80211_TXRATE_LEGACY]) {
7454 mask.control[band].legacy = rateset_to_mask(
7455 sband,
7456 nla_data(tb[NL80211_TXRATE_LEGACY]),
7457 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307458 if ((mask.control[band].legacy == 0) &&
7459 nla_len(tb[NL80211_TXRATE_LEGACY]))
7460 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007461 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007462 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007463 if (!ht_rateset_to_mask(
7464 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007465 nla_data(tb[NL80211_TXRATE_HT]),
7466 nla_len(tb[NL80211_TXRATE_HT]),
7467 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007468 return -EINVAL;
7469 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007470 if (tb[NL80211_TXRATE_VHT]) {
7471 if (!vht_set_mcs_mask(
7472 sband,
7473 nla_data(tb[NL80211_TXRATE_VHT]),
7474 mask.control[band].vht_mcs))
7475 return -EINVAL;
7476 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007477
7478 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007479 /* don't allow empty legacy rates if HT or VHT
7480 * are not even supported.
7481 */
7482 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
7483 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007484 return -EINVAL;
7485
7486 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007487 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007488 goto out;
7489
7490 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
7491 if (mask.control[band].vht_mcs[i])
7492 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007493
7494 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007495 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007496 }
7497 }
7498
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007499out:
Hila Gonene35e4d22012-06-27 17:19:42 +03007500 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007501}
7502
Johannes Berg2e161f72010-08-12 15:38:38 +02007503static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007504{
Johannes Berg4c476992010-10-04 21:36:35 +02007505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007506 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02007507 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02007508
7509 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
7510 return -EINVAL;
7511
Johannes Berg2e161f72010-08-12 15:38:38 +02007512 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
7513 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02007514
Johannes Berg71bbc992012-06-15 15:30:18 +02007515 switch (wdev->iftype) {
7516 case NL80211_IFTYPE_STATION:
7517 case NL80211_IFTYPE_ADHOC:
7518 case NL80211_IFTYPE_P2P_CLIENT:
7519 case NL80211_IFTYPE_AP:
7520 case NL80211_IFTYPE_AP_VLAN:
7521 case NL80211_IFTYPE_MESH_POINT:
7522 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007523 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007524 break;
7525 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007526 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007527 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007528
7529 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02007530 if (!rdev->ops->mgmt_tx)
7531 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007532
Eric W. Biederman15e47302012-09-07 20:12:54 +00007533 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02007534 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
7535 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02007536}
7537
Johannes Berg2e161f72010-08-12 15:38:38 +02007538static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02007539{
Johannes Berg4c476992010-10-04 21:36:35 +02007540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007541 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007542 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02007543 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01007544 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007545 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01007546 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007547 struct cfg80211_mgmt_tx_params params = {
7548 .dont_wait_for_ack =
7549 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
7550 };
Jouni Malinen026331c2010-02-15 12:53:10 +02007551
Johannes Berg683b6d32012-11-08 21:25:48 +01007552 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02007553 return -EINVAL;
7554
Johannes Berg4c476992010-10-04 21:36:35 +02007555 if (!rdev->ops->mgmt_tx)
7556 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02007557
Johannes Berg71bbc992012-06-15 15:30:18 +02007558 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02007559 case NL80211_IFTYPE_P2P_DEVICE:
7560 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7561 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02007562 case NL80211_IFTYPE_STATION:
7563 case NL80211_IFTYPE_ADHOC:
7564 case NL80211_IFTYPE_P2P_CLIENT:
7565 case NL80211_IFTYPE_AP:
7566 case NL80211_IFTYPE_AP_VLAN:
7567 case NL80211_IFTYPE_MESH_POINT:
7568 case NL80211_IFTYPE_P2P_GO:
7569 break;
7570 default:
Johannes Berg4c476992010-10-04 21:36:35 +02007571 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007572 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007573
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007574 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01007575 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007576 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007577 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02007578
7579 /*
7580 * We should wait on the channel for at least a minimum amount
7581 * of time (10ms) but no longer than the driver supports.
7582 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007583 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7584 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02007585 return -EINVAL;
7586
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007587 }
7588
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007589 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007590
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007591 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01007592 return -EINVAL;
7593
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007594 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307595
Antonio Quartulliea141b752013-06-11 14:20:03 +02007596 /* get the channel if any has been specified, otherwise pass NULL to
7597 * the driver. The latter will use the current one
7598 */
7599 chandef.chan = NULL;
7600 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
7601 err = nl80211_parse_chandef(rdev, info, &chandef);
7602 if (err)
7603 return err;
7604 }
7605
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007606 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02007607 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02007608
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007609 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01007610 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7611 if (!msg)
7612 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02007613
Eric W. Biederman15e47302012-09-07 20:12:54 +00007614 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01007615 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007616 if (!hdr) {
7617 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01007618 goto free_msg;
7619 }
Jouni Malinen026331c2010-02-15 12:53:10 +02007620 }
Johannes Berge247bd902011-11-04 11:18:21 +01007621
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02007622 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
7623 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
7624 params.chan = chandef.chan;
7625 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02007626 if (err)
7627 goto free_msg;
7628
Johannes Berge247bd902011-11-04 11:18:21 +01007629 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04007630 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7631 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02007632
Johannes Berge247bd902011-11-04 11:18:21 +01007633 genlmsg_end(msg, hdr);
7634 return genlmsg_reply(msg, info);
7635 }
7636
7637 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02007638
7639 nla_put_failure:
7640 err = -ENOBUFS;
7641 free_msg:
7642 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02007643 return err;
7644}
7645
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007646static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
7647{
7648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007649 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007650 u64 cookie;
7651
7652 if (!info->attrs[NL80211_ATTR_COOKIE])
7653 return -EINVAL;
7654
7655 if (!rdev->ops->mgmt_tx_cancel_wait)
7656 return -EOPNOTSUPP;
7657
Johannes Berg71bbc992012-06-15 15:30:18 +02007658 switch (wdev->iftype) {
7659 case NL80211_IFTYPE_STATION:
7660 case NL80211_IFTYPE_ADHOC:
7661 case NL80211_IFTYPE_P2P_CLIENT:
7662 case NL80211_IFTYPE_AP:
7663 case NL80211_IFTYPE_AP_VLAN:
7664 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02007665 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02007666 break;
7667 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007668 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02007669 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007670
7671 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7672
Hila Gonene35e4d22012-06-27 17:19:42 +03007673 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01007674}
7675
Kalle Valoffb9eb32010-02-17 17:58:10 +02007676static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
7677{
Johannes Berg4c476992010-10-04 21:36:35 +02007678 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007679 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007680 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007681 u8 ps_state;
7682 bool state;
7683 int err;
7684
Johannes Berg4c476992010-10-04 21:36:35 +02007685 if (!info->attrs[NL80211_ATTR_PS_STATE])
7686 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007687
7688 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
7689
Johannes Berg4c476992010-10-04 21:36:35 +02007690 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
7691 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007692
7693 wdev = dev->ieee80211_ptr;
7694
Johannes Berg4c476992010-10-04 21:36:35 +02007695 if (!rdev->ops->set_power_mgmt)
7696 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007697
7698 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
7699
7700 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02007701 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007702
Hila Gonene35e4d22012-06-27 17:19:42 +03007703 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02007704 if (!err)
7705 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007706 return err;
7707}
7708
7709static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
7710{
Johannes Berg4c476992010-10-04 21:36:35 +02007711 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007712 enum nl80211_ps_state ps_state;
7713 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02007714 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02007715 struct sk_buff *msg;
7716 void *hdr;
7717 int err;
7718
Kalle Valoffb9eb32010-02-17 17:58:10 +02007719 wdev = dev->ieee80211_ptr;
7720
Johannes Berg4c476992010-10-04 21:36:35 +02007721 if (!rdev->ops->set_power_mgmt)
7722 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007723
7724 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007725 if (!msg)
7726 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007727
Eric W. Biederman15e47302012-09-07 20:12:54 +00007728 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02007729 NL80211_CMD_GET_POWER_SAVE);
7730 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02007731 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007732 goto free_msg;
7733 }
7734
7735 if (wdev->ps)
7736 ps_state = NL80211_PS_ENABLED;
7737 else
7738 ps_state = NL80211_PS_DISABLED;
7739
David S. Miller9360ffd2012-03-29 04:41:26 -04007740 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
7741 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02007742
7743 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007744 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007745
Johannes Berg4c476992010-10-04 21:36:35 +02007746 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007747 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02007748 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02007749 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02007750 return err;
7751}
7752
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007753static struct nla_policy
7754nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = {
7755 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
7756 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
7757 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07007758 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
7759 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
7760 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007761};
7762
Thomas Pedersen84f10702012-07-12 16:17:33 -07007763static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01007764 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007765{
7766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07007767 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007768 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07007769
Johannes Bergd9d8b012012-11-26 12:51:52 +01007770 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07007771 return -EINVAL;
7772
Thomas Pedersen84f10702012-07-12 16:17:33 -07007773 if (!rdev->ops->set_cqm_txe_config)
7774 return -EOPNOTSUPP;
7775
7776 if (wdev->iftype != NL80211_IFTYPE_STATION &&
7777 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7778 return -EOPNOTSUPP;
7779
Hila Gonene35e4d22012-06-27 17:19:42 +03007780 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07007781}
7782
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007783static int nl80211_set_cqm_rssi(struct genl_info *info,
7784 s32 threshold, u32 hysteresis)
7785{
Johannes Berg4c476992010-10-04 21:36:35 +02007786 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007787 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007788 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007789
7790 if (threshold > 0)
7791 return -EINVAL;
7792
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007793 /* disabling - hysteresis should also be zero then */
7794 if (threshold == 0)
7795 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007796
Johannes Berg4c476992010-10-04 21:36:35 +02007797 if (!rdev->ops->set_cqm_rssi_config)
7798 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007799
Johannes Berg074ac8d2010-09-16 14:58:22 +02007800 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007801 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
7802 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007803
Hila Gonene35e4d22012-06-27 17:19:42 +03007804 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007805}
7806
7807static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
7808{
7809 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
7810 struct nlattr *cqm;
7811 int err;
7812
7813 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007814 if (!cqm)
7815 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007816
7817 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
7818 nl80211_attr_cqm_policy);
7819 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007820 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007821
7822 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
7823 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007824 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
7825 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007826
Johannes Berg1da5fcc2013-08-06 14:10:48 +02007827 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
7828 }
7829
7830 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
7831 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
7832 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
7833 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
7834 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
7835 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
7836
7837 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
7838 }
7839
7840 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02007841}
7842
Johannes Berg29cbe682010-12-03 09:20:44 +01007843static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
7844{
7845 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7846 struct net_device *dev = info->user_ptr[1];
7847 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08007848 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01007849 int err;
7850
7851 /* start with default */
7852 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08007853 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01007854
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007855 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01007856 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007857 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01007858 if (err)
7859 return err;
7860 }
7861
7862 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
7863 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
7864 return -EINVAL;
7865
Javier Cardonac80d5452010-12-16 17:37:49 -08007866 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
7867 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
7868
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08007869 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7870 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
7871 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7872 return -EINVAL;
7873
Marco Porsch9bdbf042013-01-07 16:04:51 +01007874 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7875 setup.beacon_interval =
7876 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7877 if (setup.beacon_interval < 10 ||
7878 setup.beacon_interval > 10000)
7879 return -EINVAL;
7880 }
7881
7882 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
7883 setup.dtim_period =
7884 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
7885 if (setup.dtim_period < 1 || setup.dtim_period > 100)
7886 return -EINVAL;
7887 }
7888
Javier Cardonac80d5452010-12-16 17:37:49 -08007889 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
7890 /* parse additional setup parameters if given */
7891 err = nl80211_parse_mesh_setup(info, &setup);
7892 if (err)
7893 return err;
7894 }
7895
Thomas Pedersend37bb182013-03-04 13:06:13 -08007896 if (setup.user_mpm)
7897 cfg.auto_open_plinks = false;
7898
Johannes Bergcc1d2802012-05-16 23:50:20 +02007899 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01007900 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
7901 if (err)
7902 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007903 } else {
7904 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01007905 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02007906 }
7907
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07007908 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7909 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7910 int n_rates =
7911 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7912 struct ieee80211_supported_band *sband;
7913
7914 if (!setup.chandef.chan)
7915 return -EINVAL;
7916
7917 sband = rdev->wiphy.bands[setup.chandef.chan->band];
7918
7919 err = ieee80211_get_ratemask(sband, rates, n_rates,
7920 &setup.basic_rates);
7921 if (err)
7922 return err;
7923 }
7924
Javier Cardonac80d5452010-12-16 17:37:49 -08007925 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007926}
7927
7928static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
7929{
7930 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7931 struct net_device *dev = info->user_ptr[1];
7932
7933 return cfg80211_leave_mesh(rdev, dev);
7934}
7935
Johannes Bergdfb89c52012-06-27 09:23:48 +02007936#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007937static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
7938 struct cfg80211_registered_device *rdev)
7939{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007940 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007941 struct nlattr *nl_pats, *nl_pat;
7942 int i, pat_len;
7943
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007944 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007945 return 0;
7946
7947 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
7948 if (!nl_pats)
7949 return -ENOBUFS;
7950
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007951 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007952 nl_pat = nla_nest_start(msg, i + 1);
7953 if (!nl_pat)
7954 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007955 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007956 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007957 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07007958 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
7959 wowlan->patterns[i].pattern) ||
7960 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02007961 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08007962 return -ENOBUFS;
7963 nla_nest_end(msg, nl_pat);
7964 }
7965 nla_nest_end(msg, nl_pats);
7966
7967 return 0;
7968}
7969
Johannes Berg2a0e0472013-01-23 22:57:40 +01007970static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
7971 struct cfg80211_wowlan_tcp *tcp)
7972{
7973 struct nlattr *nl_tcp;
7974
7975 if (!tcp)
7976 return 0;
7977
7978 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
7979 if (!nl_tcp)
7980 return -ENOBUFS;
7981
7982 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
7983 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
7984 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
7985 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
7986 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
7987 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
7988 tcp->payload_len, tcp->payload) ||
7989 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
7990 tcp->data_interval) ||
7991 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
7992 tcp->wake_len, tcp->wake_data) ||
7993 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
7994 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
7995 return -ENOBUFS;
7996
7997 if (tcp->payload_seq.len &&
7998 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
7999 sizeof(tcp->payload_seq), &tcp->payload_seq))
8000 return -ENOBUFS;
8001
8002 if (tcp->payload_tok.len &&
8003 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8004 sizeof(tcp->payload_tok) + tcp->tokens_size,
8005 &tcp->payload_tok))
8006 return -ENOBUFS;
8007
Johannes Berge248ad32013-05-16 10:24:28 +02008008 nla_nest_end(msg, nl_tcp);
8009
Johannes Berg2a0e0472013-01-23 22:57:40 +01008010 return 0;
8011}
8012
Johannes Bergff1b6e62011-05-04 15:37:28 +02008013static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8014{
8015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8016 struct sk_buff *msg;
8017 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008018 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008019
Johannes Berg964dc9e2013-06-03 17:25:34 +02008020 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008021 return -EOPNOTSUPP;
8022
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008023 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008024 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008025 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8026 rdev->wiphy.wowlan_config->tcp->payload_len +
8027 rdev->wiphy.wowlan_config->tcp->wake_len +
8028 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008029 }
8030
8031 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008032 if (!msg)
8033 return -ENOMEM;
8034
Eric W. Biederman15e47302012-09-07 20:12:54 +00008035 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008036 NL80211_CMD_GET_WOWLAN);
8037 if (!hdr)
8038 goto nla_put_failure;
8039
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008040 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008041 struct nlattr *nl_wowlan;
8042
8043 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8044 if (!nl_wowlan)
8045 goto nla_put_failure;
8046
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008047 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008049 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008051 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008052 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008053 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008054 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008055 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008056 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008057 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008058 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008059 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8061 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008062
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008063 if (nl80211_send_wowlan_patterns(msg, rdev))
8064 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008065
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008066 if (nl80211_send_wowlan_tcp(msg,
8067 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008068 goto nla_put_failure;
8069
Johannes Bergff1b6e62011-05-04 15:37:28 +02008070 nla_nest_end(msg, nl_wowlan);
8071 }
8072
8073 genlmsg_end(msg, hdr);
8074 return genlmsg_reply(msg, info);
8075
8076nla_put_failure:
8077 nlmsg_free(msg);
8078 return -ENOBUFS;
8079}
8080
Johannes Berg2a0e0472013-01-23 22:57:40 +01008081static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8082 struct nlattr *attr,
8083 struct cfg80211_wowlan *trig)
8084{
8085 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8086 struct cfg80211_wowlan_tcp *cfg;
8087 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8088 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8089 u32 size;
8090 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8091 int err, port;
8092
Johannes Berg964dc9e2013-06-03 17:25:34 +02008093 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008094 return -EINVAL;
8095
8096 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8097 nla_data(attr), nla_len(attr),
8098 nl80211_wowlan_tcp_policy);
8099 if (err)
8100 return err;
8101
8102 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8103 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8104 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8105 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8106 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8107 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8108 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8109 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8110 return -EINVAL;
8111
8112 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008113 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008114 return -EINVAL;
8115
8116 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008117 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008118 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008119 return -EINVAL;
8120
8121 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008122 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008123 return -EINVAL;
8124
8125 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8126 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8127 return -EINVAL;
8128
8129 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8130 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8131
8132 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8133 tokens_size = tokln - sizeof(*tok);
8134
8135 if (!tok->len || tokens_size % tok->len)
8136 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008137 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008138 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008139 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008140 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008141 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008142 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008143 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008144 return -EINVAL;
8145 if (tok->offset + tok->len > data_size)
8146 return -EINVAL;
8147 }
8148
8149 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8150 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008151 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008152 return -EINVAL;
8153 if (seq->len == 0 || seq->len > 4)
8154 return -EINVAL;
8155 if (seq->len + seq->offset > data_size)
8156 return -EINVAL;
8157 }
8158
8159 size = sizeof(*cfg);
8160 size += data_size;
8161 size += wake_size + wake_mask_size;
8162 size += tokens_size;
8163
8164 cfg = kzalloc(size, GFP_KERNEL);
8165 if (!cfg)
8166 return -ENOMEM;
8167 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8168 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8169 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8170 ETH_ALEN);
8171 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8172 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8173 else
8174 port = 0;
8175#ifdef CONFIG_INET
8176 /* allocate a socket and port for it and use it */
8177 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8178 IPPROTO_TCP, &cfg->sock, 1);
8179 if (err) {
8180 kfree(cfg);
8181 return err;
8182 }
8183 if (inet_csk_get_port(cfg->sock->sk, port)) {
8184 sock_release(cfg->sock);
8185 kfree(cfg);
8186 return -EADDRINUSE;
8187 }
8188 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8189#else
8190 if (!port) {
8191 kfree(cfg);
8192 return -EINVAL;
8193 }
8194 cfg->src_port = port;
8195#endif
8196
8197 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8198 cfg->payload_len = data_size;
8199 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8200 memcpy((void *)cfg->payload,
8201 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8202 data_size);
8203 if (seq)
8204 cfg->payload_seq = *seq;
8205 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8206 cfg->wake_len = wake_size;
8207 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8208 memcpy((void *)cfg->wake_data,
8209 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8210 wake_size);
8211 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8212 data_size + wake_size;
8213 memcpy((void *)cfg->wake_mask,
8214 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8215 wake_mask_size);
8216 if (tok) {
8217 cfg->tokens_size = tokens_size;
8218 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8219 }
8220
8221 trig->tcp = cfg;
8222
8223 return 0;
8224}
8225
Johannes Bergff1b6e62011-05-04 15:37:28 +02008226static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8227{
8228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8229 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008230 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008231 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008232 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008233 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008234 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008235
Johannes Berg964dc9e2013-06-03 17:25:34 +02008236 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008237 return -EOPNOTSUPP;
8238
Johannes Bergae33bd82012-07-12 16:25:02 +02008239 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8240 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008241 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008242 goto set_wakeup;
8243 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008244
8245 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8246 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8247 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8248 nl80211_wowlan_policy);
8249 if (err)
8250 return err;
8251
8252 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8253 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8254 return -EINVAL;
8255 new_triggers.any = true;
8256 }
8257
8258 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8259 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8260 return -EINVAL;
8261 new_triggers.disconnect = true;
8262 }
8263
8264 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8265 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8266 return -EINVAL;
8267 new_triggers.magic_pkt = true;
8268 }
8269
Johannes Berg77dbbb12011-07-13 10:48:55 +02008270 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8271 return -EINVAL;
8272
8273 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8274 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8275 return -EINVAL;
8276 new_triggers.gtk_rekey_failure = true;
8277 }
8278
8279 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8280 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8281 return -EINVAL;
8282 new_triggers.eap_identity_req = true;
8283 }
8284
8285 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8286 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8287 return -EINVAL;
8288 new_triggers.four_way_handshake = true;
8289 }
8290
8291 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8292 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8293 return -EINVAL;
8294 new_triggers.rfkill_release = true;
8295 }
8296
Johannes Bergff1b6e62011-05-04 15:37:28 +02008297 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8298 struct nlattr *pat;
8299 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008300 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008301 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008302
8303 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8304 rem)
8305 n_patterns++;
8306 if (n_patterns > wowlan->n_patterns)
8307 return -EINVAL;
8308
8309 new_triggers.patterns = kcalloc(n_patterns,
8310 sizeof(new_triggers.patterns[0]),
8311 GFP_KERNEL);
8312 if (!new_triggers.patterns)
8313 return -ENOMEM;
8314
8315 new_triggers.n_patterns = n_patterns;
8316 i = 0;
8317
8318 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8319 rem) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008320 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8321 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008322 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008323 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8324 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008325 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008326 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008327 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008328 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008329 goto error;
8330 if (pat_len > wowlan->pattern_max_len ||
8331 pat_len < wowlan->pattern_min_len)
8332 goto error;
8333
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008334 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008335 pkt_offset = 0;
8336 else
8337 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008338 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008339 if (pkt_offset > wowlan->max_pkt_offset)
8340 goto error;
8341 new_triggers.patterns[i].pkt_offset = pkt_offset;
8342
Johannes Bergff1b6e62011-05-04 15:37:28 +02008343 new_triggers.patterns[i].mask =
8344 kmalloc(mask_len + pat_len, GFP_KERNEL);
8345 if (!new_triggers.patterns[i].mask) {
8346 err = -ENOMEM;
8347 goto error;
8348 }
8349 new_triggers.patterns[i].pattern =
8350 new_triggers.patterns[i].mask + mask_len;
8351 memcpy(new_triggers.patterns[i].mask,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008352 nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008353 mask_len);
8354 new_triggers.patterns[i].pattern_len = pat_len;
8355 memcpy(new_triggers.patterns[i].pattern,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008356 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008357 pat_len);
8358 i++;
8359 }
8360 }
8361
Johannes Berg2a0e0472013-01-23 22:57:40 +01008362 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8363 err = nl80211_parse_wowlan_tcp(
8364 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8365 &new_triggers);
8366 if (err)
8367 goto error;
8368 }
8369
Johannes Bergae33bd82012-07-12 16:25:02 +02008370 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
8371 if (!ntrig) {
8372 err = -ENOMEM;
8373 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008374 }
Johannes Bergae33bd82012-07-12 16:25:02 +02008375 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008376 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008377
Johannes Bergae33bd82012-07-12 16:25:02 +02008378 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008379 if (rdev->ops->set_wakeup &&
8380 prev_enabled != !!rdev->wiphy.wowlan_config)
8381 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02008382
Johannes Bergff1b6e62011-05-04 15:37:28 +02008383 return 0;
8384 error:
8385 for (i = 0; i < new_triggers.n_patterns; i++)
8386 kfree(new_triggers.patterns[i].mask);
8387 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01008388 if (new_triggers.tcp && new_triggers.tcp->sock)
8389 sock_release(new_triggers.tcp->sock);
8390 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008391 return err;
8392}
Johannes Bergdfb89c52012-06-27 09:23:48 +02008393#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02008394
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07008395static int nl80211_send_coalesce_rules(struct sk_buff *msg,
8396 struct cfg80211_registered_device *rdev)
8397{
8398 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
8399 int i, j, pat_len;
8400 struct cfg80211_coalesce_rules *rule;
8401
8402 if (!rdev->coalesce->n_rules)
8403 return 0;
8404
8405 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
8406 if (!nl_rules)
8407 return -ENOBUFS;
8408
8409 for (i = 0; i < rdev->coalesce->n_rules; i++) {
8410 nl_rule = nla_nest_start(msg, i + 1);
8411 if (!nl_rule)
8412 return -ENOBUFS;
8413
8414 rule = &rdev->coalesce->rules[i];
8415 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
8416 rule->delay))
8417 return -ENOBUFS;
8418
8419 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
8420 rule->condition))
8421 return -ENOBUFS;
8422
8423 nl_pats = nla_nest_start(msg,
8424 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
8425 if (!nl_pats)
8426 return -ENOBUFS;
8427
8428 for (j = 0; j < rule->n_patterns; j++) {
8429 nl_pat = nla_nest_start(msg, j + 1);
8430 if (!nl_pat)
8431 return -ENOBUFS;
8432 pat_len = rule->patterns[j].pattern_len;
8433 if (nla_put(msg, NL80211_PKTPAT_MASK,
8434 DIV_ROUND_UP(pat_len, 8),
8435 rule->patterns[j].mask) ||
8436 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8437 rule->patterns[j].pattern) ||
8438 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
8439 rule->patterns[j].pkt_offset))
8440 return -ENOBUFS;
8441 nla_nest_end(msg, nl_pat);
8442 }
8443 nla_nest_end(msg, nl_pats);
8444 nla_nest_end(msg, nl_rule);
8445 }
8446 nla_nest_end(msg, nl_rules);
8447
8448 return 0;
8449}
8450
8451static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
8452{
8453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8454 struct sk_buff *msg;
8455 void *hdr;
8456
8457 if (!rdev->wiphy.coalesce)
8458 return -EOPNOTSUPP;
8459
8460 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8461 if (!msg)
8462 return -ENOMEM;
8463
8464 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8465 NL80211_CMD_GET_COALESCE);
8466 if (!hdr)
8467 goto nla_put_failure;
8468
8469 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
8470 goto nla_put_failure;
8471
8472 genlmsg_end(msg, hdr);
8473 return genlmsg_reply(msg, info);
8474
8475nla_put_failure:
8476 nlmsg_free(msg);
8477 return -ENOBUFS;
8478}
8479
8480void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
8481{
8482 struct cfg80211_coalesce *coalesce = rdev->coalesce;
8483 int i, j;
8484 struct cfg80211_coalesce_rules *rule;
8485
8486 if (!coalesce)
8487 return;
8488
8489 for (i = 0; i < coalesce->n_rules; i++) {
8490 rule = &coalesce->rules[i];
8491 for (j = 0; j < rule->n_patterns; j++)
8492 kfree(rule->patterns[j].mask);
8493 kfree(rule->patterns);
8494 }
8495 kfree(coalesce->rules);
8496 kfree(coalesce);
8497 rdev->coalesce = NULL;
8498}
8499
8500static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
8501 struct nlattr *rule,
8502 struct cfg80211_coalesce_rules *new_rule)
8503{
8504 int err, i;
8505 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8506 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
8507 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
8508 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
8509
8510 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
8511 nla_len(rule), nl80211_coalesce_policy);
8512 if (err)
8513 return err;
8514
8515 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
8516 new_rule->delay =
8517 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
8518 if (new_rule->delay > coalesce->max_delay)
8519 return -EINVAL;
8520
8521 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
8522 new_rule->condition =
8523 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
8524 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
8525 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
8526 return -EINVAL;
8527
8528 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
8529 return -EINVAL;
8530
8531 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8532 rem)
8533 n_patterns++;
8534 if (n_patterns > coalesce->n_patterns)
8535 return -EINVAL;
8536
8537 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
8538 GFP_KERNEL);
8539 if (!new_rule->patterns)
8540 return -ENOMEM;
8541
8542 new_rule->n_patterns = n_patterns;
8543 i = 0;
8544
8545 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
8546 rem) {
8547 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8548 nla_len(pat), NULL);
8549 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8550 !pat_tb[NL80211_PKTPAT_PATTERN])
8551 return -EINVAL;
8552 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
8553 mask_len = DIV_ROUND_UP(pat_len, 8);
8554 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
8555 return -EINVAL;
8556 if (pat_len > coalesce->pattern_max_len ||
8557 pat_len < coalesce->pattern_min_len)
8558 return -EINVAL;
8559
8560 if (!pat_tb[NL80211_PKTPAT_OFFSET])
8561 pkt_offset = 0;
8562 else
8563 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
8564 if (pkt_offset > coalesce->max_pkt_offset)
8565 return -EINVAL;
8566 new_rule->patterns[i].pkt_offset = pkt_offset;
8567
8568 new_rule->patterns[i].mask =
8569 kmalloc(mask_len + pat_len, GFP_KERNEL);
8570 if (!new_rule->patterns[i].mask)
8571 return -ENOMEM;
8572 new_rule->patterns[i].pattern =
8573 new_rule->patterns[i].mask + mask_len;
8574 memcpy(new_rule->patterns[i].mask,
8575 nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len);
8576 new_rule->patterns[i].pattern_len = pat_len;
8577 memcpy(new_rule->patterns[i].pattern,
8578 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len);
8579 i++;
8580 }
8581
8582 return 0;
8583}
8584
8585static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
8586{
8587 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8588 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
8589 struct cfg80211_coalesce new_coalesce = {};
8590 struct cfg80211_coalesce *n_coalesce;
8591 int err, rem_rule, n_rules = 0, i, j;
8592 struct nlattr *rule;
8593 struct cfg80211_coalesce_rules *tmp_rule;
8594
8595 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
8596 return -EOPNOTSUPP;
8597
8598 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
8599 cfg80211_rdev_free_coalesce(rdev);
8600 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
8601 return 0;
8602 }
8603
8604 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8605 rem_rule)
8606 n_rules++;
8607 if (n_rules > coalesce->n_rules)
8608 return -EINVAL;
8609
8610 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
8611 GFP_KERNEL);
8612 if (!new_coalesce.rules)
8613 return -ENOMEM;
8614
8615 new_coalesce.n_rules = n_rules;
8616 i = 0;
8617
8618 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
8619 rem_rule) {
8620 err = nl80211_parse_coalesce_rule(rdev, rule,
8621 &new_coalesce.rules[i]);
8622 if (err)
8623 goto error;
8624
8625 i++;
8626 }
8627
8628 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
8629 if (err)
8630 goto error;
8631
8632 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
8633 if (!n_coalesce) {
8634 err = -ENOMEM;
8635 goto error;
8636 }
8637 cfg80211_rdev_free_coalesce(rdev);
8638 rdev->coalesce = n_coalesce;
8639
8640 return 0;
8641error:
8642 for (i = 0; i < new_coalesce.n_rules; i++) {
8643 tmp_rule = &new_coalesce.rules[i];
8644 for (j = 0; j < tmp_rule->n_patterns; j++)
8645 kfree(tmp_rule->patterns[j].mask);
8646 kfree(tmp_rule->patterns);
8647 }
8648 kfree(new_coalesce.rules);
8649
8650 return err;
8651}
8652
Johannes Berge5497d72011-07-05 16:35:40 +02008653static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
8654{
8655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8656 struct net_device *dev = info->user_ptr[1];
8657 struct wireless_dev *wdev = dev->ieee80211_ptr;
8658 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
8659 struct cfg80211_gtk_rekey_data rekey_data;
8660 int err;
8661
8662 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
8663 return -EINVAL;
8664
8665 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
8666 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
8667 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
8668 nl80211_rekey_policy);
8669 if (err)
8670 return err;
8671
8672 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
8673 return -ERANGE;
8674 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
8675 return -ERANGE;
8676 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
8677 return -ERANGE;
8678
8679 memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]),
8680 NL80211_KEK_LEN);
8681 memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]),
8682 NL80211_KCK_LEN);
8683 memcpy(rekey_data.replay_ctr,
8684 nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]),
8685 NL80211_REPLAY_CTR_LEN);
8686
8687 wdev_lock(wdev);
8688 if (!wdev->current_bss) {
8689 err = -ENOTCONN;
8690 goto out;
8691 }
8692
8693 if (!rdev->ops->set_rekey_data) {
8694 err = -EOPNOTSUPP;
8695 goto out;
8696 }
8697
Hila Gonene35e4d22012-06-27 17:19:42 +03008698 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02008699 out:
8700 wdev_unlock(wdev);
8701 return err;
8702}
8703
Johannes Berg28946da2011-11-04 11:18:12 +01008704static int nl80211_register_unexpected_frame(struct sk_buff *skb,
8705 struct genl_info *info)
8706{
8707 struct net_device *dev = info->user_ptr[1];
8708 struct wireless_dev *wdev = dev->ieee80211_ptr;
8709
8710 if (wdev->iftype != NL80211_IFTYPE_AP &&
8711 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8712 return -EINVAL;
8713
Eric W. Biederman15e47302012-09-07 20:12:54 +00008714 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01008715 return -EBUSY;
8716
Eric W. Biederman15e47302012-09-07 20:12:54 +00008717 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01008718 return 0;
8719}
8720
Johannes Berg7f6cf312011-11-04 11:18:15 +01008721static int nl80211_probe_client(struct sk_buff *skb,
8722 struct genl_info *info)
8723{
8724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8725 struct net_device *dev = info->user_ptr[1];
8726 struct wireless_dev *wdev = dev->ieee80211_ptr;
8727 struct sk_buff *msg;
8728 void *hdr;
8729 const u8 *addr;
8730 u64 cookie;
8731 int err;
8732
8733 if (wdev->iftype != NL80211_IFTYPE_AP &&
8734 wdev->iftype != NL80211_IFTYPE_P2P_GO)
8735 return -EOPNOTSUPP;
8736
8737 if (!info->attrs[NL80211_ATTR_MAC])
8738 return -EINVAL;
8739
8740 if (!rdev->ops->probe_client)
8741 return -EOPNOTSUPP;
8742
8743 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8744 if (!msg)
8745 return -ENOMEM;
8746
Eric W. Biederman15e47302012-09-07 20:12:54 +00008747 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01008748 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008749 if (!hdr) {
8750 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008751 goto free_msg;
8752 }
8753
8754 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
8755
Hila Gonene35e4d22012-06-27 17:19:42 +03008756 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01008757 if (err)
8758 goto free_msg;
8759
David S. Miller9360ffd2012-03-29 04:41:26 -04008760 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8761 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01008762
8763 genlmsg_end(msg, hdr);
8764
8765 return genlmsg_reply(msg, info);
8766
8767 nla_put_failure:
8768 err = -ENOBUFS;
8769 free_msg:
8770 nlmsg_free(msg);
8771 return err;
8772}
8773
Johannes Berg5e760232011-11-04 11:18:17 +01008774static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
8775{
8776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07008777 struct cfg80211_beacon_registration *reg, *nreg;
8778 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008779
8780 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
8781 return -EOPNOTSUPP;
8782
Ben Greear37c73b52012-10-26 14:49:25 -07008783 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
8784 if (!nreg)
8785 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01008786
Ben Greear37c73b52012-10-26 14:49:25 -07008787 /* First, check if already registered. */
8788 spin_lock_bh(&rdev->beacon_registrations_lock);
8789 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
8790 if (reg->nlportid == info->snd_portid) {
8791 rv = -EALREADY;
8792 goto out_err;
8793 }
8794 }
8795 /* Add it to the list */
8796 nreg->nlportid = info->snd_portid;
8797 list_add(&nreg->list, &rdev->beacon_registrations);
8798
8799 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01008800
8801 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07008802out_err:
8803 spin_unlock_bh(&rdev->beacon_registrations_lock);
8804 kfree(nreg);
8805 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01008806}
8807
Johannes Berg98104fde2012-06-16 00:19:54 +02008808static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
8809{
8810 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8811 struct wireless_dev *wdev = info->user_ptr[1];
8812 int err;
8813
8814 if (!rdev->ops->start_p2p_device)
8815 return -EOPNOTSUPP;
8816
8817 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8818 return -EOPNOTSUPP;
8819
8820 if (wdev->p2p_started)
8821 return 0;
8822
Johannes Berg98104fde2012-06-16 00:19:54 +02008823 err = cfg80211_can_add_interface(rdev, wdev->iftype);
Johannes Berg98104fde2012-06-16 00:19:54 +02008824 if (err)
8825 return err;
8826
Johannes Bergeeb126e2012-10-23 15:16:50 +02008827 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008828 if (err)
8829 return err;
8830
8831 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02008832 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02008833
8834 return 0;
8835}
8836
8837static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
8838{
8839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8840 struct wireless_dev *wdev = info->user_ptr[1];
8841
8842 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
8843 return -EOPNOTSUPP;
8844
8845 if (!rdev->ops->stop_p2p_device)
8846 return -EOPNOTSUPP;
8847
Johannes Bergf9f47522013-03-19 15:04:07 +01008848 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02008849
8850 return 0;
8851}
8852
Johannes Berg3713b4e2013-02-14 16:19:38 +01008853static int nl80211_get_protocol_features(struct sk_buff *skb,
8854 struct genl_info *info)
8855{
8856 void *hdr;
8857 struct sk_buff *msg;
8858
8859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8860 if (!msg)
8861 return -ENOMEM;
8862
8863 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
8864 NL80211_CMD_GET_PROTOCOL_FEATURES);
8865 if (!hdr)
8866 goto nla_put_failure;
8867
8868 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
8869 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
8870 goto nla_put_failure;
8871
8872 genlmsg_end(msg, hdr);
8873 return genlmsg_reply(msg, info);
8874
8875 nla_put_failure:
8876 kfree_skb(msg);
8877 return -ENOBUFS;
8878}
8879
Jouni Malinen355199e2013-02-27 17:14:27 +02008880static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
8881{
8882 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8883 struct cfg80211_update_ft_ies_params ft_params;
8884 struct net_device *dev = info->user_ptr[1];
8885
8886 if (!rdev->ops->update_ft_ies)
8887 return -EOPNOTSUPP;
8888
8889 if (!info->attrs[NL80211_ATTR_MDID] ||
8890 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
8891 return -EINVAL;
8892
8893 memset(&ft_params, 0, sizeof(ft_params));
8894 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
8895 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
8896 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8897
8898 return rdev_update_ft_ies(rdev, dev, &ft_params);
8899}
8900
Arend van Spriel5de17982013-04-18 15:49:00 +02008901static int nl80211_crit_protocol_start(struct sk_buff *skb,
8902 struct genl_info *info)
8903{
8904 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8905 struct wireless_dev *wdev = info->user_ptr[1];
8906 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
8907 u16 duration;
8908 int ret;
8909
8910 if (!rdev->ops->crit_proto_start)
8911 return -EOPNOTSUPP;
8912
8913 if (WARN_ON(!rdev->ops->crit_proto_stop))
8914 return -EINVAL;
8915
8916 if (rdev->crit_proto_nlportid)
8917 return -EBUSY;
8918
8919 /* determine protocol if provided */
8920 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
8921 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
8922
8923 if (proto >= NUM_NL80211_CRIT_PROTO)
8924 return -EINVAL;
8925
8926 /* timeout must be provided */
8927 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
8928 return -EINVAL;
8929
8930 duration =
8931 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
8932
8933 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
8934 return -ERANGE;
8935
8936 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
8937 if (!ret)
8938 rdev->crit_proto_nlportid = info->snd_portid;
8939
8940 return ret;
8941}
8942
8943static int nl80211_crit_protocol_stop(struct sk_buff *skb,
8944 struct genl_info *info)
8945{
8946 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8947 struct wireless_dev *wdev = info->user_ptr[1];
8948
8949 if (!rdev->ops->crit_proto_stop)
8950 return -EOPNOTSUPP;
8951
8952 if (rdev->crit_proto_nlportid) {
8953 rdev->crit_proto_nlportid = 0;
8954 rdev_crit_proto_stop(rdev, wdev);
8955 }
8956 return 0;
8957}
8958
Johannes Bergad7e7182013-11-13 13:37:47 +01008959static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
8960{
8961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8962 struct wireless_dev *wdev =
8963 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
8964 int i, err;
8965 u32 vid, subcmd;
8966
8967 if (!rdev->wiphy.vendor_commands)
8968 return -EOPNOTSUPP;
8969
8970 if (IS_ERR(wdev)) {
8971 err = PTR_ERR(wdev);
8972 if (err != -EINVAL)
8973 return err;
8974 wdev = NULL;
8975 } else if (wdev->wiphy != &rdev->wiphy) {
8976 return -EINVAL;
8977 }
8978
8979 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
8980 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
8981 return -EINVAL;
8982
8983 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
8984 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
8985 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
8986 const struct wiphy_vendor_command *vcmd;
8987 void *data = NULL;
8988 int len = 0;
8989
8990 vcmd = &rdev->wiphy.vendor_commands[i];
8991
8992 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
8993 continue;
8994
8995 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
8996 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
8997 if (!wdev)
8998 return -EINVAL;
8999 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9000 !wdev->netdev)
9001 return -EINVAL;
9002
9003 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9004 if (wdev->netdev &&
9005 !netif_running(wdev->netdev))
9006 return -ENETDOWN;
9007 if (!wdev->netdev && !wdev->p2p_started)
9008 return -ENETDOWN;
9009 }
9010 } else {
9011 wdev = NULL;
9012 }
9013
9014 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9015 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9016 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9017 }
9018
9019 rdev->cur_cmd_info = info;
9020 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9021 data, len);
9022 rdev->cur_cmd_info = NULL;
9023 return err;
9024 }
9025
9026 return -EOPNOTSUPP;
9027}
9028
9029struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9030 enum nl80211_commands cmd,
9031 enum nl80211_attrs attr,
9032 int approxlen)
9033{
9034 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
9035
9036 if (WARN_ON(!rdev->cur_cmd_info))
9037 return NULL;
9038
9039 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9040 rdev->cur_cmd_info->snd_portid,
9041 rdev->cur_cmd_info->snd_seq,
9042 cmd, attr, GFP_KERNEL);
9043}
9044EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9045
9046int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9047{
9048 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9049 void *hdr = ((void **)skb->cb)[1];
9050 struct nlattr *data = ((void **)skb->cb)[2];
9051
9052 if (WARN_ON(!rdev->cur_cmd_info)) {
9053 kfree_skb(skb);
9054 return -EINVAL;
9055 }
9056
9057 nla_nest_end(skb, data);
9058 genlmsg_end(skb, hdr);
9059 return genlmsg_reply(skb, rdev->cur_cmd_info);
9060}
9061EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9062
9063
Johannes Berg4c476992010-10-04 21:36:35 +02009064#define NL80211_FLAG_NEED_WIPHY 0x01
9065#define NL80211_FLAG_NEED_NETDEV 0x02
9066#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009067#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9068#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9069 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009070#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009071/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009072#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9073 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg4c476992010-10-04 21:36:35 +02009074
Johannes Bergf84f7712013-11-14 17:14:45 +01009075static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009076 struct genl_info *info)
9077{
9078 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009079 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009080 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009081 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9082
9083 if (rtnl)
9084 rtnl_lock();
9085
9086 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009087 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009088 if (IS_ERR(rdev)) {
9089 if (rtnl)
9090 rtnl_unlock();
9091 return PTR_ERR(rdev);
9092 }
9093 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009094 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9095 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009096 ASSERT_RTNL();
9097
Johannes Berg89a54e42012-06-15 14:33:17 +02009098 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9099 info->attrs);
9100 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009101 if (rtnl)
9102 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009103 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009104 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009105
Johannes Berg89a54e42012-06-15 14:33:17 +02009106 dev = wdev->netdev;
9107 rdev = wiphy_to_dev(wdev->wiphy);
9108
Johannes Berg1bf614e2012-06-15 15:23:36 +02009109 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9110 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009111 if (rtnl)
9112 rtnl_unlock();
9113 return -EINVAL;
9114 }
9115
9116 info->user_ptr[1] = dev;
9117 } else {
9118 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009119 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009120
Johannes Berg1bf614e2012-06-15 15:23:36 +02009121 if (dev) {
9122 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9123 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009124 if (rtnl)
9125 rtnl_unlock();
9126 return -ENETDOWN;
9127 }
9128
9129 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009130 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9131 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009132 if (rtnl)
9133 rtnl_unlock();
9134 return -ENETDOWN;
9135 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009136 }
9137
Johannes Berg4c476992010-10-04 21:36:35 +02009138 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009139 }
9140
9141 return 0;
9142}
9143
Johannes Bergf84f7712013-11-14 17:14:45 +01009144static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009145 struct genl_info *info)
9146{
Johannes Berg1bf614e2012-06-15 15:23:36 +02009147 if (info->user_ptr[1]) {
9148 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
9149 struct wireless_dev *wdev = info->user_ptr[1];
9150
9151 if (wdev->netdev)
9152 dev_put(wdev->netdev);
9153 } else {
9154 dev_put(info->user_ptr[1]);
9155 }
9156 }
Johannes Berg4c476992010-10-04 21:36:35 +02009157 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
9158 rtnl_unlock();
9159}
9160
Johannes Berg4534de82013-11-14 17:14:46 +01009161static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -04009162 {
9163 .cmd = NL80211_CMD_GET_WIPHY,
9164 .doit = nl80211_get_wiphy,
9165 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +02009166 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -04009167 .policy = nl80211_policy,
9168 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009169 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9170 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009171 },
9172 {
9173 .cmd = NL80211_CMD_SET_WIPHY,
9174 .doit = nl80211_set_wiphy,
9175 .policy = nl80211_policy,
9176 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009177 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009178 },
9179 {
9180 .cmd = NL80211_CMD_GET_INTERFACE,
9181 .doit = nl80211_get_interface,
9182 .dumpit = nl80211_dump_interface,
9183 .policy = nl80211_policy,
9184 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +02009185 .internal_flags = NL80211_FLAG_NEED_WDEV |
9186 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009187 },
9188 {
9189 .cmd = NL80211_CMD_SET_INTERFACE,
9190 .doit = nl80211_set_interface,
9191 .policy = nl80211_policy,
9192 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009193 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9194 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009195 },
9196 {
9197 .cmd = NL80211_CMD_NEW_INTERFACE,
9198 .doit = nl80211_new_interface,
9199 .policy = nl80211_policy,
9200 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009201 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9202 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009203 },
9204 {
9205 .cmd = NL80211_CMD_DEL_INTERFACE,
9206 .doit = nl80211_del_interface,
9207 .policy = nl80211_policy,
9208 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +02009209 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009210 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -04009211 },
Johannes Berg41ade002007-12-19 02:03:29 +01009212 {
9213 .cmd = NL80211_CMD_GET_KEY,
9214 .doit = nl80211_get_key,
9215 .policy = nl80211_policy,
9216 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009217 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009218 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009219 },
9220 {
9221 .cmd = NL80211_CMD_SET_KEY,
9222 .doit = nl80211_set_key,
9223 .policy = nl80211_policy,
9224 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009225 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009226 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009227 },
9228 {
9229 .cmd = NL80211_CMD_NEW_KEY,
9230 .doit = nl80211_new_key,
9231 .policy = nl80211_policy,
9232 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009233 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009234 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009235 },
9236 {
9237 .cmd = NL80211_CMD_DEL_KEY,
9238 .doit = nl80211_del_key,
9239 .policy = nl80211_policy,
9240 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009242 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +01009243 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01009244 {
9245 .cmd = NL80211_CMD_SET_BEACON,
9246 .policy = nl80211_policy,
9247 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009248 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009250 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009251 },
9252 {
Johannes Berg88600202012-02-13 15:17:18 +01009253 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009254 .policy = nl80211_policy,
9255 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009256 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009258 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009259 },
9260 {
Johannes Berg88600202012-02-13 15:17:18 +01009261 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009262 .policy = nl80211_policy,
9263 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +01009264 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009265 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009266 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +01009267 },
Johannes Berg5727ef12007-12-19 02:03:34 +01009268 {
9269 .cmd = NL80211_CMD_GET_STATION,
9270 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009271 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01009272 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +02009273 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9274 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009275 },
9276 {
9277 .cmd = NL80211_CMD_SET_STATION,
9278 .doit = nl80211_set_station,
9279 .policy = nl80211_policy,
9280 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009281 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009282 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009283 },
9284 {
9285 .cmd = NL80211_CMD_NEW_STATION,
9286 .doit = nl80211_new_station,
9287 .policy = nl80211_policy,
9288 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009289 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009290 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009291 },
9292 {
9293 .cmd = NL80211_CMD_DEL_STATION,
9294 .doit = nl80211_del_station,
9295 .policy = nl80211_policy,
9296 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009297 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009298 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +01009299 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009300 {
9301 .cmd = NL80211_CMD_GET_MPATH,
9302 .doit = nl80211_get_mpath,
9303 .dumpit = nl80211_dump_mpath,
9304 .policy = nl80211_policy,
9305 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009306 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009307 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009308 },
9309 {
9310 .cmd = NL80211_CMD_SET_MPATH,
9311 .doit = nl80211_set_mpath,
9312 .policy = nl80211_policy,
9313 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009315 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009316 },
9317 {
9318 .cmd = NL80211_CMD_NEW_MPATH,
9319 .doit = nl80211_new_mpath,
9320 .policy = nl80211_policy,
9321 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009322 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009323 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009324 },
9325 {
9326 .cmd = NL80211_CMD_DEL_MPATH,
9327 .doit = nl80211_del_mpath,
9328 .policy = nl80211_policy,
9329 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009330 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009331 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01009332 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009333 {
9334 .cmd = NL80211_CMD_SET_BSS,
9335 .doit = nl80211_set_bss,
9336 .policy = nl80211_policy,
9337 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009338 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009339 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03009340 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009341 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009342 .cmd = NL80211_CMD_GET_REG,
9343 .doit = nl80211_get_reg,
9344 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009345 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08009346 /* can be retrieved by unprivileged users */
9347 },
9348 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009349 .cmd = NL80211_CMD_SET_REG,
9350 .doit = nl80211_set_reg,
9351 .policy = nl80211_policy,
9352 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +02009353 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07009354 },
9355 {
9356 .cmd = NL80211_CMD_REQ_SET_REG,
9357 .doit = nl80211_req_set_reg,
9358 .policy = nl80211_policy,
9359 .flags = GENL_ADMIN_PERM,
9360 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009361 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009362 .cmd = NL80211_CMD_GET_MESH_CONFIG,
9363 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009364 .policy = nl80211_policy,
9365 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009366 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009367 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009368 },
9369 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -08009370 .cmd = NL80211_CMD_SET_MESH_CONFIG,
9371 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009372 .policy = nl80211_policy,
9373 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +01009374 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009375 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07009376 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02009377 {
Johannes Berg2a519312009-02-10 21:25:55 +01009378 .cmd = NL80211_CMD_TRIGGER_SCAN,
9379 .doit = nl80211_trigger_scan,
9380 .policy = nl80211_policy,
9381 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +02009382 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009383 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +01009384 },
9385 {
9386 .cmd = NL80211_CMD_GET_SCAN,
9387 .policy = nl80211_policy,
9388 .dumpit = nl80211_dump_scan,
9389 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02009390 {
Luciano Coelho807f8a82011-05-11 17:09:35 +03009391 .cmd = NL80211_CMD_START_SCHED_SCAN,
9392 .doit = nl80211_start_sched_scan,
9393 .policy = nl80211_policy,
9394 .flags = GENL_ADMIN_PERM,
9395 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9396 NL80211_FLAG_NEED_RTNL,
9397 },
9398 {
9399 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
9400 .doit = nl80211_stop_sched_scan,
9401 .policy = nl80211_policy,
9402 .flags = GENL_ADMIN_PERM,
9403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9404 NL80211_FLAG_NEED_RTNL,
9405 },
9406 {
Jouni Malinen636a5d32009-03-19 13:39:22 +02009407 .cmd = NL80211_CMD_AUTHENTICATE,
9408 .doit = nl80211_authenticate,
9409 .policy = nl80211_policy,
9410 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009412 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009413 },
9414 {
9415 .cmd = NL80211_CMD_ASSOCIATE,
9416 .doit = nl80211_associate,
9417 .policy = nl80211_policy,
9418 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009420 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009421 },
9422 {
9423 .cmd = NL80211_CMD_DEAUTHENTICATE,
9424 .doit = nl80211_deauthenticate,
9425 .policy = nl80211_policy,
9426 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009428 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009429 },
9430 {
9431 .cmd = NL80211_CMD_DISASSOCIATE,
9432 .doit = nl80211_disassociate,
9433 .policy = nl80211_policy,
9434 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009436 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +02009437 },
Johannes Berg04a773a2009-04-19 21:24:32 +02009438 {
9439 .cmd = NL80211_CMD_JOIN_IBSS,
9440 .doit = nl80211_join_ibss,
9441 .policy = nl80211_policy,
9442 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009444 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009445 },
9446 {
9447 .cmd = NL80211_CMD_LEAVE_IBSS,
9448 .doit = nl80211_leave_ibss,
9449 .policy = nl80211_policy,
9450 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009452 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +02009453 },
Johannes Bergaff89a92009-07-01 21:26:51 +02009454#ifdef CONFIG_NL80211_TESTMODE
9455 {
9456 .cmd = NL80211_CMD_TESTMODE,
9457 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009458 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +02009459 .policy = nl80211_policy,
9460 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009461 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9462 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +02009463 },
9464#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +02009465 {
9466 .cmd = NL80211_CMD_CONNECT,
9467 .doit = nl80211_connect,
9468 .policy = nl80211_policy,
9469 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009470 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009471 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009472 },
9473 {
9474 .cmd = NL80211_CMD_DISCONNECT,
9475 .doit = nl80211_disconnect,
9476 .policy = nl80211_policy,
9477 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +02009478 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009479 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009480 },
Johannes Berg463d0182009-07-14 00:33:35 +02009481 {
9482 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
9483 .doit = nl80211_wiphy_netns,
9484 .policy = nl80211_policy,
9485 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009486 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9487 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +02009488 },
Holger Schurig61fa7132009-11-11 12:25:40 +01009489 {
9490 .cmd = NL80211_CMD_GET_SURVEY,
9491 .policy = nl80211_policy,
9492 .dumpit = nl80211_dump_survey,
9493 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009494 {
9495 .cmd = NL80211_CMD_SET_PMKSA,
9496 .doit = nl80211_setdel_pmksa,
9497 .policy = nl80211_policy,
9498 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009500 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009501 },
9502 {
9503 .cmd = NL80211_CMD_DEL_PMKSA,
9504 .doit = nl80211_setdel_pmksa,
9505 .policy = nl80211_policy,
9506 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009508 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009509 },
9510 {
9511 .cmd = NL80211_CMD_FLUSH_PMKSA,
9512 .doit = nl80211_flush_pmksa,
9513 .policy = nl80211_policy,
9514 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009516 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +01009517 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009518 {
9519 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
9520 .doit = nl80211_remain_on_channel,
9521 .policy = nl80211_policy,
9522 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009523 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009524 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009525 },
9526 {
9527 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
9528 .doit = nl80211_cancel_remain_on_channel,
9529 .policy = nl80211_policy,
9530 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009531 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009532 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009533 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009534 {
9535 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
9536 .doit = nl80211_set_tx_bitrate_mask,
9537 .policy = nl80211_policy,
9538 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009539 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9540 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +02009541 },
Jouni Malinen026331c2010-02-15 12:53:10 +02009542 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009543 .cmd = NL80211_CMD_REGISTER_FRAME,
9544 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009545 .policy = nl80211_policy,
9546 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009547 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +02009548 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009549 },
9550 {
Johannes Berg2e161f72010-08-12 15:38:38 +02009551 .cmd = NL80211_CMD_FRAME,
9552 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +02009553 .policy = nl80211_policy,
9554 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009555 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +02009556 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +02009557 },
Kalle Valoffb9eb32010-02-17 17:58:10 +02009558 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009559 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
9560 .doit = nl80211_tx_mgmt_cancel_wait,
9561 .policy = nl80211_policy,
9562 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +02009563 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +01009564 NL80211_FLAG_NEED_RTNL,
9565 },
9566 {
Kalle Valoffb9eb32010-02-17 17:58:10 +02009567 .cmd = NL80211_CMD_SET_POWER_SAVE,
9568 .doit = nl80211_set_power_save,
9569 .policy = nl80211_policy,
9570 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009571 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9572 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009573 },
9574 {
9575 .cmd = NL80211_CMD_GET_POWER_SAVE,
9576 .doit = nl80211_get_power_save,
9577 .policy = nl80211_policy,
9578 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +02009579 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9580 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +02009581 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009582 {
9583 .cmd = NL80211_CMD_SET_CQM,
9584 .doit = nl80211_set_cqm,
9585 .policy = nl80211_policy,
9586 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009587 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9588 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02009589 },
Johannes Bergf444de02010-05-05 15:25:02 +02009590 {
9591 .cmd = NL80211_CMD_SET_CHANNEL,
9592 .doit = nl80211_set_channel,
9593 .policy = nl80211_policy,
9594 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +02009595 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9596 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +02009597 },
Bill Jordane8347eb2010-10-01 13:54:28 -04009598 {
9599 .cmd = NL80211_CMD_SET_WDS_PEER,
9600 .doit = nl80211_set_wds_peer,
9601 .policy = nl80211_policy,
9602 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +02009603 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9604 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -04009605 },
Johannes Berg29cbe682010-12-03 09:20:44 +01009606 {
9607 .cmd = NL80211_CMD_JOIN_MESH,
9608 .doit = nl80211_join_mesh,
9609 .policy = nl80211_policy,
9610 .flags = GENL_ADMIN_PERM,
9611 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9612 NL80211_FLAG_NEED_RTNL,
9613 },
9614 {
9615 .cmd = NL80211_CMD_LEAVE_MESH,
9616 .doit = nl80211_leave_mesh,
9617 .policy = nl80211_policy,
9618 .flags = GENL_ADMIN_PERM,
9619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9620 NL80211_FLAG_NEED_RTNL,
9621 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009622#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02009623 {
9624 .cmd = NL80211_CMD_GET_WOWLAN,
9625 .doit = nl80211_get_wowlan,
9626 .policy = nl80211_policy,
9627 /* can be retrieved by unprivileged users */
9628 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9629 NL80211_FLAG_NEED_RTNL,
9630 },
9631 {
9632 .cmd = NL80211_CMD_SET_WOWLAN,
9633 .doit = nl80211_set_wowlan,
9634 .policy = nl80211_policy,
9635 .flags = GENL_ADMIN_PERM,
9636 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9637 NL80211_FLAG_NEED_RTNL,
9638 },
Johannes Bergdfb89c52012-06-27 09:23:48 +02009639#endif
Johannes Berge5497d72011-07-05 16:35:40 +02009640 {
9641 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
9642 .doit = nl80211_set_rekey_data,
9643 .policy = nl80211_policy,
9644 .flags = GENL_ADMIN_PERM,
9645 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9646 NL80211_FLAG_NEED_RTNL,
9647 },
Arik Nemtsov109086c2011-09-28 14:12:50 +03009648 {
9649 .cmd = NL80211_CMD_TDLS_MGMT,
9650 .doit = nl80211_tdls_mgmt,
9651 .policy = nl80211_policy,
9652 .flags = GENL_ADMIN_PERM,
9653 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9654 NL80211_FLAG_NEED_RTNL,
9655 },
9656 {
9657 .cmd = NL80211_CMD_TDLS_OPER,
9658 .doit = nl80211_tdls_oper,
9659 .policy = nl80211_policy,
9660 .flags = GENL_ADMIN_PERM,
9661 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9662 NL80211_FLAG_NEED_RTNL,
9663 },
Johannes Berg28946da2011-11-04 11:18:12 +01009664 {
9665 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
9666 .doit = nl80211_register_unexpected_frame,
9667 .policy = nl80211_policy,
9668 .flags = GENL_ADMIN_PERM,
9669 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9670 NL80211_FLAG_NEED_RTNL,
9671 },
Johannes Berg7f6cf312011-11-04 11:18:15 +01009672 {
9673 .cmd = NL80211_CMD_PROBE_CLIENT,
9674 .doit = nl80211_probe_client,
9675 .policy = nl80211_policy,
9676 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +02009677 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +01009678 NL80211_FLAG_NEED_RTNL,
9679 },
Johannes Berg5e760232011-11-04 11:18:17 +01009680 {
9681 .cmd = NL80211_CMD_REGISTER_BEACONS,
9682 .doit = nl80211_register_beacons,
9683 .policy = nl80211_policy,
9684 .flags = GENL_ADMIN_PERM,
9685 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9686 NL80211_FLAG_NEED_RTNL,
9687 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01009688 {
9689 .cmd = NL80211_CMD_SET_NOACK_MAP,
9690 .doit = nl80211_set_noack_map,
9691 .policy = nl80211_policy,
9692 .flags = GENL_ADMIN_PERM,
9693 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9694 NL80211_FLAG_NEED_RTNL,
9695 },
Johannes Berg98104fde2012-06-16 00:19:54 +02009696 {
9697 .cmd = NL80211_CMD_START_P2P_DEVICE,
9698 .doit = nl80211_start_p2p_device,
9699 .policy = nl80211_policy,
9700 .flags = GENL_ADMIN_PERM,
9701 .internal_flags = NL80211_FLAG_NEED_WDEV |
9702 NL80211_FLAG_NEED_RTNL,
9703 },
9704 {
9705 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
9706 .doit = nl80211_stop_p2p_device,
9707 .policy = nl80211_policy,
9708 .flags = GENL_ADMIN_PERM,
9709 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9710 NL80211_FLAG_NEED_RTNL,
9711 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009712 {
9713 .cmd = NL80211_CMD_SET_MCAST_RATE,
9714 .doit = nl80211_set_mcast_rate,
9715 .policy = nl80211_policy,
9716 .flags = GENL_ADMIN_PERM,
9717 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9718 NL80211_FLAG_NEED_RTNL,
9719 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05309720 {
9721 .cmd = NL80211_CMD_SET_MAC_ACL,
9722 .doit = nl80211_set_mac_acl,
9723 .policy = nl80211_policy,
9724 .flags = GENL_ADMIN_PERM,
9725 .internal_flags = NL80211_FLAG_NEED_NETDEV |
9726 NL80211_FLAG_NEED_RTNL,
9727 },
Simon Wunderlich04f39042013-02-08 18:16:19 +01009728 {
9729 .cmd = NL80211_CMD_RADAR_DETECT,
9730 .doit = nl80211_start_radar_detection,
9731 .policy = nl80211_policy,
9732 .flags = GENL_ADMIN_PERM,
9733 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9734 NL80211_FLAG_NEED_RTNL,
9735 },
Johannes Berg3713b4e2013-02-14 16:19:38 +01009736 {
9737 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
9738 .doit = nl80211_get_protocol_features,
9739 .policy = nl80211_policy,
9740 },
Jouni Malinen355199e2013-02-27 17:14:27 +02009741 {
9742 .cmd = NL80211_CMD_UPDATE_FT_IES,
9743 .doit = nl80211_update_ft_ies,
9744 .policy = nl80211_policy,
9745 .flags = GENL_ADMIN_PERM,
9746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9747 NL80211_FLAG_NEED_RTNL,
9748 },
Arend van Spriel5de17982013-04-18 15:49:00 +02009749 {
9750 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
9751 .doit = nl80211_crit_protocol_start,
9752 .policy = nl80211_policy,
9753 .flags = GENL_ADMIN_PERM,
9754 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9755 NL80211_FLAG_NEED_RTNL,
9756 },
9757 {
9758 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
9759 .doit = nl80211_crit_protocol_stop,
9760 .policy = nl80211_policy,
9761 .flags = GENL_ADMIN_PERM,
9762 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
9763 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009764 },
9765 {
9766 .cmd = NL80211_CMD_GET_COALESCE,
9767 .doit = nl80211_get_coalesce,
9768 .policy = nl80211_policy,
9769 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9770 NL80211_FLAG_NEED_RTNL,
9771 },
9772 {
9773 .cmd = NL80211_CMD_SET_COALESCE,
9774 .doit = nl80211_set_coalesce,
9775 .policy = nl80211_policy,
9776 .flags = GENL_ADMIN_PERM,
9777 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9778 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009779 },
9780 {
9781 .cmd = NL80211_CMD_CHANNEL_SWITCH,
9782 .doit = nl80211_channel_switch,
9783 .policy = nl80211_policy,
9784 .flags = GENL_ADMIN_PERM,
9785 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
9786 NL80211_FLAG_NEED_RTNL,
9787 },
Johannes Bergad7e7182013-11-13 13:37:47 +01009788 {
9789 .cmd = NL80211_CMD_VENDOR,
9790 .doit = nl80211_vendor_cmd,
9791 .policy = nl80211_policy,
9792 .flags = GENL_ADMIN_PERM,
9793 .internal_flags = NL80211_FLAG_NEED_WIPHY |
9794 NL80211_FLAG_NEED_RTNL,
9795 },
Johannes Berg55682962007-09-20 13:09:35 -04009796};
Jouni Malinen9588bbd2009-12-23 13:15:41 +01009797
Johannes Berg55682962007-09-20 13:09:35 -04009798/* notification functions */
9799
9800void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
9801{
9802 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +02009803 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04009804
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009806 if (!msg)
9807 return;
9808
Johannes Berg86e8cf92013-06-19 10:57:22 +02009809 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -04009810 nlmsg_free(msg);
9811 return;
9812 }
9813
Johannes Berg68eb5502013-11-19 15:19:38 +01009814 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009815 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04009816}
9817
Johannes Berg362a4152009-05-24 16:43:15 +02009818static int nl80211_add_scan_req(struct sk_buff *msg,
9819 struct cfg80211_registered_device *rdev)
9820{
9821 struct cfg80211_scan_request *req = rdev->scan_req;
9822 struct nlattr *nest;
9823 int i;
9824
9825 if (WARN_ON(!req))
9826 return 0;
9827
9828 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
9829 if (!nest)
9830 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009831 for (i = 0; i < req->n_ssids; i++) {
9832 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
9833 goto nla_put_failure;
9834 }
Johannes Berg362a4152009-05-24 16:43:15 +02009835 nla_nest_end(msg, nest);
9836
9837 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9838 if (!nest)
9839 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009840 for (i = 0; i < req->n_channels; i++) {
9841 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
9842 goto nla_put_failure;
9843 }
Johannes Berg362a4152009-05-24 16:43:15 +02009844 nla_nest_end(msg, nest);
9845
David S. Miller9360ffd2012-03-29 04:41:26 -04009846 if (req->ie &&
9847 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
9848 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +02009849
Johannes Bergae917c92013-10-25 11:05:22 +02009850 if (req->flags &&
9851 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
9852 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -07009853
Johannes Berg362a4152009-05-24 16:43:15 +02009854 return 0;
9855 nla_put_failure:
9856 return -ENOBUFS;
9857}
9858
Johannes Berga538e2d2009-06-16 19:56:42 +02009859static int nl80211_send_scan_msg(struct sk_buff *msg,
9860 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009861 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009862 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +02009863 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +01009864{
9865 void *hdr;
9866
Eric W. Biederman15e47302012-09-07 20:12:54 +00009867 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +01009868 if (!hdr)
9869 return -1;
9870
David S. Miller9360ffd2012-03-29 04:41:26 -04009871 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +02009872 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
9873 wdev->netdev->ifindex)) ||
9874 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009875 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009876
Johannes Berg362a4152009-05-24 16:43:15 +02009877 /* ignore errors and send incomplete event anyway */
9878 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009879
9880 return genlmsg_end(msg, hdr);
9881
9882 nla_put_failure:
9883 genlmsg_cancel(msg, hdr);
9884 return -EMSGSIZE;
9885}
9886
Luciano Coelho807f8a82011-05-11 17:09:35 +03009887static int
9888nl80211_send_sched_scan_msg(struct sk_buff *msg,
9889 struct cfg80211_registered_device *rdev,
9890 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009891 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +03009892{
9893 void *hdr;
9894
Eric W. Biederman15e47302012-09-07 20:12:54 +00009895 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009896 if (!hdr)
9897 return -1;
9898
David S. Miller9360ffd2012-03-29 04:41:26 -04009899 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
9900 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
9901 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +03009902
9903 return genlmsg_end(msg, hdr);
9904
9905 nla_put_failure:
9906 genlmsg_cancel(msg, hdr);
9907 return -EMSGSIZE;
9908}
9909
Johannes Berga538e2d2009-06-16 19:56:42 +02009910void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009911 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +02009912{
9913 struct sk_buff *msg;
9914
Thomas Graf58050fc2012-06-28 03:57:45 +00009915 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009916 if (!msg)
9917 return;
9918
Johannes Bergfd014282012-06-18 19:17:03 +02009919 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009920 NL80211_CMD_TRIGGER_SCAN) < 0) {
9921 nlmsg_free(msg);
9922 return;
9923 }
9924
Johannes Berg68eb5502013-11-19 15:19:38 +01009925 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009926 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +02009927}
9928
Johannes Berg2a519312009-02-10 21:25:55 +01009929void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009930 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009931{
9932 struct sk_buff *msg;
9933
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009934 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009935 if (!msg)
9936 return;
9937
Johannes Bergfd014282012-06-18 19:17:03 +02009938 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009939 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009940 nlmsg_free(msg);
9941 return;
9942 }
9943
Johannes Berg68eb5502013-11-19 15:19:38 +01009944 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009945 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009946}
9947
9948void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +02009949 struct wireless_dev *wdev)
Johannes Berg2a519312009-02-10 21:25:55 +01009950{
9951 struct sk_buff *msg;
9952
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07009953 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009954 if (!msg)
9955 return;
9956
Johannes Bergfd014282012-06-18 19:17:03 +02009957 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +02009958 NL80211_CMD_SCAN_ABORTED) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009959 nlmsg_free(msg);
9960 return;
9961 }
9962
Johannes Berg68eb5502013-11-19 15:19:38 +01009963 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009964 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01009965}
9966
Luciano Coelho807f8a82011-05-11 17:09:35 +03009967void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
9968 struct net_device *netdev)
9969{
9970 struct sk_buff *msg;
9971
9972 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9973 if (!msg)
9974 return;
9975
9976 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
9977 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
9978 nlmsg_free(msg);
9979 return;
9980 }
9981
Johannes Berg68eb5502013-11-19 15:19:38 +01009982 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +01009983 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009984}
9985
9986void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
9987 struct net_device *netdev, u32 cmd)
9988{
9989 struct sk_buff *msg;
9990
Thomas Graf58050fc2012-06-28 03:57:45 +00009991 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03009992 if (!msg)
9993 return;
9994
9995 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
9996 nlmsg_free(msg);
9997 return;
9998 }
9999
Johannes Berg68eb5502013-11-19 15:19:38 +010010000 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010001 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010002}
10003
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010004/*
10005 * This can happen on global regulatory changes or device specific settings
10006 * based on custom world regulatory domains.
10007 */
10008void nl80211_send_reg_change_event(struct regulatory_request *request)
10009{
10010 struct sk_buff *msg;
10011 void *hdr;
10012
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010013 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010014 if (!msg)
10015 return;
10016
10017 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10018 if (!hdr) {
10019 nlmsg_free(msg);
10020 return;
10021 }
10022
10023 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010024 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10025 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010026
David S. Miller9360ffd2012-03-29 04:41:26 -040010027 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10028 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10029 NL80211_REGDOM_TYPE_WORLD))
10030 goto nla_put_failure;
10031 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10032 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10033 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10034 goto nla_put_failure;
10035 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10036 request->intersect) {
10037 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10038 NL80211_REGDOM_TYPE_INTERSECTION))
10039 goto nla_put_failure;
10040 } else {
10041 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10042 NL80211_REGDOM_TYPE_COUNTRY) ||
10043 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10044 request->alpha2))
10045 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010046 }
10047
Johannes Bergf4173762012-12-03 18:23:37 +010010048 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010049 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10050 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010051
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010052 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010053
Johannes Bergbc43b282009-07-25 10:54:13 +020010054 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010055 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010056 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010057 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010058
10059 return;
10060
10061nla_put_failure:
10062 genlmsg_cancel(msg, hdr);
10063 nlmsg_free(msg);
10064}
10065
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010066static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
10067 struct net_device *netdev,
10068 const u8 *buf, size_t len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010069 enum nl80211_commands cmd, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010070{
10071 struct sk_buff *msg;
10072 void *hdr;
10073
Johannes Berge6d6e342009-07-01 21:26:47 +020010074 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010075 if (!msg)
10076 return;
10077
10078 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10079 if (!hdr) {
10080 nlmsg_free(msg);
10081 return;
10082 }
10083
David S. Miller9360ffd2012-03-29 04:41:26 -040010084 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10085 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10086 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
10087 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010088
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010089 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010090
Johannes Berg68eb5502013-11-19 15:19:38 +010010091 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010092 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010093 return;
10094
10095 nla_put_failure:
10096 genlmsg_cancel(msg, hdr);
10097 nlmsg_free(msg);
10098}
10099
10100void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010101 struct net_device *netdev, const u8 *buf,
10102 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010103{
10104 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010105 NL80211_CMD_AUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010106}
10107
10108void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
10109 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010110 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010111{
Johannes Berge6d6e342009-07-01 21:26:47 +020010112 nl80211_send_mlme_event(rdev, netdev, buf, len,
10113 NL80211_CMD_ASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010114}
10115
Jouni Malinen53b46b82009-03-27 20:53:56 +020010116void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010117 struct net_device *netdev, const u8 *buf,
10118 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010119{
10120 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010121 NL80211_CMD_DEAUTHENTICATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010122}
10123
Jouni Malinen53b46b82009-03-27 20:53:56 +020010124void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
10125 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020010126 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010127{
10128 nl80211_send_mlme_event(rdev, netdev, buf, len,
Johannes Berge6d6e342009-07-01 21:26:47 +020010129 NL80211_CMD_DISASSOCIATE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020010130}
10131
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010132void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
10133 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020010134{
Johannes Berg947add32013-02-22 22:05:20 +010010135 struct wireless_dev *wdev = dev->ieee80211_ptr;
10136 struct wiphy *wiphy = wdev->wiphy;
10137 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010138 const struct ieee80211_mgmt *mgmt = (void *)buf;
10139 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020010140
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010141 if (WARN_ON(len < 2))
10142 return;
10143
10144 if (ieee80211_is_deauth(mgmt->frame_control))
10145 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
10146 else
10147 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
10148
10149 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
10150 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010151}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020010152EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020010153
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040010154static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
10155 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020010156 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010157{
10158 struct sk_buff *msg;
10159 void *hdr;
10160
Johannes Berge6d6e342009-07-01 21:26:47 +020010161 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010162 if (!msg)
10163 return;
10164
10165 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10166 if (!hdr) {
10167 nlmsg_free(msg);
10168 return;
10169 }
10170
David S. Miller9360ffd2012-03-29 04:41:26 -040010171 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10172 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10173 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
10174 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10175 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030010176
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010177 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030010178
Johannes Berg68eb5502013-11-19 15:19:38 +010010179 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010180 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010181 return;
10182
10183 nla_put_failure:
10184 genlmsg_cancel(msg, hdr);
10185 nlmsg_free(msg);
10186}
10187
10188void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010189 struct net_device *netdev, const u8 *addr,
10190 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010191{
10192 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020010193 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010194}
10195
10196void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020010197 struct net_device *netdev, const u8 *addr,
10198 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030010199{
Johannes Berge6d6e342009-07-01 21:26:47 +020010200 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
10201 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030010202}
10203
Samuel Ortizb23aa672009-07-01 21:26:54 +020010204void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
10205 struct net_device *netdev, const u8 *bssid,
10206 const u8 *req_ie, size_t req_ie_len,
10207 const u8 *resp_ie, size_t resp_ie_len,
10208 u16 status, gfp_t gfp)
10209{
10210 struct sk_buff *msg;
10211 void *hdr;
10212
Thomas Graf58050fc2012-06-28 03:57:45 +000010213 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010214 if (!msg)
10215 return;
10216
10217 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
10218 if (!hdr) {
10219 nlmsg_free(msg);
10220 return;
10221 }
10222
David S. Miller9360ffd2012-03-29 04:41:26 -040010223 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10224 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10225 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
10226 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
10227 (req_ie &&
10228 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10229 (resp_ie &&
10230 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10231 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010232
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010233 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010234
Johannes Berg68eb5502013-11-19 15:19:38 +010010235 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010236 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010237 return;
10238
10239 nla_put_failure:
10240 genlmsg_cancel(msg, hdr);
10241 nlmsg_free(msg);
10242
10243}
10244
10245void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
10246 struct net_device *netdev, const u8 *bssid,
10247 const u8 *req_ie, size_t req_ie_len,
10248 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
10249{
10250 struct sk_buff *msg;
10251 void *hdr;
10252
Thomas Graf58050fc2012-06-28 03:57:45 +000010253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010254 if (!msg)
10255 return;
10256
10257 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
10258 if (!hdr) {
10259 nlmsg_free(msg);
10260 return;
10261 }
10262
David S. Miller9360ffd2012-03-29 04:41:26 -040010263 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10264 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10265 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
10266 (req_ie &&
10267 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
10268 (resp_ie &&
10269 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
10270 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010271
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010272 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010273
Johannes Berg68eb5502013-11-19 15:19:38 +010010274 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010275 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010276 return;
10277
10278 nla_put_failure:
10279 genlmsg_cancel(msg, hdr);
10280 nlmsg_free(msg);
10281
10282}
10283
10284void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
10285 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020010286 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020010287{
10288 struct sk_buff *msg;
10289 void *hdr;
10290
Thomas Graf58050fc2012-06-28 03:57:45 +000010291 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010292 if (!msg)
10293 return;
10294
10295 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
10296 if (!hdr) {
10297 nlmsg_free(msg);
10298 return;
10299 }
10300
David S. Miller9360ffd2012-03-29 04:41:26 -040010301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10302 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10303 (from_ap && reason &&
10304 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
10305 (from_ap &&
10306 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
10307 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
10308 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010309
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010310 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010311
Johannes Berg68eb5502013-11-19 15:19:38 +010010312 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010313 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010314 return;
10315
10316 nla_put_failure:
10317 genlmsg_cancel(msg, hdr);
10318 nlmsg_free(msg);
10319
10320}
10321
Johannes Berg04a773a2009-04-19 21:24:32 +020010322void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
10323 struct net_device *netdev, const u8 *bssid,
10324 gfp_t gfp)
10325{
10326 struct sk_buff *msg;
10327 void *hdr;
10328
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010329 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010330 if (!msg)
10331 return;
10332
10333 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
10334 if (!hdr) {
10335 nlmsg_free(msg);
10336 return;
10337 }
10338
David S. Miller9360ffd2012-03-29 04:41:26 -040010339 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10340 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10341 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10342 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020010343
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010344 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020010345
Johannes Berg68eb5502013-11-19 15:19:38 +010010346 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010347 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020010348 return;
10349
10350 nla_put_failure:
10351 genlmsg_cancel(msg, hdr);
10352 nlmsg_free(msg);
10353}
10354
Johannes Berg947add32013-02-22 22:05:20 +010010355void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
10356 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070010357{
Johannes Berg947add32013-02-22 22:05:20 +010010358 struct wireless_dev *wdev = dev->ieee80211_ptr;
10359 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010360 struct sk_buff *msg;
10361 void *hdr;
10362
Johannes Berg947add32013-02-22 22:05:20 +010010363 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
10364 return;
10365
10366 trace_cfg80211_notify_new_peer_candidate(dev, addr);
10367
Javier Cardonac93b5e72011-04-07 15:08:34 -070010368 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10369 if (!msg)
10370 return;
10371
10372 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
10373 if (!hdr) {
10374 nlmsg_free(msg);
10375 return;
10376 }
10377
David S. Miller9360ffd2012-03-29 04:41:26 -040010378 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010379 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10380 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010381 (ie_len && ie &&
10382 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
10383 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070010384
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010385 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010386
Johannes Berg68eb5502013-11-19 15:19:38 +010010387 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010388 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010389 return;
10390
10391 nla_put_failure:
10392 genlmsg_cancel(msg, hdr);
10393 nlmsg_free(msg);
10394}
Johannes Berg947add32013-02-22 22:05:20 +010010395EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070010396
Jouni Malinena3b8b052009-03-27 21:59:49 +020010397void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
10398 struct net_device *netdev, const u8 *addr,
10399 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020010400 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020010401{
10402 struct sk_buff *msg;
10403 void *hdr;
10404
Johannes Berge6d6e342009-07-01 21:26:47 +020010405 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010406 if (!msg)
10407 return;
10408
10409 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
10410 if (!hdr) {
10411 nlmsg_free(msg);
10412 return;
10413 }
10414
David S. Miller9360ffd2012-03-29 04:41:26 -040010415 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10416 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10417 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
10418 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
10419 (key_id != -1 &&
10420 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
10421 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
10422 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020010423
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010424 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010425
Johannes Berg68eb5502013-11-19 15:19:38 +010010426 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010427 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020010428 return;
10429
10430 nla_put_failure:
10431 genlmsg_cancel(msg, hdr);
10432 nlmsg_free(msg);
10433}
10434
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010435void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
10436 struct ieee80211_channel *channel_before,
10437 struct ieee80211_channel *channel_after)
10438{
10439 struct sk_buff *msg;
10440 void *hdr;
10441 struct nlattr *nl_freq;
10442
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010443 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010444 if (!msg)
10445 return;
10446
10447 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
10448 if (!hdr) {
10449 nlmsg_free(msg);
10450 return;
10451 }
10452
10453 /*
10454 * Since we are applying the beacon hint to a wiphy we know its
10455 * wiphy_idx is valid
10456 */
David S. Miller9360ffd2012-03-29 04:41:26 -040010457 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
10458 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010459
10460 /* Before */
10461 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
10462 if (!nl_freq)
10463 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010464 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010465 goto nla_put_failure;
10466 nla_nest_end(msg, nl_freq);
10467
10468 /* After */
10469 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
10470 if (!nl_freq)
10471 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010010472 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010473 goto nla_put_failure;
10474 nla_nest_end(msg, nl_freq);
10475
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010476 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010477
Johannes Berg463d0182009-07-14 00:33:35 +020010478 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010479 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010480 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020010481 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040010482
10483 return;
10484
10485nla_put_failure:
10486 genlmsg_cancel(msg, hdr);
10487 nlmsg_free(msg);
10488}
10489
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010490static void nl80211_send_remain_on_chan_event(
10491 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020010492 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010493 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010494 unsigned int duration, gfp_t gfp)
10495{
10496 struct sk_buff *msg;
10497 void *hdr;
10498
10499 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10500 if (!msg)
10501 return;
10502
10503 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
10504 if (!hdr) {
10505 nlmsg_free(msg);
10506 return;
10507 }
10508
David S. Miller9360ffd2012-03-29 04:41:26 -040010509 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010510 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10511 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020010512 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010513 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010010514 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
10515 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010516 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
10517 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010518
David S. Miller9360ffd2012-03-29 04:41:26 -040010519 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
10520 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
10521 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010522
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010523 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010524
Johannes Berg68eb5502013-11-19 15:19:38 +010010525 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010526 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010527 return;
10528
10529 nla_put_failure:
10530 genlmsg_cancel(msg, hdr);
10531 nlmsg_free(msg);
10532}
10533
Johannes Berg947add32013-02-22 22:05:20 +010010534void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
10535 struct ieee80211_channel *chan,
10536 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010537{
Johannes Berg947add32013-02-22 22:05:20 +010010538 struct wiphy *wiphy = wdev->wiphy;
10539 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10540
10541 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010542 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020010543 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010010544 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010545}
Johannes Berg947add32013-02-22 22:05:20 +010010546EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010547
Johannes Berg947add32013-02-22 22:05:20 +010010548void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
10549 struct ieee80211_channel *chan,
10550 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010551{
Johannes Berg947add32013-02-22 22:05:20 +010010552 struct wiphy *wiphy = wdev->wiphy;
10553 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10554
10555 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010556 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010010557 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010558}
Johannes Berg947add32013-02-22 22:05:20 +010010559EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010560
Johannes Berg947add32013-02-22 22:05:20 +010010561void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
10562 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010010563{
Johannes Berg947add32013-02-22 22:05:20 +010010564 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10565 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010010566 struct sk_buff *msg;
10567
Johannes Berg947add32013-02-22 22:05:20 +010010568 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
10569
Thomas Graf58050fc2012-06-28 03:57:45 +000010570 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010571 if (!msg)
10572 return;
10573
John W. Linville66266b32012-03-15 13:25:41 -040010574 if (nl80211_send_station(msg, 0, 0, 0,
10575 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010010576 nlmsg_free(msg);
10577 return;
10578 }
10579
Johannes Berg68eb5502013-11-19 15:19:38 +010010580 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010581 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010010582}
Johannes Berg947add32013-02-22 22:05:20 +010010583EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010010584
Johannes Berg947add32013-02-22 22:05:20 +010010585void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020010586{
Johannes Berg947add32013-02-22 22:05:20 +010010587 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10588 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020010589 struct sk_buff *msg;
10590 void *hdr;
10591
Johannes Berg947add32013-02-22 22:05:20 +010010592 trace_cfg80211_del_sta(dev, mac_addr);
10593
Thomas Graf58050fc2012-06-28 03:57:45 +000010594 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010595 if (!msg)
10596 return;
10597
10598 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
10599 if (!hdr) {
10600 nlmsg_free(msg);
10601 return;
10602 }
10603
David S. Miller9360ffd2012-03-29 04:41:26 -040010604 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10605 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
10606 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020010607
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010608 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020010609
Johannes Berg68eb5502013-11-19 15:19:38 +010010610 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010611 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020010612 return;
10613
10614 nla_put_failure:
10615 genlmsg_cancel(msg, hdr);
10616 nlmsg_free(msg);
10617}
Johannes Berg947add32013-02-22 22:05:20 +010010618EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020010619
Johannes Berg947add32013-02-22 22:05:20 +010010620void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
10621 enum nl80211_connect_failed_reason reason,
10622 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010623{
Johannes Berg947add32013-02-22 22:05:20 +010010624 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
10625 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010626 struct sk_buff *msg;
10627 void *hdr;
10628
10629 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
10630 if (!msg)
10631 return;
10632
10633 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
10634 if (!hdr) {
10635 nlmsg_free(msg);
10636 return;
10637 }
10638
10639 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10640 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
10641 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
10642 goto nla_put_failure;
10643
10644 genlmsg_end(msg, hdr);
10645
Johannes Berg68eb5502013-11-19 15:19:38 +010010646 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010647 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010648 return;
10649
10650 nla_put_failure:
10651 genlmsg_cancel(msg, hdr);
10652 nlmsg_free(msg);
10653}
Johannes Berg947add32013-02-22 22:05:20 +010010654EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053010655
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010656static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
10657 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010010658{
10659 struct wireless_dev *wdev = dev->ieee80211_ptr;
10660 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
10661 struct sk_buff *msg;
10662 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000010663 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010664
Eric W. Biederman15e47302012-09-07 20:12:54 +000010665 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010010666 return false;
10667
10668 msg = nlmsg_new(100, gfp);
10669 if (!msg)
10670 return true;
10671
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010672 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010010673 if (!hdr) {
10674 nlmsg_free(msg);
10675 return true;
10676 }
10677
David S. Miller9360ffd2012-03-29 04:41:26 -040010678 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10679 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
10680 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
10681 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010010682
Johannes Berg9c90a9f2013-06-04 12:46:03 +020010683 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000010684 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010010685 return true;
10686
10687 nla_put_failure:
10688 genlmsg_cancel(msg, hdr);
10689 nlmsg_free(msg);
10690 return true;
10691}
10692
Johannes Berg947add32013-02-22 22:05:20 +010010693bool cfg80211_rx_spurious_frame(struct net_device *dev,
10694 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010695{
Johannes Berg947add32013-02-22 22:05:20 +010010696 struct wireless_dev *wdev = dev->ieee80211_ptr;
10697 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010698
Johannes Berg947add32013-02-22 22:05:20 +010010699 trace_cfg80211_rx_spurious_frame(dev, addr);
10700
10701 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10702 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
10703 trace_cfg80211_return_bool(false);
10704 return false;
10705 }
10706 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
10707 addr, gfp);
10708 trace_cfg80211_return_bool(ret);
10709 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010710}
Johannes Berg947add32013-02-22 22:05:20 +010010711EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
10712
10713bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
10714 const u8 *addr, gfp_t gfp)
10715{
10716 struct wireless_dev *wdev = dev->ieee80211_ptr;
10717 bool ret;
10718
10719 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
10720
10721 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
10722 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
10723 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
10724 trace_cfg80211_return_bool(false);
10725 return false;
10726 }
10727 ret = __nl80211_unexpected_frame(dev,
10728 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
10729 addr, gfp);
10730 trace_cfg80211_return_bool(ret);
10731 return ret;
10732}
10733EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010010734
Johannes Berg2e161f72010-08-12 15:38:38 +020010735int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010736 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010010737 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010738 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010739{
Johannes Berg71bbc992012-06-15 15:30:18 +020010740 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010741 struct sk_buff *msg;
10742 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020010743
10744 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10745 if (!msg)
10746 return -ENOMEM;
10747
Johannes Berg2e161f72010-08-12 15:38:38 +020010748 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020010749 if (!hdr) {
10750 nlmsg_free(msg);
10751 return -ENOMEM;
10752 }
10753
David S. Miller9360ffd2012-03-29 04:41:26 -040010754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010755 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10756 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010757 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010758 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
10759 (sig_dbm &&
10760 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030010761 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10762 (flags &&
10763 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010764 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010765
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010766 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010767
Eric W. Biederman15e47302012-09-07 20:12:54 +000010768 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020010769
10770 nla_put_failure:
10771 genlmsg_cancel(msg, hdr);
10772 nlmsg_free(msg);
10773 return -ENOBUFS;
10774}
10775
Johannes Berg947add32013-02-22 22:05:20 +010010776void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
10777 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020010778{
Johannes Berg947add32013-02-22 22:05:20 +010010779 struct wiphy *wiphy = wdev->wiphy;
10780 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020010781 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020010782 struct sk_buff *msg;
10783 void *hdr;
10784
Johannes Berg947add32013-02-22 22:05:20 +010010785 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
10786
Jouni Malinen026331c2010-02-15 12:53:10 +020010787 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
10788 if (!msg)
10789 return;
10790
Johannes Berg2e161f72010-08-12 15:38:38 +020010791 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020010792 if (!hdr) {
10793 nlmsg_free(msg);
10794 return;
10795 }
10796
David S. Miller9360ffd2012-03-29 04:41:26 -040010797 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020010798 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10799 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030010800 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040010801 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
10802 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
10803 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
10804 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010805
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010806 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020010807
Johannes Berg68eb5502013-11-19 15:19:38 +010010808 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010809 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020010810 return;
10811
10812 nla_put_failure:
10813 genlmsg_cancel(msg, hdr);
10814 nlmsg_free(msg);
10815}
Johannes Berg947add32013-02-22 22:05:20 +010010816EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020010817
Johannes Berg947add32013-02-22 22:05:20 +010010818void cfg80211_cqm_rssi_notify(struct net_device *dev,
10819 enum nl80211_cqm_rssi_threshold_event rssi_event,
10820 gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010821{
Johannes Berg947add32013-02-22 22:05:20 +010010822 struct wireless_dev *wdev = dev->ieee80211_ptr;
10823 struct wiphy *wiphy = wdev->wiphy;
10824 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010825 struct sk_buff *msg;
10826 struct nlattr *pinfoattr;
10827 void *hdr;
10828
Johannes Berg947add32013-02-22 22:05:20 +010010829 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
10830
Thomas Graf58050fc2012-06-28 03:57:45 +000010831 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010832 if (!msg)
10833 return;
10834
10835 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
10836 if (!hdr) {
10837 nlmsg_free(msg);
10838 return;
10839 }
10840
David S. Miller9360ffd2012-03-29 04:41:26 -040010841 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010010842 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040010843 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010844
10845 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
10846 if (!pinfoattr)
10847 goto nla_put_failure;
10848
David S. Miller9360ffd2012-03-29 04:41:26 -040010849 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
10850 rssi_event))
10851 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010852
10853 nla_nest_end(msg, pinfoattr);
10854
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010855 genlmsg_end(msg, hdr);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010856
Johannes Berg68eb5502013-11-19 15:19:38 +010010857 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010858 NL80211_MCGRP_MLME, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010859 return;
10860
10861 nla_put_failure:
10862 genlmsg_cancel(msg, hdr);
10863 nlmsg_free(msg);
10864}
Johannes Berg947add32013-02-22 22:05:20 +010010865EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010866
Johannes Berg947add32013-02-22 22:05:20 +010010867static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
10868 struct net_device *netdev, const u8 *bssid,
10869 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020010870{
10871 struct sk_buff *msg;
10872 struct nlattr *rekey_attr;
10873 void *hdr;
10874
Thomas Graf58050fc2012-06-28 03:57:45 +000010875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010876 if (!msg)
10877 return;
10878
10879 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
10880 if (!hdr) {
10881 nlmsg_free(msg);
10882 return;
10883 }
10884
David S. Miller9360ffd2012-03-29 04:41:26 -040010885 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10886 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
10887 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
10888 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010889
10890 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
10891 if (!rekey_attr)
10892 goto nla_put_failure;
10893
David S. Miller9360ffd2012-03-29 04:41:26 -040010894 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
10895 NL80211_REPLAY_CTR_LEN, replay_ctr))
10896 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020010897
10898 nla_nest_end(msg, rekey_attr);
10899
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010900 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020010901
Johannes Berg68eb5502013-11-19 15:19:38 +010010902 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010903 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020010904 return;
10905
10906 nla_put_failure:
10907 genlmsg_cancel(msg, hdr);
10908 nlmsg_free(msg);
10909}
10910
Johannes Berg947add32013-02-22 22:05:20 +010010911void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
10912 const u8 *replay_ctr, gfp_t gfp)
10913{
10914 struct wireless_dev *wdev = dev->ieee80211_ptr;
10915 struct wiphy *wiphy = wdev->wiphy;
10916 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10917
10918 trace_cfg80211_gtk_rekey_notify(dev, bssid);
10919 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
10920}
10921EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
10922
10923static void
10924nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
10925 struct net_device *netdev, int index,
10926 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010927{
10928 struct sk_buff *msg;
10929 struct nlattr *attr;
10930 void *hdr;
10931
Thomas Graf58050fc2012-06-28 03:57:45 +000010932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010933 if (!msg)
10934 return;
10935
10936 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
10937 if (!hdr) {
10938 nlmsg_free(msg);
10939 return;
10940 }
10941
David S. Miller9360ffd2012-03-29 04:41:26 -040010942 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10943 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10944 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010945
10946 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
10947 if (!attr)
10948 goto nla_put_failure;
10949
David S. Miller9360ffd2012-03-29 04:41:26 -040010950 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
10951 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
10952 (preauth &&
10953 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
10954 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010955
10956 nla_nest_end(msg, attr);
10957
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010958 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010959
Johannes Berg68eb5502013-11-19 15:19:38 +010010960 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010961 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030010962 return;
10963
10964 nla_put_failure:
10965 genlmsg_cancel(msg, hdr);
10966 nlmsg_free(msg);
10967}
10968
Johannes Berg947add32013-02-22 22:05:20 +010010969void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
10970 const u8 *bssid, bool preauth, gfp_t gfp)
10971{
10972 struct wireless_dev *wdev = dev->ieee80211_ptr;
10973 struct wiphy *wiphy = wdev->wiphy;
10974 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
10975
10976 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
10977 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
10978}
10979EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
10980
10981static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
10982 struct net_device *netdev,
10983 struct cfg80211_chan_def *chandef,
10984 gfp_t gfp)
Thomas Pedersen53145262012-04-06 13:35:47 -070010985{
10986 struct sk_buff *msg;
10987 void *hdr;
10988
Thomas Graf58050fc2012-06-28 03:57:45 +000010989 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070010990 if (!msg)
10991 return;
10992
10993 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY);
10994 if (!hdr) {
10995 nlmsg_free(msg);
10996 return;
10997 }
10998
Johannes Berg683b6d32012-11-08 21:25:48 +010010999 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11000 goto nla_put_failure;
11001
11002 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040011003 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070011004
11005 genlmsg_end(msg, hdr);
11006
Johannes Berg68eb5502013-11-19 15:19:38 +010011007 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011008 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070011009 return;
11010
11011 nla_put_failure:
11012 genlmsg_cancel(msg, hdr);
11013 nlmsg_free(msg);
11014}
11015
Johannes Berg947add32013-02-22 22:05:20 +010011016void cfg80211_ch_switch_notify(struct net_device *dev,
11017 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011018{
Johannes Berg947add32013-02-22 22:05:20 +010011019 struct wireless_dev *wdev = dev->ieee80211_ptr;
11020 struct wiphy *wiphy = wdev->wiphy;
11021 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11022
Simon Wunderliche487eae2013-11-21 18:19:51 +010011023 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010011024
Simon Wunderliche487eae2013-11-21 18:19:51 +010011025 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010011026
11027 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +020011028 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -070011029 wdev->iftype != NL80211_IFTYPE_ADHOC &&
11030 wdev->iftype != NL80211_IFTYPE_MESH_POINT))
Simon Wunderliche487eae2013-11-21 18:19:51 +010011031 return;
Johannes Berg947add32013-02-22 22:05:20 +010011032
11033 wdev->channel = chandef->chan;
11034 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL);
Johannes Berg947add32013-02-22 22:05:20 +010011035}
11036EXPORT_SYMBOL(cfg80211_ch_switch_notify);
11037
11038void cfg80211_cqm_txe_notify(struct net_device *dev,
11039 const u8 *peer, u32 num_packets,
11040 u32 rate, u32 intvl, gfp_t gfp)
11041{
11042 struct wireless_dev *wdev = dev->ieee80211_ptr;
11043 struct wiphy *wiphy = wdev->wiphy;
11044 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011045 struct sk_buff *msg;
11046 struct nlattr *pinfoattr;
11047 void *hdr;
11048
11049 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11050 if (!msg)
11051 return;
11052
11053 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11054 if (!hdr) {
11055 nlmsg_free(msg);
11056 return;
11057 }
11058
11059 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011060 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Thomas Pedersen84f10702012-07-12 16:17:33 -070011061 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11062 goto nla_put_failure;
11063
11064 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11065 if (!pinfoattr)
11066 goto nla_put_failure;
11067
11068 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11069 goto nla_put_failure;
11070
11071 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11072 goto nla_put_failure;
11073
11074 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11075 goto nla_put_failure;
11076
11077 nla_nest_end(msg, pinfoattr);
11078
11079 genlmsg_end(msg, hdr);
11080
Johannes Berg68eb5502013-11-19 15:19:38 +010011081 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011082 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011083 return;
11084
11085 nla_put_failure:
11086 genlmsg_cancel(msg, hdr);
11087 nlmsg_free(msg);
11088}
Johannes Berg947add32013-02-22 22:05:20 +010011089EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011090
11091void
Simon Wunderlich04f39042013-02-08 18:16:19 +010011092nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010011093 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010011094 enum nl80211_radar_event event,
11095 struct net_device *netdev, gfp_t gfp)
11096{
11097 struct sk_buff *msg;
11098 void *hdr;
11099
11100 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11101 if (!msg)
11102 return;
11103
11104 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
11105 if (!hdr) {
11106 nlmsg_free(msg);
11107 return;
11108 }
11109
11110 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
11111 goto nla_put_failure;
11112
11113 /* NOP and radar events don't need a netdev parameter */
11114 if (netdev) {
11115 struct wireless_dev *wdev = netdev->ieee80211_ptr;
11116
11117 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11118 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11119 goto nla_put_failure;
11120 }
11121
11122 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
11123 goto nla_put_failure;
11124
11125 if (nl80211_send_chandef(msg, chandef))
11126 goto nla_put_failure;
11127
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011128 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011129
Johannes Berg68eb5502013-11-19 15:19:38 +010011130 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011131 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010011132 return;
11133
11134 nla_put_failure:
11135 genlmsg_cancel(msg, hdr);
11136 nlmsg_free(msg);
11137}
11138
Johannes Berg947add32013-02-22 22:05:20 +010011139void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11140 const u8 *peer, u32 num_packets, gfp_t gfp)
Johannes Bergc063dbf2010-11-24 08:10:05 +010011141{
Johannes Berg947add32013-02-22 22:05:20 +010011142 struct wireless_dev *wdev = dev->ieee80211_ptr;
11143 struct wiphy *wiphy = wdev->wiphy;
11144 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011145 struct sk_buff *msg;
11146 struct nlattr *pinfoattr;
11147 void *hdr;
11148
Johannes Berg947add32013-02-22 22:05:20 +010011149 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11150
Thomas Graf58050fc2012-06-28 03:57:45 +000011151 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011152 if (!msg)
11153 return;
11154
11155 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11156 if (!hdr) {
11157 nlmsg_free(msg);
11158 return;
11159 }
11160
David S. Miller9360ffd2012-03-29 04:41:26 -040011161 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011162 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011163 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer))
11164 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011165
11166 pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM);
11167 if (!pinfoattr)
11168 goto nla_put_failure;
11169
David S. Miller9360ffd2012-03-29 04:41:26 -040011170 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11171 goto nla_put_failure;
Johannes Bergc063dbf2010-11-24 08:10:05 +010011172
11173 nla_nest_end(msg, pinfoattr);
11174
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011175 genlmsg_end(msg, hdr);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011176
Johannes Berg68eb5502013-11-19 15:19:38 +010011177 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011178 NL80211_MCGRP_MLME, gfp);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011179 return;
11180
11181 nla_put_failure:
11182 genlmsg_cancel(msg, hdr);
11183 nlmsg_free(msg);
11184}
Johannes Berg947add32013-02-22 22:05:20 +010011185EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
Johannes Bergc063dbf2010-11-24 08:10:05 +010011186
Johannes Berg7f6cf312011-11-04 11:18:15 +010011187void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
11188 u64 cookie, bool acked, gfp_t gfp)
11189{
11190 struct wireless_dev *wdev = dev->ieee80211_ptr;
11191 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11192 struct sk_buff *msg;
11193 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011194
Beni Lev4ee3e062012-08-27 12:49:39 +030011195 trace_cfg80211_probe_status(dev, addr, cookie, acked);
11196
Thomas Graf58050fc2012-06-28 03:57:45 +000011197 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030011198
Johannes Berg7f6cf312011-11-04 11:18:15 +010011199 if (!msg)
11200 return;
11201
11202 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
11203 if (!hdr) {
11204 nlmsg_free(msg);
11205 return;
11206 }
11207
David S. Miller9360ffd2012-03-29 04:41:26 -040011208 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11209 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11210 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
11211 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11212 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
11213 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010011214
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011215 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011216
Johannes Berg68eb5502013-11-19 15:19:38 +010011217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011218 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010011219 return;
11220
11221 nla_put_failure:
11222 genlmsg_cancel(msg, hdr);
11223 nlmsg_free(msg);
11224}
11225EXPORT_SYMBOL(cfg80211_probe_status);
11226
Johannes Berg5e760232011-11-04 11:18:17 +010011227void cfg80211_report_obss_beacon(struct wiphy *wiphy,
11228 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070011229 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010011230{
11231 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11232 struct sk_buff *msg;
11233 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070011234 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010011235
Beni Lev4ee3e062012-08-27 12:49:39 +030011236 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
11237
Ben Greear37c73b52012-10-26 14:49:25 -070011238 spin_lock_bh(&rdev->beacon_registrations_lock);
11239 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
11240 msg = nlmsg_new(len + 100, GFP_ATOMIC);
11241 if (!msg) {
11242 spin_unlock_bh(&rdev->beacon_registrations_lock);
11243 return;
11244 }
Johannes Berg5e760232011-11-04 11:18:17 +010011245
Ben Greear37c73b52012-10-26 14:49:25 -070011246 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
11247 if (!hdr)
11248 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010011249
Ben Greear37c73b52012-10-26 14:49:25 -070011250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11251 (freq &&
11252 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
11253 (sig_dbm &&
11254 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
11255 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
11256 goto nla_put_failure;
11257
11258 genlmsg_end(msg, hdr);
11259
11260 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010011261 }
Ben Greear37c73b52012-10-26 14:49:25 -070011262 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011263 return;
11264
11265 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070011266 spin_unlock_bh(&rdev->beacon_registrations_lock);
11267 if (hdr)
11268 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010011269 nlmsg_free(msg);
11270}
11271EXPORT_SYMBOL(cfg80211_report_obss_beacon);
11272
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011273#ifdef CONFIG_PM
11274void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
11275 struct cfg80211_wowlan_wakeup *wakeup,
11276 gfp_t gfp)
11277{
11278 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11279 struct sk_buff *msg;
11280 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011281 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011282
11283 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
11284
11285 if (wakeup)
11286 size += wakeup->packet_present_len;
11287
11288 msg = nlmsg_new(size, gfp);
11289 if (!msg)
11290 return;
11291
11292 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
11293 if (!hdr)
11294 goto free_msg;
11295
11296 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11297 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11298 goto free_msg;
11299
11300 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11301 wdev->netdev->ifindex))
11302 goto free_msg;
11303
11304 if (wakeup) {
11305 struct nlattr *reasons;
11306
11307 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020011308 if (!reasons)
11309 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011310
11311 if (wakeup->disconnect &&
11312 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
11313 goto free_msg;
11314 if (wakeup->magic_pkt &&
11315 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
11316 goto free_msg;
11317 if (wakeup->gtk_rekey_failure &&
11318 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
11319 goto free_msg;
11320 if (wakeup->eap_identity_req &&
11321 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
11322 goto free_msg;
11323 if (wakeup->four_way_handshake &&
11324 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
11325 goto free_msg;
11326 if (wakeup->rfkill_release &&
11327 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
11328 goto free_msg;
11329
11330 if (wakeup->pattern_idx >= 0 &&
11331 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
11332 wakeup->pattern_idx))
11333 goto free_msg;
11334
Johannes Bergae917c92013-10-25 11:05:22 +020011335 if (wakeup->tcp_match &&
11336 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
11337 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011338
Johannes Bergae917c92013-10-25 11:05:22 +020011339 if (wakeup->tcp_connlost &&
11340 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
11341 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011342
Johannes Bergae917c92013-10-25 11:05:22 +020011343 if (wakeup->tcp_nomoretokens &&
11344 nla_put_flag(msg,
11345 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
11346 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011347
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011348 if (wakeup->packet) {
11349 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
11350 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
11351
11352 if (!wakeup->packet_80211) {
11353 pkt_attr =
11354 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
11355 len_attr =
11356 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
11357 }
11358
11359 if (wakeup->packet_len &&
11360 nla_put_u32(msg, len_attr, wakeup->packet_len))
11361 goto free_msg;
11362
11363 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
11364 wakeup->packet))
11365 goto free_msg;
11366 }
11367
11368 nla_nest_end(msg, reasons);
11369 }
11370
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011371 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011372
Johannes Berg68eb5502013-11-19 15:19:38 +010011373 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011374 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010011375 return;
11376
11377 free_msg:
11378 nlmsg_free(msg);
11379}
11380EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
11381#endif
11382
Jouni Malinen3475b092012-11-16 22:49:57 +020011383void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
11384 enum nl80211_tdls_operation oper,
11385 u16 reason_code, gfp_t gfp)
11386{
11387 struct wireless_dev *wdev = dev->ieee80211_ptr;
11388 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
11389 struct sk_buff *msg;
11390 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020011391
11392 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
11393 reason_code);
11394
11395 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11396 if (!msg)
11397 return;
11398
11399 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
11400 if (!hdr) {
11401 nlmsg_free(msg);
11402 return;
11403 }
11404
11405 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11406 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11407 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
11408 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
11409 (reason_code > 0 &&
11410 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
11411 goto nla_put_failure;
11412
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011413 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020011414
Johannes Berg68eb5502013-11-19 15:19:38 +010011415 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011416 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020011417 return;
11418
11419 nla_put_failure:
11420 genlmsg_cancel(msg, hdr);
11421 nlmsg_free(msg);
11422}
11423EXPORT_SYMBOL(cfg80211_tdls_oper_request);
11424
Jouni Malinen026331c2010-02-15 12:53:10 +020011425static int nl80211_netlink_notify(struct notifier_block * nb,
11426 unsigned long state,
11427 void *_notify)
11428{
11429 struct netlink_notify *notify = _notify;
11430 struct cfg80211_registered_device *rdev;
11431 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070011432 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020011433
11434 if (state != NETLINK_URELEASE)
11435 return NOTIFY_DONE;
11436
11437 rcu_read_lock();
11438
Johannes Berg5e760232011-11-04 11:18:17 +010011439 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020011440 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list)
Eric W. Biederman15e47302012-09-07 20:12:54 +000011441 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070011442
11443 spin_lock_bh(&rdev->beacon_registrations_lock);
11444 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
11445 list) {
11446 if (reg->nlportid == notify->portid) {
11447 list_del(&reg->list);
11448 kfree(reg);
11449 break;
11450 }
11451 }
11452 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010011453 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011454
11455 rcu_read_unlock();
11456
11457 return NOTIFY_DONE;
11458}
11459
11460static struct notifier_block nl80211_netlink_notifier = {
11461 .notifier_call = nl80211_netlink_notify,
11462};
11463
Jouni Malinen355199e2013-02-27 17:14:27 +020011464void cfg80211_ft_event(struct net_device *netdev,
11465 struct cfg80211_ft_event_params *ft_event)
11466{
11467 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
11468 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
11469 struct sk_buff *msg;
11470 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020011471
11472 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
11473
11474 if (!ft_event->target_ap)
11475 return;
11476
11477 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11478 if (!msg)
11479 return;
11480
11481 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020011482 if (!hdr)
11483 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011484
Johannes Bergae917c92013-10-25 11:05:22 +020011485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11486 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11487 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
11488 goto out;
11489
11490 if (ft_event->ies &&
11491 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
11492 goto out;
11493 if (ft_event->ric_ies &&
11494 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
11495 ft_event->ric_ies))
11496 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020011497
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011498 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020011499
Johannes Berg68eb5502013-11-19 15:19:38 +010011500 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011501 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020011502 return;
11503 out:
11504 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020011505}
11506EXPORT_SYMBOL(cfg80211_ft_event);
11507
Arend van Spriel5de17982013-04-18 15:49:00 +020011508void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
11509{
11510 struct cfg80211_registered_device *rdev;
11511 struct sk_buff *msg;
11512 void *hdr;
11513 u32 nlportid;
11514
11515 rdev = wiphy_to_dev(wdev->wiphy);
11516 if (!rdev->crit_proto_nlportid)
11517 return;
11518
11519 nlportid = rdev->crit_proto_nlportid;
11520 rdev->crit_proto_nlportid = 0;
11521
11522 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11523 if (!msg)
11524 return;
11525
11526 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
11527 if (!hdr)
11528 goto nla_put_failure;
11529
11530 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11531 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
11532 goto nla_put_failure;
11533
11534 genlmsg_end(msg, hdr);
11535
11536 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
11537 return;
11538
11539 nla_put_failure:
11540 if (hdr)
11541 genlmsg_cancel(msg, hdr);
11542 nlmsg_free(msg);
11543
11544}
11545EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
11546
Johannes Berg55682962007-09-20 13:09:35 -040011547/* initialisation/exit functions */
11548
11549int nl80211_init(void)
11550{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000011551 int err;
Johannes Berg55682962007-09-20 13:09:35 -040011552
Johannes Berg2a94fe42013-11-19 15:19:39 +010011553 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
11554 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040011555 if (err)
11556 return err;
11557
Jouni Malinen026331c2010-02-15 12:53:10 +020011558 err = netlink_register_notifier(&nl80211_netlink_notifier);
11559 if (err)
11560 goto err_out;
11561
Johannes Berg55682962007-09-20 13:09:35 -040011562 return 0;
11563 err_out:
11564 genl_unregister_family(&nl80211_fam);
11565 return err;
11566}
11567
11568void nl80211_exit(void)
11569{
Jouni Malinen026331c2010-02-15 12:53:10 +020011570 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040011571 genl_unregister_family(&nl80211_fam);
11572}